| 281 | } |
| 282 | |
| 283 | void *cbm_realloc(cbm_mem_class_t cls, void *block, size_t bytes) { |
| 284 | if (!block) { |
| 285 | return cbm_alloc(cls, bytes); |
| 286 | } |
| 287 | check_owned(block, "realloc"); |
| 288 | /* Measure BEFORE: after realloc the old block is gone and its size is |
| 289 | * unknowable, so the decrement has to be computed first. */ |
| 290 | size_t old = charge_size(block, 0); |
| 291 | MEMEV_HINT(cls); |
| 292 | CBM_MEMEV_BACKING(1); |
| 293 | void *next = CBM_BACKING_REALLOC(block, bytes ? bytes : CBM_ALLOC_ONE); |
| 294 | CBM_MEMEV_BACKING(-1); |
| 295 | MEMEV_REALLOCATED(block, next, bytes); |
| 296 | if (!next) { |
| 297 | return NULL; /* original intact and still charged - correct */ |
| 298 | } |
| 299 | class_sub(cls, old, 0); |
| 300 | class_add(cls, charge_size(next, bytes), 0); |
| 301 | return next; |
| 302 | } |
| 303 | |
| 304 | char *cbm_mem_strdup(cbm_mem_class_t cls, const char *s) { |
| 305 | if (!s) { |