string.c fix

cvs
Slava Pestov 2005-02-10 00:58:53 +00:00
parent a8c34f50a8
commit 5de9e55e26
6 changed files with 19 additions and 11 deletions

View File

@ -33,6 +33,7 @@
- utf16 string boxing
- slot compile problem
- nulls at the end of utf16 strings
- x86 register decl
+ compiler/ffi:

View File

@ -253,7 +253,7 @@ M: cons ' ( c -- tagged )
string-type >header emit
dup str-length emit
dup hashcode emit-fixnum
pack-string
"\0" cat2 pack-string
align-here ;
M: string ' ( string -- pointer )

View File

@ -27,6 +27,9 @@ CELL cs_bot;
/* raw pointer to callstack top */
DLLEXPORT CELL cs;
/* TAGGED currently executing quotation */
CELL callframe;
#include <errno.h>
#include <fcntl.h>
#include <limits.h>

View File

@ -26,9 +26,6 @@ jmp_buf toplevel;
sigjmp_buf toplevel;
#endif
/* TAGGED currently executing quotation */
CELL callframe;
/* TAGGED pointer to currently executing word */
CELL executing;

View File

@ -4,7 +4,12 @@
F_STRING* allot_string(CELL capacity)
{
F_STRING* string = allot_object(STRING_TYPE,
sizeof(F_STRING) + capacity * CHARS);
sizeof(F_STRING) + (capacity + 1) * CHARS);
/* strings are null-terminated in memory, even though they also
have a length field. The null termination allows us to add
the sizeof(F_STRING) to a Factor string to get a C-style
UTF16 string for C library calls. */
cput(SREF(string,capacity),(uint16_t)'\0');
string->capacity = capacity;
return string;
}

View File

@ -1,11 +1,18 @@
typedef struct {
CELL header;
/* untagged */
/* untagged num of chars */
CELL capacity;
/* tagged */
CELL hashcode;
} F_STRING;
#define SREF(string,index) ((CELL)string + sizeof(F_STRING) + index * CHARS)
#define SSIZE(pointer) align8(sizeof(F_STRING) + \
(((F_STRING*)pointer)->capacity + 1) * CHARS)
INLINE F_STRING* untag_string(CELL tagged)
{
type_check(STRING_TYPE,tagged);
@ -26,11 +33,6 @@ void primitive_memory_to_string(void);
DLLEXPORT BYTE* unbox_c_string(void);
DLLEXPORT uint16_t* unbox_utf16_string(void);
#define SREF(string,index) ((CELL)string + sizeof(F_STRING) + index * CHARS)
#define SSIZE(pointer) align8(sizeof(F_STRING) + \
((F_STRING*)pointer)->capacity * CHARS)
/* untagged & unchecked */
INLINE CELL string_nth(F_STRING* string, CELL index)
{