3 ms·
So a from a quick googling it looks like xfree()[1] is a ruby specific thing, and should be used internally for everything allocated by ruby. It also looks lik
by simcop2387 10y ago
So a from a quick googling it looks like xfree()[1] is a ruby specific thing, and should be used internally for everything allocated by ruby. It also looks like it's got the same signature as the function created for this so that should work there too. [2]
[1] http://clalance.blogspot.com/2011/01/writing-ruby-extensions-in-c-part-12.html http://clalance.blogspot.com/2011/01/writing-ruby-extensions...
[2] http://inferior-products.com/docs/userdocs/ruby19/html/d8/d16/gc_8c.html#a0bffec5b2cc004adcebb6802e7620387 http://inferior-products.com/docs/userdocs/ruby19/html/d8/d1...
- busterarm 10y ago...Are you sure? I was pretty sure that it gets it from the same place as xmalloc...wouldn't that be in libc?
- mrud 10y agoThere is no xmalloc in the libc.
- busterarm 10y agoOkay, interesting. I guess I've seen it before, so I didn't think it was Ruby-specific, but I also haven't had to do that kind of programming in a very super long time. Publib then? I'm finding this when I search: http://man.cx/xfree(3) http://man.cx/xfree(3) http://man.cx/publib(3) http://man.cx/publib(3) Also, are you sure? I see xmalloc in glibc all over the internet...
- kristianp 10y agoedit: actually xmalloc and xfree are defined as #define xmalloc ruby_xmalloc #define xfree ruby_xfree
- busterarm 10y agoThat's actually fascinating. I wonder if anyone has background on this...any comments I see are in Japanese.
- eudox 10y agoReplacing malloc/calloc/free etc an application-specific xmalloc/xcalloc/xfree is seemingly a fairly common pattern. There's one example in libiberty[0] (-liberty, get it?) where, for instance, the return value of malloc is checked for NULL and the program terminates if so. [0]: http://www.delorie.com/gnu/docs/gcc/libiberty_5.html http://www.delorie.com/gnu/docs/gcc/libiberty_5.html
- makomk 10y agoIt's fairly common to define malloc and free wrappers called xmalloc and xfree. The usual idiomatic thing to do is to have xmalloc check the return value of malloc and terminate the program if it ever fails, though this is traditionally done in application code rather than a library. I doubt libc would ever add an xmalloc function because it'd break all the code that defined its own xmalloc.