3 ms·
There is no xmalloc in the libc.
by mrud 10y ago
There 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.