| 1048 | } |
| 1049 | |
| 1050 | void * 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 | |
| 1072 | void das_context_free ( das_context * context, void * ptr, uint32_t size ) { |
| 1073 | if ( !ptr ) return; |
no test coverage detected