2000-05-01 05:42:38 -04:00
|
|
|
/**********************************************************************
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
gc.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
$Date$
|
|
|
|
created at: Tue Oct 5 09:44:46 JST 1993
|
|
|
|
|
2000-01-04 23:41:21 -05:00
|
|
|
Copyright (C) 1993-2000 Yukihiro Matsumoto
|
2000-05-01 05:42:38 -04:00
|
|
|
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
2000-05-09 00:53:16 -04:00
|
|
|
Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-01 05:42:38 -04:00
|
|
|
**********************************************************************/
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
#include "ruby.h"
|
1999-01-19 23:59:39 -05:00
|
|
|
#include "rubysig.h"
|
1998-01-16 07:13:05 -05:00
|
|
|
#include "st.h"
|
|
|
|
#include "node.h"
|
|
|
|
#include "env.h"
|
|
|
|
#include "re.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
void re_free_registers _((struct re_registers*));
|
|
|
|
void rb_io_fptr_finalize _((struct OpenFile*));
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
#ifndef setjmp
|
|
|
|
#ifdef HAVE__SETJMP
|
|
|
|
#define setjmp(env) _setjmp(env)
|
|
|
|
#define longjmp(env,val) _longjmp(env,val)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef C_ALLOCA
|
1999-01-19 23:59:39 -05:00
|
|
|
#ifndef alloca
|
1998-01-16 07:13:05 -05:00
|
|
|
void *alloca();
|
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
static void run_final();
|
|
|
|
|
|
|
|
#ifndef GC_MALLOC_LIMIT
|
|
|
|
#if defined(MSDOS) || defined(__human68k__)
|
1999-01-19 23:59:39 -05:00
|
|
|
#define GC_MALLOC_LIMIT 100000
|
1998-01-16 07:13:05 -05:00
|
|
|
#else
|
2000-07-04 00:17:26 -04:00
|
|
|
#define GC_MALLOC_LIMIT 4000000
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static unsigned long malloc_memories = 0;
|
|
|
|
|
1999-12-14 01:50:43 -05:00
|
|
|
static void
|
|
|
|
mem_error(mesg)
|
|
|
|
char *mesg;
|
|
|
|
{
|
|
|
|
if (rb_safe_level() >= 4) {
|
|
|
|
rb_raise(rb_eNoMemError, mesg);
|
|
|
|
}
|
|
|
|
rb_fatal(mesg);
|
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
void *
|
2000-05-15 22:46:57 -04:00
|
|
|
ruby_xmalloc(size)
|
1999-01-19 23:59:39 -05:00
|
|
|
size_t size;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
void *mem;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (size < 0) {
|
2000-01-04 23:41:21 -05:00
|
|
|
rb_raise(rb_eNoMemError, "negative allocation size (or too big)");
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
if (size == 0) size = 1;
|
|
|
|
malloc_memories += size;
|
2000-06-28 04:31:35 -04:00
|
|
|
if (malloc_memories > GC_MALLOC_LIMIT) {
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc();
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
mem = malloc(size);
|
|
|
|
if (!mem) {
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc();
|
1998-01-16 07:13:05 -05:00
|
|
|
mem = malloc(size);
|
1999-12-14 01:50:43 -05:00
|
|
|
if (!mem) {
|
|
|
|
if (size >= 10 * 1024 * 1024) {
|
2000-06-28 04:31:35 -04:00
|
|
|
rb_raise(rb_eNoMemError, "tryed to allocate too big memory");
|
1999-12-14 01:50:43 -05:00
|
|
|
}
|
|
|
|
mem_error("failed to allocate memory");
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2000-05-15 22:46:57 -04:00
|
|
|
ruby_xcalloc(n, size)
|
1999-01-19 23:59:39 -05:00
|
|
|
size_t n, size;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
void *mem;
|
|
|
|
|
|
|
|
mem = xmalloc(n * size);
|
|
|
|
memset(mem, 0, n * size);
|
|
|
|
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2000-05-15 22:46:57 -04:00
|
|
|
ruby_xrealloc(ptr, size)
|
1998-01-16 07:13:05 -05:00
|
|
|
void *ptr;
|
1999-01-19 23:59:39 -05:00
|
|
|
size_t size;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
void *mem;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (size < 0) {
|
|
|
|
rb_raise(rb_eArgError, "negative re-allocation size");
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
if (!ptr) return xmalloc(size);
|
1999-01-19 23:59:39 -05:00
|
|
|
if (size == 0) size = 1;
|
|
|
|
malloc_memories += size;
|
1998-01-16 07:13:05 -05:00
|
|
|
mem = realloc(ptr, size);
|
|
|
|
if (!mem) {
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc();
|
1998-01-16 07:13:05 -05:00
|
|
|
mem = realloc(ptr, size);
|
|
|
|
if (!mem)
|
1999-12-14 01:50:43 -05:00
|
|
|
if (size >= 10 * 1024 * 1024) {
|
2000-06-28 04:31:35 -04:00
|
|
|
rb_raise(rb_eNoMemError, "tryed to re-allocate too big memory");
|
1999-12-14 01:50:43 -05:00
|
|
|
}
|
|
|
|
mem_error("failed to allocate memory(realloc)");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
2000-02-08 03:54:01 -05:00
|
|
|
void
|
2000-05-15 22:46:57 -04:00
|
|
|
ruby_xfree(x)
|
1999-08-13 01:45:20 -04:00
|
|
|
void *x;
|
|
|
|
{
|
2000-02-08 03:54:01 -05:00
|
|
|
if (x) free(x);
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
extern int ruby_in_compile;
|
1998-01-16 07:13:05 -05:00
|
|
|
static int dont_gc;
|
1999-01-19 23:59:39 -05:00
|
|
|
static int during_gc;
|
|
|
|
static int need_call_final = 0;
|
2000-07-15 09:37:03 -04:00
|
|
|
static st_table *finalizer_table = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
|
|
|
gc_enable()
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
int old = dont_gc;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
dont_gc = Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
|
|
|
gc_disable()
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
int old = dont_gc;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
dont_gc = Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE rb_mGC;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
static struct gc_list {
|
|
|
|
VALUE *varptr;
|
|
|
|
struct gc_list *next;
|
|
|
|
} *Global_List = 0;
|
|
|
|
|
|
|
|
void
|
2000-02-08 03:54:01 -05:00
|
|
|
rb_gc_register_address(addr)
|
|
|
|
VALUE *addr;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
struct gc_list *tmp;
|
|
|
|
|
|
|
|
tmp = ALLOC(struct gc_list);
|
|
|
|
tmp->next = Global_List;
|
2000-02-08 03:54:01 -05:00
|
|
|
tmp->varptr = addr;
|
1998-01-16 07:13:05 -05:00
|
|
|
Global_List = tmp;
|
|
|
|
}
|
|
|
|
|
2000-02-08 03:54:01 -05:00
|
|
|
void
|
|
|
|
rb_gc_unregister_address(addr)
|
|
|
|
VALUE *addr;
|
|
|
|
{
|
|
|
|
struct gc_list *tmp = Global_List;
|
|
|
|
|
|
|
|
if (tmp->varptr == addr) {
|
|
|
|
Global_List = tmp->next;
|
|
|
|
free(tmp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (tmp->next) {
|
|
|
|
if (tmp->next->varptr == addr) {
|
|
|
|
struct gc_list *t = tmp->next;
|
|
|
|
|
|
|
|
tmp->next = tmp->next->next;
|
|
|
|
free(t);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_global_variable(var)
|
|
|
|
VALUE *var;
|
|
|
|
{
|
|
|
|
rb_gc_register_address(var);
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
typedef struct RVALUE {
|
|
|
|
union {
|
|
|
|
struct {
|
1999-01-19 23:59:39 -05:00
|
|
|
unsigned long flag; /* always 0 for freed obj */
|
1998-01-16 07:13:05 -05:00
|
|
|
struct RVALUE *next;
|
|
|
|
} free;
|
|
|
|
struct RBasic basic;
|
|
|
|
struct RObject object;
|
1999-01-19 23:59:39 -05:00
|
|
|
struct RClass klass;
|
1998-01-16 07:13:05 -05:00
|
|
|
struct RFloat flonum;
|
|
|
|
struct RString string;
|
|
|
|
struct RArray array;
|
|
|
|
struct RRegexp regexp;
|
|
|
|
struct RHash hash;
|
|
|
|
struct RData data;
|
|
|
|
struct RStruct rstruct;
|
|
|
|
struct RBignum bignum;
|
|
|
|
struct RFile file;
|
|
|
|
struct RNode node;
|
|
|
|
struct RMatch match;
|
|
|
|
struct RVarmap varmap;
|
|
|
|
struct SCOPE scope;
|
|
|
|
} as;
|
|
|
|
} RVALUE;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static RVALUE *freelist = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
#define HEAPS_INCREMENT 10
|
|
|
|
static RVALUE **heaps;
|
|
|
|
static int heaps_length = 0;
|
|
|
|
static int heaps_used = 0;
|
|
|
|
|
|
|
|
#define HEAP_SLOTS 10000
|
2000-06-28 04:31:35 -04:00
|
|
|
#define FREE_MIN 4096
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
static RVALUE *himem, *lomem;
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_heap()
|
|
|
|
{
|
|
|
|
RVALUE *p, *pend;
|
|
|
|
|
|
|
|
if (heaps_used == heaps_length) {
|
|
|
|
/* Realloc heaps */
|
|
|
|
heaps_length += HEAPS_INCREMENT;
|
|
|
|
heaps = (heaps_used>0)?
|
1999-12-06 04:04:03 -05:00
|
|
|
(RVALUE**)realloc(heaps, heaps_length*sizeof(RVALUE*)):
|
|
|
|
(RVALUE**)malloc(heaps_length*sizeof(RVALUE*));
|
1999-12-14 01:50:43 -05:00
|
|
|
if (heaps == 0) mem_error("heaps: can't alloc memory");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
p = heaps[heaps_used++] = (RVALUE*)malloc(sizeof(RVALUE)*HEAP_SLOTS);
|
1999-12-14 01:50:43 -05:00
|
|
|
if (p == 0) mem_error("add_heap: can't alloc memory");
|
1998-01-16 07:13:05 -05:00
|
|
|
pend = p + HEAP_SLOTS;
|
|
|
|
if (lomem == 0 || lomem > p) lomem = p;
|
|
|
|
if (himem < pend) himem = pend;
|
|
|
|
|
|
|
|
while (p < pend) {
|
|
|
|
p->as.free.flag = 0;
|
|
|
|
p->as.free.next = freelist;
|
|
|
|
freelist = p;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
#define RANY(o) ((RVALUE*)(o))
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE
|
1998-01-16 07:13:05 -05:00
|
|
|
rb_newobj()
|
|
|
|
{
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj;
|
|
|
|
|
2000-08-07 01:05:04 -04:00
|
|
|
if (!freelist) rb_gc();
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-08-07 01:05:04 -04:00
|
|
|
obj = (VALUE)freelist;
|
|
|
|
freelist = freelist->as.free.next;
|
2000-08-09 00:32:24 -04:00
|
|
|
MEMZERO((void*)obj, RVALUE, 1);
|
2000-08-07 01:05:04 -04:00
|
|
|
return obj;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_data_object_alloc(klass, datap, dmark, dfree)
|
|
|
|
VALUE klass;
|
1998-01-16 07:13:05 -05:00
|
|
|
void *datap;
|
2000-06-26 11:16:03 -04:00
|
|
|
RUBY_DATA_FUNC dmark;
|
|
|
|
RUBY_DATA_FUNC dfree;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1998-01-16 07:19:22 -05:00
|
|
|
NEWOBJ(data, struct RData);
|
1999-01-19 23:59:39 -05:00
|
|
|
OBJSETUP(data, klass, T_DATA);
|
1998-01-16 07:13:05 -05:00
|
|
|
data->data = datap;
|
|
|
|
data->dfree = dfree;
|
|
|
|
data->dmark = dmark;
|
|
|
|
|
|
|
|
return (VALUE)data;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern st_table *rb_class_tbl;
|
1999-08-13 01:45:20 -04:00
|
|
|
VALUE *rb_gc_stack_start = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
#if defined(__GNUC__) && __GNUC__ >= 2
|
|
|
|
__inline__
|
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
static int
|
2000-05-09 00:53:16 -04:00
|
|
|
is_pointer_to_heap(ptr)
|
1998-01-16 07:19:22 -05:00
|
|
|
void *ptr;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1998-01-16 07:19:22 -05:00
|
|
|
register RVALUE *p = RANY(ptr);
|
1998-01-16 07:13:05 -05:00
|
|
|
register RVALUE *heap_org;
|
|
|
|
register long i;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (p < lomem || p > himem) return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
/* check if p looks like a pointer */
|
|
|
|
for (i=0; i < heaps_used; i++) {
|
|
|
|
heap_org = heaps[i];
|
|
|
|
if (heap_org <= p && p < heap_org + HEAP_SLOTS
|
|
|
|
&& ((((char*)p)-((char*)heap_org))%sizeof(RVALUE)) == 0)
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mark_locations_array(x, n)
|
1999-01-19 23:59:39 -05:00
|
|
|
register VALUE *x;
|
|
|
|
register long n;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
while (n--) {
|
2000-05-09 00:53:16 -04:00
|
|
|
if (is_pointer_to_heap(*x)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark(*x);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark_locations(start, end)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE *start, *end;
|
|
|
|
{
|
|
|
|
VALUE *tmp;
|
|
|
|
long n;
|
|
|
|
|
|
|
|
if (start > end) {
|
|
|
|
tmp = start;
|
|
|
|
start = end;
|
|
|
|
end = tmp;
|
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
n = end - start + 1;
|
1998-01-16 07:13:05 -05:00
|
|
|
mark_locations_array(start,n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mark_entry(key, value)
|
|
|
|
ID key;
|
|
|
|
VALUE value;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark(value);
|
1998-01-16 07:13:05 -05:00
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
void
|
|
|
|
rb_mark_tbl(tbl)
|
1998-01-16 07:13:05 -05:00
|
|
|
st_table *tbl;
|
|
|
|
{
|
|
|
|
if (!tbl) return;
|
|
|
|
st_foreach(tbl, mark_entry, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mark_hashentry(key, value)
|
1999-12-14 01:50:43 -05:00
|
|
|
VALUE key;
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE value;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark(key);
|
|
|
|
rb_gc_mark(value);
|
1998-01-16 07:13:05 -05:00
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
void
|
|
|
|
rb_mark_hash(tbl)
|
1998-01-16 07:13:05 -05:00
|
|
|
st_table *tbl;
|
|
|
|
{
|
|
|
|
if (!tbl) return;
|
|
|
|
st_foreach(tbl, mark_hashentry, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark_maybe(obj)
|
1998-01-16 07:13:05 -05:00
|
|
|
void *obj;
|
|
|
|
{
|
2000-05-09 00:53:16 -04:00
|
|
|
if (is_pointer_to_heap(obj)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark(obj);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark(ptr)
|
1998-01-16 07:19:22 -05:00
|
|
|
void *ptr;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1998-01-16 07:19:22 -05:00
|
|
|
register RVALUE *obj = RANY(ptr);
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
Top:
|
1999-08-13 01:45:20 -04:00
|
|
|
if (FIXNUM_P(obj)) return; /* fixnum not marked */
|
1998-01-16 07:13:05 -05:00
|
|
|
if (rb_special_const_p((VALUE)obj)) return; /* special const not marked */
|
1999-08-13 01:45:20 -04:00
|
|
|
if (obj->as.basic.flags == 0) return; /* free cell */
|
|
|
|
if (obj->as.basic.flags & FL_MARK) return; /* already marked */
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
obj->as.basic.flags |= FL_MARK;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (FL_TEST(obj, FL_EXIVAR)) {
|
|
|
|
rb_mark_generic_ivar((VALUE)obj);
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
switch (obj->as.basic.flags & T_MASK) {
|
|
|
|
case T_NIL:
|
|
|
|
case T_FIXNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_bug("rb_gc_mark() called for broken object");
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_NODE:
|
|
|
|
switch (nd_type(obj)) {
|
|
|
|
case NODE_IF: /* 1,2,3 */
|
|
|
|
case NODE_FOR:
|
|
|
|
case NODE_ITER:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_CREF:
|
|
|
|
case NODE_WHEN:
|
|
|
|
case NODE_MASGN:
|
|
|
|
case NODE_RESCUE:
|
|
|
|
case NODE_RESBODY:
|
|
|
|
rb_gc_mark(obj->as.node.u2.node);
|
1998-01-16 07:13:05 -05:00
|
|
|
/* fall through */
|
|
|
|
case NODE_BLOCK: /* 1,3 */
|
|
|
|
case NODE_ARRAY:
|
|
|
|
case NODE_DSTR:
|
|
|
|
case NODE_DXSTR:
|
|
|
|
case NODE_EVSTR:
|
|
|
|
case NODE_DREGX:
|
|
|
|
case NODE_DREGX_ONCE:
|
|
|
|
case NODE_FBODY:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_ENSURE:
|
1998-01-16 07:13:05 -05:00
|
|
|
case NODE_CALL:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_DEFS:
|
|
|
|
case NODE_OP_ASGN1:
|
|
|
|
rb_gc_mark(obj->as.node.u1.node);
|
1998-01-16 07:13:05 -05:00
|
|
|
/* fall through */
|
|
|
|
case NODE_SUPER: /* 3 */
|
|
|
|
case NODE_FCALL:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_DEFN:
|
1998-01-16 07:13:05 -05:00
|
|
|
case NODE_NEWLINE:
|
1998-01-16 07:19:22 -05:00
|
|
|
obj = RANY(obj->as.node.u3.node);
|
1998-01-16 07:13:05 -05:00
|
|
|
goto Top;
|
|
|
|
|
|
|
|
case NODE_WHILE: /* 1,2 */
|
|
|
|
case NODE_UNTIL:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_AND:
|
|
|
|
case NODE_OR:
|
|
|
|
case NODE_CASE:
|
|
|
|
case NODE_SCLASS:
|
|
|
|
case NODE_DOT2:
|
|
|
|
case NODE_DOT3:
|
|
|
|
case NODE_FLIP2:
|
|
|
|
case NODE_FLIP3:
|
1998-01-16 07:19:22 -05:00
|
|
|
case NODE_MATCH2:
|
|
|
|
case NODE_MATCH3:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_OP_ASGN_OR:
|
|
|
|
case NODE_OP_ASGN_AND:
|
|
|
|
rb_gc_mark(obj->as.node.u1.node);
|
1998-01-16 07:13:05 -05:00
|
|
|
/* fall through */
|
|
|
|
case NODE_METHOD: /* 2 */
|
|
|
|
case NODE_NOT:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_GASGN:
|
|
|
|
case NODE_LASGN:
|
|
|
|
case NODE_DASGN:
|
2000-01-31 22:12:21 -05:00
|
|
|
case NODE_DASGN_CURR:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_IASGN:
|
2000-08-28 05:53:42 -04:00
|
|
|
case NODE_CDECL:
|
|
|
|
case NODE_CVDECL:
|
|
|
|
case NODE_CVASGN2:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_MODULE:
|
|
|
|
case NODE_COLON3:
|
|
|
|
case NODE_OPT_N:
|
1998-01-16 07:19:22 -05:00
|
|
|
obj = RANY(obj->as.node.u2.node);
|
1998-01-16 07:13:05 -05:00
|
|
|
goto Top;
|
|
|
|
|
|
|
|
case NODE_HASH: /* 1 */
|
|
|
|
case NODE_LIT:
|
|
|
|
case NODE_STR:
|
|
|
|
case NODE_XSTR:
|
|
|
|
case NODE_DEFINED:
|
1998-01-16 07:19:22 -05:00
|
|
|
case NODE_MATCH:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_RETURN:
|
|
|
|
case NODE_YIELD:
|
|
|
|
case NODE_COLON2:
|
1999-08-13 01:45:20 -04:00
|
|
|
case NODE_ARGS:
|
1998-01-16 07:19:22 -05:00
|
|
|
obj = RANY(obj->as.node.u1.node);
|
1998-01-16 07:13:05 -05:00
|
|
|
goto Top;
|
|
|
|
|
|
|
|
case NODE_SCOPE: /* 2,3 */
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_CLASS:
|
|
|
|
case NODE_BLOCK_PASS:
|
|
|
|
rb_gc_mark(obj->as.node.u3.node);
|
1998-01-16 07:19:22 -05:00
|
|
|
obj = RANY(obj->as.node.u2.node);
|
1998-01-16 07:13:05 -05:00
|
|
|
goto Top;
|
|
|
|
|
|
|
|
case NODE_ZARRAY: /* - */
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_ZSUPER:
|
1998-01-16 07:13:05 -05:00
|
|
|
case NODE_CFUNC:
|
|
|
|
case NODE_VCALL:
|
|
|
|
case NODE_GVAR:
|
|
|
|
case NODE_LVAR:
|
|
|
|
case NODE_DVAR:
|
|
|
|
case NODE_IVAR:
|
|
|
|
case NODE_CVAR:
|
2000-08-28 05:53:42 -04:00
|
|
|
case NODE_CVAR2:
|
1998-01-16 07:13:05 -05:00
|
|
|
case NODE_NTH_REF:
|
|
|
|
case NODE_BACK_REF:
|
|
|
|
case NODE_ALIAS:
|
|
|
|
case NODE_VALIAS:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_BREAK:
|
|
|
|
case NODE_NEXT:
|
|
|
|
case NODE_REDO:
|
|
|
|
case NODE_RETRY:
|
1998-01-16 07:13:05 -05:00
|
|
|
case NODE_UNDEF:
|
|
|
|
case NODE_SELF:
|
|
|
|
case NODE_NIL:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_TRUE:
|
|
|
|
case NODE_FALSE:
|
|
|
|
case NODE_ATTRSET:
|
|
|
|
case NODE_BLOCK_ARG:
|
1998-01-16 07:19:22 -05:00
|
|
|
case NODE_POSTEXE:
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
1999-01-19 23:59:39 -05:00
|
|
|
#ifdef C_ALLOCA
|
|
|
|
case NODE_ALLOCA:
|
|
|
|
mark_locations_array((VALUE*)obj->as.node.u1.value,
|
|
|
|
obj->as.node.u3.cnt);
|
|
|
|
obj = RANY(obj->as.node.u2.node);
|
|
|
|
goto Top;
|
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
default:
|
2000-05-09 00:53:16 -04:00
|
|
|
if (is_pointer_to_heap(obj->as.node.u1.node)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark(obj->as.node.u1.node);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-05-09 00:53:16 -04:00
|
|
|
if (is_pointer_to_heap(obj->as.node.u2.node)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark(obj->as.node.u2.node);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-05-09 00:53:16 -04:00
|
|
|
if (is_pointer_to_heap(obj->as.node.u3.node)) {
|
1998-01-16 07:19:22 -05:00
|
|
|
obj = RANY(obj->as.node.u3.node);
|
1998-01-16 07:13:05 -05:00
|
|
|
goto Top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return; /* no need to mark class. */
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark(obj->as.basic.klass);
|
1998-01-16 07:13:05 -05:00
|
|
|
switch (obj->as.basic.flags & T_MASK) {
|
|
|
|
case T_ICLASS:
|
|
|
|
case T_CLASS:
|
|
|
|
case T_MODULE:
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark(obj->as.klass.super);
|
|
|
|
rb_mark_tbl(obj->as.klass.m_tbl);
|
|
|
|
rb_mark_tbl(obj->as.klass.iv_tbl);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_ARRAY:
|
|
|
|
{
|
|
|
|
int i, len = obj->as.array.len;
|
|
|
|
VALUE *ptr = obj->as.array.ptr;
|
|
|
|
|
|
|
|
for (i=0; i < len; i++)
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark(*ptr++);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_HASH:
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_mark_hash(obj->as.hash.tbl);
|
|
|
|
rb_gc_mark(obj->as.hash.ifnone);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_STRING:
|
|
|
|
if (obj->as.string.orig) {
|
1998-01-16 07:19:22 -05:00
|
|
|
obj = RANY(obj->as.string.orig);
|
1998-01-16 07:13:05 -05:00
|
|
|
goto Top;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_DATA:
|
|
|
|
if (obj->as.data.dmark) (*obj->as.data.dmark)(DATA_PTR(obj));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_OBJECT:
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_mark_tbl(obj->as.object.iv_tbl);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_FILE:
|
|
|
|
case T_REGEXP:
|
|
|
|
case T_FLOAT:
|
|
|
|
case T_BIGNUM:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_MATCH:
|
|
|
|
if (obj->as.match.str) {
|
1998-01-16 07:19:22 -05:00
|
|
|
obj = RANY(obj->as.match.str);
|
1998-01-16 07:13:05 -05:00
|
|
|
goto Top;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_VARMAP:
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark(obj->as.varmap.val);
|
1998-01-16 07:19:22 -05:00
|
|
|
obj = RANY(obj->as.varmap.next);
|
1998-01-16 07:13:05 -05:00
|
|
|
goto Top;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_SCOPE:
|
2000-08-31 23:31:05 -04:00
|
|
|
if (obj->as.scope.local_vars && (obj->as.scope.flag & SCOPE_MALLOC)) {
|
1998-01-16 07:13:05 -05:00
|
|
|
int n = obj->as.scope.local_tbl[0]+1;
|
|
|
|
VALUE *vars = &obj->as.scope.local_vars[-1];
|
|
|
|
|
|
|
|
while (n--) {
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark(*vars);
|
1998-01-16 07:13:05 -05:00
|
|
|
vars++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_STRUCT:
|
|
|
|
{
|
|
|
|
int i, len = obj->as.rstruct.len;
|
|
|
|
VALUE *ptr = obj->as.rstruct.ptr;
|
|
|
|
|
|
|
|
for (i=0; i < len; i++)
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark(*ptr++);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_bug("rb_gc_mark(): unknown data type 0x%x(0x%x) %s",
|
|
|
|
obj->as.basic.flags & T_MASK, obj,
|
2000-05-09 00:53:16 -04:00
|
|
|
is_pointer_to_heap(obj)?"corrupted object":"non object");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static void obj_free _((VALUE));
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
static void
|
|
|
|
gc_sweep()
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
RVALUE *p, *pend, *final_list;
|
1998-01-16 07:13:05 -05:00
|
|
|
int freed = 0;
|
1999-01-19 23:59:39 -05:00
|
|
|
int i, used = heaps_used;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
freelist = 0;
|
1999-01-19 23:59:39 -05:00
|
|
|
final_list = 0;
|
|
|
|
for (i = 0; i < used; i++) {
|
1998-01-16 07:13:05 -05:00
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
p = heaps[i]; pend = p + HEAP_SLOTS;
|
|
|
|
while (p < pend) {
|
|
|
|
if (!(p->as.basic.flags & FL_MARK)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
if (p->as.basic.flags) {
|
|
|
|
obj_free((VALUE)p);
|
|
|
|
}
|
2000-08-07 02:11:34 -04:00
|
|
|
if (need_call_final && FL_TEST(p, FL_FINALIZE)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
p->as.free.flag = FL_MARK; /* remain marked */
|
|
|
|
p->as.free.next = final_list;
|
|
|
|
final_list = p;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p->as.free.flag = 0;
|
|
|
|
p->as.free.next = freelist;
|
|
|
|
freelist = p;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
n++;
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
else if (RBASIC(p)->flags == FL_MARK) {
|
|
|
|
/* objects to be finalized */
|
|
|
|
/* do notning remain marked */
|
|
|
|
}
|
|
|
|
else {
|
1998-01-16 07:13:05 -05:00
|
|
|
RBASIC(p)->flags &= ~FL_MARK;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
freed += n;
|
|
|
|
}
|
|
|
|
if (freed < FREE_MIN) {
|
|
|
|
add_heap();
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
during_gc = 0;
|
|
|
|
|
|
|
|
/* clear finalization list */
|
|
|
|
if (need_call_final) {
|
|
|
|
RVALUE *tmp;
|
|
|
|
|
|
|
|
for (p = final_list; p; p = tmp) {
|
|
|
|
tmp = p->as.free.next;
|
|
|
|
run_final((VALUE)p);
|
|
|
|
p->as.free.flag = 0;
|
|
|
|
p->as.free.next = freelist;
|
|
|
|
freelist = p;
|
|
|
|
}
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_force_recycle(p)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE p;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1998-01-16 07:19:22 -05:00
|
|
|
RANY(p)->as.free.flag = 0;
|
|
|
|
RANY(p)->as.free.next = freelist;
|
|
|
|
freelist = RANY(p);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
obj_free(obj)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1998-01-16 07:19:22 -05:00
|
|
|
switch (RANY(obj)->as.basic.flags & T_MASK) {
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_NIL:
|
|
|
|
case T_FIXNUM:
|
|
|
|
case T_TRUE:
|
|
|
|
case T_FALSE:
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_bug("obj_free() called for broken object");
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (FL_TEST(obj, FL_EXIVAR)) {
|
|
|
|
rb_free_generic_ivar((VALUE)obj);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
switch (RANY(obj)->as.basic.flags & T_MASK) {
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_OBJECT:
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RANY(obj)->as.object.iv_tbl) {
|
|
|
|
st_free_table(RANY(obj)->as.object.iv_tbl);
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case T_MODULE:
|
|
|
|
case T_CLASS:
|
|
|
|
rb_clear_cache();
|
1999-01-19 23:59:39 -05:00
|
|
|
st_free_table(RANY(obj)->as.klass.m_tbl);
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RANY(obj)->as.object.iv_tbl) {
|
|
|
|
st_free_table(RANY(obj)->as.object.iv_tbl);
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case T_STRING:
|
1999-01-19 23:59:39 -05:00
|
|
|
#define STR_NO_ORIG FL_USER3 /* copied from string.c */
|
|
|
|
if (!RANY(obj)->as.string.orig || FL_TEST(obj, STR_NO_ORIG))
|
|
|
|
free(RANY(obj)->as.string.ptr);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case T_ARRAY:
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RANY(obj)->as.array.ptr) free(RANY(obj)->as.array.ptr);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case T_HASH:
|
1999-01-19 23:59:39 -05:00
|
|
|
if (RANY(obj)->as.hash.tbl)
|
|
|
|
st_free_table(RANY(obj)->as.hash.tbl);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case T_REGEXP:
|
1999-01-19 23:59:39 -05:00
|
|
|
if (RANY(obj)->as.regexp.ptr) re_free_pattern(RANY(obj)->as.regexp.ptr);
|
|
|
|
if (RANY(obj)->as.regexp.str) free(RANY(obj)->as.regexp.str);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case T_DATA:
|
1999-01-19 23:59:39 -05:00
|
|
|
if (DATA_PTR(obj)) {
|
|
|
|
if ((long)RANY(obj)->as.data.dfree == -1) {
|
|
|
|
free(DATA_PTR(obj));
|
|
|
|
}
|
|
|
|
else if (RANY(obj)->as.data.dfree) {
|
|
|
|
(*RANY(obj)->as.data.dfree)(DATA_PTR(obj));
|
|
|
|
}
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case T_MATCH:
|
1999-08-13 01:45:20 -04:00
|
|
|
if (RANY(obj)->as.match.regs) {
|
1999-01-19 23:59:39 -05:00
|
|
|
re_free_registers(RANY(obj)->as.match.regs);
|
|
|
|
free(RANY(obj)->as.match.regs);
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case T_FILE:
|
1999-01-19 23:59:39 -05:00
|
|
|
if (RANY(obj)->as.file.fptr) {
|
|
|
|
rb_io_fptr_finalize(RANY(obj)->as.file.fptr);
|
|
|
|
free(RANY(obj)->as.file.fptr);
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case T_ICLASS:
|
|
|
|
/* iClass shares table with the module */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_FLOAT:
|
|
|
|
case T_VARMAP:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RANY(obj)->as.bignum.digits) free(RANY(obj)->as.bignum.digits);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case T_NODE:
|
1999-01-19 23:59:39 -05:00
|
|
|
switch (nd_type(obj)) {
|
|
|
|
case NODE_SCOPE:
|
|
|
|
if (RANY(obj)->as.node.u1.tbl) {
|
|
|
|
free(RANY(obj)->as.node.u1.tbl);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#ifdef C_ALLOCA
|
|
|
|
case NODE_ALLOCA:
|
|
|
|
free(RANY(obj)->as.node.u1.value);
|
|
|
|
break;
|
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
return; /* no need to free iv_tbl */
|
|
|
|
|
|
|
|
case T_SCOPE:
|
1999-08-13 01:45:20 -04:00
|
|
|
if (RANY(obj)->as.scope.local_vars &&
|
|
|
|
RANY(obj)->as.scope.flag != SCOPE_ALLOCA) {
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE *vars = RANY(obj)->as.scope.local_vars-1;
|
1998-01-16 07:13:05 -05:00
|
|
|
if (vars[0] == 0)
|
1998-01-16 07:19:22 -05:00
|
|
|
free(RANY(obj)->as.scope.local_tbl);
|
|
|
|
if (RANY(obj)->as.scope.flag&SCOPE_MALLOC)
|
1998-01-16 07:13:05 -05:00
|
|
|
free(vars);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_STRUCT:
|
1999-01-19 23:59:39 -05:00
|
|
|
if (RANY(obj)->as.rstruct.ptr)
|
|
|
|
free(RANY(obj)->as.rstruct.ptr);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_bug("gc_sweep(): unknown data type %d",
|
|
|
|
RANY(obj)->as.basic.flags & T_MASK);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark_frame(frame)
|
1998-01-16 07:13:05 -05:00
|
|
|
struct FRAME *frame;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
mark_locations_array(frame->argv, frame->argc);
|
|
|
|
rb_gc_mark(frame->cbase);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#if defined(__human68k__) || defined(DJGPP)
|
|
|
|
#if defined(__human68k__)
|
|
|
|
typedef unsigned long rb_jmp_buf[8];
|
|
|
|
__asm__ (".even
|
|
|
|
_rb_setjmp:
|
|
|
|
move.l 4(sp),a0
|
|
|
|
movem.l d3-d7/a3-a5,(a0)
|
|
|
|
moveq.l #0,d0
|
|
|
|
rts");
|
2000-01-04 23:41:21 -05:00
|
|
|
#ifdef setjmp
|
|
|
|
#undef setjmp
|
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
#else
|
|
|
|
#if defined(DJGPP)
|
|
|
|
typedef unsigned long rb_jmp_buf[6];
|
|
|
|
__asm__ (".align 4
|
|
|
|
_rb_setjmp:
|
|
|
|
pushl %ebp
|
|
|
|
movl %esp,%ebp
|
|
|
|
movl 8(%ebp),%ebp
|
|
|
|
movl %eax,(%ebp)
|
|
|
|
movl %ebx,4(%ebp)
|
|
|
|
movl %ecx,8(%ebp)
|
|
|
|
movl %edx,12(%ebp)
|
|
|
|
movl %esi,16(%ebp)
|
|
|
|
movl %edi,20(%ebp)
|
|
|
|
popl %ebp
|
|
|
|
xorl %eax,%eax
|
|
|
|
ret");
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
int rb_setjmp (rb_jmp_buf);
|
|
|
|
#define jmp_buf rb_jmp_buf
|
|
|
|
#define setjmp rb_setjmp
|
|
|
|
#endif /* __human68k__ or DJGPP */
|
|
|
|
#endif /* __GNUC__ */
|
|
|
|
|
|
|
|
void
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc()
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
struct gc_list *list;
|
1999-08-24 04:21:56 -04:00
|
|
|
struct FRAME * volatile frame; /* gcc 2.7.2.3 -O2 bug?? */
|
1998-01-16 07:13:05 -05:00
|
|
|
jmp_buf save_regs_gc_mark;
|
1999-09-01 05:48:03 -04:00
|
|
|
#ifdef C_ALLOCA
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE stack_end;
|
1999-11-26 04:07:26 -05:00
|
|
|
alloca(0);
|
|
|
|
# define STACK_END (&stack_end)
|
|
|
|
#else
|
1999-11-29 01:33:02 -05:00
|
|
|
VALUE *stack_end = alloca(1);
|
|
|
|
# define STACK_END (stack_end)
|
1999-09-01 05:48:03 -04:00
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-07-27 05:49:34 -04:00
|
|
|
if (dont_gc || during_gc || rb_prohibit_interrupt || ruby_in_compile) {
|
2000-08-02 00:54:21 -04:00
|
|
|
if (!freelist || malloc_memories > GC_MALLOC_LIMIT) {
|
|
|
|
malloc_memories = 0;
|
|
|
|
add_heap();
|
|
|
|
}
|
2000-07-27 05:49:34 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
malloc_memories = 0;
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
if (during_gc) return;
|
|
|
|
during_gc++;
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
/* mark frame stack */
|
1999-01-19 23:59:39 -05:00
|
|
|
for (frame = ruby_frame; frame; frame = frame->prev) {
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_gc_mark_frame(frame);
|
|
|
|
if (frame->tmp) {
|
|
|
|
struct FRAME *tmp = frame->tmp;
|
|
|
|
while (tmp) {
|
|
|
|
rb_gc_mark_frame(tmp);
|
|
|
|
tmp = tmp->prev;
|
|
|
|
}
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark(ruby_class);
|
|
|
|
rb_gc_mark(ruby_scope);
|
|
|
|
rb_gc_mark(ruby_dyna_vars);
|
2000-07-15 09:37:03 -04:00
|
|
|
if (finalizer_table) {
|
|
|
|
rb_mark_tbl(finalizer_table);
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
FLUSH_REGISTER_WINDOWS;
|
|
|
|
/* This assumes that all registers are saved into the jmp_buf */
|
|
|
|
setjmp(save_regs_gc_mark);
|
1999-08-24 04:21:56 -04:00
|
|
|
mark_locations_array((VALUE*)save_regs_gc_mark, sizeof(save_regs_gc_mark) / sizeof(VALUE *));
|
1999-11-26 04:07:26 -05:00
|
|
|
rb_gc_mark_locations(rb_gc_stack_start, (VALUE*)STACK_END);
|
2000-05-12 05:07:57 -04:00
|
|
|
#if defined(__human68k__)
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark_locations((VALUE*)((char*)rb_gc_stack_start + 2),
|
1999-11-26 04:07:26 -05:00
|
|
|
(VALUE*)((char*)STACK_END + 2));
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark_threads();
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
/* mark protected global variables */
|
|
|
|
for (list = Global_List; list; list = list->next) {
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark(*list->varptr);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-11-26 04:07:26 -05:00
|
|
|
rb_mark_end_proc();
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark_global_tbl();
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_mark_tbl(rb_class_tbl);
|
|
|
|
rb_gc_mark_trap_list();
|
|
|
|
|
|
|
|
/* mark generic instance variables for special constants */
|
|
|
|
rb_mark_generic_ivar_tbl();
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
gc_sweep();
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
gc_start()
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc();
|
1998-01-16 07:13:05 -05:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-08-13 01:45:20 -04:00
|
|
|
Init_stack(addr)
|
|
|
|
VALUE *addr;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
#ifdef __human68k__
|
|
|
|
extern void *_SEND;
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_gc_stack_start = _SEND;
|
1998-01-16 07:13:05 -05:00
|
|
|
#else
|
|
|
|
VALUE start;
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
if (!addr) addr = &start;
|
|
|
|
rb_gc_stack_start = addr;
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-01-19 23:59:39 -05:00
|
|
|
Init_heap()
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
if (!rb_gc_stack_start) {
|
|
|
|
Init_stack(0);
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
add_heap();
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
os_live_obj()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < heaps_used; i++) {
|
|
|
|
RVALUE *p, *pend;
|
|
|
|
|
|
|
|
p = heaps[i]; pend = p + HEAP_SLOTS;
|
|
|
|
for (;p < pend; p++) {
|
|
|
|
if (p->as.basic.flags) {
|
|
|
|
switch (TYPE(p)) {
|
|
|
|
case T_ICLASS:
|
|
|
|
case T_VARMAP:
|
|
|
|
case T_SCOPE:
|
|
|
|
case T_NODE:
|
|
|
|
continue;
|
|
|
|
case T_CLASS:
|
|
|
|
if (FL_TEST(p, FL_SINGLETON)) continue;
|
|
|
|
default:
|
1998-01-16 07:19:22 -05:00
|
|
|
rb_yield((VALUE)p);
|
1998-01-16 07:13:05 -05:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return INT2FIX(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
os_obj_of(of)
|
|
|
|
VALUE of;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < heaps_used; i++) {
|
|
|
|
RVALUE *p, *pend;
|
|
|
|
|
|
|
|
p = heaps[i]; pend = p + HEAP_SLOTS;
|
|
|
|
for (;p < pend; p++) {
|
|
|
|
if (p->as.basic.flags) {
|
|
|
|
switch (TYPE(p)) {
|
|
|
|
case T_ICLASS:
|
|
|
|
case T_VARMAP:
|
|
|
|
case T_SCOPE:
|
|
|
|
case T_NODE:
|
|
|
|
continue;
|
|
|
|
case T_CLASS:
|
|
|
|
if (FL_TEST(p, FL_SINGLETON)) continue;
|
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_obj_is_kind_of((VALUE)p, of)) {
|
1998-01-16 07:19:22 -05:00
|
|
|
rb_yield((VALUE)p);
|
1998-01-16 07:13:05 -05:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return INT2FIX(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
os_each_obj(argc, argv)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
|
|
|
VALUE of;
|
|
|
|
|
|
|
|
if (rb_scan_args(argc, argv, "01", &of) == 0) {
|
|
|
|
return os_live_obj();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return os_obj_of(of);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE finalizers;
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
add_final(os, proc)
|
|
|
|
VALUE os, proc;
|
|
|
|
{
|
2000-07-15 09:37:03 -04:00
|
|
|
rb_warn("ObjectSpace::add_finalizer is deprecated; use define_finalizer");
|
1999-01-19 23:59:39 -05:00
|
|
|
if (!rb_obj_is_kind_of(proc, rb_cProc)) {
|
|
|
|
rb_raise(rb_eArgError, "wrong type argument %s (Proc required)",
|
|
|
|
rb_class2name(CLASS_OF(proc)));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_ary_push(finalizers, proc);
|
1998-01-16 07:13:05 -05:00
|
|
|
return proc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rm_final(os, proc)
|
|
|
|
VALUE os, proc;
|
|
|
|
{
|
2000-07-15 09:37:03 -04:00
|
|
|
rb_warn("ObjectSpace::remove_finalizer is deprecated; use undefine_finalizer");
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_ary_delete(finalizers, proc);
|
1998-01-16 07:13:05 -05:00
|
|
|
return proc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
finals()
|
|
|
|
{
|
2000-07-15 09:37:03 -04:00
|
|
|
rb_warn("ObjectSpace::finals is deprecated");
|
1998-01-16 07:13:05 -05:00
|
|
|
return finalizers;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
call_final(os, obj)
|
|
|
|
VALUE os, obj;
|
|
|
|
{
|
2000-07-15 09:37:03 -04:00
|
|
|
rb_warn("ObjectSpace::call_final is deprecated; use define_finalizer");
|
1998-01-16 07:13:05 -05:00
|
|
|
need_call_final = 1;
|
|
|
|
FL_SET(obj, FL_FINALIZE);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2000-07-15 09:37:03 -04:00
|
|
|
static VALUE
|
|
|
|
undefine_final(os, obj)
|
|
|
|
VALUE os, obj;
|
|
|
|
{
|
|
|
|
VALUE table;
|
|
|
|
|
|
|
|
if (finalizer_table) {
|
|
|
|
st_delete(finalizer_table, &obj, 0);
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
define_final(argc, argv, os)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
VALUE os;
|
|
|
|
{
|
|
|
|
VALUE obj, proc, table;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &obj, &proc);
|
|
|
|
if (argc == 1) {
|
|
|
|
proc = rb_f_lambda();
|
|
|
|
}
|
|
|
|
else if (!rb_obj_is_kind_of(proc, rb_cProc)) {
|
|
|
|
rb_raise(rb_eArgError, "wrong type argument %s (Proc required)",
|
|
|
|
rb_class2name(CLASS_OF(proc)));
|
|
|
|
}
|
|
|
|
need_call_final = 1;
|
|
|
|
FL_SET(obj, FL_FINALIZE);
|
|
|
|
|
|
|
|
if (!finalizer_table) {
|
|
|
|
finalizer_table = st_init_numtable();
|
|
|
|
}
|
|
|
|
if (st_lookup(finalizer_table, obj, &table)) {
|
|
|
|
rb_ary_push(table, proc);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
st_add_direct(finalizer_table, obj, rb_ary_new3(1, proc));
|
|
|
|
}
|
|
|
|
return proc;
|
|
|
|
}
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
|
|
|
run_single_final(args)
|
|
|
|
VALUE *args;
|
|
|
|
{
|
|
|
|
rb_eval_cmd(args[0], args[1]);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static void
|
|
|
|
run_final(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
int i, status;
|
2000-07-17 05:38:10 -04:00
|
|
|
VALUE args[2], table;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-07-17 05:38:10 -04:00
|
|
|
args[1] = rb_ary_new3(1, rb_obj_id(obj)); /* make obj into id */
|
1998-01-16 07:13:05 -05:00
|
|
|
for (i=0; i<RARRAY(finalizers)->len; i++) {
|
1999-08-13 01:45:20 -04:00
|
|
|
args[0] = RARRAY(finalizers)->ptr[i];
|
|
|
|
rb_protect(run_single_final, (VALUE)args, &status);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
2000-07-15 09:37:03 -04:00
|
|
|
if (finalizer_table && st_lookup(finalizer_table, obj, &table)) {
|
|
|
|
st_delete(finalizer_table, &obj, 0);
|
|
|
|
for (i=0; i<RARRAY(table)->len; i++) {
|
|
|
|
args[0] = RARRAY(table)->ptr[i];
|
|
|
|
rb_protect(run_single_final, (VALUE)args, &status);
|
|
|
|
}
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_call_finalizer_at_exit()
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
|
|
|
RVALUE *p, *pend;
|
|
|
|
int i;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
/* run finalizers */
|
|
|
|
for (i = 0; i < heaps_used; i++) {
|
|
|
|
p = heaps[i]; pend = p + HEAP_SLOTS;
|
|
|
|
while (p < pend) {
|
2000-04-10 01:48:43 -04:00
|
|
|
if (FL_TEST(p, FL_FINALIZE)) {
|
|
|
|
p->as.free.flag = 0;
|
1999-01-19 23:59:39 -05:00
|
|
|
run_final((VALUE)p);
|
2000-04-10 01:48:43 -04:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* run data object's finaliers */
|
1998-01-16 07:19:22 -05:00
|
|
|
for (i = 0; i < heaps_used; i++) {
|
|
|
|
p = heaps[i]; pend = p + HEAP_SLOTS;
|
|
|
|
while (p < pend) {
|
|
|
|
if (BUILTIN_TYPE(p) == T_DATA &&
|
1999-08-13 01:45:20 -04:00
|
|
|
DATA_PTR(p) && RANY(p)->as.data.dfree) {
|
1998-01-16 07:19:22 -05:00
|
|
|
(*RANY(p)->as.data.dfree)(DATA_PTR(p));
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
else if (BUILTIN_TYPE(p) == T_FILE) {
|
|
|
|
rb_io_fptr_finalize(RANY(p)->as.file.fptr);
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
id2ref(obj, id)
|
|
|
|
VALUE obj, id;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
unsigned long ptr;
|
1998-01-16 07:19:22 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_secure(4);
|
|
|
|
ptr = NUM2UINT(id);
|
1998-01-16 07:19:22 -05:00
|
|
|
if (FIXNUM_P(ptr)) return (VALUE)ptr;
|
1999-01-19 23:59:39 -05:00
|
|
|
if (ptr == Qtrue) return Qtrue;
|
|
|
|
if (ptr == Qfalse) return Qfalse;
|
|
|
|
if (ptr == Qnil) return Qnil;
|
|
|
|
|
2000-05-09 00:53:16 -04:00
|
|
|
ptr = id ^ FIXNUM_FLAG; /* unset FIXNUM_FLAG */
|
|
|
|
if (!is_pointer_to_heap(ptr)) {
|
2000-03-07 03:37:59 -05:00
|
|
|
rb_raise(rb_eRangeError, "0x%x is not id value", ptr);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
if (BUILTIN_TYPE(ptr) == 0) {
|
2000-03-07 03:37:59 -05:00
|
|
|
rb_raise(rb_eRangeError, "0x%x is recycled object", ptr);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
return (VALUE)ptr;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Init_GC()
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE rb_mObSpace;
|
|
|
|
|
|
|
|
rb_mGC = rb_define_module("GC");
|
|
|
|
rb_define_singleton_method(rb_mGC, "start", gc_start, 0);
|
|
|
|
rb_define_singleton_method(rb_mGC, "enable", gc_enable, 0);
|
|
|
|
rb_define_singleton_method(rb_mGC, "disable", gc_disable, 0);
|
|
|
|
rb_define_method(rb_mGC, "garbage_collect", gc_start, 0);
|
|
|
|
|
|
|
|
rb_mObSpace = rb_define_module("ObjectSpace");
|
|
|
|
rb_define_module_function(rb_mObSpace, "each_object", os_each_obj, -1);
|
|
|
|
rb_define_module_function(rb_mObSpace, "garbage_collect", gc_start, 0);
|
|
|
|
rb_define_module_function(rb_mObSpace, "add_finalizer", add_final, 1);
|
|
|
|
rb_define_module_function(rb_mObSpace, "remove_finalizer", rm_final, 1);
|
|
|
|
rb_define_module_function(rb_mObSpace, "finalizers", finals, 0);
|
|
|
|
rb_define_module_function(rb_mObSpace, "call_finalizer", call_final, 1);
|
2000-07-15 09:37:03 -04:00
|
|
|
|
|
|
|
rb_define_module_function(rb_mObSpace, "define_finalizer", define_final, -1);
|
|
|
|
rb_define_module_function(rb_mObSpace, "undefine_finalizer", undefine_final, 1);
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_module_function(rb_mObSpace, "_id2ref", id2ref, 1);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-02-08 03:54:01 -05:00
|
|
|
rb_gc_register_address(&rb_mObSpace);
|
1998-01-16 07:13:05 -05:00
|
|
|
rb_global_variable(&finalizers);
|
2000-02-08 03:54:01 -05:00
|
|
|
rb_gc_unregister_address(&rb_mObSpace);
|
1999-01-19 23:59:39 -05:00
|
|
|
finalizers = rb_ary_new();
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-05-15 22:46:57 -04:00
|
|
|
|
|
|
|
#undef xmalloc
|
|
|
|
#undef xcalloc
|
|
|
|
#undef xrealloc
|
|
|
|
#undef xfree
|
|
|
|
|
|
|
|
void*
|
|
|
|
xmalloc(size)
|
|
|
|
size_t size;
|
|
|
|
{
|
|
|
|
return ruby_xmalloc(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
xcalloc(n,size)
|
|
|
|
size_t n,size;
|
|
|
|
{
|
|
|
|
return ruby_xcalloc(n, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
xrealloc(ptr,size)
|
|
|
|
void *ptr;
|
|
|
|
size_t size;
|
|
|
|
{
|
|
|
|
return ruby_xrealloc(ptr, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xfree(ptr)
|
|
|
|
void *ptr;
|
|
|
|
{
|
2000-05-17 00:38:19 -04:00
|
|
|
ruby_xfree(ptr);
|
2000-05-15 22:46:57 -04:00
|
|
|
}
|
|
|
|
|