mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-13 07:57:35 +02:00
Fixing truncation handling in SEXP_WRITE_STRING_OP.
This commit is contained in:
parent
befd0ecfd9
commit
9c0bf42077
1 changed files with 15 additions and 9 deletions
24
vm.c
24
vm.c
|
@ -1807,22 +1807,28 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) {
|
|||
if (sexp_port_stream(_ARG3)) {
|
||||
i = fwrite(sexp_bytes_data(tmp1), 1, sexp_unbox_fixnum(_ARG2), sexp_port_stream(_ARG3));
|
||||
#if SEXP_USE_GREEN_THREADS
|
||||
if ((i < sexp_unbox_fixnum(_ARG2)) && ferror(sexp_port_stream(_ARG3))
|
||||
&& (errno == EAGAIN)
|
||||
&& sexp_applicablep(sexp_global(ctx, SEXP_G_THREADS_BLOCKER))) {
|
||||
if ((i < sexp_unbox_fixnum(_ARG2))
|
||||
&& ferror(sexp_port_stream(_ARG3))
|
||||
&& (errno == EAGAIN)) {
|
||||
clearerr(sexp_port_stream(_ARG3));
|
||||
/* modify stack in-place so we continue where we left off next time */
|
||||
if (i > 0) {
|
||||
/* modify stack in-place so we continue where we left off next time */
|
||||
_ARG1 = sexp_substring(ctx, _ARG1, SEXP_ZERO, sexp_make_fixnum(i));
|
||||
if (sexp_stringp(_ARG1))
|
||||
_ARG1 = sexp_substring(ctx, _ARG1, sexp_make_fixnum(i), SEXP_FALSE);
|
||||
else
|
||||
_ARG1 = sexp_subbytes(ctx, _ARG1, sexp_make_fixnum(i), SEXP_FALSE);
|
||||
_ARG2 = sexp_make_fixnum(sexp_unbox_fixnum(_ARG2) - i);
|
||||
}
|
||||
clearerr(sexp_port_stream(_ARG3));
|
||||
sexp_apply1(ctx, sexp_global(ctx, SEXP_G_THREADS_BLOCKER), _ARG3);
|
||||
fuel = 0;
|
||||
/* yield if threads are enabled */
|
||||
if (sexp_applicablep(sexp_global(ctx, SEXP_G_THREADS_BLOCKER))) {
|
||||
sexp_apply1(ctx, sexp_global(ctx, SEXP_G_THREADS_BLOCKER), _ARG3);
|
||||
fuel = 0;
|
||||
}
|
||||
ip--; /* try again */
|
||||
goto loop;
|
||||
}
|
||||
#endif
|
||||
} else { /* not a stream-backed string */
|
||||
} else { /* not a stream-backed string, won't block */
|
||||
if (sexp_bytes_length(tmp1) != sexp_unbox_fixnum(_ARG2))
|
||||
tmp1 = sexp_subbytes(ctx, tmp1, SEXP_ZERO, _ARG2);
|
||||
sexp_write_string(ctx, sexp_bytes_data(tmp1), _ARG3);
|
||||
|
|
Loading…
Add table
Reference in a new issue