[前][次][番号順一覧][スレッド一覧]

ruby-changes:22208

From: naruse <ko1@a...>
Date: Tue, 10 Jan 2012 12:49:23 +0900 (JST)
Subject: [ruby-changes:22208] naruse:r34257 (trunk): * gc.c (ruby_mimmalloc): defined for objects need not rb_objspace,

naruse	2012-01-10 12:49:10 +0900 (Tue, 10 Jan 2012)

  New Revision: 34257

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34257

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/ext/dl/cfunc.c
    trunk/ext/syslog/syslog.c
    trunk/gc.c
    trunk/internal.h
    trunk/vm.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 34256)
+++ ChangeLog	(revision 34257)
@@ -1,3 +1,19 @@
+Tue Jan 10 12:44:11 2012  NARUSE, Yui  <naruse@r...>
+
+	* 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@m...>
 
 	* ext/readline/readline.c (readline_attempted_completion_function):
Index: gc.c
===================================================================
--- gc.c	(revision 34256)
+++ gc.c	(revision 34257)
@@ -941,6 +941,24 @@
 }
 
 
+/* 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
Index: ext/syslog/syslog.c
===================================================================
--- ext/syslog/syslog.c	(revision 34256)
+++ ext/syslog/syslog.c	(revision 34257)
@@ -49,7 +49,7 @@
 
     closelog();
 
-    free((void *)syslog_ident);
+    xfree((void *)syslog_ident);
     syslog_ident = NULL;
     syslog_options = syslog_facility = syslog_mask = -1;
     syslog_opened = 0;
Index: ext/dl/cfunc.c
===================================================================
--- ext/dl/cfunc.c	(revision 34256)
+++ ext/dl/cfunc.c	(revision 34257)
@@ -2,7 +2,8 @@
  * $Id$
  */
 
-#include <ruby.h>
+#include <ruby/ruby.h>
+#include <ruby/util.h>
 #include <errno.h>
 #include "dl.h"
 
Index: internal.h
===================================================================
--- internal.h	(revision 34256)
+++ internal.h	(revision 34257)
@@ -93,6 +93,7 @@
 
 /* gc.c */
 void Init_heap(void);
+void *ruby_mimmalloc(size_t size);
 
 /* inits.c */
 void rb_call_inits(void);
Index: vm.c
===================================================================
--- vm.c	(revision 34256)
+++ vm.c	(revision 34257)
@@ -1620,7 +1620,7 @@
 #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 @@
 		free(th->altstack);
 	    }
 #endif
-	    free(ptr);
+	    ruby_xfree(ptr);
 	}
         if (ruby_current_thread == th)
             ruby_current_thread = NULL;
@@ -2198,8 +2198,8 @@
 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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]