Changed AllocStringInstance to accept data and length.

This commit is contained in:
Alexander Gorshenev
2016-12-01 16:24:08 +03:00
committed by alexander-gorshenev
parent d0cd28fe5a
commit 0e7b13027e
3 changed files with 4 additions and 5 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ ArrayHeader* setupArgs(int argc, char** argv) {
ArrayHeader* args = AllocArrayInstance(theArrayTypeInfo, SCOPE_GLOBAL, argc-1); ArrayHeader* args = AllocArrayInstance(theArrayTypeInfo, SCOPE_GLOBAL, argc-1);
for (int i = 0; i < argc-1; i++) { for (int i = 0; i < argc-1; i++) {
Kotlin_Array_set(args, i, AllocStringInstance( argv[i+1] )); Kotlin_Array_set(args, i, AllocStringInstance( argv[i+1], strlen(argv[i+1]) ));
} }
return args; return args;
+2 -3
View File
@@ -89,12 +89,11 @@ ArrayHeader* AllocArrayInstance(
return ArrayContainer(type_info, elements).GetPlace(); return ArrayContainer(type_info, elements).GetPlace();
} }
ArrayHeader* AllocStringInstance(const char* cstring) { ArrayHeader* AllocStringInstance(const char* data, uint32_t length) {
uint32_t length = strlen(cstring);
ArrayHeader* result = ArrayContainer(theStringTypeInfo, length).GetPlace(); ArrayHeader* result = ArrayContainer(theStringTypeInfo, length).GetPlace();
memcpy( memcpy(
ByteArrayAddressOfElementAt(result, 0), ByteArrayAddressOfElementAt(result, 0),
cstring, data,
length); length);
return result; return result;
} }
+1 -1
View File
@@ -254,7 +254,7 @@ void InitMemory();
ObjHeader* AllocInstance(const TypeInfo* type_info, PlacementHint hint); ObjHeader* AllocInstance(const TypeInfo* type_info, PlacementHint hint);
ArrayHeader* AllocArrayInstance( ArrayHeader* AllocArrayInstance(
const TypeInfo* type_info, PlacementHint hint, uint32_t elements); const TypeInfo* type_info, PlacementHint hint, uint32_t elements);
ArrayHeader* AllocStringInstance(const char* cstring); ArrayHeader* AllocStringInstance(const char* data, uint32_t length);
#ifdef __cplusplus #ifdef __cplusplus
} }