Skip to content

Make ruby workable with CALC_EXACT_MALLOC_SIZE set to 1 #78

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 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix Init_BareVM
  • Loading branch information
funny-falcon committed Jan 6, 2012
commit 09ed965aea25e627e0a64ace8f255b64dc989629
17 changes: 17 additions & 0 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,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
4 changes: 2 additions & 2 deletions vm.c
Original file line number Diff line number Diff line change
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy