about summary refs log tree commit
path: root/ext/rpatricia/patricia.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-09-02 14:23:09 -0700
committerEric Wong <normalperson@yhbt.net>2010-09-02 14:23:09 -0700
commitb758b29f5842d60933d98c1c292f00f73fedf24b (patch)
tree6ecc1de7e6a947b907fa20f9c4931a7c0954d384 /ext/rpatricia/patricia.c
parent03daddf53a88bf1a3b7890d02577dd8921d70b76 (diff)
downloadrpatricia-b758b29f5842d60933d98c1c292f00f73fedf24b.tar.gz
make allocations go through xcalloc in Ruby
Ruby's xcalloc() has built-in failure handling and will force
GC to run if memory is needed.  Patricia.new will no longer
fail with anything other than NoMemoryError, which rare.
Diffstat (limited to 'ext/rpatricia/patricia.c')
-rw-r--r--ext/rpatricia/patricia.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/ext/rpatricia/patricia.c b/ext/rpatricia/patricia.c
index d211a34..7fc3d27 100644
--- a/ext/rpatricia/patricia.c
+++ b/ext/rpatricia/patricia.c
@@ -31,7 +31,13 @@ static char copyright[] =
 
 #include "patricia.h"
 
-#define Delete free
+#if defined(HAVE_RUBY_XCALLOC)
+#  include <ruby.h>
+#  define calloc xcalloc
+#  define Delete xfree
+#else
+#  define Delete free
+#endif
 
 /* { from prefix.c */