[Rd] Pointer ownership with GECreateDevDesc/GEDestroyDevDesc

Ritch Melton skyguy94 at gmail.com
Fri Sep 19 17:37:30 CEST 2014


According to the "R Internals" document, for a custom device, I should
create a pDevDesc structure that gets passed to GECreateDevDesc.

..elided...
pDevDesc dev;
/* Allocate and initialize the device driver data */
if (!(dev = (pDevDesc) calloc(1, sizeof(DevDesc)))) return 0;
/* or error() */
/* set up device driver or free ’dev’ and error() */
gdd = GEcreateDevDesc(dev); GEaddDevice2(gdd, "dev_name");
...elided...

which indicates to me that the calling code owns the pDevDesc structure and
should be responsible for freeing it.
However, in GEdestroyDevDesc, that particular code calls free(dd->dev),
freeing the pointer.

In my case, I have a device implemented and created in a language that is
using a different allocator. The pDevDesc I pass in is not owned by R and
causes a crash on free with "dev.off()".

I thought I could mitigate the issue, by making a call to the allocator R
is using via an exported R function, such as R_alloc, but I did not see
such a function available to me.

I would like to know if I should be creating the pDevDesc via an imported
alloc routine somehow? or is there a way to prevent this code from freeing
the structure I pass in.

Blue Skies,
Ritch

	[[alternative HTML version deleted]]



More information about the R-devel mailing list