Displaying 2 results from an estimated 2 matches for "xmlfreenode".
2015 Nov 23
4
Custom C finalizers for .Call
...hese are rare. A lot of C code in packages might
become safer and cleaner if authors would have an option to let this
be automated.
The most general feature would a hook for adding custom C functions to
the .Call exit, similar to on.exit() in R:
xmlNodePtr *node = xmlNewNode(...);
Rf_on_exit(xmlFreeNode, node);
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(...);
Rf_on_exit(EVP_PKEY_CTX_free, ctx);
SEXP out = PROTECT(allocVector(...));
Rf_on_exit(UNPROTECT, 1);
I don't know R's internals well enough to estimate if something like
this would be possible. I did put together a simple C example...
2015 Nov 25
0
Custom C finalizers for .Call
...mlNodePtr *node;
EVP_PKEY_CTX *ctx;
} my_context_t;
// define how to dispose of all things you care about correctly
static void context_fin(SEXP what) {
my_context_t *c = (my_context_t*) EXTPTR_PTR(what);
if (!c) return;
if (c->ctx) EVP_PKEY_CTX_free(c->ctx);
if (c->node) xmlFreeNode(c->node);
}
[...]
// allocate the context and tell R to manage its protection and finalization
// (you could write a macro to make this one-liner)
my_context_t* c = (my_context_t*) R_Calloc(1, my_context_t);
SEXP res = PROTECT(R_MakeExternalPtr(c, R_NilValue, R_NilValue));
R_RegisterCFinalizer(...