diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e0e2078..2644e7e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Bug Fixes -- Fixed `utf8->string`, `string->utf8`, `list->vector`, and `list->string` to use the heap to allocate objects that exceed the maximum size for objects on the stack. +- Fixed `utf8->string`, `string->utf8`, `bytevector-copy`, `list->vector`, and `list->string` to use the heap to allocate objects that exceed the maximum size for objects on the stack. ## 0.7.1 - December 21, 2017 diff --git a/runtime.c b/runtime.c index 494b9c35..c037be3b 100644 --- a/runtime.c +++ b/runtime.c @@ -2610,7 +2610,6 @@ object Cyc_bytevector_copy(void *data, object cont, object bv, object start, { int s, e; int len; - make_empty_bytevector(result); Cyc_check_bvec(data, bv); Cyc_check_num(data, start); @@ -2628,10 +2627,27 @@ object Cyc_bytevector_copy(void *data, object cont, object bv, object start, Cyc_rt_raise2(data, "bytevector-copy - invalid end", end); } - result.len = len; - result.data = alloca(sizeof(char) * len); - memcpy(&result.data[0], &(((bytevector) bv)->data)[s], len); - _return_closcall1(data, cont, &result); + if (len >= MAX_STACK_OBJ) { + int heap_grown; + object result = 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) result)->hdr.mark = ((gc_thread_data *)data)->gc_alloc_color; + ((bytevector) result)->hdr.grayed = 0; + ((bytevector) result)->tag = bytevector_tag; + ((bytevector) result)->len = len; + ((bytevector) result)->data = (char *)(((char *)result) + sizeof(bytevector_type)); + memcpy(&(((bytevector) result)->data[0]), &(((bytevector) bv)->data)[s], len); + _return_closcall1(data, cont, result); + } else { + make_empty_bytevector(result); + result.len = len; + result.data = alloca(sizeof(char) * len); + memcpy(&result.data[0], &(((bytevector) bv)->data)[s], len); + _return_closcall1(data, cont, &result); + } } object Cyc_utf82string(void *data, object cont, object bv, object start,