Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Make ruby workable with CALC_EXACT_MALLOC_SIZE set to 1 #79

Closed
wants to merge 3 commits into from

2 participants

Sokolov Yura NARUSE, Yui
Sokolov Yura

Updated pull request #78

NARUSE, Yui nurse closed this
NARUSE, Yui
Collaborator

Merged in r34257, thanks!

Sandor Szücs szuecs referenced this pull request from a commit in szuecs/ruby
NARUSE, Yui nurse * 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. ruby#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
56dc6f5
Aaron Patterson tenderlove referenced this pull request from a commit in tenderlove/ruby
NARUSE, Yui nurse * 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. ruby#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
fa70656
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 09, 2012
  1. Sokolov Yura

    fix Init_BareVM

    funny-falcon authored
  2. Sokolov Yura

    fix cfunc.c

    funny-falcon authored
  3. Sokolov Yura

    fix syslog.c

    funny-falcon authored
This page is out of date. Refresh to see the latest.
1  ext/dl/cfunc.c
View
@@ -3,6 +3,7 @@
*/
#include <ruby.h>
+#include <ruby/util.h>
#include <errno.h>
#include "dl.h"
2  ext/syslog/syslog.c
View
@@ -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;
17 gc.c
View
@@ -932,6 +932,23 @@ ruby_xfree(void *x)
vm_xfree(&rb_objspace, 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:
1  internal.h
View
@@ -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);
8 vm.c
View
@@ -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);
Something went wrong with that request. Please try again.