Commit 3437509f 3437509ff40a5e7cc86f8b26fb182592cab43b74 by Sergey Poznyakoff

Fix compilation of libmu_scm.

* libmu_scm/mu_body.c (mu_scm_body_free): Unref the stream.
Return 0.
(mu-body-read-line, mu-body-write): Use stringrefs.
* libmu_scm/mu_mailbox.c (mu-mailbox-get-port): Use stringrefs.
* libmu_scm/mu_message.c (mu-message-copy): Use stringrefs.
Use mu_stream_copy instead of manually copying stream contents.
(mu-message-get-port): Use stringrefs.
* libmu_scm/mu_port.c (mu_port_free): Unref the stream.
1 parent 7220d9dd
......@@ -47,8 +47,9 @@ mu_scm_body_free (SCM body_smob)
struct mu_body *mbp = (struct mu_body *) SCM_CDR (body_smob);
if (mbp->buffer)
free (mbp->buffer);
mu_stream_unref (mbp->stream);
free (mbp);
return sizeof (struct mu_body);
return 0;
}
static int
......@@ -114,7 +115,7 @@ SCM_DEFINE_PUBLIC (scm_mu_body_read_line, "mu-body-read-line", 1, 0, 0,
if (!mbp->stream)
{
status = mu_body_get_stream (mbp->body, &mbp->stream);
status = mu_body_get_streamref (mbp->body, &mbp->stream);
if (status)
mu_scm_error (FUNC_NAME, status,
"Cannot get body stream",
......@@ -158,7 +159,7 @@ SCM_DEFINE_PUBLIC (scm_mu_body_write, "mu-body-write", 2, 0, 0,
if (!mbp->stream)
{
status = mu_body_get_stream (mbp->body, &mbp->stream);
status = mu_body_get_streamref (mbp->body, &mbp->stream);
if (status)
mu_scm_error (FUNC_NAME, status,
"Cannot get body stream", SCM_BOOL_F);
......
......@@ -316,7 +316,7 @@ SCM_DEFINE_PUBLIC (scm_mu_mailbox_get_port, "mu-mailbox-get-port", 2, 0, 0,
SCM_ASSERT (mu_scm_is_mailbox (mbox), mbox, SCM_ARG1, FUNC_NAME);
SCM_ASSERT (scm_is_string (mode), mode, SCM_ARG2, FUNC_NAME);
mum = (struct mu_mailbox *) SCM_CDR (mbox);
status = mu_mailbox_get_stream (mum->mbox, &stream);
status = mu_mailbox_get_streamref (mum->mbox, &stream);
if (status)
mu_scm_error (FUNC_NAME, status,
"Cannot get mailbox stream",
......
......@@ -195,14 +195,12 @@ SCM_DEFINE_PUBLIC (scm_mu_message_copy, "mu-message-copy", 1, 0, 0,
{
mu_message_t msg, newmsg;
mu_stream_t in = NULL, out = NULL;
char buffer[512];
size_t n;
int status;
SCM_ASSERT (mu_scm_is_message (mesg), mesg, SCM_ARG1, FUNC_NAME);
msg = mu_scm_message_get (mesg);
status = mu_message_get_stream (msg, &in);
status = mu_message_get_streamref (msg, &in);
if (status)
mu_scm_error (FUNC_NAME, status,
"Cannot get input stream from message ~A",
......@@ -213,7 +211,7 @@ SCM_DEFINE_PUBLIC (scm_mu_message_copy, "mu-message-copy", 1, 0, 0,
mu_scm_error (FUNC_NAME, status,
"Cannot create message", SCM_BOOL_F);
status = mu_message_get_stream (newmsg, &out);
status = mu_message_get_streamref (newmsg, &out);
if (status)
{
mu_message_destroy (&newmsg, NULL);
......@@ -221,18 +219,14 @@ SCM_DEFINE_PUBLIC (scm_mu_message_copy, "mu-message-copy", 1, 0, 0,
"Cannot get output stream", SCM_BOOL_F);
}
mu_stream_seek (in, 0, MU_SEEK_SET, NULL);
while ((status = mu_stream_read (in, buffer, sizeof (buffer) - 1, &n))
== 0
&& n != 0)
status = mu_stream_copy (out, in, 0);
mu_stream_destroy (&in);
mu_stream_destroy (&out);
if (status)
{
status = mu_stream_write (out, buffer, n, NULL);
if (status)
{
mu_message_destroy (&newmsg, NULL);
mu_scm_error (FUNC_NAME, status,
"Error writing to stream", SCM_BOOL_F);
}
mu_message_destroy (&newmsg, NULL);
mu_scm_error (FUNC_NAME, status,
"Error writing to stream", SCM_BOOL_F);
}
return mu_scm_message_create (SCM_BOOL_F, newmsg);
......@@ -905,7 +899,7 @@ SCM_DEFINE_PUBLIC (scm_mu_message_get_port, "mu-message-get-port", 2, 1, 0,
SCM_ASSERT (scm_is_bool (full), full, SCM_ARG3, FUNC_NAME);
if (full == SCM_BOOL_T)
{
status = mu_message_get_stream (msg, &stream);
status = mu_message_get_streamref (msg, &stream);
if (status)
mu_scm_error (FUNC_NAME, status, "Cannot get message stream",
SCM_BOOL_F);
......@@ -920,7 +914,7 @@ SCM_DEFINE_PUBLIC (scm_mu_message_get_port, "mu-message-get-port", 2, 1, 0,
if (status)
mu_scm_error (FUNC_NAME, status, "Cannot get message body",
SCM_BOOL_F);
status = mu_body_get_stream (body, &stream);
status = mu_body_get_streamref (body, &stream);
if (status)
mu_scm_error (FUNC_NAME, status, "Cannot get message body stream",
SCM_BOOL_F);
......
......@@ -151,6 +151,8 @@ mu_port_close (SCM port)
static scm_sizet
mu_port_free (SCM port)
{
struct mu_port *mp = MU_PORT (port);
mu_stream_unref (mp->stream);
mu_port_close (port);
return 0;
}
......