Making C string port API names match the Scheme side.

This commit is contained in:
Alex Shinn 2013-07-21 15:24:04 +09:00
parent afe1bf8901
commit 6dea74036a
5 changed files with 22 additions and 20 deletions

View file

@ -783,7 +783,9 @@ Any of these may fail and return the OOM exception object.
\item{\ccode{sexp_debug(sexp ctx, char* msg, sexp obj)} - write \var{obj} with a debug message prefix to \scheme{current-error-port}} \item{\ccode{sexp_debug(sexp ctx, char* msg, sexp obj)} - write \var{obj} with a debug message prefix to \scheme{current-error-port}}
\item{\ccode{sexp_read_from_string(sexp ctx, char* str, int len)} - read a single datum from \var{str}, using at most \var{len} bytes if \var{len} is non-negative} \item{\ccode{sexp_read_from_string(sexp ctx, char* str, int len)} - read a single datum from \var{str}, using at most \var{len} bytes if \var{len} is non-negative}
\item{\ccode{sexp_write_to_string(sexp ctx, sexp obj)} - return a Scheme string representation of \var{obj}} \item{\ccode{sexp_write_to_string(sexp ctx, sexp obj)} - return a Scheme string representation of \var{obj}}
\item{\ccode{sexp_make_input_string_port(sexp ctx, sexp str)} - equivalent to \scheme{open-input-string}} \item{\ccode{sexp_open_input_string(sexp ctx, sexp str)} - equivalent to \scheme{open-input-string}}
\item{\ccode{sexp_open_output_string(sexp ctx)} - equivalent to \scheme{open-output-string}}
\item{\ccode{sexp_get_output_string(sexp ctx, sexp port)} - equivalent to \scheme{open-output-string}}
] ]
\subsubsection{Utilities} \subsubsection{Utilities}

View file

