search for: context_fin

Displaying 2 results from an estimated 2 matches for "context_fin".

2015 Nov 25
0
Custom C finalizers for .Call
...ocation* you make. That also seems IMHO less error prone. So to take your example, the way would typically write that code safely is something like typedef struct { xmlNodePtr *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...
2015 Nov 23
4
Custom C finalizers for .Call
WRE explains that R_alloc() can be used to allocate memory which automatically gets released by R at the end of a .C, .Call or .External, even in the case of an error or interruption. This is a really great feature to prevent memory leaks. I was wondering if there is a way to extend this mechanism to allow for automatically running UNPROTECT and custom finalizers at the end of a .Call as well.