From c5179f2271298c3f1d13f7949770fc8cc0336ab3 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Wed, 11 Jun 2014 23:19:00 +0900 Subject: [PATCH] Hopefully the last fd gc issue: also preserve for newly opening FILE* ports if the corresponding fd still exists in the cache. --- sexp.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sexp.c b/sexp.c index af41f354..146f3b89 100644 --- a/sexp.c +++ b/sexp.c @@ -1752,6 +1752,15 @@ sexp sexp_make_input_port (sexp ctx, FILE* in, sexp name) { sexp_port_blockedp(p) = 0; #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 the fd was previously opened by a non-stream port, preserve it */ + /* here to avoid gc timing issues */ + if (in && fileno(in) >= 0) { + sexp_port_fd(p) = sexp_lookup_fileno(ctx, fileno(in)); + if (sexp_filenop(sexp_port_fd(p))) + sexp_fileno_openp(sexp_port_fd(p)) = 1; + } #endif sexp_port_cookie(p) = SEXP_VOID; return p;