@ -1383,8 +1383,8 @@ SEXP_API sexp sexp_set_port_fold_case (sexp ctx, sexp self, sexp_sint_t n, sexp
#if SEXP_USE_OBJECT_BRACE_LITERALS #if SEXP_USE_OBJECT_BRACE_LITERALS
SEXP_API sexp sexp_lookup_type_op (sexp ctx, sexp self, sexp_sint_t n, sexp name, sexp id); SEXP_API sexp sexp_lookup_type_op (sexp ctx, sexp self, sexp_sint_t n, sexp name, sexp id);
#endif #endif
SEXP_API sexp sexp_make_input_string_port_op (sexp ctx, sexp self, sexp_sint_t n, sexp str); SEXP_API sexp sexp_open_input_string_op (sexp ctx, sexp self, sexp_sint_t n, sexp str);
SEXP_API sexp sexp_make_output_string_port_op (sexp ctx, sexp self, sexp_sint_t n); SEXP_API sexp sexp_open_output_string_op (sexp ctx, sexp self, sexp_sint_t n);
SEXP_API sexp sexp_get_output_string_op (sexp ctx, sexp self, sexp_sint_t n, sexp port); SEXP_API sexp sexp_get_output_string_op (sexp ctx, sexp self, sexp_sint_t n, sexp port);
SEXP_API sexp sexp_make_exception (sexp ctx, sexp kind, sexp message, sexp irritants, sexp procedure, sexp source); SEXP_API sexp sexp_make_exception (sexp ctx, sexp kind, sexp message, sexp irritants, sexp procedure, sexp source);
SEXP_API sexp sexp_user_exception (sexp ctx, sexp self, const char *msg, sexp x); SEXP_API sexp sexp_user_exception (sexp ctx, sexp self, const char *msg, sexp x);
@ -1524,8 +1524,8 @@ SEXP_API sexp sexp_finalize_c_type (sexp ctx, sexp self, sexp_sint_t n, sexp obj
#define sexp_string_concatenate(ctx, ls, s) sexp_string_concatenate_op(ctx, NULL, 2, ls, s) #define sexp_string_concatenate(ctx, ls, s) sexp_string_concatenate_op(ctx, NULL, 2, ls, s)
#define sexp_memq(ctx, a, b) sexp_memq_op(ctx, NULL, 2, a, b) #define sexp_memq(ctx, a, b) sexp_memq_op(ctx, NULL, 2, a, b)
#define sexp_assq(ctx, a, b) sexp_assq_op(ctx, NULL, 2, a, b) #define sexp_assq(ctx, a, b) sexp_assq_op(ctx, NULL, 2, a, b)
#define sexp_make_output_string_port(ctx) sexp_make_output_string_port_op(ctx, NULL, 0) #define sexp_open_output_string(ctx) sexp_open_output_string_op(ctx, NULL, 0)
#define sexp_make_input_string_port(ctx, s) sexp_make_input_string_port_op(ctx, NULL, 1, s) #define sexp_open_input_string(ctx, s) sexp_open_input_string_op(ctx, NULL, 1, s)
#define sexp_get_output_string(ctx, out) sexp_get_output_string_op(ctx, NULL, 1, out) #define sexp_get_output_string(ctx, out) sexp_get_output_string_op(ctx, NULL, 1, out)
#define sexp_expt(ctx, a, b) sexp_expt_op(ctx, NULL, 2, a, b) #define sexp_expt(ctx, a, b) sexp_expt_op(ctx, NULL, 2, a, b)
#define sexp_register_simple_type(ctx, a, b, c) sexp_register_simple_type_op(ctx, NULL, 3, a, b, c) #define sexp_register_simple_type(ctx, a, b, c) sexp_register_simple_type_op(ctx, NULL, 3, a, b, c)

View file

@ -195,7 +195,7 @@ static sexp sexp_make_custom_port (sexp ctx, sexp self,
sexp_gc_preserve2(ctx, res, str); sexp_gc_preserve2(ctx, res, str);
str = sexp_make_string(ctx, sexp_make_fixnum(SEXP_PORT_BUFFER_SIZE), SEXP_VOID); str = sexp_make_string(ctx, sexp_make_fixnum(SEXP_PORT_BUFFER_SIZE), SEXP_VOID);
if (sexp_exceptionp(str)) return str; if (sexp_exceptionp(str)) return str;
res = sexp_make_input_string_port(ctx, str); res = sexp_open_input_string(ctx, str);
if (sexp_exceptionp(res)) return res; if (sexp_exceptionp(res)) return res;
if (mode && mode[0] == 'w') { if (mode && mode[0] == 'w') {
sexp_pointer_tag(res) = SEXP_OPORT; sexp_pointer_tag(res) = SEXP_OPORT;
@ -252,14 +252,14 @@ sexp sexp_open_input_bytevector (sexp ctx, sexp self, sexp vec) {
sexp_assert_type(ctx, sexp_bytesp, SEXP_BYTES, vec); sexp_assert_type(ctx, sexp_bytesp, SEXP_BYTES, vec);
sexp_gc_preserve2(ctx, str, res); sexp_gc_preserve2(ctx, str, res);
str = sexp_bytes_to_string(ctx, vec); str = sexp_bytes_to_string(ctx, vec);
res = sexp_make_input_string_port(ctx, str); res = sexp_open_input_string(ctx, str);
sexp_port_binaryp(res) = 1; sexp_port_binaryp(res) = 1;
sexp_gc_release2(ctx); sexp_gc_release2(ctx);
return res; return res;
} }
sexp sexp_open_output_bytevector (sexp ctx, sexp self) { sexp sexp_open_output_bytevector (sexp ctx, sexp self) {
sexp res = sexp_make_output_string_port(ctx); sexp res = sexp_open_output_string(ctx);
sexp_port_binaryp(res) = 1; sexp_port_binaryp(res) = 1;
return res; return res;
} }

View file

@ -187,8 +187,8 @@ _FN2(_I(SEXP_OBJECT), _I(SEXP_OBJECT), SEXP_NULL, "memq", 0, sexp_memq_op),
_FN2(_I(SEXP_OBJECT), _I(SEXP_OBJECT), SEXP_NULL, "assq", 0, sexp_assq_op), _FN2(_I(SEXP_OBJECT), _I(SEXP_OBJECT), SEXP_NULL, "assq", 0, sexp_assq_op),
_FN3(_I(SEXP_SYNCLO), _I(SEXP_ENV), SEXP_NULL, _I(SEXP_OBJECT), "make-syntactic-closure", 0, sexp_make_synclo_op), _FN3(_I(SEXP_SYNCLO), _I(SEXP_ENV), SEXP_NULL, _I(SEXP_OBJECT), "make-syntactic-closure", 0, sexp_make_synclo_op),
_FN1(_I(SEXP_OBJECT), _I(SEXP_OBJECT), "strip-syntactic-closures", 0, sexp_strip_synclos), _FN1(_I(SEXP_OBJECT), _I(SEXP_OBJECT), "strip-syntactic-closures", 0, sexp_strip_synclos),
_FN0(_I(SEXP_OPORT), "open-output-string", 0, sexp_make_output_string_port_op), _FN0(_I(SEXP_OPORT), "open-output-string", 0, sexp_open_output_string_op),
_FN1(_I(SEXP_IPORT), _I(SEXP_STRING), "open-input-string", 0, sexp_make_input_string_port_op), _FN1(_I(SEXP_IPORT), _I(SEXP_STRING), "open-input-string", 0, sexp_open_input_string_op),
_FN1(_I(SEXP_STRING), _I(SEXP_OPORT), "get-output-string", 0, sexp_get_output_string_op), _FN1(_I(SEXP_STRING), _I(SEXP_OPORT), "get-output-string", 0, sexp_get_output_string_op),
_FN2OPT(_I(SEXP_IPORT), _I(SEXP_FIXNUM), _I(SEXP_BOOLEAN), "open-input-file-descriptor", SEXP_FALSE, sexp_open_input_file_descriptor), _FN2OPT(_I(SEXP_IPORT), _I(SEXP_FIXNUM), _I(SEXP_BOOLEAN), "open-input-file-descriptor", SEXP_FALSE, sexp_open_input_file_descriptor),
_FN2OPT(_I(SEXP_OPORT), _I(SEXP_FIXNUM), _I(SEXP_BOOLEAN), "open-output-file-descriptor", SEXP_FALSE, sexp_open_output_file_descriptor), _FN2OPT(_I(SEXP_OPORT), _I(SEXP_FIXNUM), _I(SEXP_BOOLEAN), "open-output-file-descriptor", SEXP_FALSE, sexp_open_output_file_descriptor),

20
sexp.c
View file

@ -1282,7 +1282,7 @@ static off_t sstream_seek (void *vec, off_t offset, int whence) {
return pos; return pos;
} }
sexp sexp_make_input_string_port_op (sexp ctx, sexp self, sexp_sint_t n, sexp str) { sexp sexp_open_input_string_op (sexp ctx, sexp self, sexp_sint_t n, sexp str) {
FILE *in; FILE *in;
sexp res; sexp res;
sexp_gc_var1(cookie); sexp_gc_var1(cookie);
@ -1301,7 +1301,7 @@ sexp sexp_make_input_string_port_op (sexp ctx, sexp self, sexp_sint_t n, sexp st
return res; return res;
} }
sexp sexp_make_output_string_port_op (sexp ctx, sexp self, sexp_sint_t n) { sexp sexp_open_output_string_op (sexp ctx, sexp self, sexp_sint_t n) {
FILE *out; FILE *out;
sexp res, size; sexp res, size;
sexp_gc_var1(cookie); sexp_gc_var1(cookie);
@ -1335,7 +1335,7 @@ sexp sexp_get_output_string_op (sexp ctx, sexp self, sexp_sint_t n, sexp port) {
#else /* SEXP_USE_STRING_STREAMS && ! SEXP_BSD */ #else /* SEXP_USE_STRING_STREAMS && ! SEXP_BSD */
sexp sexp_make_input_string_port_op (sexp ctx, sexp self, sexp_sint_t n, sexp str) { sexp sexp_open_input_string_op (sexp ctx, sexp self, sexp_sint_t n, sexp str) {
FILE *in; FILE *in;
sexp res; sexp res;
sexp_assert_type(ctx, sexp_stringp, SEXP_STRING, str); sexp_assert_type(ctx, sexp_stringp, SEXP_STRING, str);
@ -1355,7 +1355,7 @@ sexp sexp_make_input_string_port_op (sexp ctx, sexp self, sexp_sint_t n, sexp st
return res; return res;
} }
sexp sexp_make_output_string_port_op (sexp ctx, sexp self, sexp_sint_t n) { 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 res = sexp_make_output_port(ctx, NULL, SEXP_FALSE);
sexp_port_stream(res) sexp_port_stream(res)
= open_memstream(&sexp_port_buf(res), &sexp_port_size(res)); = open_memstream(&sexp_port_buf(res), &sexp_port_size(res));
@ -1520,7 +1520,7 @@ int sexp_buffered_flush (sexp ctx, sexp p, int forcep) {
return res; return res;
} }
sexp sexp_make_input_string_port_op (sexp ctx, sexp self, sexp_sint_t n, sexp str) { sexp sexp_open_input_string_op (sexp ctx, sexp self, sexp_sint_t n, sexp str) {
sexp res; sexp res;
sexp_assert_type(ctx, sexp_stringp, SEXP_STRING, str); sexp_assert_type(ctx, sexp_stringp, SEXP_STRING, str);
res = sexp_make_input_port(ctx, NULL, SEXP_FALSE); res = sexp_make_input_port(ctx, NULL, SEXP_FALSE);
@ -1533,7 +1533,7 @@ sexp sexp_make_input_string_port_op (sexp ctx, sexp self, sexp_sint_t n, sexp st
return res; return res;
} }
sexp sexp_make_output_string_port_op (sexp ctx, sexp self, sexp_sint_t n) { 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 res = sexp_make_output_port(ctx, NULL, SEXP_FALSE);
if (sexp_exceptionp(res)) return res; if (sexp_exceptionp(res)) return res;
sexp_port_buf(res) = (char*) sexp_malloc(SEXP_PORT_BUFFER_SIZE); sexp_port_buf(res) = (char*) sexp_malloc(SEXP_PORT_BUFFER_SIZE);
@ -1579,7 +1579,7 @@ sexp sexp_open_input_file_descriptor (sexp ctx, sexp self, sexp_sint_t n, sexp f
return sexp_file_exception(ctx, self, "invalid file descriptor", fileno); return sexp_file_exception(ctx, self, "invalid file descriptor", fileno);
sexp_gc_preserve2(ctx, res, str); sexp_gc_preserve2(ctx, res, str);
str = sexp_make_string(ctx, sexp_make_fixnum(SEXP_PORT_BUFFER_SIZE), SEXP_VOID); str = sexp_make_string(ctx, sexp_make_fixnum(SEXP_PORT_BUFFER_SIZE), SEXP_VOID);
res = sexp_make_input_string_port(ctx, str); res = sexp_open_input_string(ctx, str);
if (!sexp_exceptionp(res)) { if (!sexp_exceptionp(res)) {
sexp_port_fd(res) = fileno; sexp_port_fd(res) = fileno;
sexp_port_offset(res) = SEXP_PORT_BUFFER_SIZE; sexp_port_offset(res) = SEXP_PORT_BUFFER_SIZE;
@ -3067,7 +3067,7 @@ sexp sexp_read_from_string (sexp ctx, const char *str, sexp_sint_t len) {
sexp_gc_var2(s, in); sexp_gc_var2(s, in);
sexp_gc_preserve2(ctx, s, in); sexp_gc_preserve2(ctx, s, in);
s = sexp_c_string(ctx, str, len); s = sexp_c_string(ctx, str, len);
in = sexp_make_input_string_port(ctx, s); in = sexp_open_input_string(ctx, s);
res = sexp_read(ctx, in); res = sexp_read(ctx, in);
sexp_gc_release2(ctx); sexp_gc_release2(ctx);
return res; return res;
@ -3084,7 +3084,7 @@ sexp sexp_string_to_number_op (sexp ctx, sexp self, sexp_sint_t n, sexp str, sex
|| (sexp_string_data(str)[1]=='\0' && !sexp_isxdigit((unsigned char)(sexp_string_data(str)[0])))) || (sexp_string_data(str)[1]=='\0' && !sexp_isxdigit((unsigned char)(sexp_string_data(str)[0]))))
return SEXP_FALSE; return SEXP_FALSE;
sexp_gc_preserve1(ctx, in); sexp_gc_preserve1(ctx, in);
in = sexp_make_input_string_port(ctx, str); in = sexp_open_input_string(ctx, str);
if (sexp_string_data(str)[0] == '+') { if (sexp_string_data(str)[0] == '+') {
if (sexp_isdigit((unsigned char)(sexp_string_data(str)[1])) if (sexp_isdigit((unsigned char)(sexp_string_data(str)[1]))
|| sexp_string_data(str)[1] == '.' || sexp_string_data(str)[1] == '#') || sexp_string_data(str)[1] == '.' || sexp_string_data(str)[1] == '#')
@ -3100,7 +3100,7 @@ sexp sexp_write_to_string (sexp ctx, sexp obj) {
sexp str; sexp str;
sexp_gc_var1(out); sexp_gc_var1(out);
sexp_gc_preserve1(ctx, out); sexp_gc_preserve1(ctx, out);
out = sexp_make_output_string_port(ctx); out = sexp_open_output_string(ctx);
str = sexp_write(ctx, obj, out); str = sexp_write(ctx, obj, out);
if (! sexp_exceptionp(str)) if (! sexp_exceptionp(str))
str = sexp_get_output_string(ctx, out); str = sexp_get_output_string(ctx, out);