]> gitweb.factorcode.org Git - factor.git/commitdiff
string.c fix
authorSlava Pestov <slava@factorcode.org>
Thu, 10 Feb 2005 00:58:53 +0000 (00:58 +0000)
committerSlava Pestov <slava@factorcode.org>
Thu, 10 Feb 2005 00:58:53 +0000 (00:58 +0000)
TODO.FACTOR.txt
library/bootstrap/image.factor
native/factor.h
native/run.h
native/string.c
native/string.h

index 47916b3e9145760906913dc5fc76cc8dc99f0133..9733f8c6e5791eedd4c7b93f0d4e19cd1c61fb60 100644 (file)
@@ -33,6 +33,7 @@
 - utf16 string boxing\r
 - slot compile problem\r
 - nulls at the end of utf16 strings\r
+- x86 register decl\r
 \r
 + compiler/ffi:\r
 \r
index b5337eb04fceda82b1fbc041cf465ff8969ac8ab..7f0f21ff48b7740c1dfb06d1c054c5a7c35b9709 100644 (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 )
index c880678c6409398d3bc4ab4775213e3cd1082386..08c7259fab7def3fa46ab91d4755e83e2192f3e6 100644 (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>
index 7331bf5f68f06a199f1977d879302e462f6cd8f3..146135470443a78f4ba0b32c80d0636035ed88e1 100644 (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;
 
index e5a88bd7a590764fcd3a222f64c6728f1d14801c..be8547722b14dca773c8de6bd01b78340db983af 100644 (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;
 }
index 1087193118201879a7f68e9357ef556c328354e0..6f06c7f50e00c6fe6fd328afd4b6867240795b4b 100644 (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)
 {