diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-07-02 18:46:50 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-07-02 18:46:50 -0700 |
commit | 4fd7bddd0e7fda8c5e476cba5e7882dae86fd59d (patch) | |
tree | 2e694e379a3b054768b89f5f4a6129f8f1fbf1a7 /lib.c | |
parent | db8aeddade93adde5c9e4e14888fb53a64bdc377 (diff) | |
download | txr-4fd7bddd0e7fda8c5e476cba5e7882dae86fd59d.tar.gz txr-4fd7bddd0e7fda8c5e476cba5e7882dae86fd59d.tar.bz2 txr-4fd7bddd0e7fda8c5e476cba5e7882dae86fd59d.zip |
ffi: relaxation in cptr put semantics.
For convenience, we allow a cptr to be converted to foreign
representation even if its tag doesn't match the FFI type
being used for the conversion. This is allowed only in the
case that the cptr is a null pointer, and its tag is nil.
* lib.c (cptr_handle): Defeat the type check if the pointer
is null, and its tag is nil. Thus, the FFI variable cptr-null
will conveniently convert to any cptr type in the ffi_cptr_put
operation and others.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -7571,12 +7571,17 @@ val int_cptr(val cptr) mem_t *cptr_handle(val cptr, val type_sym, val self) { - if (type(cptr) != CPTR) + if (type(cptr) != CPTR) { uw_throwf(error_s, lit("~a: ~s isn't a cptr"), self, cptr, nao); - if (type_sym && cptr->co.cls != type_sym) - uw_throwf(error_s, lit("~a: cptr ~s isn't of type ~s"), self, cptr, - type_sym, nao); - return cptr->co.handle; + } else { + mem_t *ptr = cptr->co.handle; + + if (type_sym && cptr->co.cls != type_sym && (ptr != 0 || cptr->co.cls)) + uw_throwf(error_s, lit("~a: cptr ~s isn't of type ~s"), self, cptr, + type_sym, nao); + + return ptr; + } } mem_t *cptr_get(val cptr) |