summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-10 03:49:10 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-10 03:49:10 +0000
commit56dc6f5acc944e06420614b6c2a475376a887d95 (patch)
treeb2b77a562fceac69b005e0cfcb902c3adb9f77b6
parent107b713438a54770d68be98f3c385e77aecd056e (diff)
* gc.c (ruby_mimmalloc): defined for objects need not rb_objspace,
but should return pointer suitable for ruby_xfree; main vm and main thread. patched by Sokolov Yura. https://github.com/ruby/ruby/pull/79 * internal.h: ditto. * vm.c (Init_BareVM): use ruby_mimmalloc. * ext/dl/cfunc.c: #include <ruby/util.h>. * ext/syslog/syslog.c: use xfree because it is allocated by ruby_strdup. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34257 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog16
-rw-r--r--ext/dl/cfunc.c3
-rw-r--r--ext/syslog/syslog.c2
-rw-r--r--gc.c18
-rw-r--r--internal.h1
-rw-r--r--vm.c8
6 files changed, 42 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index aa1c25c..9d2f7eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+Tue Jan 10 12:44:11 2012 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * gc.c (ruby_mimmalloc): defined for objects need not rb_objspace,
+ but should return pointer suitable for ruby_xfree;
+ main vm and main thread.
+ patched by Sokolov Yura. https://github.com/ruby/ruby/pull/79
+
+ * internal.h: ditto.
+
+ * vm.c (Init_BareVM): use ruby_mimmalloc.
+
+ * ext/dl/cfunc.c: #include <ruby/util.h>.
+
+ * ext/syslog/syslog.c: use xfree because it is allocated by
+ ruby_strdup.
+
Tue Jan 10 12:13:56 2012 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* ext/readline/readline.c (readline_attempted_completion_function):
diff --git a/ext/dl/cfunc.c b/ext/dl/cfunc.c
index 66aebf2..70cf6c4 100644
--- a/ext/dl/cfunc.c
+++ b/ext/dl/cfunc.c
@@ -2,7 +2,8 @@
* $Id$
*/
-#include <ruby.h>
+#include <ruby/ruby.h>
+#include <ruby/util.h>
#include <errno.h>
#include "dl.h"
diff --git a/ext/syslog/syslog.c b/ext/syslog/syslog.c
index 02f36aa..f4c45df 100644
--- a/ext/syslog/syslog.c
+++ b/ext/syslog/syslog.c
@@ -49,7 +49,7 @@ static VALUE mSyslog_close(VALUE self)
closelog();
- free((void *)syslog_ident);
+ xfree((void *)syslog_ident);
syslog_ident = NULL;
syslog_options = syslog_facility = syslog_mask = -1;
syslog_opened = 0;
diff --git a/gc.c b/gc.c
index e6a7fcc..696fb7a 100644
--- a/gc.c
+++ b/gc.c
@@ -941,6 +941,24 @@ ruby_xfree(void *x)
}
+/* Mimic ruby_xmalloc, but need not rb_objspace.
+ * should return pointer suitable for ruby_xfree
+ */
+void *
+ruby_mimmalloc(size_t size)
+{
+ void *mem;
+#if CALC_EXACT_MALLOC_SIZE
+ size += sizeof(size_t);
+#endif
+ mem = malloc(size);
+#if CALC_EXACT_MALLOC_SIZE
+ ((size_t *)mem)[0] = size;
+ mem = (size_t *)mem + 1;
+#endif
+ return mem;
+}
+
/*
* call-seq:
* GC.enable -> true or false
diff --git a/internal.h b/internal.h
index cf3fec2..4c476ec 100644
--- a/internal.h
+++ b/internal.h
@@ -93,6 +93,7 @@ void Init_File(void);
/* gc.c */
void Init_heap(void);
+void *ruby_mimmalloc(size_t size);
/* inits.c */
void rb_call_inits(void);
diff --git a/vm.c b/vm.c
index f029d45..90f7e3e 100644
--- a/vm.c
+++ b/vm.c
@@ -1620,7 +1620,7 @@ ruby_vm_destruct(rb_vm_t *vm)
#endif
ruby_vm_run_at_exit_hooks(vm);
rb_vm_gvl_destroy(vm);
- free(vm);
+ ruby_xfree(vm);
ruby_current_vm = 0;
}
RUBY_FREE_LEAVE("vm");
@@ -1795,7 +1795,7 @@ thread_free(void *ptr)
free(th->altstack);
}
#endif
- free(ptr);
+ ruby_xfree(ptr);
}
if (ruby_current_thread == th)
ruby_current_thread = NULL;
@@ -2198,8 +2198,8 @@ void
Init_BareVM(void)
{
/* VM bootstrap: phase 1 */
- rb_vm_t * vm = malloc(sizeof(*vm));
- rb_thread_t * th = malloc(sizeof(*th));
+ rb_vm_t * vm = ruby_mimmalloc(sizeof(*vm));
+ rb_thread_t * th = ruby_mimmalloc(sizeof(*th));
if (!vm || !th) {
fprintf(stderr, "[FATAL] failed to allocate memory\n");
exit(EXIT_FAILURE);