diff -r 08539b8273fa -r 4fbfac557df8 src/cx/allocator.h --- a/src/cx/allocator.h Mon Apr 18 16:56:29 2022 +0200 +++ b/src/cx/allocator.h Mon Apr 18 17:26:21 2022 +0200 @@ -117,6 +117,57 @@ typedef void (*cx_destructor_func)(void *memory) __attribute__((__nonnull__)); /** + * Function pointer type for destructor functions. + * + * A destructor function deallocates possible contents and MAY free the memory + * pointed to by \p memory. Read the documentation of the respective function + * pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in that + * particular implementation. + * + * @param data an optional pointer to custom data + * @param memory a pointer to the object to destruct + */ +typedef void (*cx_destructor_func2)( + void *data, + void *memory +) __attribute__((__nonnull__(2))); + +/** + * Structure holding an advanced destructor function and the desired payload. + * Invocations of func should use data as first argument. + */ +typedef struct { + /** + * A pointer to the data that SHALL be used to invoke func. + */ + void *data; + /** + * A pointer to the function to invoke. + */ + cx_destructor_func2 func; +} cx_advanced_destructor; + +/** + * Specifies the type of destructor to use. + */ +enum cx_destructor_type { + /** + * Do not use a destructor function. + */ + CX_DESTRUCTOR_NONE, + /** + * Use a simple destructor. + * @see cx_destructor_func + */ + CX_DESTRUCTOR_SIMPLE, + /** + * Use an advanced destructor. + * @see cx_advanced_destructor + */ + CX_DESTRUCTOR_ADVANCED +}; + +/** * Allocate \p n bytes of memory. * * @param allocator the allocator