Removing warnings and fixing some build configurations from the last fd gc change.

This commit is contained in:
Alex Shinn 2011-12-17 14:29:20 +09:00
parent 3a511302c4
commit 32763cd214
3 changed files with 24 additions and 22 deletions

30
eval.c
View file

@ -1011,17 +1011,12 @@ sexp sexp_open_input_file_op (sexp ctx, sexp self, sexp_sint_t n, sexp path) {
FILE *in; FILE *in;
int count = 0; int count = 0;
sexp_assert_type(ctx, sexp_stringp, SEXP_STRING, path); sexp_assert_type(ctx, sexp_stringp, SEXP_STRING, path);
loop: do {
in = fopen(sexp_string_data(path), "r"); if (count != 0) sexp_gc(ctx, NULL);
if (!in) { in = fopen(sexp_string_data(path), "r");
#if SEXP_USE_GC_FILE_DESCRIPTORS } while (!in && sexp_out_of_file_descriptors() && !count++);
if (errno == EMFILE && !count++) { if (!in)
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
@ -1032,17 +1027,12 @@ sexp sexp_open_output_file_op (sexp ctx, sexp self, sexp_sint_t n, sexp path) {
FILE *out; FILE *out;
int count = 0; int count = 0;
sexp_assert_type(ctx, sexp_stringp, SEXP_STRING, path); sexp_assert_type(ctx, sexp_stringp, SEXP_STRING, path);
loop: do {
out = fopen(sexp_string_data(path), "w"); if (count != 0) sexp_gc(ctx, NULL);
if (!out) { out = fopen(sexp_string_data(path), "w");
#if SEXP_USE_GC_FILE_DESCRIPTORS } while (!out && sexp_out_of_file_descriptors() && !count++);
if (errno == EMFILE && !count++) { if (!out)
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);
} }

View file

@ -507,7 +507,7 @@
#endif #endif
#ifndef SEXP_USE_GC_FILE_DESCRIPTORS #ifndef SEXP_USE_GC_FILE_DESCRIPTORS
#define SEXP_USE_GC_FILE_DESCRIPTORS (SEXP_USE_AUTOCLOSE_PORTS &&!SEXP_USE_BOEHM) #define SEXP_USE_GC_FILE_DESCRIPTORS (SEXP_USE_AUTOCLOSE_PORTS &&!SEXP_USE_BOEHM && !defined(PLAN9))
#endif #endif
#ifndef SEXP_USE_2010_EPOCH #ifndef SEXP_USE_2010_EPOCH

View file

@ -25,9 +25,11 @@ extern "C" {
#if SEXP_USE_DL #if SEXP_USE_DL
#include <dlfcn.h> #include <dlfcn.h>
#endif #endif
#if SEXP_USE_GREEN_THREADS || SEXP_USE_GC_FILE_DESCRIPTORS
#include <errno.h>
#endif
#if SEXP_USE_GREEN_THREADS #if SEXP_USE_GREEN_THREADS
#include <sys/time.h> #include <sys/time.h>
#include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#endif #endif
#define sexp_isalpha(x) (isalpha(x)) #define sexp_isalpha(x) (isalpha(x))
@ -37,6 +39,12 @@ extern "C" {
#define sexp_toupper(x) (toupper(x)) #define sexp_toupper(x) (toupper(x))
#endif #endif
#if SEXP_USE_GC_FILE_DESCRIPTORS
#define sexp_out_of_file_descriptors() (errno == EMFILE)
#else
#define sexp_out_of_file_descriptors() (0)
#endif
#ifdef PLAN9 #ifdef PLAN9
#include <u.h> #include <u.h>
#include <libc.h> #include <libc.h>
@ -430,6 +438,8 @@ void sexp_free(void* ptr);
#if SEXP_USE_BOEHM #if SEXP_USE_BOEHM
#define sexp_gc(ctx, sum)
#define sexp_gc_var(ctx, x, y) sexp x; #define sexp_gc_var(ctx, x, y) sexp x;
#define sexp_gc_preserve(ctx, x, y) #define sexp_gc_preserve(ctx, x, y)
#define sexp_gc_release(ctx, x, y) #define sexp_gc_release(ctx, x, y)
@ -443,6 +453,8 @@ void sexp_free(void* ptr);
#else #else
SEXP_API sexp sexp_gc(sexp ctx, size_t *sum_freed);
#define sexp_gc_var(ctx, x, y) \ #define sexp_gc_var(ctx, x, y) \
sexp x = SEXP_VOID; \ sexp x = SEXP_VOID; \
struct sexp_gc_var_t y = {NULL, NULL}; struct sexp_gc_var_t y = {NULL, NULL};