115 * @param memory a pointer to the object to destruct |
115 * @param memory a pointer to the object to destruct |
116 */ |
116 */ |
117 typedef void (*cx_destructor_func)(void *memory) __attribute__((__nonnull__)); |
117 typedef void (*cx_destructor_func)(void *memory) __attribute__((__nonnull__)); |
118 |
118 |
119 /** |
119 /** |
|
120 * Function pointer type for destructor functions. |
|
121 * |
|
122 * A destructor function deallocates possible contents and MAY free the memory |
|
123 * pointed to by \p memory. Read the documentation of the respective function |
|
124 * pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in that |
|
125 * particular implementation. |
|
126 * |
|
127 * @param data an optional pointer to custom data |
|
128 * @param memory a pointer to the object to destruct |
|
129 */ |
|
130 typedef void (*cx_destructor_func2)( |
|
131 void *data, |
|
132 void *memory |
|
133 ) __attribute__((__nonnull__(2))); |
|
134 |
|
135 /** |
|
136 * Structure holding an advanced destructor function and the desired payload. |
|
137 * Invocations of func should use data as first argument. |
|
138 */ |
|
139 typedef struct { |
|
140 /** |
|
141 * A pointer to the data that SHALL be used to invoke func. |
|
142 */ |
|
143 void *data; |
|
144 /** |
|
145 * A pointer to the function to invoke. |
|
146 */ |
|
147 cx_destructor_func2 func; |
|
148 } cx_advanced_destructor; |
|
149 |
|
150 /** |
|
151 * Specifies the type of destructor to use. |
|
152 */ |
|
153 enum cx_destructor_type { |
|
154 /** |
|
155 * Do not use a destructor function. |
|
156 */ |
|
157 CX_DESTRUCTOR_NONE, |
|
158 /** |
|
159 * Use a simple destructor. |
|
160 * @see cx_destructor_func |
|
161 */ |
|
162 CX_DESTRUCTOR_SIMPLE, |
|
163 /** |
|
164 * Use an advanced destructor. |
|
165 * @see cx_advanced_destructor |
|
166 */ |
|
167 CX_DESTRUCTOR_ADVANCED |
|
168 }; |
|
169 |
|
170 /** |
120 * Allocate \p n bytes of memory. |
171 * Allocate \p n bytes of memory. |
121 * |
172 * |
122 * @param allocator the allocator |
173 * @param allocator the allocator |
123 * @param n the number of bytes |
174 * @param n the number of bytes |
124 * @return a pointer to the allocated memory |
175 * @return a pointer to the allocated memory |