From: Matt Birkholz Date: Fri, 19 Aug 2011 01:52:18 +0000 (-0700) Subject: c-peek-cstringp: Return () when the char* is NULL. X-Git-Tag: release-9.2.0~347^2~2^2~6 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=5e4d2456aab0ad7c469afbc16269b2f6c0daeaf9;p=mit-scheme.git c-peek-cstringp: Return () when the char* is NULL. --- diff --git a/src/microcode/pruxffi.c b/src/microcode/pruxffi.c index e3924af2e..a64179e18 100644 --- a/src/microcode/pruxffi.c +++ b/src/microcode/pruxffi.c @@ -173,21 +173,45 @@ DEFINE_PRIMITIVE ("C-PEEK-CSTRING!", Prim_peek_cstring_bang, 2, 2, 0) } DEFINE_PRIMITIVE ("C-PEEK-CSTRINGP", Prim_peek_cstringp, 2, 2, 0) - C_PEEKER (char_pointer_to_string, char *) +{ + /* Follow the pointer at the address ALIEN+OFFSET to a C string. + Copy the C string into the heap and return the new Scheme + string. If the pointer is null, return (). */ + + PRIMITIVE_HEADER (2); + { + char ** ptr = (ALIEN_ADDRESS_LOC (char *)); + if (*ptr == NULL) + { + PRIMITIVE_RETURN (EMPTY_LIST); + } + else + { + PRIMITIVE_RETURN (char_pointer_to_string (*ptr)); + } + } +} DEFINE_PRIMITIVE ("C-PEEK-CSTRINGP!", Prim_peek_cstringp_bang, 2, 2, 0) { /* Follow the pointer at the address ALIEN+OFFSET to a C string. Set ALIEN to the address of the char pointer after ALIEN+OFFSET. Copy the C string into the heap and return the new Scheme - string. */ + string. If the pointer is null, return (). */ PRIMITIVE_HEADER (2); { char ** ptr = (ALIEN_ADDRESS_LOC (char *)); - SCM string = char_pointer_to_string (*ptr); - set_alien_address ((ARG_REF (1)), (ptr + 1)); /* No more aborts! */ - PRIMITIVE_RETURN (string); + if (*ptr == NULL) + { + PRIMITIVE_RETURN (EMPTY_LIST); + } + else + { + SCM string = char_pointer_to_string (*ptr); + set_alien_address ((ARG_REF (1)), (ptr + 1)); /* No more aborts! */ + PRIMITIVE_RETURN (string); + } } }