Maybe-null patch for strings in chibi-ffi from Lorenzo.

This commit is contained in:
Alex Shinn 2012-11-10 20:56:27 +09:00
parent 122d8b8a00
commit 41c80d06ca
2 changed files with 11 additions and 3 deletions

View file

@ -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)

View file

@ -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