Skip to content

Commit 76cad3c

Browse files
mflattrmculpepper
authored andcommitted
fix mismanagement of temporary print buffer
Closes PR 13199 Merge to v5.3.1 (cherry picked from commit 70fee17)
1 parent 47ca55e commit 76cad3c

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/racket/src/print.c

+20-7
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static void print_vector(Scheme_Object *vec, int notdisplay, int compact,
124124
static void print_char(Scheme_Object *chobj, int notdisplay, PrintParams *pp);
125125
static char *print_to_string(Scheme_Object *obj, intptr_t * volatile len, int write,
126126
Scheme_Object *port, intptr_t maxl,
127-
Scheme_Object *qq_depth);
127+
Scheme_Object *qq_depth, int *_release_to_quick);
128128

129129
static void custom_write_struct(Scheme_Object *s, Scheme_Hash_Table *ht,
130130
Scheme_Marshal_Tables *mt,
@@ -384,7 +384,7 @@ static void *print_to_string_k(void)
384384
p->ku.k.p2 = NULL;
385385
p->ku.k.p3 = NULL;
386386

387-
return (void *)print_to_string(obj, len, iswrite, NULL, maxl, qq_depth);
387+
return (void *)print_to_string(obj, len, iswrite, NULL, maxl, qq_depth, NULL);
388388
}
389389

390390
char *scheme_write_to_string_w_max(Scheme_Object *obj, intptr_t *len, intptr_t maxl)
@@ -956,7 +956,7 @@ static char *
956956
print_to_string(Scheme_Object *obj,
957957
intptr_t * volatile len, int write,
958958
Scheme_Object *port, intptr_t maxl,
959-
Scheme_Object *qq_depth)
959+
Scheme_Object *qq_depth, int *_release_to_quick)
960960
{
961961
Scheme_Hash_Table *ht;
962962
Scheme_Hash_Table *uq_ht;
@@ -1111,8 +1111,14 @@ print_to_string(Scheme_Object *obj,
11111111

11121112
params.inspector = NULL;
11131113

1114-
if (port && !quick_print_buffer)
1115-
quick_print_buffer = ca;
1114+
if (_release_to_quick) {
1115+
*_release_to_quick = 0;
1116+
if (params.print_buffer != ca) {
1117+
if (!quick_print_buffer)
1118+
quick_print_buffer = ca;
1119+
} else
1120+
*_release_to_quick = 1;
1121+
}
11161122

11171123
return params.print_buffer;
11181124
}
@@ -1124,16 +1130,20 @@ print_to_port(char *name, Scheme_Object *obj, Scheme_Object *port, int notdispla
11241130
Scheme_Output_Port *op;
11251131
char *str;
11261132
intptr_t len;
1133+
int rel;
11271134

11281135
op = scheme_output_port_record(port);
11291136
if (op->closed)
11301137
scheme_raise_exn(MZEXN_FAIL, "%s: output port is closed\n"
11311138
" port: %V",
11321139
name, port);
11331140

1134-
str = print_to_string(obj, &len, notdisplay, port, maxl, qq_depth);
1141+
str = print_to_string(obj, &len, notdisplay, port, maxl, qq_depth, &rel);
11351142

11361143
scheme_write_byte_string(str, len, port);
1144+
1145+
if (rel && !quick_print_buffer)
1146+
quick_print_buffer = str;
11371147
}
11381148

11391149
static void print_this_string(PrintParams *pp, const char *str, int offset, int autolen)
@@ -2850,10 +2860,13 @@ print(Scheme_Object *obj, int notdisplay, int compact, Scheme_Hash_Table *ht,
28502860
if (pp->print_syntax) {
28512861
intptr_t slen;
28522862
char *str;
2863+
int rel;
28532864
print_utf8_string(pp, " ", 0, 1);
28542865
str = print_to_string(scheme_syntax_to_datum((Scheme_Object *)stx, 0, NULL),
2855-
&slen, 1, NULL, pp->print_syntax, NULL);
2866+
&slen, 1, NULL, pp->print_syntax, NULL, &rel);
28562867
print_utf8_string(pp, str, 0, slen);
2868+
if (rel && !quick_print_buffer)
2869+
quick_print_buffer = str;
28572870
}
28582871
print_utf8_string(pp, ">", 0, 1);
28592872
} else {

0 commit comments

Comments
 (0)