Merge branch 'master' of git://factorcode.org/git/factor

db4
Slava Pestov 2008-02-04 16:20:34 -06:00
commit b7f1e84eef
4 changed files with 13 additions and 19 deletions

View File

@ -255,7 +255,7 @@ M: wrapper '
emit-seq ; emit-seq ;
: pack-string ( string -- newstr ) : pack-string ( string -- newstr )
dup length 1+ bootstrap-cell align 0 pad-right ; dup length bootstrap-cell align 0 pad-right ;
: emit-string ( string -- ptr ) : emit-string ( string -- ptr )
string type-number object tag-number [ string type-number object tag-number [

View File

@ -13,6 +13,7 @@ void init_signals(void)
void early_init(void) { } void early_init(void) { }
#define SUFFIX ".image" #define SUFFIX ".image"
#define SUFFIX_LEN 6
const char *default_image_path(void) const char *default_image_path(void)
{ {
@ -21,8 +22,14 @@ const char *default_image_path(void)
if(!path) if(!path)
return "factor.image"; return "factor.image";
char *new_path = safe_malloc(PATH_MAX + strlen(SUFFIX) + 1); /* We can't call strlen() here because with gcc 4.1.2 this
memcpy(new_path,path,strlen(path) + 1); causes an internal compiler error. */
strcat(new_path,SUFFIX); int len = 0;
const char *iter = path;
while(*iter) { len++; iter++; }
char *new_path = safe_malloc(PATH_MAX + SUFFIX_LEN + 1);
memcpy(new_path,path,len + 1);
memcpy(new_path + len,SUFFIX,SUFFIX_LEN + 1);
return new_path; return new_path;
} }

View File

@ -463,16 +463,10 @@ F_STRING* allot_string_internal(CELL capacity)
{ {
F_STRING *string = allot_object(STRING_TYPE,string_size(capacity)); F_STRING *string = allot_object(STRING_TYPE,string_size(capacity));
/* 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
char* string for C library calls. */
string->length = tag_fixnum(capacity); string->length = tag_fixnum(capacity);
string->hashcode = F; string->hashcode = F;
string->aux = F; string->aux = F;
set_string_nth(string,capacity,0);
return string; return string;
} }
@ -645,13 +639,6 @@ F_BYTE_ARRAY *allot_c_string(CELL capacity, CELL size)
} \ } \
type *to_##type##_string(F_STRING *s, bool check) \ type *to_##type##_string(F_STRING *s, bool check) \
{ \ { \
if(sizeof(type) == sizeof(char)) \
{ \
if(check && !check_string(s,sizeof(type))) \
general_error(ERROR_C_STRING,tag_object(s),F,NULL); \
return (type*)(s + 1); \
} \
else \
return (type*)(string_to_##type##_alien(s,check) + 1); \ return (type*)(string_to_##type##_alien(s,check) + 1); \
} \ } \
type *unbox_##type##_string(void) \ type *unbox_##type##_string(void) \

View File

@ -11,7 +11,7 @@ INLINE CELL string_capacity(F_STRING* str)
INLINE CELL string_size(CELL size) INLINE CELL string_size(CELL size)
{ {
return sizeof(F_STRING) + size + 1; return sizeof(F_STRING) + size;
} }
DEFINE_UNTAG(F_BYTE_ARRAY,BYTE_ARRAY_TYPE,byte_array) DEFINE_UNTAG(F_BYTE_ARRAY,BYTE_ARRAY_TYPE,byte_array)