Advertisement
Guest User

Untitled

a guest
Mar 17th, 2022
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. --- src/6model/reprs/CStr.c
  2. +++ src/6model/reprs/CStr.c
  3. @@ -33,7 +33,11 @@ static void copy_to(MVMThreadContext *tc, MVMSTable *st, void *src, MVMObject *d
  4. static void set_str(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data, MVMString *value) {
  5. MVMCStrBody *body = (MVMCStrBody *)data;
  6. MVM_ASSIGN_REF(tc, &(root->header), body->orig, value);
  7. +#ifdef MVM_USE_MIMALLOC
  8. + body->cstr = MVM_string_utf8_encode_C_string_malloc(tc, value);
  9. +#else
  10. body->cstr = MVM_string_utf8_encode_C_string(tc, value);
  11. +#endif
  12. }
  13.  
  14. static MVMString * get_str(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data) {
  15. @@ -64,7 +68,11 @@ static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorkli
  16. static void gc_free(MVMThreadContext *tc, MVMObject *obj) {
  17. MVMCStr *cstr = (MVMCStr *)obj;
  18. if (obj && cstr->body.cstr)
  19. +#ifdef MVM_USE_MIMALLOC
  20. free(cstr->body.cstr);
  21. +#else
  22. + MVM_free(cstr->body.cstr);
  23. +#endif
  24. }
  25.  
  26. static void deserialize_stable_size(MVMThreadContext *tc, MVMSTable *st, MVMSerializationReader *reader) {
  27. @@ -76,18 +84,13 @@ static void deserialize(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, vo
  28. MVMCStrBody *body = (MVMCStrBody *)data;
  29. MVM_ASSIGN_REF(tc, &(root->header), body->orig, orig);
  30.  
  31. - char *mvm_allocated_cstr = MVM_string_utf8_encode_C_string(tc, orig);
  32. + char *cstr;
  33. #ifdef MVM_USE_MIMALLOC
  34. - /* Safe because MVM_string_utf8_encode_C_string is guaranteed to return a null-terminated string */
  35. - size_t cstr_len = strlen(mvm_allocated_cstr) + 1;
  36. - char *libc_allocated_cstr = malloc(cstr_len);
  37. - memcpy(libc_allocated_cstr, mvm_allocated_cstr, cstr_len);
  38. - MVM_free(mvm_allocated_cstr);
  39. -
  40. - body->cstr = libc_allocated_cstr;
  41. + cstr = MVM_string_utf8_encode_C_string_malloc(tc, orig);
  42. #else
  43. - body->cstr = mvm_allocated_cstr;
  44. + cstr = MVM_string_utf8_encode_C_string(tc, orig);
  45. #endif
  46. + body->cstr = cstr;
  47. }
  48.  
  49. static void serialize(MVMThreadContext *tc, MVMSTable *st, void *data, MVMSerializationWriter *writer) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement