1.1 --- a/src/cx/allocator.h Mon Apr 18 16:56:29 2022 +0200 1.2 +++ b/src/cx/allocator.h Mon Apr 18 17:26:21 2022 +0200 1.3 @@ -117,6 +117,57 @@ 1.4 typedef void (*cx_destructor_func)(void *memory) __attribute__((__nonnull__)); 1.5 1.6 /** 1.7 + * Function pointer type for destructor functions. 1.8 + * 1.9 + * A destructor function deallocates possible contents and MAY free the memory 1.10 + * pointed to by \p memory. Read the documentation of the respective function 1.11 + * pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in that 1.12 + * particular implementation. 1.13 + * 1.14 + * @param data an optional pointer to custom data 1.15 + * @param memory a pointer to the object to destruct 1.16 + */ 1.17 +typedef void (*cx_destructor_func2)( 1.18 + void *data, 1.19 + void *memory 1.20 +) __attribute__((__nonnull__(2))); 1.21 + 1.22 +/** 1.23 + * Structure holding an advanced destructor function and the desired payload. 1.24 + * Invocations of func should use data as first argument. 1.25 + */ 1.26 +typedef struct { 1.27 + /** 1.28 + * A pointer to the data that SHALL be used to invoke func. 1.29 + */ 1.30 + void *data; 1.31 + /** 1.32 + * A pointer to the function to invoke. 1.33 + */ 1.34 + cx_destructor_func2 func; 1.35 +} cx_advanced_destructor; 1.36 + 1.37 +/** 1.38 + * Specifies the type of destructor to use. 1.39 + */ 1.40 +enum cx_destructor_type { 1.41 + /** 1.42 + * Do not use a destructor function. 1.43 + */ 1.44 + CX_DESTRUCTOR_NONE, 1.45 + /** 1.46 + * Use a simple destructor. 1.47 + * @see cx_destructor_func 1.48 + */ 1.49 + CX_DESTRUCTOR_SIMPLE, 1.50 + /** 1.51 + * Use an advanced destructor. 1.52 + * @see cx_advanced_destructor 1.53 + */ 1.54 + CX_DESTRUCTOR_ADVANCED 1.55 +}; 1.56 + 1.57 +/** 1.58 * Allocate \p n bytes of memory. 1.59 * 1.60 * @param allocator the allocator