* and an internal wrapper adds the relevant pointers to the gc.
* The latter method is preferred for obvious performance reasons.
*
- * No temporary objects allocated from the pool should be explicitly freed.
- * Calling libxl_free_all() before returning from a public functions will do
- * this. The upshot of this is that almost all calls to libxl_free() are
- * erroneous.
+ * No temporary objects allocated from the pool may be explicitly freed.
+ * Therefore public functions which initialize a libxl_gc MUST call
+ * libxl_free_all() before returning.
*/
#ifndef LIBXL_H
#define LIBXL_H
return 0;
}
-void libxl_free(libxl_gc *gc, void *ptr)
-{
- int i;
-
- if (!ptr)
- return;
-
- /* remove the pointer from the tracked ptrs */
- for (i = 0; i < gc->alloc_maxsize; i++) {
- if (gc->alloc_ptrs[i] == ptr) {
- gc->alloc_ptrs[i] = NULL;
- free(ptr);
- return;
- }
- }
- /* haven't find the pointer, really bad */
- abort();
-}
-
void libxl_free_all(libxl_gc *gc)
{
void *ptr;
/* memory allocation tracking/helpers */
_hidden int libxl_ptr_add(libxl_gc *gc, void *ptr);
-_hidden void libxl_free(libxl_gc *gc, void *ptr);
_hidden void libxl_free_all(libxl_gc *gc);
_hidden void *libxl_zalloc(libxl_gc *gc, int bytes);
_hidden void *libxl_calloc(libxl_gc *gc, size_t nmemb, size_t size);