Made the string returned by c_type null-character terminated. Fixes #6.
This is probably the wrong fix; probably I should have fixed read_string so that it did not create null-character terminated strings, but it will do for now. Probably will revisit.
This commit is contained in:
parent
f21f763f94
commit
b720211b7b
6 changed files with 225 additions and 9 deletions
|
|
@ -387,7 +387,7 @@ int main( int argc, char *argv[] ) {
|
|||
L"`(not arg)`: Return`t` only if `arg` is `nil`, else `nil`.",
|
||||
&lisp_not);
|
||||
bind_function( L"oblist", L"`(oblist)`: Return the current symbol bindings, as a map.", &lisp_oblist );
|
||||
bind_function( L"open", L"`(open url read?)`: Open a stream to this `url`. If `read` is present and is non-nil, open it for reading, else writing.", &lisp_open );
|
||||
bind_function( L"open", L"`(open url write?)`: Open a stream to this `url`. If `write?` is present and is non-nil, open it for writing, else reading.", &lisp_open );
|
||||
bind_function( L"or",
|
||||
L"`(or args...)`: Return a logical `or` of all the arguments and return `t` if any is truthy, else `nil`.",
|
||||
&lisp_or);
|
||||
|
|
|
|||
|
|
@ -420,7 +420,7 @@ struct cons_pointer get_default_stream( bool inputp, struct cons_pointer env ) {
|
|||
|
||||
/**
|
||||
* Function: return a stream open on the URL indicated by the first argument;
|
||||
* if a second argument is present and is non-nil, open it for reading. At
|
||||
* if a second argument is present and is non-nil, open it for writing. At
|
||||
* present, further arguments are ignored and there is no mechanism to open
|
||||
* to append, or error if the URL is faulty or indicates an unavailable
|
||||
* resource.
|
||||
|
|
|
|||
|
|
@ -114,11 +114,15 @@ struct cons_pointer dec_ref( struct cons_pointer pointer ) {
|
|||
* @return As a Lisp string, the tag of the object which is at that pointer.
|
||||
*/
|
||||
struct cons_pointer c_type( struct cons_pointer pointer ) {
|
||||
struct cons_pointer result = NIL;
|
||||
struct cons_space_object cell = pointer2cell( pointer );
|
||||
/* Strings read by `read` have the null character termination. This means
|
||||
* that for the same printable string, the hashcode is different from
|
||||
* strings made with NIL termination. The question is which should be
|
||||
* fixed, and actually that's probably strings read by `read`. However,
|
||||
* for now, it was easier to add a null character here. */
|
||||
struct cons_pointer result = make_string( (wchar_t) 0, NIL);
|
||||
struct cons_space_object * cell = &pointer2cell( pointer );
|
||||
|
||||
if ( strncmp( ( char * ) &cell.tag.bytes, VECTORPOINTTAG, TAGLENGTH ) ==
|
||||
0 ) {
|
||||
if ( cell->tag.value == VECTORPOINTTV ) {
|
||||
struct vector_space_object *vec = pointer_to_vso( pointer );
|
||||
|
||||
for ( int i = TAGLENGTH - 1; i >= 0; i-- ) {
|
||||
|
|
@ -127,7 +131,7 @@ struct cons_pointer c_type( struct cons_pointer pointer ) {
|
|||
}
|
||||
} else {
|
||||
for ( int i = TAGLENGTH - 1; i >= 0; i-- ) {
|
||||
result = make_string( ( wchar_t ) cell.tag.bytes[i], result );
|
||||
result = make_string( ( wchar_t ) cell->tag.bytes[i], result );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -333,6 +337,8 @@ struct cons_pointer make_string_like_thing( wint_t c, struct cons_pointer tail,
|
|||
cell->payload.string.cdr = tail;
|
||||
|
||||
cell->payload.string.hash = calculate_hash( c, tail );
|
||||
debug_dump_object( pointer, DEBUG_ALLOC);
|
||||
debug_println( DEBUG_ALLOC);
|
||||
} else {
|
||||
// \todo should throw an exception!
|
||||
debug_printf( DEBUG_ALLOC,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue