Fixes for make-string

This commit is contained in:
Justin Ethier 2017-10-26 21:56:35 +00:00
parent 0bd0eeb7a6
commit 703f863e48
2 changed files with 12 additions and 10 deletions

View file

@ -722,6 +722,7 @@ void Cyc_set_globals_changed(gc_thread_data *thd);
#define Cyc_utf8_encode_char(dest, dest_size, char_value) \ #define Cyc_utf8_encode_char(dest, dest_size, char_value) \
Cyc_utf8_encode(dest, dest_size, &char_value, 1) Cyc_utf8_encode(dest, dest_size, &char_value, 1)
int Cyc_utf8_encode(char *dest, int sz, uint32_t *src, int srcsz);
uint32_t Cyc_utf8_decode(uint32_t* state, uint32_t* codep, uint32_t byte); uint32_t Cyc_utf8_decode(uint32_t* state, uint32_t* codep, uint32_t byte);
int Cyc_utf8_count_code_points(uint8_t* s); int Cyc_utf8_count_code_points(uint8_t* s);
uint32_t Cyc_utf8_validate_stream(uint32_t *state, char *str, size_t len); uint32_t Cyc_utf8_validate_stream(uint32_t *state, char *str, size_t len);

View file

@ -953,9 +953,9 @@
char ch_buf[5]; char ch_buf[5];
Cyc_check_int(data, count); Cyc_check_int(data, count);
char_type c = obj_obj2char(fill); char_type c = obj_obj2char(fill);
Cyc_utf8_encode_char(ch_buf, 5, &c); Cyc_utf8_encode_char(ch_buf, 5, c);
int num_cp = obj_obj2int(count); int num_cp = obj_obj2int(count);
TODO: read encoded ch_buf int len = num_cp * uint32_num_bytes(c); int len = num_cp * strlen(ch_buf);
if (len >= MAX_STACK_OBJ) { if (len >= MAX_STACK_OBJ) {
int heap_grown; int heap_grown;
s = gc_alloc(((gc_thread_data *)data)->heap, s = gc_alloc(((gc_thread_data *)data)->heap,
@ -978,14 +978,15 @@ TODO: read encoded ch_buf int len = num_cp * uint32_num_bytes(c);
((string_type *)s)->num_cp = num_cp; ((string_type *)s)->num_cp = num_cp;
((string_type *)s)->str = alloca(sizeof(char) * (len + 1)); ((string_type *)s)->str = alloca(sizeof(char) * (len + 1));
} }
//if (num_cp == 1) { /* Fast path */ if (0 && num_cp == 1) { /* Fast path */
memset(((string_type *)s)->str, c, len); memset(((string_type *)s)->str, ch_buf[0], len);
//} else { } else {
// int i; char *buf = ((string_type *)s)->str;
// uint32_t* int bi, si, slen = strlen(ch_buf);
// for (i = 0; i < len; i++) { for (bi = 0, si = 0; bi < len; bi++, si++) {
// } buf[bi] = ch_buf[si % slen];
//} }
}
((string_type *)s)->str[len] = '\\0'; ((string_type *)s)->str[len] = '\\0';
return_closcall1(data, k, s); return_closcall1(data, k, s);
") ")