From 4d22949f71f7e59440d0c6340b6766f019204612 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Tue, 27 Apr 2021 18:30:43 +0900 Subject: [PATCH] disable fileno unification by default --- include/chibi/features.h | 17 +++++++++++++++++ sexp.c | 10 +++++----- tests/build/build-opts.txt | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/include/chibi/features.h b/include/chibi/features.h index e5b5b924..a4c22954 100644 --- a/include/chibi/features.h +++ b/include/chibi/features.h @@ -64,6 +64,15 @@ /* if you suspect a bug in the native GC. */ /* #define SEXP_USE_BOEHM 1 */ +/* uncomment this to enable automatic file descriptor unification */ +/* File descriptors as returned by C functions are raw integers, */ +/* which are convereted to GC'ed first-class objects on the Scheme */ +/* side. By default we assume that each fd is new, however if this */ +/* option is enabled and an fd is returned which matches an existing */ +/* open fd, they are assumed to refer to the same descriptor and */ +/* unified. */ +/* #define SEXP_USE_UNIFY_FILENOS_BY_NUMBER 1 */ + /* uncomment this to disable weak references */ /* #define SEXP_USE_WEAK_REFERENCES 0 */ @@ -464,9 +473,17 @@ #define SEXP_USE_BOEHM 0 #endif +#ifdef SEXP_USE_UNIFY_FILENOS_BY_NUMBER +#define SEXP_USE_UNIFY_FILENOS_BY_NUMBER 0 +#endif + #ifndef SEXP_USE_WEAK_REFERENCES +#if SEXP_USE_UNIFY_FILENOS_BY_NUMBER +#define SEXP_USE_WEAK_REFERENCES 1 +#else #define SEXP_USE_WEAK_REFERENCES ! SEXP_USE_NO_FEATURES #endif +#endif #ifndef SEXP_USE_FIXED_CHUNK_SIZE_HEAPS #define SEXP_USE_FIXED_CHUNK_SIZE_HEAPS 0 diff --git a/sexp.c b/sexp.c index 9b83c5ba..7baa0fee 100644 --- a/sexp.c +++ b/sexp.c @@ -1806,7 +1806,7 @@ sexp sexp_open_output_file_descriptor (sexp ctx, sexp self, sexp_sint_t n, sexp return res; } -#if SEXP_USE_WEAK_REFERENCES +#if SEXP_USE_UNIFY_FILENOS_BY_NUMBER sexp sexp_make_ephemeron_op(sexp ctx, sexp self, sexp_sint_t n, sexp key, sexp value) { sexp res = sexp_alloc_type(ctx, pair, SEXP_EPHEMERON); if (!sexp_exceptionp(res)) { @@ -1878,13 +1878,13 @@ static void sexp_insert_fileno(sexp ctx, sexp fileno) { n++; sexp_global(ctx, SEXP_G_NUM_FILE_DESCRIPTORS) = sexp_make_fixnum(n); } -#endif +#endif /* SEXP_USE_UNIFY_FILENOS_BY_NUMBER */ sexp sexp_make_fileno_op (sexp ctx, sexp self, sexp_sint_t n, sexp fd, sexp no_closep) { sexp_gc_var1(res); sexp_assert_type(ctx, sexp_fixnump, SEXP_FIXNUM, fd); if (sexp_unbox_fixnum(fd) < 0) return SEXP_FALSE; -#if SEXP_USE_WEAK_REFERENCES +#if SEXP_USE_UNIFY_FILENOS_BY_NUMBER res = sexp_lookup_fileno(ctx, sexp_unbox_fixnum(fd)); if (sexp_filenop(res)) { sexp_fileno_no_closep(res) = sexp_truep(no_closep); @@ -1898,7 +1898,7 @@ sexp sexp_make_fileno_op (sexp ctx, sexp self, sexp_sint_t n, sexp fd, sexp no_c sexp_fileno_fd(res) = sexp_unbox_fixnum(fd); sexp_fileno_openp(res) = 1; sexp_fileno_no_closep(res) = sexp_truep(no_closep); -#if SEXP_USE_WEAK_REFERENCES +#if SEXP_USE_UNIFY_FILENOS_BY_NUMBER sexp_insert_fileno(ctx, res); #endif } @@ -1925,7 +1925,7 @@ sexp sexp_make_input_port (sexp ctx, FILE* in, sexp name) { #if SEXP_USE_FOLD_CASE_SYMS sexp_port_fold_casep(p) = sexp_truep(sexp_global(ctx, SEXP_G_FOLD_CASE_P)); #endif -#if SEXP_USE_WEAK_REFERENCES +#if SEXP_USE_UNIFY_FILENOS_BY_NUMBER /* if the fd was previously opened by a non-stream port, preserve it */ /* here to avoid gc timing issues */ if (in && fileno(in) >= 0) { diff --git a/tests/build/build-opts.txt b/tests/build/build-opts.txt index 93431524..279a53d5 100644 --- a/tests/build/build-opts.txt +++ b/tests/build/build-opts.txt @@ -25,6 +25,7 @@ CPPFLAGS=-DSEXP_USE_2010_EPOCH=0 CPPFLAGS=-DSEXP_USE_CHECK_STACK=0 CPPFLAGS=-DSEXP_USE_EXTENDED_FCALL=0 CPPFLAGS=-DSEXP_USE_WEAK_REFERENCES=0 +CPPFLAGS=-DSEXP_USE_UNIFY_FILENOS_BY_NUMBER=1 CPPFLAGS=-DSEXP_USE_OBJECT_BRACE_LITERALS=0 CPPFLAGS=-DSEXP_USE_TAIL_JUMPS=0 CPPFLAGS=-DSEXP_USE_RESERVE_OPCODE=0