mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-14 08:17:35 +02:00
Issue #81 - Fixing string->utf8
This commit is contained in:
parent
0951be3d2b
commit
a7de0994a5
1 changed files with 24 additions and 6 deletions
22
runtime.c
22
runtime.c
|
@ -2673,7 +2673,6 @@ object Cyc_string2utf8(void *data, object cont, object str, object start,
|
|||
{
|
||||
int s, e;
|
||||
int len;
|
||||
make_empty_bytevector(result);
|
||||
|
||||
Cyc_check_str(data, str);
|
||||
Cyc_check_num(data, start);
|
||||
|
@ -2692,12 +2691,31 @@ object Cyc_string2utf8(void *data, object cont, object str, object start,
|
|||
}
|
||||
|
||||
// Fast path
|
||||
if (string_num_cp(str) == string_len(str)) { // TODO: disable for testing purposes
|
||||
if (string_num_cp(str) == string_len(str)) {
|
||||
if (len >= MAX_STACK_OBJ) {
|
||||
int heap_grown;
|
||||
object bv = gc_alloc(((gc_thread_data *)data)->heap,
|
||||
sizeof(bytevector_type) + len,
|
||||
boolean_f, // OK to populate manually over here
|
||||
(gc_thread_data *)data,
|
||||
&heap_grown);
|
||||
((bytevector) bv)->hdr.mark = ((gc_thread_data *)data)->gc_alloc_color;
|
||||
((bytevector) bv)->hdr.grayed = 0;
|
||||
((bytevector) bv)->tag = bytevector_tag;
|
||||
((bytevector) bv)->len = len;
|
||||
((bytevector) bv)->data = (char *)(((char *)bv) + sizeof(bytevector_type));
|
||||
memcpy(&(((bytevector) bv)->data[0]), &(string_str(str))[s], len);
|
||||
_return_closcall1(data, cont, bv);
|
||||
} else {
|
||||
make_empty_bytevector(result);
|
||||
result.len = len;
|
||||
result.data = alloca(sizeof(char) * len);
|
||||
memcpy(&result.data[0], &(string_str(str))[s], len);
|
||||
_return_closcall1(data, cont, &result);
|
||||
}
|
||||
} else {
|
||||
// TODO: if len > MAX_STACK_OBJ
|
||||
make_empty_bytevector(result);
|
||||
const char *tmp = string_str(str);
|
||||
char_type codepoint;
|
||||
uint32_t state = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue