Previous: system memory gcalloc, Up: system memory [Contents][Index]
realloc()To allocate and reallocate memory using a clean handler with a guarded function, we can do:
cce_location_t L[1];
cce_clean_handler_t P_H[1];
if (cce_location(L)) {
cce_run_catch_handlers_final(L);
} else {
void * P = cce_sys_calloc_guarded(L, P_H, 4, 1024);
P = cce_sys_realloc_guarded(L, P_H, P, 16 * 1024);
/* Do something with P. */
cce_run_body_handlers(L);
}
while to use an error handler we can do:
cce_location_t L[1];
cce_error_handler_t P_H[1];
if (cce_location(L)) {
cce_run_catch_handlers_final(L);
} else {
void * P = cce_sys_calloc_guarded(L, P_H, 4, 1024);
P = cce_sys_realloc_guarded(L, P_H, P, 16 * 1024);
/* Do something with P. */
cce_run_body_handlers(L);
}
Like cce_sys_realloc(), but register the resulting pointer in the handler referenced by
P_H. The handler is updated to reference the new memory pointer. If, upon entering this
function, the handler P_H does not reference the pointer old_P: raise an exception by
performing a non–local exit to L, with condition object of type
cce_condition_invalid_argument_t.
This preprocessor macro uses _Generic to dispatch the call according to the type of the
pointer P_H; if the type is:
cce_clean_handler_tThe macro expands into a call to cce_sys_realloc_guarded_clean().
cce_error_handler_tThe macro expands into a call to cce_sys_realloc_guarded_error().
Previous: system memory gcalloc, Up: system memory [Contents][Index]
This document describes version 0.9.0-devel.3 of CCExceptions.