mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-22 07:09:18 +02:00
Calling gc when open returns EMFILE (out of open file descriptors).
This still needs to be done for fd's created as sockets and other sources.
This commit is contained in:
parent
9a8395c69d
commit
3a511302c4
2 changed files with 24 additions and 2 deletions
22
eval.c
22
eval.c
|
@ -1009,10 +1009,19 @@ sexp sexp_exception_type_op (sexp ctx, sexp self, sexp_sint_t n, sexp exn) {
|
||||||
|
|
||||||
sexp sexp_open_input_file_op (sexp ctx, sexp self, sexp_sint_t n, sexp path) {
|
sexp sexp_open_input_file_op (sexp ctx, sexp self, sexp_sint_t n, sexp path) {
|
||||||
FILE *in;
|
FILE *in;
|
||||||
|
int count = 0;
|
||||||
sexp_assert_type(ctx, sexp_stringp, SEXP_STRING, path);
|
sexp_assert_type(ctx, sexp_stringp, SEXP_STRING, path);
|
||||||
|
loop:
|
||||||
in = fopen(sexp_string_data(path), "r");
|
in = fopen(sexp_string_data(path), "r");
|
||||||
if (! in)
|
if (!in) {
|
||||||
|
#if SEXP_USE_GC_FILE_DESCRIPTORS
|
||||||
|
if (errno == EMFILE && !count++) {
|
||||||
|
sexp_gc(ctx, NULL);
|
||||||
|
goto loop;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return sexp_user_exception(ctx, self, "couldn't open input file", path);
|
return sexp_user_exception(ctx, self, "couldn't open input file", path);
|
||||||
|
}
|
||||||
#if SEXP_USE_GREEN_THREADS
|
#if SEXP_USE_GREEN_THREADS
|
||||||
fcntl(fileno(in), F_SETFL, O_NONBLOCK);
|
fcntl(fileno(in), F_SETFL, O_NONBLOCK);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1021,10 +1030,19 @@ sexp sexp_open_input_file_op (sexp ctx, sexp self, sexp_sint_t n, sexp path) {
|
||||||
|
|
||||||
sexp sexp_open_output_file_op (sexp ctx, sexp self, sexp_sint_t n, sexp path) {
|
sexp sexp_open_output_file_op (sexp ctx, sexp self, sexp_sint_t n, sexp path) {
|
||||||
FILE *out;
|
FILE *out;
|
||||||
|
int count = 0;
|
||||||
sexp_assert_type(ctx, sexp_stringp, SEXP_STRING, path);
|
sexp_assert_type(ctx, sexp_stringp, SEXP_STRING, path);
|
||||||
|
loop:
|
||||||
out = fopen(sexp_string_data(path), "w");
|
out = fopen(sexp_string_data(path), "w");
|
||||||
if (! out)
|
if (!out) {
|
||||||
|
#if SEXP_USE_GC_FILE_DESCRIPTORS
|
||||||
|
if (errno == EMFILE && !count++) {
|
||||||
|
sexp_gc(ctx, NULL);
|
||||||
|
goto loop;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return sexp_user_exception(ctx, self, "couldn't open output file", path);
|
return sexp_user_exception(ctx, self, "couldn't open output file", path);
|
||||||
|
}
|
||||||
return sexp_make_output_port(ctx, out, path);
|
return sexp_make_output_port(ctx, out, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -506,6 +506,10 @@
|
||||||
#define SEXP_USE_AUTOCLOSE_PORTS ! SEXP_USE_NO_FEATURES
|
#define SEXP_USE_AUTOCLOSE_PORTS ! SEXP_USE_NO_FEATURES
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef SEXP_USE_GC_FILE_DESCRIPTORS
|
||||||
|
#define SEXP_USE_GC_FILE_DESCRIPTORS (SEXP_USE_AUTOCLOSE_PORTS &&!SEXP_USE_BOEHM)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef SEXP_USE_2010_EPOCH
|
#ifndef SEXP_USE_2010_EPOCH
|
||||||
#define SEXP_USE_2010_EPOCH ! SEXP_USE_NO_FEATURES
|
#define SEXP_USE_2010_EPOCH ! SEXP_USE_NO_FEATURES
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue