8000 Make ruby workable with CALC_EXACT_MALLOC_SIZE set to 1 by funny-falcon · Pull Request #79 · ruby/ruby · GitHub
[go: up one dir, main page]

Skip to content

Make ruby workable with CALC_EXACT_MALLOC_SIZE set to 1 #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/dl/cfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

#include <ruby.h>
#include <ruby/util.h>
#include <errno.h>
#include "dl.h"

Expand Down
2 changes: 1 addition & 1 deletion ext/syslog/syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
0