MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / das_context_reallocate

Function das_context_reallocate

src/misc/daScriptC.cpp:1050–1070  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1048}
1049
1050void * das_context_reallocate ( das_context * context, void * ptr, uint32_t old_size, uint32_t new_size ) {
1051 // The runtime allocator's reallocate path doesn't handle new_size==0 — it
1052 // routes through allocate(0) which returns null, then DAS_VERIFY fires.
1053 // Implement realloc-to-zero here as free + return NULL so the C-side
1054 // contract (free the block and return NULL) holds independent of which
1055 // heap impl the context is using.
1056 if ( !new_size ) {
1057 if ( ptr ) {
1058 // Mirror the das_context_free guard — old_size must match the
1059 // allocation, and 0 with non-null is a caller bug that some heap
1060 // impls assert on.
1061 if ( !old_size ) {
1062 ((Context *)context)->throw_error("das_context_reallocate: old_size must be non-zero when ptr is non-null");
1063 return nullptr;
1064 }
1065 ((Context *)context)->free((char *)ptr, old_size, nullptr);
1066 }
1067 return nullptr;
1068 }
1069 return ((Context *)context)->reallocate((char *)ptr, old_size, new_size, nullptr);
1070}
1071
1072void das_context_free ( das_context * context, void * ptr, uint32_t size ) {
1073 if ( !ptr ) return;

Callers 2

Calls 3

throw_errorMethod · 0.80
freeMethod · 0.45
reallocateMethod · 0.45

Tested by

no test coverage detected