Skip to main content

xmlMemSetup

Function xmlMemSetup 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn xmlMemSetup( freeFunc: Option<xmlFreeFunc>, mallocFunc: Option<xmlMallocFunc>, reallocFunc: Option<xmlReallocFunc>, strdupFunc: Option<xmlStrdupFunc>, ) -> c_int
Expand description

Set custom memory allocator functions (upstream xmlmemory.h).

§UPSTREAM-PARITY

int xmlMemSetup(xmlFreeFunc freeFunc,
                xmlMallocFunc mallocFunc,
                xmlReallocFunc reallocFunc,
                xmlStrdupFunc strdupFunc);

Returns -1 if any function is NULL (upstream xmlmemory.c: “Returns 0 on success”); otherwise assigns the five exported allocator variables (xmlFree, xmlMalloc, xmlMallocAtomic = mallocFunc, xmlRealloc, xmlMemStrdup) and returns 0. The exported variables are the single source of truth: every internal allocation reads them through the *Impl indirection, so this call — or a direct xmlMalloc = custom assignment — re-routes all allocations immediately (R-000176 fix).

§SAFETY

  • All function pointers must be valid (non-null) and thread-safe
  • The functions must follow the C malloc/realloc/free/strdup contract
  • Once set, the functions remain in effect until the next xmlMemSetup call
  • The caller is responsible for ensuring the functions remain valid for the entire time they are installed
  • Must not race with concurrent allocation (upstream ordering contract: “This has to be called before any other libxml routines !”)