Fix set-string-nth GC issue
parent
8dd333cbb5
commit
cef80543ad
28
vm/types.c
28
vm/types.c
|
@ -431,23 +431,30 @@ CELL string_nth(F_STRING* string, CELL index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* allocates memory */
|
||||||
void set_string_nth(F_STRING* string, CELL index, CELL value)
|
void set_string_nth(F_STRING* string, CELL index, CELL value)
|
||||||
{
|
{
|
||||||
bput(SREF(string,index),value & 0xff);
|
bput(SREF(string,index),value & 0xff);
|
||||||
|
|
||||||
|
F_BYTE_ARRAY *aux;
|
||||||
|
|
||||||
if(string->aux == F)
|
if(string->aux == F)
|
||||||
{
|
{
|
||||||
if(value <= 0xff)
|
if(value <= 0xff)
|
||||||
return;
|
return;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string->aux = tag_object(allot_byte_array(
|
REGISTER_UNTAGGED(string);
|
||||||
|
aux = allot_byte_array(
|
||||||
untag_fixnum_fast(string->length)
|
untag_fixnum_fast(string->length)
|
||||||
* sizeof(u16)));
|
* sizeof(u16));
|
||||||
|
UNREGISTER_UNTAGGED(string);
|
||||||
|
string->aux = tag_object(aux);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
aux = untag_object(string->aux);
|
||||||
|
|
||||||
F_BYTE_ARRAY *aux = untag_object(string->aux);
|
|
||||||
cput(BREF(aux,index * sizeof(u16)),value >> 8);
|
cput(BREF(aux,index * sizeof(u16)),value >> 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,10 +470,13 @@ F_STRING* allot_string_internal(CELL capacity)
|
||||||
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);
|
set_string_nth(string,capacity,0);
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* allocates memory */
|
||||||
void fill_string(F_STRING *string, CELL start, CELL capacity, CELL fill)
|
void fill_string(F_STRING *string, CELL start, CELL capacity, CELL fill)
|
||||||
{
|
{
|
||||||
if(fill == 0)
|
if(fill == 0)
|
||||||
|
@ -476,7 +486,11 @@ void fill_string(F_STRING *string, CELL start, CELL capacity, CELL fill)
|
||||||
CELL i;
|
CELL i;
|
||||||
|
|
||||||
for(i = start; i < capacity; i++)
|
for(i = start; i < capacity; i++)
|
||||||
|
{
|
||||||
|
REGISTER_UNTAGGED(string);
|
||||||
set_string_nth(string,i,fill);
|
set_string_nth(string,i,fill);
|
||||||
|
UNREGISTER_UNTAGGED(string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,7 +498,9 @@ void fill_string(F_STRING *string, CELL start, CELL capacity, CELL fill)
|
||||||
F_STRING *allot_string(CELL capacity, CELL fill)
|
F_STRING *allot_string(CELL capacity, CELL fill)
|
||||||
{
|
{
|
||||||
F_STRING* string = allot_string_internal(capacity);
|
F_STRING* string = allot_string_internal(capacity);
|
||||||
|
REGISTER_UNTAGGED(string);
|
||||||
fill_string(string,0,capacity,fill);
|
fill_string(string,0,capacity,fill);
|
||||||
|
UNREGISTER_UNTAGGED(string);
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,7 +522,10 @@ F_STRING* reallot_string(F_STRING* string, CELL capacity, CELL fill)
|
||||||
UNREGISTER_UNTAGGED(string);
|
UNREGISTER_UNTAGGED(string);
|
||||||
|
|
||||||
memcpy(new_string + 1,string + 1,to_copy);
|
memcpy(new_string + 1,string + 1,to_copy);
|
||||||
|
|
||||||
|
REGISTER_UNTAGGED(string);
|
||||||
fill_string(new_string,to_copy,capacity,fill);
|
fill_string(new_string,to_copy,capacity,fill);
|
||||||
|
UNREGISTER_UNTAGGED(string);
|
||||||
|
|
||||||
return new_string;
|
return new_string;
|
||||||
}
|
}
|
||||||
|
@ -529,7 +548,9 @@ DEFINE_PRIMITIVE(resize_string)
|
||||||
CELL i; \
|
CELL i; \
|
||||||
for(i = 0; i < length; i++) \
|
for(i = 0; i < length; i++) \
|
||||||
{ \
|
{ \
|
||||||
|
REGISTER_UNTAGGED(s); \
|
||||||
set_string_nth(s,i,(utype)*string); \
|
set_string_nth(s,i,(utype)*string); \
|
||||||
|
UNREGISTER_UNTAGGED(s); \
|
||||||
string++; \
|
string++; \
|
||||||
} \
|
} \
|
||||||
return s; \
|
return s; \
|
||||||
|
@ -552,6 +573,7 @@ DEFINE_PRIMITIVE(resize_string)
|
||||||
|
|
||||||
MEMORY_TO_STRING(char,u8)
|
MEMORY_TO_STRING(char,u8)
|
||||||
MEMORY_TO_STRING(u16,u16)
|
MEMORY_TO_STRING(u16,u16)
|
||||||
|
// MEMORY_TO_STRING(u32,u32)
|
||||||
|
|
||||||
bool check_string(F_STRING *s, CELL max)
|
bool check_string(F_STRING *s, CELL max)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue