removing support for SEXP_USE_STRING_STREAMS

This commit is contained in:
Alex Shinn 2015-07-04 23:25:40 +09:00
parent 94067a1ffe
commit 42c14af4b9
5 changed files with 0 additions and 224 deletions

3
eval.c
View file

@ -2259,9 +2259,6 @@ static const char* sexp_initial_features[] = {
#if SEXP_USE_BIDIRECTIONAL_PORTS #if SEXP_USE_BIDIRECTIONAL_PORTS
"bidir-ports", "bidir-ports",
#endif #endif
#if SEXP_USE_STRING_STREAMS
"string-streams",
#endif
#if SEXP_USE_MODULES #if SEXP_USE_MODULES
"modules", "modules",
#endif #endif

View file

@ -205,11 +205,6 @@
/* Making them immutable allows for packed UTF-8 strings. */ /* Making them immutable allows for packed UTF-8 strings. */
/* #define SEXP_USE_MUTABLE_STRINGS 0 */ /* #define SEXP_USE_MUTABLE_STRINGS 0 */
/* uncomment this to base string ports on C streams */
/* This historic option enables string and custom ports backed */
/* by FILE* objects using memstreams and funopen/fopencookie. */
/* #define SEXP_USE_STRING_STREAMS 1 */
/* uncomment this to disable automatic closing of ports */ /* uncomment this to disable automatic closing of ports */
/* If enabled, the underlying FILE* for file ports will be */ /* If enabled, the underlying FILE* for file ports will be */
/* automatically closed when they're garbage collected. Doesn't */ /* automatically closed when they're garbage collected. Doesn't */
@ -614,10 +609,6 @@
#define SEXP_USE_PACKED_STRINGS 1 #define SEXP_USE_PACKED_STRINGS 1
#endif #endif
#ifndef SEXP_USE_STRING_STREAMS
#define SEXP_USE_STRING_STREAMS 0
#endif
#ifndef SEXP_USE_AUTOCLOSE_PORTS #ifndef SEXP_USE_AUTOCLOSE_PORTS
#define SEXP_USE_AUTOCLOSE_PORTS ! SEXP_USE_NO_FEATURES #define SEXP_USE_AUTOCLOSE_PORTS ! SEXP_USE_NO_FEATURES
#endif #endif

View file

@ -740,11 +740,7 @@ SEXP_API int sexp_idp(sexp x);
#define sexp_portp(x) (sexp_check_tag(x, SEXP_IPORT) || sexp_check_tag(x, SEXP_OPORT)) #define sexp_portp(x) (sexp_check_tag(x, SEXP_IPORT) || sexp_check_tag(x, SEXP_OPORT))
#if SEXP_USE_STRING_STREAMS
#define sexp_stream_portp(x) 1
#else
#define sexp_stream_portp(x) (sexp_port_stream(x) != NULL) #define sexp_stream_portp(x) (sexp_port_stream(x) != NULL)
#endif
#define sexp_port_customp(x) (sexp_vectorp(sexp_port_cookie(x)) && sexp_vector_length(sexp_port_cookie(x)) == 6) #define sexp_port_customp(x) (sexp_vectorp(sexp_port_cookie(x)) && sexp_vector_length(sexp_port_cookie(x)) == 6)
@ -1340,18 +1336,6 @@ SEXP_API sexp sexp_push_op(sexp ctx, sexp* loc, sexp x);
/***************************** general API ****************************/ /***************************** general API ****************************/
#if SEXP_USE_STRING_STREAMS
#define sexp_read_char(x, p) (getc(sexp_port_stream(p)))
#define sexp_push_char(x, c, p) (ungetc(c, sexp_port_stream(p)))
#define sexp_write_char(x, c, p) (putc(c, sexp_port_stream(p)))
#define sexp_write_string(x, s, p) (fputs(s, sexp_port_stream(p)))
#define sexp_write_string_n(x, s, n, p) (fwrite(s, 1, n, sexp_port_stream(p)))
#define sexp_flush(x, p) (fflush(sexp_port_stream(p)))
#define sexp_flush_forced sexp_flush
#else
#define sexp_read_char(x, p) (sexp_port_buf(p) ? ((sexp_port_offset(p) < sexp_port_size(p)) ? ((unsigned char*)sexp_port_buf(p))[sexp_port_offset(p)++] : sexp_buffered_read_char(x, p)) : getc(sexp_port_stream(p))) #define sexp_read_char(x, p) (sexp_port_buf(p) ? ((sexp_port_offset(p) < sexp_port_size(p)) ? ((unsigned char*)sexp_port_buf(p))[sexp_port_offset(p)++] : sexp_buffered_read_char(x, p)) : getc(sexp_port_stream(p)))
#define sexp_push_char(x, c, p) ((c!=EOF) && (sexp_port_buf(p) ? (sexp_port_buf(p)[--sexp_port_offset(p)] = ((char)(c))) : ungetc(c, sexp_port_stream(p)))) #define sexp_push_char(x, c, p) ((c!=EOF) && (sexp_port_buf(p) ? (sexp_port_buf(p)[--sexp_port_offset(p)] = ((char)(c))) : ungetc(c, sexp_port_stream(p))))
#define sexp_write_char(x, c, p) (sexp_port_buf(p) ? ((sexp_port_offset(p) < sexp_port_size(p)) ? ((((sexp_port_buf(p))[sexp_port_offset(p)++]) = (char)(c)), 0) : sexp_buffered_write_char(x, c, p)) : putc(c, sexp_port_stream(p))) #define sexp_write_char(x, c, p) (sexp_port_buf(p) ? ((sexp_port_offset(p) < sexp_port_size(p)) ? ((((sexp_port_buf(p))[sexp_port_offset(p)++]) = (char)(c)), 0) : sexp_buffered_write_char(x, c, p)) : putc(c, sexp_port_stream(p)))
@ -1366,8 +1350,6 @@ SEXP_API int sexp_buffered_write_string_n (sexp ctx, const char *str, sexp_uint_
SEXP_API int sexp_buffered_write_string (sexp ctx, const char *str, sexp p); SEXP_API int sexp_buffered_write_string (sexp ctx, const char *str, sexp p);
SEXP_API int sexp_buffered_flush (sexp ctx, sexp p, int forcep); SEXP_API int sexp_buffered_flush (sexp ctx, sexp p, int forcep);
#endif
#define sexp_newline(ctx, p) sexp_write_char((ctx), '\n', (p)) #define sexp_newline(ctx, p) sexp_write_char((ctx), '\n', (p))
#define sexp_at_eofp(p) (feof(sexp_port_stream(p))) #define sexp_at_eofp(p) (feof(sexp_port_stream(p)))
#define sexp_port_fileno(p) (sexp_port_stream(p) ? fileno(sexp_port_stream(p)) : sexp_filenop(sexp_port_fd(p)) ? sexp_fileno_fd(sexp_port_fd(p)) : -1) #define sexp_port_fileno(p) (sexp_port_stream(p) ? fileno(sexp_port_stream(p)) : sexp_filenop(sexp_port_fd(p)) ? sexp_fileno_fd(sexp_port_fd(p)) : -1)

193
sexp.c
View file

@ -1265,195 +1265,6 @@ sexp sexp_make_cpointer (sexp ctx, sexp_uint_t type_id, void *value,
/************************ reading and writing *************************/ /************************ reading and writing *************************/
#if SEXP_USE_STRING_STREAMS
#define SEXP_INIT_STRING_PORT_SIZE 128
#if SEXP_BSD
#define sexp_streamp(vec) sexp_vectorp(vec)
#define sexp_stream_ctx(vec) sexp_vector_ref((sexp)vec, SEXP_ZERO)
#define sexp_stream_buf(vec) sexp_vector_ref((sexp)vec, SEXP_ONE)
#define sexp_stream_size(vec) sexp_vector_ref((sexp)vec, SEXP_TWO)
#define sexp_stream_pos(vec) sexp_vector_ref((sexp)vec, SEXP_THREE)
#define sexp_stream_ctx_set(vec, x) sexp_vector_set((sexp)vec, SEXP_ZERO, x)
#define sexp_stream_buf_set(vec, x) sexp_vector_set((sexp)vec, SEXP_ONE, x)
#define sexp_stream_size_set(vec, x) sexp_vector_set((sexp)vec, SEXP_TWO, x)
#define sexp_stream_pos_set(vec, x) sexp_vector_set((sexp)vec, SEXP_THREE, x)
static int sstream_read (void *vec, char *dst, int n) {
sexp_uint_t len = sexp_unbox_fixnum(sexp_stream_size(vec));
sexp_uint_t pos = sexp_unbox_fixnum(sexp_stream_pos(vec));
if (pos >= len) return 0;
if (n > (len - pos)) n = (len - pos);
memcpy(dst, sexp_string_data(sexp_stream_buf(vec))+pos, n);
sexp_stream_pos_set(vec, sexp_make_fixnum(pos + n));
return n;
}
static int sstream_write (void *vec, const char *src, int n) {
sexp_uint_t len, pos, newpos;
sexp newbuf;
len = sexp_unbox_fixnum(sexp_stream_size(vec));
pos = sexp_unbox_fixnum(sexp_stream_pos(vec));
newpos = pos+n;
if (newpos >= len) {
newbuf = sexp_make_string(sexp_stream_ctx(vec),
sexp_make_fixnum(newpos*2),
SEXP_VOID);
memcpy(sexp_string_data(newbuf),
sexp_string_data(sexp_stream_buf(vec)),
pos);
sexp_stream_buf_set(vec, newbuf);
sexp_stream_size_set(vec, sexp_make_fixnum(newpos*2));
}
memcpy(sexp_string_data(sexp_stream_buf(vec))+pos, src, n);
sexp_stream_pos_set(vec, sexp_make_fixnum(newpos));
return n;
}
static off_t sstream_seek (void *vec, off_t offset, int whence) {
sexp_sint_t pos;
if (whence == SEEK_SET) {
pos = offset;
} else if (whence == SEEK_CUR) {
pos = sexp_unbox_fixnum(sexp_stream_pos(vec)) + offset;
} else { /* SEEK_END */
pos = sexp_unbox_fixnum(sexp_stream_size(vec)) + offset;
}
sexp_stream_pos_set(vec, sexp_make_fixnum(pos));
return pos;
}
sexp sexp_open_input_string_op (sexp ctx, sexp self, sexp_sint_t n, sexp str) {
FILE *in;
sexp res;
sexp_gc_var1(cookie);
sexp_assert_type(ctx, sexp_stringp, SEXP_STRING, str);
sexp_gc_preserve1(ctx, cookie);
cookie = sexp_make_vector(ctx, sexp_make_fixnum(4), SEXP_VOID);
sexp_stream_ctx_set(cookie, ctx);
sexp_stream_buf_set(cookie, str);
sexp_stream_size_set(cookie, sexp_make_fixnum(sexp_string_size(str)));
sexp_stream_pos_set(cookie, SEXP_ZERO);
in = funopen(cookie, &sstream_read, NULL, &sstream_seek, NULL);
res = sexp_make_input_port(ctx, in, SEXP_FALSE);
sexp_port_cookie(res) = cookie;
sexp_port_binaryp(res) = 0;
sexp_gc_release1(ctx);
return res;
}
sexp sexp_open_output_string_op (sexp ctx, sexp self, sexp_sint_t n) {
FILE *out;
sexp res, size;
sexp_gc_var1(cookie);
sexp_gc_preserve1(ctx, cookie);
size = sexp_make_fixnum(SEXP_INIT_STRING_PORT_SIZE);
cookie = sexp_make_vector(ctx, sexp_make_fixnum(4), SEXP_VOID);
sexp_stream_ctx_set(cookie, ctx);
sexp_stream_buf_set(cookie, sexp_make_string(ctx, size, SEXP_VOID));
sexp_stream_size_set(cookie, size);
sexp_stream_pos_set(cookie, SEXP_ZERO);
out = funopen(cookie, NULL, &sstream_write, &sstream_seek, NULL);
res = sexp_make_output_port(ctx, out, SEXP_FALSE);
sexp_port_cookie(res) = cookie;
sexp_port_binaryp(res) = 0;
sexp_gc_release1(ctx);
return res;
}
sexp sexp_get_output_string_op (sexp ctx, sexp self, sexp_sint_t n, sexp port) {
sexp cookie;
sexp_assert_type(ctx, sexp_oportp, SEXP_OPORT, port);
if (!sexp_port_openp(port))
return sexp_xtype_exception(ctx, self, "output port is closed", port);
cookie = sexp_port_cookie(port);
if (!sexp_streamp(cookie))
return sexp_xtype_exception(ctx, self, "not a string port", port);
fflush(sexp_port_stream(port));
return sexp_substring_cursor(ctx,
sexp_stream_buf(cookie),
SEXP_ZERO,
sexp_stream_pos(cookie));
}
#else /* SEXP_USE_STRING_STREAMS && ! SEXP_BSD */
sexp sexp_open_input_string_op (sexp ctx, sexp self, sexp_sint_t n, sexp str) {
FILE *in;
sexp res;
sexp_assert_type(ctx, sexp_stringp, SEXP_STRING, str);
if (sexp_string_size(str) == 0)
in = fopen("/dev/null", "r");
else
in = fmemopen(sexp_string_data(str), sexp_string_size(str), "r");
if (in) {
res = sexp_make_input_port(ctx, in, SEXP_FALSE);
if (sexp_string_size(str) == 0)
sexp_port_name(res) = sexp_c_string(ctx, "/dev/null", -1);
sexp_port_cookie(res) = str; /* for gc preservation */
sexp_port_binaryp(res) = 0;
} else {
res = sexp_user_exception(ctx, SEXP_FALSE, "couldn't open string", str);
}
return res;
}
sexp sexp_open_output_string_op (sexp ctx, sexp self, sexp_sint_t n) {
sexp res = sexp_make_output_port(ctx, NULL, SEXP_FALSE);
sexp_port_stream(res)
= open_memstream(&sexp_port_buf(res), &sexp_port_size(res));
sexp_port_binaryp(res) = 0;
sexp_port_cookie(res) = SEXP_STRING_OPORT;
return res;
}
sexp sexp_get_output_string_op (sexp ctx, sexp self, sexp_sint_t n, sexp port) {
sexp_assert_type(ctx, sexp_oportp, SEXP_OPORT, port);
if (sexp_port_cookie(port) != SEXP_STRING_OPORT)
return sexp_xtype_exception(ctx, self, "not an output string port", port);
if (!sexp_port_openp(port))
return sexp_xtype_exception(ctx, self, "output port is closed", port);
fflush(sexp_port_stream(port));
return sexp_c_string(ctx, sexp_port_buf(port), sexp_port_size(port));
}
#endif
sexp sexp_open_input_file_descriptor (sexp ctx, sexp self, sexp_sint_t n, sexp fileno, sexp shutdownp) {
sexp res;
FILE* in;
sexp_assert_type(ctx, sexp_filenop, SEXP_FILENO, fileno);
in = fdopen(sexp_fileno_fd(fileno), "r");
if (!in) return sexp_file_exception(ctx, SEXP_FALSE, "couldn't open fileno", fileno);
res = sexp_make_input_port(ctx, in, SEXP_FALSE);
if (!sexp_exceptionp(res)) {
sexp_port_binaryp(res) = 1;
sexp_port_shutdownp(res) = sexp_truep(shutdownp);
sexp_fileno_count(fileno)++;
}
return res;
}
sexp sexp_open_output_file_descriptor (sexp ctx, sexp self, sexp_sint_t n, sexp fileno, sexp shutdownp) {
sexp res;
FILE* out;
sexp_assert_type(ctx, sexp_filenop, SEXP_FILENO, fileno);
out = fdopen(sexp_fileno_fd(fileno), "w");
if (!out) return sexp_user_exception(ctx, SEXP_FALSE, "couldn't open fileno", fileno);
res = sexp_make_output_port(ctx, out, SEXP_FALSE);
if (!sexp_exceptionp(res)) {
sexp_port_shutdownp(res) = sexp_truep(shutdownp);
sexp_fileno_count(fileno)++;
}
return res;
}
#else /* ! SEXP_USE_STRING_STREAMS */
int sexp_buffered_read_char (sexp ctx, sexp p) { int sexp_buffered_read_char (sexp ctx, sexp p) {
sexp_gc_var2(tmp, origbytes); sexp_gc_var2(tmp, origbytes);
int res = 0; int res = 0;
@ -1669,8 +1480,6 @@ sexp sexp_open_output_file_descriptor (sexp ctx, sexp self, sexp_sint_t n, sexp
return res; return res;
} }
#endif /* ! SEXP_USE_STRING_STREAMS */
#if SEXP_USE_WEAK_REFERENCES #if SEXP_USE_WEAK_REFERENCES
sexp sexp_make_ephemeron_op(sexp ctx, sexp self, sexp_sint_t n, sexp key, sexp value) { 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); sexp res = sexp_alloc_type(ctx, pair, SEXP_EPHEMERON);
@ -1928,12 +1737,10 @@ sexp sexp_char_ready_p (sexp ctx, sexp self, sexp_sint_t n, sexp in) {
sexp_assert_type(ctx, sexp_iportp, SEXP_IPORT, in); sexp_assert_type(ctx, sexp_iportp, SEXP_IPORT, in);
if (!sexp_port_openp(in)) if (!sexp_port_openp(in))
return SEXP_FALSE; return SEXP_FALSE;
#if !SEXP_USE_STRING_STREAMS
if (sexp_port_buf(in)) if (sexp_port_buf(in))
if (sexp_port_offset(in) < sexp_port_size(in) if (sexp_port_offset(in) < sexp_port_size(in)
|| (!sexp_filenop(sexp_port_fd(in)) && !sexp_port_stream(in))) || (!sexp_filenop(sexp_port_fd(in)) && !sexp_port_stream(in)))
return SEXP_TRUE; return SEXP_TRUE;
#endif
#if SEXP_USE_GREEN_THREADS /* maybe not just when threads are enabled */ #if SEXP_USE_GREEN_THREADS /* maybe not just when threads are enabled */
if (sexp_filenop(sexp_port_fd(in))) if (sexp_filenop(sexp_port_fd(in)))
return sexp_make_boolean(sexp_fileno_ready_p(sexp_port_fileno(in))); return sexp_make_boolean(sexp_fileno_ready_p(sexp_port_fileno(in)));

View file

@ -18,7 +18,6 @@ CPPFLAGS=-DSEXP_USE_MATH=0
CPPFLAGS=-DSEXP_WARN_UNDEFS=0 CPPFLAGS=-DSEXP_WARN_UNDEFS=0
CPPFLAGS=-DSEXP_USE_HUFF_SYMS=0 CPPFLAGS=-DSEXP_USE_HUFF_SYMS=0
CPPFLAGS=-DSEXP_USE_HASH_SYMS=0 CPPFLAGS=-DSEXP_USE_HASH_SYMS=0
CPPFLAGS=-DSEXP_USE_STRING_STREAMS=1
CPPFLAGS=-DSEXP_USE_AUTOCLOSE_PORTS=0 CPPFLAGS=-DSEXP_USE_AUTOCLOSE_PORTS=0
CPPFLAGS=-DSEXP_USE_2010_EPOCH=0 CPPFLAGS=-DSEXP_USE_2010_EPOCH=0
CPPFLAGS=-DSEXP_USE_CHECK_STACK=0 CPPFLAGS=-DSEXP_USE_CHECK_STACK=0