From 5699fcf8df3d564f831e2b483aae784b346598ec Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 25 Aug 2016 18:28:17 -0400 Subject: [PATCH] Final set of bugfixes for string output ports --- mstreams.c | 23 ++++++++--------------- runtime.c | 4 ++-- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/mstreams.c b/mstreams.c index da232716..323fc620 100644 --- a/mstreams.c +++ b/mstreams.c @@ -33,19 +33,13 @@ if (type_is_pair_prim(clo)) { \ } \ } -object Cyc_heap_alloc_port(void *data); +object Cyc_heap_alloc_port(void *data, port_type *p); port_type *Cyc_io_open_output_string(void *data) { // Allocate port on the heap so the location of mem_buf does not change - // make_port(p, NULL, 0); - port_type *p = (port_type *)Cyc_heap_alloc_port(data); - p->hdr.mark = ((gc_thread_data *)data)->gc_alloc_color; - p->hdr.grayed = 0; - p->tag = port_tag; - p->fp = NULL; - p->mode = 0; // Output - p->mem_buf = NULL; - p->mem_buf_len = 0; + port_type *p; + make_port(sp, NULL, 0); + p = (port_type *)Cyc_heap_alloc_port(data, &sp); errno = 0; #if CYC_HAVE_OPEN_MEMSTREAM p->fp = open_memstream(&(p->mem_buf), &(p->mem_buf_len)); @@ -58,15 +52,14 @@ port_type *Cyc_io_open_output_string(void *data) void Cyc_io_get_output_string(void *data, object cont, object port) { - port_type *p; + port_type *p = (port_type *)port; Cyc_check_port(data, port); - if (((port_type *)port)->mem_buf == NULL) { - Cyc_rt_raise2(data, "Not an in-memory port", port); - } - p = (port_type *)port; if (p->fp) { fflush(p->fp); } + if (p->mem_buf == NULL) { + Cyc_rt_raise2(data, "Not an in-memory port", port); + } { make_string_with_len(s, p->mem_buf, p->mem_buf_len); return_closcall1(data, cont, &s); diff --git a/runtime.c b/runtime.c index 49a3b00b..2bc55f4b 100644 --- a/runtime.c +++ b/runtime.c @@ -927,13 +927,13 @@ object Cyc_write_char(void *data, object c, object port) } // Internal function, do not use this anywhere outside the runtime -object Cyc_heap_alloc_port(void *data) +object Cyc_heap_alloc_port(void *data, port_type *stack_p) { object p = NULL; int heap_grown; p = gc_alloc(Cyc_heap, sizeof(port_type), -TODO: no, need an actual port object for this guy... guess we'll pass it in? //boolean_f, // OK to populate manually over here + (char *)stack_p, (gc_thread_data *)data, &heap_grown); return p;