mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-04 19:56:36 +02:00
Closing a port should reset the offset and force an error on further access.
This commit is contained in:
parent
05e5e1d499
commit
424efbe67a
2 changed files with 15 additions and 0 deletions
4
sexp.c
4
sexp.c
|
@ -172,6 +172,8 @@ sexp sexp_finalize_port (sexp ctx, sexp self, sexp_sint_t n, sexp port) {
|
|||
#endif
|
||||
)
|
||||
free(sexp_port_buf(port));
|
||||
sexp_port_offset(port) = 0;
|
||||
sexp_port_size(port) = 0;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -1444,6 +1446,8 @@ int sexp_buffered_read_char (sexp ctx, sexp p) {
|
|||
int res = 0;
|
||||
if (sexp_port_offset(p) < sexp_port_size(p)) {
|
||||
return ((unsigned char*)sexp_port_buf(p))[sexp_port_offset(p)++];
|
||||
} else if (!sexp_port_openp(p)) {
|
||||
return EOF;
|
||||
} else if (sexp_port_stream(p)) {
|
||||
res = fread(sexp_port_buf(p), 1, SEXP_PORT_BUFFER_SIZE, sexp_port_stream(p));
|
||||
if (res >= 0) {
|
||||
|
|
11
vm.c
11
vm.c
|
@ -1936,6 +1936,9 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) {
|
|||
#endif
|
||||
i = sexp_write_char(ctx, sexp_unbox_character(_ARG1), _ARG2);
|
||||
if (i == EOF) {
|
||||
if (!sexp_port_openp(_ARG2))
|
||||
sexp_raise("write-char: port is closed", _ARG2);
|
||||
else
|
||||
#if SEXP_USE_GREEN_THREADS
|
||||
if ((sexp_port_stream(_ARG2) ? ferror(sexp_port_stream(_ARG2)) : 1)
|
||||
&& (errno == EAGAIN)) {
|
||||
|
@ -1973,6 +1976,8 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) {
|
|||
sexp_raise("write-string: not a valid string count", sexp_list2(ctx, tmp1, _ARG2));
|
||||
if (! sexp_oportp(_ARG3))
|
||||
sexp_raise("write-string: not an output-port", sexp_list1(ctx, _ARG3));
|
||||
if (!sexp_port_openp(_ARG3))
|
||||
sexp_raise("write-string: port is closed", _ARG3);
|
||||
sexp_context_top(ctx) = top;
|
||||
#if SEXP_USE_GREEN_THREADS
|
||||
errno = 0;
|
||||
|
@ -2015,6 +2020,9 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) {
|
|||
else
|
||||
#endif
|
||||
if (i == EOF) {
|
||||
if (!sexp_port_openp(_ARG1))
|
||||
sexp_raise("peek-char: port is closed", _ARG1);
|
||||
else
|
||||
#if SEXP_USE_GREEN_THREADS
|
||||
if ((sexp_port_stream(_ARG1) ? ferror(sexp_port_stream(_ARG1)) : 1)
|
||||
&& (errno == EAGAIN)) {
|
||||
|
@ -2042,6 +2050,9 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) {
|
|||
#endif
|
||||
i = sexp_read_char(ctx, _ARG1);
|
||||
if (i == EOF) {
|
||||
if (!sexp_port_openp(_ARG1))
|
||||
sexp_raise("read-char: port is closed", _ARG1);
|
||||
else
|
||||
#if SEXP_USE_GREEN_THREADS
|
||||
if ((sexp_port_stream(_ARG1) ? ferror(sexp_port_stream(_ARG1)) : 1)
|
||||
&& (errno == EAGAIN)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue