don't try to make ports from NULL FILE*s

This commit is contained in:
Alex Shinn 2011-11-23 10:47:36 +09:00
parent cd91d4aa72
commit 327be34719
3 changed files with 14 additions and 2 deletions

View file

@ -1198,6 +1198,8 @@ SEXP_API sexp sexp_write_simple_object (sexp ctx, sexp self, sexp_sint_t n, sexp
SEXP_API sexp sexp_finalize_port (sexp ctx, sexp self, sexp_sint_t n, sexp port);
SEXP_API sexp sexp_make_input_port (sexp ctx, FILE* in, sexp name);
SEXP_API sexp sexp_make_output_port (sexp ctx, FILE* out, sexp name);
SEXP_API sexp sexp_make_non_null_input_port (sexp ctx, FILE* in, sexp name);
SEXP_API sexp sexp_make_non_null_output_port (sexp ctx, FILE* out, sexp name);
SEXP_API sexp sexp_port_binaryp_op (sexp ctx, sexp self, sexp_sint_t n, sexp port);
SEXP_API sexp sexp_port_openp_op (sexp ctx, sexp self, sexp_sint_t n, sexp port);
#if SEXP_USE_FOLD_CASE_SYMS

10
sexp.c
View file

@ -1407,6 +1407,16 @@ sexp sexp_make_output_port (sexp ctx, FILE* out, sexp name) {
return p;
}
sexp sexp_make_non_null_input_port (sexp ctx, FILE* in, sexp name) {
if (!in) return sexp_user_exception(ctx, SEXP_FALSE, "null input-port", name);
return sexp_make_input_port(ctx, in, name);
}
sexp sexp_make_non_null_output_port (sexp ctx, FILE* out, sexp name) {
if (!out) return sexp_user_exception(ctx, SEXP_FALSE, "null output-port", name);
return sexp_make_output_port(ctx, out, name);
}
sexp sexp_port_binaryp_op (sexp ctx, sexp self, sexp_sint_t n, sexp port) {
sexp_assert_type(ctx, sexp_portp, SEXP_IPORT, port);
return sexp_make_boolean(sexp_port_binaryp(port));

View file

@ -393,9 +393,9 @@
((string-type? base)
(cat "sexp_c_string(ctx, " val ", -1)"))
((eq? 'input-port base)
(cat "sexp_make_input_port(ctx, " val ", SEXP_FALSE)"))
(cat "sexp_make_non_null_input_port(ctx, " val ", SEXP_FALSE)"))
((eq? 'output-port base)
(cat "sexp_make_output_port(ctx, " val ", SEXP_FALSE)"))
(cat "sexp_make_non_null_output_port(ctx, " val ", SEXP_FALSE)"))
(else
(let ((ctype (assq base *types*))
(void*? (void-pointer-type? type)))