From 41c80d06caa07e3f691546543ab3019c632d3c3f Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sat, 10 Nov 2012 20:56:27 +0900 Subject: [PATCH] Maybe-null patch for strings in chibi-ffi from Lorenzo. --- include/chibi/sexp.h | 1 + tools/chibi-ffi | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/chibi/sexp.h b/include/chibi/sexp.h index 33742a26..1526656e 100755 --- a/include/chibi/sexp.h +++ b/include/chibi/sexp.h @@ -869,6 +869,7 @@ SEXP_API sexp sexp_make_unsigned_integer(sexp ctx, sexp_luint_t x); #define sexp_string_offset(x) (sexp_field(x, string, SEXP_STRING, offset)) #define sexp_string_data(x) (sexp_bytes_data(sexp_string_bytes(x))+sexp_string_offset(x)) #endif +#define sexp_string_maybe_null_data(x) (sexp_not(x) ? NULL : sexp_string_data(x)) #if SEXP_USE_PACKED_STRINGS #define sexp_string_to_bytes(ctx, x) ((x)->tag = SEXP_BYTES, x) diff --git a/tools/chibi-ffi b/tools/chibi-ffi index b9367bf2..7ba7f2bb 100755 --- a/tools/chibi-ffi +++ b/tools/chibi-ffi @@ -649,7 +649,10 @@ ((eq? base 'env-string) (cat "sexp_concat_env_string(" val ")")) ((string-type? base) - (cat "sexp_string_data(" val ")")) + (cat (if (type-null? type) + "sexp_string_maybe_null_data" + "sexp_string_data") + "(" val ")")) ((eq? base 'port-or-fileno) (cat "(sexp_portp(" val ") ? sexp_port_fileno(" val ")" " : sexp_fileno_fd(" val "))")) @@ -714,8 +717,12 @@ ")) && sexp_stringp(sexp_cdr(" arg ")))")) ((eq? base 'fileno) (cat "(sexp_filenop(" arg ") || sexp_fixnump(" arg "))")) - ((or (int-type? base) (float-type? base) - (string-type? base) (port-type? base)) + ((string-type? base) + (cat + (if (type-null? type) "(" "") + (type-predicate type) "(" arg ")" + (lambda () (if (type-null? type) (cat " || sexp_not(" arg "))"))))) + ((or (int-type? base) (float-type? base) (port-type? base)) (cat (type-predicate type) "(" arg ")")) ((or (lookup-type base) (void-pointer-type? type)) (cat