mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-25 04:55:04 +02:00
Final set of bugfixes for string output ports
This commit is contained in:
parent
0e820f9794
commit
5699fcf8df
2 changed files with 10 additions and 17 deletions
23
mstreams.c
23
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)
|
port_type *Cyc_io_open_output_string(void *data)
|
||||||
{
|
{
|
||||||
// Allocate port on the heap so the location of mem_buf does not change
|
// Allocate port on the heap so the location of mem_buf does not change
|
||||||
// make_port(p, NULL, 0);
|
port_type *p;
|
||||||
port_type *p = (port_type *)Cyc_heap_alloc_port(data);
|
make_port(sp, NULL, 0);
|
||||||
p->hdr.mark = ((gc_thread_data *)data)->gc_alloc_color;
|
p = (port_type *)Cyc_heap_alloc_port(data, &sp);
|
||||||
p->hdr.grayed = 0;
|
|
||||||
p->tag = port_tag;
|
|
||||||
p->fp = NULL;
|
|
||||||
p->mode = 0; // Output
|
|
||||||
p->mem_buf = NULL;
|
|
||||||
p->mem_buf_len = 0;
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
#if CYC_HAVE_OPEN_MEMSTREAM
|
#if CYC_HAVE_OPEN_MEMSTREAM
|
||||||
p->fp = open_memstream(&(p->mem_buf), &(p->mem_buf_len));
|
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)
|
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);
|
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) {
|
if (p->fp) {
|
||||||
fflush(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);
|
make_string_with_len(s, p->mem_buf, p->mem_buf_len);
|
||||||
return_closcall1(data, cont, &s);
|
return_closcall1(data, cont, &s);
|
||||||
|
|
|
@ -927,13 +927,13 @@ object Cyc_write_char(void *data, object c, object port)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal function, do not use this anywhere outside the runtime
|
// 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;
|
object p = NULL;
|
||||||
int heap_grown;
|
int heap_grown;
|
||||||
p = gc_alloc(Cyc_heap,
|
p = gc_alloc(Cyc_heap,
|
||||||
sizeof(port_type),
|
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,
|
(gc_thread_data *)data,
|
||||||
&heap_grown);
|
&heap_grown);
|
||||||
return p;
|
return p;
|
||||||
|
|
Loading…
Add table
Reference in a new issue