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
|
|
|
|
|
2003-01-16 02:34:03 -05:00
|
|
|
Copyright (C) 1993-2003 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>
|
2001-11-19 09:42:45 -05:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2001-11-19 00:03:03 -05:00
|
|
|
#ifdef HAVE_SYS_RESOURCE_H
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#endif
|
|
|
|
|
2004-07-08 06:27:23 -04:00
|
|
|
#if defined _WIN32 || defined __CYGWIN__
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 02:32:32 -04:00
|
|
|
int rb_io_fptr_finalize(struct OpenFile*);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2002-08-12 03:39:12 -04:00
|
|
|
#if !defined(setjmp) && defined(HAVE__SETJMP)
|
1998-01-16 07:13:05 -05:00
|
|
|
#define setjmp(env) _setjmp(env)
|
|
|
|
#endif
|
|
|
|
|
2001-02-11 02:12:02 -05:00
|
|
|
/* Make alloca work the best possible way. */
|
2002-10-25 14:39:30 -04:00
|
|
|
#ifdef __GNUC__
|
|
|
|
# ifndef atarist
|
|
|
|
# ifndef alloca
|
|
|
|
# define alloca __builtin_alloca
|
|
|
|
# endif
|
|
|
|
# endif /* atarist */
|
|
|
|
#else
|
|
|
|
# ifdef HAVE_ALLOCA_H
|
2001-02-11 02:12:02 -05:00
|
|
|
# include <alloca.h>
|
2001-03-26 03:57:16 -05:00
|
|
|
# else
|
2006-08-06 23:37:47 -04:00
|
|
|
# ifndef _AIX
|
2001-03-26 03:57:16 -05:00
|
|
|
# ifndef alloca /* predefined by HP cc +Olibcalls */
|
|
|
|
void *alloca ();
|
|
|
|
# endif
|
2002-10-25 14:39:30 -04:00
|
|
|
# endif /* AIX */
|
|
|
|
# endif /* HAVE_ALLOCA_H */
|
|
|
|
#endif /* __GNUC__ */
|
2001-02-11 02:12:02 -05:00
|
|
|
|
2002-10-10 11:26:58 -04:00
|
|
|
#ifndef GC_MALLOC_LIMIT
|
|
|
|
#if defined(MSDOS) || defined(__human68k__)
|
|
|
|
#define GC_MALLOC_LIMIT 200000
|
|
|
|
#else
|
|
|
|
#define GC_MALLOC_LIMIT 8000000
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2002-10-10 13:11:18 -04:00
|
|
|
static unsigned long malloc_increase = 0;
|
2002-10-10 11:26:58 -04:00
|
|
|
static unsigned long malloc_limit = GC_MALLOC_LIMIT;
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
static void run_final(VALUE obj);
|
2002-04-24 00:54:16 -04:00
|
|
|
static VALUE nomem_error;
|
2005-09-16 09:44:59 -04:00
|
|
|
static int garbage_collect(void);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2002-04-24 00:54:16 -04:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_memerror(void)
|
1999-12-14 01:50:43 -05:00
|
|
|
{
|
2000-12-28 21:47:07 -05:00
|
|
|
static int recurse = 0;
|
|
|
|
|
2005-09-16 09:44:59 -04:00
|
|
|
if (!nomem_error || (recurse > 0 && rb_safe_level() < 4)) {
|
2002-04-24 00:54:16 -04:00
|
|
|
fprintf(stderr, "[FATAL] failed to allocate memory\n");
|
|
|
|
exit(1);
|
1999-12-14 01:50:43 -05:00
|
|
|
}
|
2002-04-24 00:54:16 -04:00
|
|
|
recurse++;
|
|
|
|
rb_exc_raise(nomem_error);
|
1999-12-14 01:50:43 -05:00
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2006-01-09 17:32:55 -05:00
|
|
|
int gc_stress = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* GC.stress => true or false
|
|
|
|
*
|
|
|
|
* returns current status of GC stress mode.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_stress_get(VALUE self)
|
|
|
|
{
|
|
|
|
return gc_stress ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* GC.stress = bool => bool
|
|
|
|
*
|
|
|
|
* updates GC stress mode.
|
|
|
|
*
|
|
|
|
* When GC.stress = true, GC is invoked for all GC opportunity:
|
|
|
|
* all memory and object allocation.
|
|
|
|
*
|
|
|
|
* Since it makes Ruby very slow, it is only for debugging.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
gc_stress_set(VALUE self, VALUE bool)
|
|
|
|
{
|
|
|
|
rb_secure(2);
|
|
|
|
gc_stress = RTEST(bool);
|
|
|
|
return bool;
|
|
|
|
}
|
2005-12-11 19:36:54 -05:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
void *
|
2005-12-06 02:52:18 -05:00
|
|
|
ruby_xmalloc(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;
|
2002-10-10 13:11:18 -04:00
|
|
|
malloc_increase += size;
|
2000-09-25 13:51:29 -04:00
|
|
|
|
2006-01-09 17:32:55 -05:00
|
|
|
if (gc_stress || malloc_increase > malloc_limit) {
|
2004-10-01 11:56:05 -04:00
|
|
|
garbage_collect();
|
2002-10-10 11:26:58 -04:00
|
|
|
}
|
2000-11-14 02:10:31 -05:00
|
|
|
RUBY_CRITICAL(mem = malloc(size));
|
1998-01-16 07:13:05 -05:00
|
|
|
if (!mem) {
|
2005-09-16 09:44:59 -04:00
|
|
|
if (garbage_collect()) {
|
|
|
|
RUBY_CRITICAL(mem = malloc(size));
|
|
|
|
}
|
1999-12-14 01:50:43 -05:00
|
|
|
if (!mem) {
|
2002-04-24 00:54:16 -04:00
|
|
|
rb_memerror();
|
1999-12-14 01:50:43 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
2005-10-05 12:15:16 -04:00
|
|
|
void *
|
2005-12-06 02:52:18 -05:00
|
|
|
ruby_xmalloc2(size_t n, size_t size)
|
2005-10-05 12:15:16 -04:00
|
|
|
{
|
|
|
|
long len = size * n;
|
2005-12-06 02:52:18 -05:00
|
|
|
if (n != 0 && size != len / n) {
|
2005-10-05 12:15:16 -04:00
|
|
|
rb_raise(rb_eArgError, "malloc: possible integer overflow");
|
|
|
|
}
|
|
|
|
return ruby_xmalloc(len);
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
void *
|
2005-12-06 02:52:18 -05:00
|
|
|
ruby_xcalloc(size_t n, size_t size)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
void *mem;
|
|
|
|
|
2005-10-05 12:15:16 -04:00
|
|
|
mem = ruby_xmalloc2(n, size);
|
1998-01-16 07:13:05 -05:00
|
|
|
memset(mem, 0, n * size);
|
|
|
|
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2005-12-06 02:52:18 -05:00
|
|
|
ruby_xrealloc(void *ptr, 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");
|
|
|
|
}
|
2005-10-05 12:15:16 -04:00
|
|
|
if (!ptr) return ruby_xmalloc(size);
|
1999-01-19 23:59:39 -05:00
|
|
|
if (size == 0) size = 1;
|
2002-10-10 13:11:18 -04:00
|
|
|
malloc_increase += size;
|
2006-01-09 17:32:55 -05:00
|
|
|
if (gc_stress) garbage_collect();
|
2000-11-14 02:10:31 -05:00
|
|
|
RUBY_CRITICAL(mem = realloc(ptr, size));
|
1998-01-16 07:13:05 -05:00
|
|
|
if (!mem) {
|
2005-09-16 09:44:59 -04:00
|
|
|
if (garbage_collect()) {
|
|
|
|
RUBY_CRITICAL(mem = realloc(ptr, size));
|
|
|
|
}
|
2001-07-20 11:20:25 -04:00
|
|
|
if (!mem) {
|
2002-04-24 00:54:16 -04:00
|
|
|
rb_memerror();
|
2001-07-20 11:20:25 -04:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
2005-10-05 12:15:16 -04:00
|
|
|
void *
|
2005-12-06 02:52:18 -05:00
|
|
|
ruby_xrealloc2(void *ptr, size_t n, size_t size)
|
2005-10-05 12:15:16 -04:00
|
|
|
{
|
2005-12-06 02:52:18 -05:00
|
|
|
size_t len = size * n;
|
|
|
|
if (n != 0 && size != len / n) {
|
2005-10-05 12:15:16 -04:00
|
|
|
rb_raise(rb_eArgError, "realloc: possible integer overflow");
|
|
|
|
}
|
|
|
|
return ruby_xrealloc(ptr, len);
|
|
|
|
}
|
|
|
|
|
2000-02-08 03:54:01 -05:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
ruby_xfree(void *x)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
2000-11-14 02:10:31 -05:00
|
|
|
if (x)
|
|
|
|
RUBY_CRITICAL(free(x));
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2003-12-22 01:20:14 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* GC.enable => true or false
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* Enables garbage collection, returning <code>true</code> if garbage
|
|
|
|
* collection was previously disabled.
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* GC.disable #=> false
|
|
|
|
* GC.enable #=> true
|
|
|
|
* GC.enable #=> false
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
*/
|
|
|
|
|
2001-01-29 00:10:42 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_gc_enable(void)
|
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;
|
|
|
|
}
|
|
|
|
|
2003-12-22 01:20:14 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* GC.disable => true or false
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* Disables garbage collection, returning <code>true</code> if garbage
|
|
|
|
* collection was already disabled.
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* GC.disable #=> false
|
|
|
|
* GC.disable #=> true
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
*/
|
|
|
|
|
2001-01-29 00:10:42 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_gc_disable(void)
|
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;
|
2001-10-31 01:53:22 -05:00
|
|
|
} *global_List = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_gc_register_address(VALUE *addr)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
struct gc_list *tmp;
|
|
|
|
|
|
|
|
tmp = ALLOC(struct gc_list);
|
2001-10-31 01:53:22 -05:00
|
|
|
tmp->next = global_List;
|
2000-02-08 03:54:01 -05:00
|
|
|
tmp->varptr = addr;
|
2001-10-31 01:53:22 -05:00
|
|
|
global_List = tmp;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2000-02-08 03:54:01 -05:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_gc_unregister_address(VALUE *addr)
|
2000-02-08 03:54:01 -05:00
|
|
|
{
|
2001-10-31 01:53:22 -05:00
|
|
|
struct gc_list *tmp = global_List;
|
2000-02-08 03:54:01 -05:00
|
|
|
|
|
|
|
if (tmp->varptr == addr) {
|
2001-10-31 01:53:22 -05:00
|
|
|
global_List = tmp->next;
|
2000-11-14 02:10:31 -05:00
|
|
|
RUBY_CRITICAL(free(tmp));
|
2000-02-08 03:54:01 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (tmp->next) {
|
|
|
|
if (tmp->next->varptr == addr) {
|
|
|
|
struct gc_list *t = tmp->next;
|
|
|
|
|
|
|
|
tmp->next = tmp->next->next;
|
2000-11-14 02:10:31 -05:00
|
|
|
RUBY_CRITICAL(free(t));
|
2000-02-08 03:54:01 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-20 11:59:09 -05:00
|
|
|
#undef GC_DEBUG
|
|
|
|
|
2000-02-08 03:54:01 -05:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_global_variable(VALUE *var)
|
2000-02-08 03:54:01 -05:00
|
|
|
{
|
|
|
|
rb_gc_register_address(var);
|
|
|
|
}
|
|
|
|
|
2006-03-02 04:01:51 -05:00
|
|
|
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__CYGWIN__)
|
|
|
|
#pragma pack(push, 1) /* magic for reducing sizeof(RVALUE): 24 -> 20 */
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
typedef struct RVALUE {
|
|
|
|
union {
|
|
|
|
struct {
|
2001-02-02 06:38:20 -05:00
|
|
|
unsigned long flags; /* 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;
|
2005-06-19 13:16:14 -04:00
|
|
|
struct RVarmap varmap;
|
1998-01-16 07:13:05 -05:00
|
|
|
struct SCOPE scope;
|
|
|
|
} as;
|
2003-12-20 11:59:09 -05:00
|
|
|
#ifdef GC_DEBUG
|
|
|
|
char *file;
|
|
|
|
int line;
|
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
} RVALUE;
|
|
|
|
|
2006-03-02 04:01:51 -05:00
|
|
|
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__CYGWIN__)
|
|
|
|
#pragma pack(pop)
|
|
|
|
#endif
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static RVALUE *freelist = 0;
|
2000-11-20 03:26:48 -05:00
|
|
|
static RVALUE *deferred_final_list = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
#define HEAPS_INCREMENT 10
|
2003-10-01 07:49:44 -04:00
|
|
|
static struct heaps_slot {
|
2006-03-02 00:22:30 -05:00
|
|
|
void *membase;
|
2003-10-01 07:49:44 -04:00
|
|
|
RVALUE *slot;
|
|
|
|
int limit;
|
|
|
|
} *heaps;
|
1998-01-16 07:13:05 -05:00
|
|
|
static int heaps_length = 0;
|
|
|
|
static int heaps_used = 0;
|
|
|
|
|
2001-07-02 04:46:28 -04:00
|
|
|
#define HEAP_MIN_SLOTS 10000
|
|
|
|
static int heap_slots = HEAP_MIN_SLOTS;
|
|
|
|
|
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
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
add_heap(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
RVALUE *p, *pend;
|
|
|
|
|
|
|
|
if (heaps_used == heaps_length) {
|
|
|
|
/* Realloc heaps */
|
2003-10-01 07:49:44 -04:00
|
|
|
struct heaps_slot *p;
|
|
|
|
int length;
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
heaps_length += HEAPS_INCREMENT;
|
2003-10-01 07:49:44 -04:00
|
|
|
length = heaps_length*sizeof(struct heaps_slot);
|
|
|
|
RUBY_CRITICAL(
|
|
|
|
if (heaps_used > 0) {
|
|
|
|
p = (struct heaps_slot *)realloc(heaps, length);
|
|
|
|
if (p) heaps = p;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p = heaps = (struct heaps_slot *)malloc(length);
|
|
|
|
});
|
|
|
|
if (p == 0) rb_memerror();
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2001-07-02 04:46:28 -04:00
|
|
|
for (;;) {
|
2006-03-02 00:22:30 -05:00
|
|
|
RUBY_CRITICAL(p = (RVALUE*)malloc(sizeof(RVALUE)*(heap_slots+1)));
|
2001-07-02 04:46:28 -04:00
|
|
|
if (p == 0) {
|
|
|
|
if (heap_slots == HEAP_MIN_SLOTS) {
|
2002-04-24 00:54:16 -04:00
|
|
|
rb_memerror();
|
2001-07-02 04:46:28 -04:00
|
|
|
}
|
|
|
|
heap_slots = HEAP_MIN_SLOTS;
|
|
|
|
continue;
|
|
|
|
}
|
2006-03-02 00:22:30 -05:00
|
|
|
heaps[heaps_used].membase = p;
|
|
|
|
if ((VALUE)p % sizeof(RVALUE) == 0)
|
|
|
|
heap_slots += 1;
|
|
|
|
else
|
|
|
|
p = (RVALUE*)((VALUE)p + sizeof(RVALUE) - ((VALUE)p % sizeof(RVALUE)));
|
|
|
|
heaps[heaps_used].slot = p;
|
|
|
|
heaps[heaps_used].limit = heap_slots;
|
2001-07-02 04:46:28 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
pend = p + heap_slots;
|
1998-01-16 07:13:05 -05:00
|
|
|
if (lomem == 0 || lomem > p) lomem = p;
|
|
|
|
if (himem < pend) himem = pend;
|
2001-07-02 04:46:28 -04:00
|
|
|
heaps_used++;
|
2001-11-02 02:20:58 -05:00
|
|
|
heap_slots *= 1.8;
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
if (heap_slots <= 0) heap_slots = HEAP_MIN_SLOTS;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
while (p < pend) {
|
2001-02-02 06:38:20 -05:00
|
|
|
p->as.free.flags = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
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
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_newobj(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj;
|
|
|
|
|
2006-01-09 17:32:55 -05:00
|
|
|
if ((gc_stress || !freelist) && !garbage_collect())
|
2005-09-16 09:44:59 -04:00
|
|
|
rb_memerror();
|
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);
|
2003-12-20 11:59:09 -05:00
|
|
|
#ifdef GC_DEBUG
|
|
|
|
RANY(obj)->file = ruby_sourcefile;
|
|
|
|
RANY(obj)->line = ruby_sourceline;
|
|
|
|
#endif
|
2000-08-07 01:05:04 -04:00
|
|
|
return obj;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_data_object_alloc(VALUE klass, void *datap, 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);
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 01:47:45 -05:00
|
|
|
if (klass) Check_Type(klass, T_CLASS);
|
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;
|
2006-01-22 08:32:40 -05:00
|
|
|
#ifdef __ia64
|
2005-12-27 00:40:04 -05:00
|
|
|
VALUE *rb_gc_register_stack_start = 0;
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2004-06-25 05:08:55 -04:00
|
|
|
#ifdef DJGPP
|
|
|
|
/* set stack size (http://www.delorie.com/djgpp/v2faq/faq15_9.html) */
|
|
|
|
unsigned int _stklen = 0x180000; /* 1.5 kB */
|
|
|
|
#endif
|
|
|
|
|
2003-04-25 05:45:43 -04:00
|
|
|
#if defined(DJGPP) || defined(_WIN32_WCE)
|
2001-11-19 00:03:03 -05:00
|
|
|
static unsigned int STACK_LEVEL_MAX = 65535;
|
2004-06-23 08:59:01 -04:00
|
|
|
#elif defined(__human68k__)
|
|
|
|
unsigned int _stacksize = 262144;
|
2001-11-19 00:03:03 -05:00
|
|
|
# define STACK_LEVEL_MAX (_stacksize - 4096)
|
|
|
|
# undef HAVE_GETRLIMIT
|
2006-09-13 12:15:48 -04:00
|
|
|
#elif defined(HAVE_GETRLIMIT) || defined(_WIN32)
|
2001-11-19 00:03:03 -05:00
|
|
|
static unsigned int STACK_LEVEL_MAX = 655300;
|
|
|
|
#else
|
|
|
|
# define STACK_LEVEL_MAX 655300
|
|
|
|
#endif
|
|
|
|
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 02:32:32 -04:00
|
|
|
NOINLINE(static void set_stack_end(VALUE **stack_end_p));
|
2005-04-29 22:59:44 -04:00
|
|
|
|
2004-12-13 04:57:41 -05:00
|
|
|
static void
|
|
|
|
set_stack_end(VALUE **stack_end_p)
|
|
|
|
{
|
|
|
|
VALUE stack_end;
|
|
|
|
*stack_end_p = &stack_end;
|
|
|
|
}
|
|
|
|
#define SET_STACK_END VALUE *stack_end; set_stack_end(&stack_end)
|
|
|
|
#define STACK_END (stack_end)
|
|
|
|
|
2003-01-04 13:48:24 -05:00
|
|
|
#if defined(sparc) || defined(__sparc__)
|
2001-11-19 00:03:03 -05:00
|
|
|
# define STACK_LENGTH (rb_gc_stack_start - STACK_END + 0x80)
|
2003-06-27 23:29:00 -04:00
|
|
|
#elif STACK_GROW_DIRECTION < 0
|
|
|
|
# define STACK_LENGTH (rb_gc_stack_start - STACK_END)
|
|
|
|
#elif STACK_GROW_DIRECTION > 0
|
2003-08-01 10:57:48 -04:00
|
|
|
# define STACK_LENGTH (STACK_END - rb_gc_stack_start + 1)
|
2001-11-19 00:03:03 -05:00
|
|
|
#else
|
|
|
|
# define STACK_LENGTH ((STACK_END < rb_gc_stack_start) ? rb_gc_stack_start - STACK_END\
|
2003-08-01 10:57:48 -04:00
|
|
|
: STACK_END - rb_gc_stack_start + 1)
|
2001-11-19 00:03:03 -05:00
|
|
|
#endif
|
2003-06-27 23:29:00 -04:00
|
|
|
#if STACK_GROW_DIRECTION > 0
|
|
|
|
# define STACK_UPPER(x, a, b) a
|
|
|
|
#elif STACK_GROW_DIRECTION < 0
|
|
|
|
# define STACK_UPPER(x, a, b) b
|
|
|
|
#else
|
2004-06-16 03:01:32 -04:00
|
|
|
static int grow_direction;
|
2003-06-27 23:29:00 -04:00
|
|
|
static int
|
2006-08-13 05:44:16 -04:00
|
|
|
stack_grow_direction(VALUE *addr)
|
2003-06-27 23:29:00 -04:00
|
|
|
{
|
|
|
|
SET_STACK_END;
|
|
|
|
|
2004-06-16 03:01:32 -04:00
|
|
|
if (STACK_END > addr) return grow_direction = 1;
|
|
|
|
return grow_direction = -1;
|
2003-06-27 23:29:00 -04:00
|
|
|
}
|
2004-06-16 03:01:32 -04:00
|
|
|
# define stack_growup_p(x) ((grow_direction ? grow_direction : stack_grow_direction(x)) > 0)
|
2003-06-27 23:29:00 -04:00
|
|
|
# define STACK_UPPER(x, a, b) (stack_growup_p(x) ? a : b)
|
|
|
|
#endif
|
2001-11-19 00:03:03 -05:00
|
|
|
|
2003-12-13 04:13:39 -05:00
|
|
|
#define GC_WATER_MARK 512
|
2003-04-09 02:44:34 -04:00
|
|
|
|
2001-11-19 00:03:03 -05:00
|
|
|
#define CHECK_STACK(ret) do {\
|
|
|
|
SET_STACK_END;\
|
2003-12-13 04:13:39 -05:00
|
|
|
(ret) = (STACK_LENGTH > STACK_LEVEL_MAX + GC_WATER_MARK);\
|
2002-04-25 09:57:01 -04:00
|
|
|
} while (0)
|
2001-11-19 00:03:03 -05:00
|
|
|
|
|
|
|
int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
ruby_stack_length(VALUE **p)
|
2001-11-19 00:03:03 -05:00
|
|
|
{
|
|
|
|
SET_STACK_END;
|
2003-06-27 23:29:00 -04:00
|
|
|
if (p) *p = STACK_UPPER(STACK_END, rb_gc_stack_start, STACK_END);
|
2001-11-19 00:03:03 -05:00
|
|
|
return STACK_LENGTH;
|
|
|
|
}
|
|
|
|
|
2001-11-21 10:42:12 -05:00
|
|
|
int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
ruby_stack_check(void)
|
2001-11-19 00:03:03 -05:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
CHECK_STACK(ret);
|
2001-11-21 10:42:12 -05:00
|
|
|
return ret;
|
2001-11-19 00:03:03 -05:00
|
|
|
}
|
2001-11-13 03:19:52 -05:00
|
|
|
|
|
|
|
#define MARK_STACK_MAX 1024
|
|
|
|
static VALUE mark_stack[MARK_STACK_MAX];
|
|
|
|
static VALUE *mark_stack_ptr;
|
|
|
|
static int mark_stack_overflow;
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
init_mark_stack(void)
|
2001-11-13 03:19:52 -05:00
|
|
|
{
|
|
|
|
mark_stack_overflow = 0;
|
|
|
|
mark_stack_ptr = mark_stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MARK_STACK_EMPTY (mark_stack_ptr == mark_stack)
|
2005-04-29 22:59:44 -04:00
|
|
|
|
2002-03-07 06:19:37 -05:00
|
|
|
static st_table *source_filenames;
|
|
|
|
|
|
|
|
char *
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_source_filename(const char *f)
|
2002-03-07 06:19:37 -05:00
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
|
* st.h, st.c: Introduce new conventional typedef's, st_data_t,
st_compare_func_t, st_hash_func_t and st_each_func_t.
* st.h, st.c: Do explicit function declarations and do not rely on
implicit declarations. On such platforms as IA64, int argument
values are NOT automatically promoted to long (64bit) values, so
explicit declarations are mandatory for those functions that
take long values or pointers. This fixes miniruby's coredump on
FreeBSD/IA64.
* class.c, eval.c, gc.c, hash.c, marshal.c, parse.y, variable.c:
Add proper casts to avoid warnings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-01-06 10:55:43 -05:00
|
|
|
if (!st_lookup(source_filenames, (st_data_t)f, (st_data_t *)&name)) {
|
2002-03-07 06:19:37 -05:00
|
|
|
long len = strlen(f) + 1;
|
|
|
|
char *ptr = name = ALLOC_N(char, len + 1);
|
|
|
|
*ptr++ = 0;
|
|
|
|
MEMCPY(ptr, f, char, len);
|
* st.h, st.c: Introduce new conventional typedef's, st_data_t,
st_compare_func_t, st_hash_func_t and st_each_func_t.
* st.h, st.c: Do explicit function declarations and do not rely on
implicit declarations. On such platforms as IA64, int argument
values are NOT automatically promoted to long (64bit) values, so
explicit declarations are mandatory for those functions that
take long values or pointers. This fixes miniruby's coredump on
FreeBSD/IA64.
* class.c, eval.c, gc.c, hash.c, marshal.c, parse.y, variable.c:
Add proper casts to avoid warnings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-01-06 10:55:43 -05:00
|
|
|
st_add_direct(source_filenames, (st_data_t)ptr, (st_data_t)name);
|
2002-03-07 06:19:37 -05:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
return name + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
mark_source_filename(char *f)
|
2002-03-07 06:19:37 -05:00
|
|
|
{
|
|
|
|
if (f) {
|
|
|
|
f[-1] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
* st.h, st.c: Introduce new conventional typedef's, st_data_t,
st_compare_func_t, st_hash_func_t and st_each_func_t.
* st.h, st.c: Do explicit function declarations and do not rely on
implicit declarations. On such platforms as IA64, int argument
values are NOT automatically promoted to long (64bit) values, so
explicit declarations are mandatory for those functions that
take long values or pointers. This fixes miniruby's coredump on
FreeBSD/IA64.
* class.c, eval.c, gc.c, hash.c, marshal.c, parse.y, variable.c:
Add proper casts to avoid warnings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-01-06 10:55:43 -05:00
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
sweep_source_filename(char *key, char *value)
|
2002-03-07 06:19:37 -05:00
|
|
|
{
|
|
|
|
if (*value) {
|
|
|
|
*value = 0;
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
free(value);
|
|
|
|
return ST_DELETE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 02:32:32 -04:00
|
|
|
static void gc_mark(VALUE ptr, int lev);
|
|
|
|
static void gc_mark_children(VALUE ptr, int lev);
|
2003-04-09 02:44:34 -04:00
|
|
|
|
2001-11-13 03:19:52 -05:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
gc_mark_all(void)
|
2001-11-13 03:19:52 -05:00
|
|
|
{
|
|
|
|
RVALUE *p, *pend;
|
|
|
|
int i;
|
2001-11-27 05:00:35 -05:00
|
|
|
|
|
|
|
init_mark_stack();
|
|
|
|
for (i = 0; i < heaps_used; i++) {
|
2003-10-01 07:49:44 -04:00
|
|
|
p = heaps[i].slot; pend = p + heaps[i].limit;
|
2001-11-27 05:00:35 -05:00
|
|
|
while (p < pend) {
|
|
|
|
if ((p->as.basic.flags & FL_MARK) &&
|
|
|
|
(p->as.basic.flags != FL_MARK)) {
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark_children((VALUE)p, 0);
|
2001-11-13 03:19:52 -05:00
|
|
|
}
|
2001-11-27 05:00:35 -05:00
|
|
|
p++;
|
2001-11-13 03:19:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-09 04:27:01 -04:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
gc_mark_rest(void)
|
2003-04-09 04:27:01 -04:00
|
|
|
{
|
|
|
|
VALUE tmp_arry[MARK_STACK_MAX];
|
|
|
|
VALUE *p;
|
|
|
|
|
|
|
|
p = (mark_stack_ptr - mark_stack) + tmp_arry;
|
|
|
|
MEMCPY(tmp_arry, mark_stack, VALUE, MARK_STACK_MAX);
|
|
|
|
|
|
|
|
init_mark_stack();
|
2005-12-14 22:41:13 -05:00
|
|
|
while (p != tmp_arry){
|
2003-04-09 04:27:01 -04:00
|
|
|
p--;
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark_children(*p, 0);
|
2003-04-09 04:27:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-10 05:07:31 -05:00
|
|
|
static inline int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
is_pointer_to_heap(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;
|
2006-03-02 00:22:30 -05:00
|
|
|
if ((VALUE)p % sizeof(RVALUE) != 0) return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
/* check if p looks like a pointer */
|
|
|
|
for (i=0; i < heaps_used; i++) {
|
2003-10-01 07:49:44 -04:00
|
|
|
heap_org = heaps[i].slot;
|
2006-03-02 00:22:30 -05:00
|
|
|
if (heap_org <= p && p < heap_org + heaps[i].limit)
|
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
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
mark_locations_array(register VALUE *x, register long n)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2005-01-07 04:08:19 -05:00
|
|
|
VALUE v;
|
1998-01-16 07:13:05 -05:00
|
|
|
while (n--) {
|
2005-01-07 04:08:19 -05:00
|
|
|
v = *x;
|
|
|
|
if (is_pointer_to_heap((void *)v)) {
|
|
|
|
gc_mark(v, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_gc_mark_locations(VALUE *start, VALUE *end)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
long n;
|
|
|
|
|
2003-06-27 23:29:00 -04:00
|
|
|
n = end - start;
|
1998-01-16 07:13:05 -05:00
|
|
|
mark_locations_array(start,n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
mark_entry(ID key, VALUE value, int lev)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark(value, lev);
|
1998-01-16 07:13:05 -05:00
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2005-10-18 13:35:18 -04:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
mark_tbl(st_table *tbl, int lev)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
if (!tbl) return;
|
2004-11-03 19:53:21 -05:00
|
|
|
st_foreach(tbl, mark_entry, lev);
|
2003-11-28 09:23:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_mark_tbl(st_table *tbl)
|
2003-11-28 09:23:33 -05:00
|
|
|
{
|
|
|
|
mark_tbl(tbl, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
mark_keyvalue(VALUE key, VALUE value, int lev)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark(key, lev);
|
|
|
|
gc_mark(value, lev);
|
1998-01-16 07:13:05 -05:00
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2005-10-18 13:35:18 -04:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
mark_hash(st_table *tbl, int lev)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
if (!tbl) return;
|
2004-11-03 19:53:21 -05:00
|
|
|
st_foreach(tbl, mark_keyvalue, lev);
|
2003-11-28 09:23:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_mark_hash(st_table *tbl)
|
2003-11-28 09:23:33 -05:00
|
|
|
{
|
|
|
|
mark_hash(tbl, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_gc_mark_maybe(VALUE obj)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2002-05-14 01:59:35 -04:00
|
|
|
if (is_pointer_to_heap((void *)obj)) {
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark(obj, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-28 09:23:33 -05:00
|
|
|
#define GC_LEVEL_MAX 250
|
|
|
|
|
2005-06-19 13:16:14 -04:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
gc_mark(VALUE ptr, int lev)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2003-02-20 19:28:04 -05:00
|
|
|
register RVALUE *obj;
|
2001-11-27 05:00:35 -05:00
|
|
|
|
2003-04-09 04:27:01 -04:00
|
|
|
obj = RANY(ptr);
|
|
|
|
if (rb_special_const_p(ptr)) return; /* special const not marked */
|
|
|
|
if (obj->as.basic.flags == 0) return; /* free cell */
|
2005-06-19 13:16:14 -04:00
|
|
|
if (obj->as.basic.flags & FL_MARK) return; /* already marked */
|
2003-04-09 04:27:01 -04:00
|
|
|
obj->as.basic.flags |= FL_MARK;
|
|
|
|
|
2004-11-10 02:17:53 -05:00
|
|
|
if (lev > GC_LEVEL_MAX || (lev == 0 && ruby_stack_check())) {
|
2001-11-27 05:00:35 -05:00
|
|
|
if (!mark_stack_overflow) {
|
2001-11-13 03:19:52 -05:00
|
|
|
if (mark_stack_ptr - mark_stack < MARK_STACK_MAX) {
|
|
|
|
*mark_stack_ptr = ptr;
|
2001-11-27 05:00:35 -05:00
|
|
|
mark_stack_ptr++;
|
|
|
|
}
|
|
|
|
else {
|
2001-11-13 03:19:52 -05:00
|
|
|
mark_stack_overflow = 1;
|
|
|
|
}
|
|
|
|
}
|
2003-02-20 19:28:04 -05:00
|
|
|
return;
|
2001-11-13 03:19:52 -05:00
|
|
|
}
|
2004-11-03 19:53:21 -05:00
|
|
|
gc_mark_children(ptr, lev+1);
|
2003-11-28 09:23:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_gc_mark(VALUE ptr)
|
2003-11-28 09:23:33 -05:00
|
|
|
{
|
|
|
|
gc_mark(ptr, 0);
|
2003-04-09 04:27:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
gc_mark_children(VALUE ptr, int lev)
|
2003-04-09 04:27:01 -04:00
|
|
|
{
|
|
|
|
register RVALUE *obj = RANY(ptr);
|
|
|
|
|
|
|
|
goto marking; /* skip */
|
2001-11-13 03:19:52 -05:00
|
|
|
|
2003-02-20 19:28:04 -05:00
|
|
|
again:
|
|
|
|
obj = RANY(ptr);
|
|
|
|
if (rb_special_const_p(ptr)) return; /* special const not marked */
|
|
|
|
if (obj->as.basic.flags == 0) return; /* free cell */
|
2005-06-19 13:16:14 -04:00
|
|
|
if (obj->as.basic.flags & FL_MARK) return; /* already marked */
|
2003-02-20 19:28:04 -05:00
|
|
|
obj->as.basic.flags |= FL_MARK;
|
|
|
|
|
2003-04-09 04:27:01 -04:00
|
|
|
marking:
|
1999-01-19 23:59:39 -05:00
|
|
|
if (FL_TEST(obj, FL_EXIVAR)) {
|
2003-02-20 19:28:04 -05:00
|
|
|
rb_mark_generic_ivar(ptr);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
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:
|
2002-03-07 06:19:37 -05:00
|
|
|
mark_source_filename(obj->as.node.nd_file);
|
1998-01-16 07:13:05 -05:00
|
|
|
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_WHEN:
|
|
|
|
case NODE_MASGN:
|
|
|
|
case NODE_RESCUE:
|
|
|
|
case NODE_RESBODY:
|
2003-02-19 04:27:49 -05:00
|
|
|
case NODE_CLASS:
|
2005-07-27 03:27:19 -04:00
|
|
|
case NODE_ARGS:
|
2006-06-29 10:57:42 -04:00
|
|
|
case NODE_BLOCK_PASS:
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark((VALUE)obj->as.node.u2.node, lev);
|
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_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:
|
2006-02-12 23:53:22 -05:00
|
|
|
case NODE_CREF:
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark((VALUE)obj->as.node.u1.node, lev);
|
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:
|
2003-02-20 19:28:04 -05:00
|
|
|
ptr = (VALUE)obj->as.node.u3.node;
|
|
|
|
goto again;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
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:
|
2003-02-19 04:27:49 -05:00
|
|
|
case NODE_MODULE:
|
2004-10-30 02:56:18 -04:00
|
|
|
case NODE_ALIAS:
|
|
|
|
case NODE_VALIAS:
|
2006-06-29 10:05:40 -04:00
|
|
|
case NODE_LAMBDA:
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark((VALUE)obj->as.node.u1.node, lev);
|
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_CVDECL:
|
2000-11-21 09:26:25 -05:00
|
|
|
case NODE_CVASGN:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_COLON3:
|
|
|
|
case NODE_OPT_N:
|
2002-07-26 02:12:39 -04:00
|
|
|
case NODE_EVSTR:
|
2004-10-30 02:56:18 -04:00
|
|
|
case NODE_UNDEF:
|
2006-10-29 22:40:11 -05:00
|
|
|
case NODE_POSTEXE:
|
2003-02-20 19:28:04 -05:00
|
|
|
ptr = (VALUE)obj->as.node.u2.node;
|
|
|
|
goto again;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
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:
|
2001-07-02 04:46:28 -04:00
|
|
|
case NODE_BREAK:
|
|
|
|
case NODE_NEXT:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_YIELD:
|
|
|
|
case NODE_COLON2:
|
2003-03-26 02:01:14 -05:00
|
|
|
case NODE_SPLAT:
|
2003-10-06 13:59:53 -04:00
|
|
|
case NODE_TO_ARY:
|
2003-02-20 19:28:04 -05:00
|
|
|
ptr = (VALUE)obj->as.node.u1.node;
|
|
|
|
goto again;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
case NODE_SCOPE: /* 2,3 */
|
2003-02-19 22:35:44 -05:00
|
|
|
case NODE_CDECL:
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark((VALUE)obj->as.node.u3.node, lev);
|
2003-02-20 19:28:04 -05:00
|
|
|
ptr = (VALUE)obj->as.node.u2.node;
|
|
|
|
goto again;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
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:
|
|
|
|
case NODE_NTH_REF:
|
|
|
|
case NODE_BACK_REF:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_REDO:
|
|
|
|
case NODE_RETRY:
|
1998-01-16 07:13:05 -05:00
|
|
|
case NODE_SELF:
|
|
|
|
case NODE_NIL:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_TRUE:
|
|
|
|
case NODE_FALSE:
|
2004-01-22 03:31:33 -05:00
|
|
|
case NODE_ERRINFO:
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_ATTRSET:
|
|
|
|
case NODE_BLOCK_ARG:
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
1999-01-19 23:59:39 -05:00
|
|
|
case NODE_ALLOCA:
|
|
|
|
mark_locations_array((VALUE*)obj->as.node.u1.value,
|
|
|
|
obj->as.node.u3.cnt);
|
2003-02-20 19:28:04 -05:00
|
|
|
ptr = (VALUE)obj->as.node.u2.node;
|
|
|
|
goto again;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-02-20 19:28:04 -05:00
|
|
|
default: /* unlisted NODE */
|
2000-05-09 00:53:16 -04:00
|
|
|
if (is_pointer_to_heap(obj->as.node.u1.node)) {
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark((VALUE)obj->as.node.u1.node, lev);
|
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)) {
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark((VALUE)obj->as.node.u2.node, lev);
|
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)) {
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark((VALUE)obj->as.node.u3.node, lev);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return; /* no need to mark class. */
|
|
|
|
}
|
|
|
|
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark(obj->as.basic.klass, lev);
|
1998-01-16 07:13:05 -05:00
|
|
|
switch (obj->as.basic.flags & T_MASK) {
|
|
|
|
case T_ICLASS:
|
|
|
|
case T_CLASS:
|
|
|
|
case T_MODULE:
|
2003-11-28 09:23:33 -05:00
|
|
|
mark_tbl(obj->as.klass.m_tbl, lev);
|
|
|
|
mark_tbl(obj->as.klass.iv_tbl, lev);
|
2003-02-20 19:28:04 -05:00
|
|
|
ptr = obj->as.klass.super;
|
|
|
|
goto again;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
case T_ARRAY:
|
2002-09-04 05:23:51 -04:00
|
|
|
if (FL_TEST(obj, ELTS_SHARED)) {
|
2006-11-01 09:42:39 -05:00
|
|
|
ptr = obj->as.array.aux.shared;
|
2003-02-20 19:28:04 -05:00
|
|
|
goto again;
|
2002-09-04 05:23:51 -04:00
|
|
|
}
|
|
|
|
else {
|
2006-09-02 10:42:08 -04:00
|
|
|
long i, len = RARRAY_LEN(obj);
|
|
|
|
VALUE *ptr = RARRAY_PTR(obj);
|
2001-10-31 01:53:22 -05:00
|
|
|
|
2002-09-04 05:23:51 -04:00
|
|
|
for (i=0; i < len; i++) {
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark(*ptr++, lev);
|
2002-09-04 05:23:51 -04:00
|
|
|
}
|
2001-11-13 03:19:52 -05:00
|
|
|
}
|
|
|
|
break;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
case T_HASH:
|
2003-11-28 09:23:33 -05:00
|
|
|
mark_hash(obj->as.hash.tbl, lev);
|
2003-02-20 19:28:04 -05:00
|
|
|
ptr = obj->as.hash.ifnone;
|
|
|
|
goto again;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
case T_STRING:
|
2001-12-10 22:48:08 -05:00
|
|
|
#define STR_ASSOC FL_USER3 /* copied from string.c */
|
2006-09-02 10:42:08 -04:00
|
|
|
if (FL_TEST(obj, RSTRING_NOEMBED) && FL_ANY(obj, ELTS_SHARED|STR_ASSOC)) {
|
2006-08-31 06:47:44 -04:00
|
|
|
ptr = obj->as.string.as.heap.aux.shared;
|
2003-02-20 19:28:04 -05:00
|
|
|
goto again;
|
2001-11-13 03:19:52 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_DATA:
|
|
|
|
if (obj->as.data.dmark) (*obj->as.data.dmark)(DATA_PTR(obj));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_OBJECT:
|
2003-11-28 09:23:33 -05:00
|
|
|
mark_tbl(obj->as.object.iv_tbl, lev);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_FILE:
|
|
|
|
case T_REGEXP:
|
|
|
|
case T_FLOAT:
|
|
|
|
case T_BIGNUM:
|
2004-03-10 02:05:19 -05:00
|
|
|
case T_BLOCK:
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_MATCH:
|
2006-03-21 08:16:21 -05:00
|
|
|
gc_mark(obj->as.match.regexp, lev);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (obj->as.match.str) {
|
2003-02-20 19:28:04 -05:00
|
|
|
ptr = obj->as.match.str;
|
|
|
|
goto again;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_VARMAP:
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark(obj->as.varmap.val, lev);
|
2003-02-20 19:28:04 -05:00
|
|
|
ptr = (VALUE)obj->as.varmap.next;
|
|
|
|
goto again;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
case T_SCOPE:
|
2001-02-02 06:38:20 -05:00
|
|
|
if (obj->as.scope.local_vars && (obj->as.scope.flags & 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];
|
|
|
|
|
2001-11-13 03:19:52 -05:00
|
|
|
while (n--) {
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark(*vars++, lev);
|
2001-11-13 03:19:52 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_STRUCT:
|
2001-11-13 03:19:52 -05:00
|
|
|
{
|
2006-02-05 09:40:01 -05:00
|
|
|
long len = RSTRUCT_LEN(obj);
|
|
|
|
VALUE *ptr = RSTRUCT_PTR(obj);
|
2001-10-31 01:53:22 -05:00
|
|
|
|
2003-02-20 19:28:04 -05:00
|
|
|
while (len--) {
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark(*ptr++, lev);
|
2003-02-20 19:28:04 -05:00
|
|
|
}
|
2001-11-13 03:19:52 -05:00
|
|
|
}
|
|
|
|
break;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
default:
|
2005-12-15 23:58:51 -05:00
|
|
|
rb_bug("rb_gc_mark(): unknown data type 0x%lx(%p) %s",
|
1999-01-19 23:59:39 -05:00
|
|
|
obj->as.basic.flags & T_MASK, obj,
|
2005-12-15 23:58:51 -05:00
|
|
|
is_pointer_to_heap(obj) ? "corrupted object" : "non object");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 02:32:32 -04:00
|
|
|
static void obj_free(VALUE);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2004-09-27 08:25:21 -04:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
finalize_list(RVALUE *p)
|
2004-09-27 08:25:21 -04:00
|
|
|
{
|
|
|
|
while (p) {
|
|
|
|
RVALUE *tmp = p->as.free.next;
|
|
|
|
run_final((VALUE)p);
|
|
|
|
if (!FL_TEST(p, FL_SINGLETON)) { /* not freeing page */
|
|
|
|
p->as.free.flags = 0;
|
|
|
|
p->as.free.next = freelist;
|
|
|
|
freelist = p;
|
|
|
|
}
|
|
|
|
p = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
free_unused_heaps(void)
|
2004-09-27 08:25:21 -04:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = j = 1; j < heaps_used; i++) {
|
|
|
|
if (heaps[i].limit == 0) {
|
2006-03-02 00:22:30 -05:00
|
|
|
free(heaps[i].membase);
|
2004-09-27 08:25:21 -04:00
|
|
|
heaps_used--;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (i != j) {
|
|
|
|
heaps[j] = heaps[i];
|
|
|
|
}
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-29 12:11:28 -05:00
|
|
|
void rb_gc_abort_threads(void);
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
gc_sweep(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
RVALUE *p, *pend, *final_list;
|
1998-01-16 07:13:05 -05:00
|
|
|
int freed = 0;
|
2004-10-06 03:40:06 -04:00
|
|
|
int i;
|
2003-01-16 02:38:40 -05:00
|
|
|
unsigned long live = 0;
|
2006-07-10 06:26:45 -04:00
|
|
|
unsigned long free_min = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < heaps_used; i++) {
|
|
|
|
free_min += heaps[i].limit;
|
|
|
|
}
|
|
|
|
free_min = free_min * 0.2;
|
|
|
|
if (free_min < FREE_MIN)
|
|
|
|
free_min = FREE_MIN;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2002-03-07 06:19:37 -05:00
|
|
|
mark_source_filename(ruby_sourcefile);
|
2005-12-11 22:08:35 -05:00
|
|
|
if (source_filenames) {
|
|
|
|
st_foreach(source_filenames, sweep_source_filename, 0);
|
|
|
|
}
|
2002-03-07 06:19:37 -05:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
freelist = 0;
|
2000-11-20 03:26:48 -05:00
|
|
|
final_list = deferred_final_list;
|
|
|
|
deferred_final_list = 0;
|
2002-10-02 02:02:17 -04:00
|
|
|
for (i = 0; i < heaps_used; i++) {
|
1998-01-16 07:13:05 -05:00
|
|
|
int n = 0;
|
2002-10-02 02:02:17 -04:00
|
|
|
RVALUE *free = freelist;
|
|
|
|
RVALUE *final = final_list;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-10-01 07:49:44 -04:00
|
|
|
p = heaps[i].slot; pend = p + heaps[i].limit;
|
1998-01-16 07:13:05 -05:00
|
|
|
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)) {
|
2001-02-02 06:38:20 -05:00
|
|
|
p->as.free.flags = FL_MARK; /* remain marked */
|
1999-01-19 23:59:39 -05:00
|
|
|
p->as.free.next = final_list;
|
|
|
|
final_list = p;
|
|
|
|
}
|
|
|
|
else {
|
2001-02-02 06:38:20 -05:00
|
|
|
p->as.free.flags = 0;
|
1999-01-19 23:59:39 -05:00
|
|
|
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 */
|
2006-02-05 21:49:37 -05:00
|
|
|
/* do nothing remain marked */
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
else {
|
1998-01-16 07:13:05 -05:00
|
|
|
RBASIC(p)->flags &= ~FL_MARK;
|
2002-12-29 09:51:22 -05:00
|
|
|
live++;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
p++;
|
|
|
|
}
|
2006-07-10 06:26:45 -04:00
|
|
|
if (n == heaps[i].limit && freed > free_min) {
|
2002-10-02 02:02:17 -04:00
|
|
|
RVALUE *pp;
|
|
|
|
|
2003-10-01 07:49:44 -04:00
|
|
|
heaps[i].limit = 0;
|
2002-10-02 02:02:17 -04:00
|
|
|
for (pp = final_list; pp != final; pp = pp->as.free.next) {
|
2006-08-30 05:49:41 -04:00
|
|
|
pp->as.free.flags |= FL_SINGLETON; /* freeing page mark */
|
2002-10-02 02:02:17 -04:00
|
|
|
}
|
|
|
|
freelist = free; /* cancel this page from freelist */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
freed += n;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2003-10-19 22:06:42 -04:00
|
|
|
if (malloc_increase > malloc_limit) {
|
|
|
|
malloc_limit += (malloc_increase - malloc_limit) * (double)live / (live + freed);
|
|
|
|
if (malloc_limit < GC_MALLOC_LIMIT) malloc_limit = GC_MALLOC_LIMIT;
|
|
|
|
}
|
2002-10-10 13:11:18 -04:00
|
|
|
malloc_increase = 0;
|
2006-07-10 06:26:45 -04:00
|
|
|
if (freed < free_min) {
|
1998-01-16 07:13:05 -05:00
|
|
|
add_heap();
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
during_gc = 0;
|
|
|
|
|
|
|
|
/* clear finalization list */
|
2001-01-23 04:55:10 -05:00
|
|
|
if (final_list) {
|
2004-09-27 08:25:21 -04:00
|
|
|
deferred_final_list = final_list;
|
|
|
|
return;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2004-09-27 08:25:21 -04:00
|
|
|
free_unused_heaps();
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_gc_force_recycle(VALUE p)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-02-02 06:38:20 -05:00
|
|
|
RANY(p)->as.free.flags = 0;
|
1998-01-16 07:19:22 -05:00
|
|
|
RANY(p)->as.free.next = freelist;
|
|
|
|
freelist = RANY(p);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
obj_free(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:
|
2003-07-07 04:28:19 -04:00
|
|
|
rb_clear_cache_by_class((VALUE)obj);
|
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:
|
2006-09-26 18:46:16 -04:00
|
|
|
rb_str_free(obj);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case T_ARRAY:
|
2006-09-26 18:46:16 -04:00
|
|
|
rb_ary_free(obj);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case T_HASH:
|
2000-09-26 23:43:15 -04:00
|
|
|
if (RANY(obj)->as.hash.tbl) {
|
1999-01-19 23:59:39 -05:00
|
|
|
st_free_table(RANY(obj)->as.hash.tbl);
|
2000-09-26 23:43:15 -04:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
case T_REGEXP:
|
2000-09-26 23:43:15 -04:00
|
|
|
if (RANY(obj)->as.regexp.ptr) {
|
2005-02-17 09:43:38 -05:00
|
|
|
onig_free(RANY(obj)->as.regexp.ptr);
|
2000-09-26 23:43:15 -04:00
|
|
|
}
|
|
|
|
if (RANY(obj)->as.regexp.str) {
|
2000-11-14 02:10:31 -05:00
|
|
|
RUBY_CRITICAL(free(RANY(obj)->as.regexp.str));
|
2000-09-26 23:43:15 -04:00
|
|
|
}
|
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) {
|
2000-11-14 02:10:31 -05:00
|
|
|
RUBY_CRITICAL(free(DATA_PTR(obj)));
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
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) {
|
2005-02-17 09:43:38 -05:00
|
|
|
onig_region_free(RANY(obj)->as.match.regs, 0);
|
2000-11-14 02:10:31 -05:00
|
|
|
RUBY_CRITICAL(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);
|
|
|
|
}
|
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:
|
2004-03-10 02:05:19 -05:00
|
|
|
case T_BLOCK:
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
2000-09-26 23:43:15 -04:00
|
|
|
if (RANY(obj)->as.bignum.digits) {
|
2000-11-14 02:10:31 -05:00
|
|
|
RUBY_CRITICAL(free(RANY(obj)->as.bignum.digits));
|
2000-09-26 23:43:15 -04:00
|
|
|
}
|
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) {
|
2000-11-14 02:10:31 -05:00
|
|
|
RUBY_CRITICAL(free(RANY(obj)->as.node.u1.tbl));
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NODE_ALLOCA:
|
2001-03-26 03:57:16 -05:00
|
|
|
RUBY_CRITICAL(free(RANY(obj)->as.node.u1.node));
|
1999-01-19 23:59:39 -05:00
|
|
|
break;
|
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 &&
|
2001-02-02 06:38:20 -05:00
|
|
|
RANY(obj)->as.scope.flags != 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)
|
2000-11-14 02:10:31 -05:00
|
|
|
RUBY_CRITICAL(free(RANY(obj)->as.scope.local_tbl));
|
2001-02-02 06:38:20 -05:00
|
|
|
if (RANY(obj)->as.scope.flags & SCOPE_MALLOC)
|
2000-11-14 02:10:31 -05:00
|
|
|
RUBY_CRITICAL(free(vars));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_STRUCT:
|
2006-02-05 09:40:01 -05:00
|
|
|
if (RBASIC(obj)->flags & RSTRUCT_EMBED_LEN_MASK == 0 &&
|
|
|
|
RANY(obj)->as.rstruct.as.heap.ptr) {
|
|
|
|
RUBY_CRITICAL(free(RANY(obj)->as.rstruct.as.heap.ptr));
|
2000-09-26 23:43:15 -04:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2005-07-27 10:30:09 -04:00
|
|
|
rb_bug("gc_sweep(): unknown data type 0x%lx(%p)",
|
2006-09-17 21:59:00 -04:00
|
|
|
RANY(obj)->as.basic.flags & T_MASK, (void*)obj);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_gc_mark_frame(struct FRAME *frame)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark((VALUE)frame->node, 0);
|
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];
|
2001-06-19 11:42:00 -04:00
|
|
|
__asm__ (".even\n\
|
|
|
|
_rb_setjmp:\n\
|
|
|
|
move.l 4(sp),a0\n\
|
|
|
|
movem.l d3-d7/a3-a5,(a0)\n\
|
|
|
|
moveq.l #0,d0\n\
|
1998-01-16 07:13:05 -05:00
|
|
|
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];
|
2001-06-19 11:42:00 -04:00
|
|
|
__asm__ (".align 4\n\
|
|
|
|
_rb_setjmp:\n\
|
|
|
|
pushl %ebp\n\
|
|
|
|
movl %esp,%ebp\n\
|
|
|
|
movl 8(%ebp),%ebp\n\
|
|
|
|
movl %eax,(%ebp)\n\
|
|
|
|
movl %ebx,4(%ebp)\n\
|
|
|
|
movl %ecx,8(%ebp)\n\
|
|
|
|
movl %edx,12(%ebp)\n\
|
|
|
|
movl %esi,16(%ebp)\n\
|
|
|
|
movl %edi,20(%ebp)\n\
|
|
|
|
popl %ebp\n\
|
|
|
|
xorl %eax,%eax\n\
|
1998-01-16 07:13:05 -05:00
|
|
|
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__ */
|
|
|
|
|
2005-09-16 09:44:59 -04:00
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
garbage_collect(void)
|
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;
|
2002-05-14 02:22:31 -04:00
|
|
|
SET_STACK_END;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2005-09-16 09:44:59 -04:00
|
|
|
if (!heaps) return Qfalse;
|
2003-11-19 22:50:32 -05:00
|
|
|
#ifdef HAVE_NATIVETHREAD
|
|
|
|
if (!is_ruby_native_thread()) {
|
|
|
|
rb_bug("cross-thread violation on rb_gc()");
|
|
|
|
}
|
|
|
|
#endif
|
2000-11-20 03:26:48 -05:00
|
|
|
if (dont_gc || during_gc) {
|
2002-09-06 04:59:41 -04:00
|
|
|
if (!freelist) {
|
2000-08-02 00:54:21 -04:00
|
|
|
add_heap();
|
|
|
|
}
|
2005-10-25 01:30:10 -04:00
|
|
|
return Qtrue;
|
2000-07-27 05:49:34 -04:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
during_gc++;
|
|
|
|
|
2001-11-13 03:19:52 -05:00
|
|
|
init_mark_stack();
|
2005-06-19 13:16:14 -04:00
|
|
|
|
2006-01-10 05:50:17 -05:00
|
|
|
gc_mark((VALUE)ruby_current_node, 0);
|
|
|
|
|
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) {
|
2005-06-19 13:16:14 -04:00
|
|
|
rb_gc_mark_frame(frame);
|
1999-08-13 01:45:20 -04:00
|
|
|
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
|
|
|
}
|
2003-11-28 09:23:33 -05:00
|
|
|
gc_mark((VALUE)ruby_scope, 0);
|
|
|
|
gc_mark((VALUE)ruby_dyna_vars, 0);
|
2000-07-15 09:37:03 -04:00
|
|
|
if (finalizer_table) {
|
2003-11-28 09:23:33 -05:00
|
|
|
mark_tbl(finalizer_table, 0);
|
2000-07-15 09:37:03 -04:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
FLUSH_REGISTER_WINDOWS;
|
2003-08-01 06:57:32 -04:00
|
|
|
/* This assumes that all registers are saved into the jmp_buf (and stack) */
|
1998-01-16 07:13:05 -05:00
|
|
|
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 *));
|
2003-06-27 23:29:00 -04:00
|
|
|
#if STACK_GROW_DIRECTION < 0
|
|
|
|
rb_gc_mark_locations((VALUE*)STACK_END, rb_gc_stack_start);
|
|
|
|
#elif STACK_GROW_DIRECTION > 0
|
2003-08-01 10:57:48 -04:00
|
|
|
rb_gc_mark_locations(rb_gc_stack_start, (VALUE*)STACK_END + 1);
|
2003-06-27 23:29:00 -04:00
|
|
|
#else
|
|
|
|
if ((VALUE*)STACK_END < rb_gc_stack_start)
|
|
|
|
rb_gc_mark_locations((VALUE*)STACK_END, rb_gc_stack_start);
|
|
|
|
else
|
2003-08-01 10:57:48 -04:00
|
|
|
rb_gc_mark_locations(rb_gc_stack_start, (VALUE*)STACK_END + 1);
|
2003-06-27 23:29:00 -04:00
|
|
|
#endif
|
2006-01-22 08:32:40 -05:00
|
|
|
#ifdef __ia64
|
2005-12-27 00:40:04 -05:00
|
|
|
/* mark backing store (flushed register stack) */
|
2003-08-01 06:57:32 -04:00
|
|
|
/* the basic idea from guile GC code */
|
2005-12-27 00:40:04 -05:00
|
|
|
rb_gc_mark_locations(rb_gc_register_stack_start, (VALUE*)rb_ia64_bsp());
|
2003-08-01 06:57:32 -04:00
|
|
|
#endif
|
2003-05-08 05:45:52 -04:00
|
|
|
#if defined(__human68k__) || defined(__mc68000__)
|
2003-06-27 23:29:00 -04:00
|
|
|
rb_gc_mark_locations((VALUE*)((char*)STACK_END + 2),
|
|
|
|
(VALUE*)((char*)rb_gc_stack_start + 2));
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_gc_mark_threads();
|
2006-09-02 11:05:27 -04:00
|
|
|
rb_gc_mark_symbols();
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
/* mark protected global variables */
|
2001-10-31 01:53:22 -05:00
|
|
|
for (list = global_List; list; list = list->next) {
|
2003-04-21 04:17:18 -04:00
|
|
|
rb_gc_mark_maybe(*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();
|
2002-09-05 16:00:52 -04:00
|
|
|
|
|
|
|
rb_gc_mark_parser();
|
2005-06-19 13:16:14 -04:00
|
|
|
|
2001-11-13 03:19:52 -05:00
|
|
|
/* gc_mark objects whose marking are not completed*/
|
2005-12-30 04:15:56 -05:00
|
|
|
do {
|
|
|
|
while (!MARK_STACK_EMPTY) {
|
|
|
|
if (mark_stack_overflow){
|
|
|
|
gc_mark_all();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gc_mark_rest();
|
|
|
|
}
|
2001-10-31 01:53:22 -05:00
|
|
|
}
|
2005-12-30 04:15:56 -05:00
|
|
|
rb_gc_abort_threads();
|
|
|
|
} while (!MARK_STACK_EMPTY);
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
gc_sweep();
|
2005-09-16 09:44:59 -04:00
|
|
|
|
|
|
|
return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2004-09-27 08:25:21 -04:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_gc(void)
|
2004-09-27 08:25:21 -04:00
|
|
|
{
|
2004-10-01 11:56:05 -04:00
|
|
|
garbage_collect();
|
2004-09-27 08:25:21 -04:00
|
|
|
rb_gc_finalize_deferred();
|
|
|
|
}
|
|
|
|
|
2003-12-22 01:20:14 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* GC.start => nil
|
|
|
|
* gc.garbage_collect => nil
|
|
|
|
* ObjectSpace.garbage_collect => nil
|
|
|
|
*
|
|
|
|
* Initiates garbage collection, unless manually disabled.
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
*/
|
|
|
|
|
2001-01-29 00:10:42 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_gc_start(void)
|
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;
|
|
|
|
}
|
|
|
|
|
2004-10-27 05:29:26 -04:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
ruby_set_stack_size(size_t size)
|
2004-10-27 05:29:26 -04:00
|
|
|
{
|
|
|
|
#ifndef STACK_LEVEL_MAX
|
|
|
|
STACK_LEVEL_MAX = size/sizeof(VALUE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
Init_stack(VALUE *addr)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2006-01-22 08:32:40 -05:00
|
|
|
#ifdef __ia64
|
2005-12-27 00:40:04 -05:00
|
|
|
if (rb_gc_register_stack_start == 0) {
|
|
|
|
# if defined(__FreeBSD__)
|
|
|
|
/*
|
|
|
|
* FreeBSD/ia64 currently does not have a way for a process to get the
|
|
|
|
* base address for the RSE backing store, so hardcode it.
|
|
|
|
*/
|
|
|
|
rb_gc_register_stack_start = (4ULL<<61);
|
|
|
|
# elif defined(HAVE___LIBC_IA64_REGISTER_BACKING_STORE_BASE)
|
|
|
|
# pragma weak __libc_ia64_register_backing_store_base
|
|
|
|
extern unsigned long __libc_ia64_register_backing_store_base;
|
|
|
|
rb_gc_register_stack_start = (VALUE*)__libc_ia64_register_backing_store_base;
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
{
|
|
|
|
VALUE *bsp = (VALUE*)rb_ia64_bsp();
|
|
|
|
if (rb_gc_register_stack_start == 0 ||
|
|
|
|
bsp < rb_gc_register_stack_start) {
|
|
|
|
rb_gc_register_stack_start = bsp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2004-07-08 06:27:23 -04:00
|
|
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
|
|
|
MEMORY_BASIC_INFORMATION m;
|
|
|
|
memset(&m, 0, sizeof(m));
|
|
|
|
VirtualQuery(&m, &m, sizeof(m));
|
|
|
|
rb_gc_stack_start =
|
|
|
|
STACK_UPPER((VALUE *)&m, (VALUE *)m.BaseAddress,
|
|
|
|
(VALUE *)((char *)m.BaseAddress + m.RegionSize) - 1);
|
|
|
|
#elif defined(STACK_END_ADDRESS)
|
2005-12-27 00:40:04 -05:00
|
|
|
{
|
|
|
|
extern void *STACK_END_ADDRESS;
|
|
|
|
rb_gc_stack_start = STACK_END_ADDRESS;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
#else
|
2002-10-03 07:24:24 -04:00
|
|
|
if (!addr) addr = (VALUE *)&addr;
|
2004-06-16 03:01:32 -04:00
|
|
|
STACK_UPPER(&addr, addr, ++addr);
|
2003-02-27 03:04:32 -05:00
|
|
|
if (rb_gc_stack_start) {
|
2003-06-27 23:29:00 -04:00
|
|
|
if (STACK_UPPER(&addr,
|
2003-08-01 10:57:48 -04:00
|
|
|
rb_gc_stack_start > addr,
|
2004-06-16 03:01:32 -04:00
|
|
|
rb_gc_stack_start < addr))
|
2003-06-27 23:29:00 -04:00
|
|
|
rb_gc_stack_start = addr;
|
2003-02-27 03:04:32 -05:00
|
|
|
return;
|
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_gc_stack_start = addr;
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
2001-11-19 00:03:03 -05:00
|
|
|
#ifdef HAVE_GETRLIMIT
|
|
|
|
{
|
|
|
|
struct rlimit rlim;
|
|
|
|
|
|
|
|
if (getrlimit(RLIMIT_STACK, &rlim) == 0) {
|
2003-10-04 08:51:32 -04:00
|
|
|
unsigned int space = rlim.rlim_cur/5;
|
2001-11-19 00:03:03 -05:00
|
|
|
|
|
|
|
if (space > 1024*1024) space = 1024*1024;
|
|
|
|
STACK_LEVEL_MAX = (rlim.rlim_cur - space) / sizeof(VALUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2005-12-27 00:40:04 -05:00
|
|
|
void ruby_init_stack(VALUE *addr
|
2006-01-22 08:32:40 -05:00
|
|
|
#ifdef __ia64
|
2005-12-27 00:40:04 -05:00
|
|
|
, void *bsp
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (!rb_gc_stack_start ||
|
|
|
|
STACK_UPPER(&addr,
|
|
|
|
rb_gc_stack_start > addr,
|
|
|
|
rb_gc_stack_start < addr)) {
|
|
|
|
rb_gc_stack_start = addr;
|
|
|
|
}
|
2006-01-22 08:32:40 -05:00
|
|
|
#ifdef __ia64
|
2005-12-27 00:40:04 -05:00
|
|
|
if (!rb_gc_register_stack_start ||
|
|
|
|
(VALUE*)bsp < rb_gc_register_stack_start) {
|
|
|
|
rb_gc_register_stack_start = (VALUE*)bsp;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GETRLIMIT
|
|
|
|
{
|
|
|
|
struct rlimit rlim;
|
|
|
|
|
|
|
|
if (getrlimit(RLIMIT_STACK, &rlim) == 0) {
|
|
|
|
unsigned int space = rlim.rlim_cur/5;
|
|
|
|
|
|
|
|
if (space > 1024*1024) space = 1024*1024;
|
|
|
|
STACK_LEVEL_MAX = (rlim.rlim_cur - space) / sizeof(VALUE);
|
|
|
|
}
|
|
|
|
}
|
2006-09-13 12:15:48 -04:00
|
|
|
#elif defined _WIN32
|
|
|
|
{
|
|
|
|
MEMORY_BASIC_INFORMATION mi;
|
|
|
|
DWORD size;
|
|
|
|
DWORD space;
|
|
|
|
|
|
|
|
if (VirtualQuery(&mi, &mi, sizeof(mi))) {
|
|
|
|
size = (char *)mi.BaseAddress - (char *)mi.AllocationBase;
|
|
|
|
space = size / 5;
|
|
|
|
if (space > 1024*1024) space = 1024*1024;
|
|
|
|
STACK_LEVEL_MAX = (size - space) / sizeof(VALUE);
|
|
|
|
}
|
|
|
|
}
|
2005-12-27 00:40:04 -05:00
|
|
|
#endif
|
|
|
|
}
|
2003-12-22 01:20:14 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-class: ObjectSpace
|
|
|
|
*
|
|
|
|
* The <code>ObjectSpace</code> module contains a number of routines
|
|
|
|
* that interact with the garbage collection facility and allow you to
|
|
|
|
* traverse all living objects with an iterator.
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* <code>ObjectSpace</code> also provides support for object
|
|
|
|
* finalizers, procs that will be called when a specific object is
|
|
|
|
* about to be destroyed by garbage collection.
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* include ObjectSpace
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* a = "A"
|
|
|
|
* b = "B"
|
|
|
|
* c = "C"
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* define_finalizer(a, proc {|id| puts "Finalizer one on #{id}" })
|
|
|
|
* define_finalizer(a, proc {|id| puts "Finalizer two on #{id}" })
|
|
|
|
* define_finalizer(b, proc {|id| puts "Finalizer three on #{id}" })
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* <em>produces:</em>
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* Finalizer three on 537763470
|
|
|
|
* Finalizer one on 537763480
|
|
|
|
* Finalizer two on 537763480
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
Init_heap(void)
|
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
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
os_live_obj(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < heaps_used; i++) {
|
|
|
|
RVALUE *p, *pend;
|
|
|
|
|
2003-10-01 07:49:44 -04:00
|
|
|
p = heaps[i].slot; pend = p + heaps[i].limit;
|
1998-01-16 07:13:05 -05:00
|
|
|
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:
|
2001-01-23 03:08:59 -05:00
|
|
|
if (!p->as.basic.klass) continue;
|
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
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
os_obj_of(VALUE of)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < heaps_used; i++) {
|
|
|
|
RVALUE *p, *pend;
|
|
|
|
|
2003-10-01 07:49:44 -04:00
|
|
|
p = heaps[i].slot; pend = p + heaps[i].limit;
|
1998-01-16 07:13:05 -05:00
|
|
|
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:
|
2001-01-23 03:08:59 -05:00
|
|
|
if (!p->as.basic.klass) continue;
|
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);
|
|
|
|
}
|
|
|
|
|
2003-12-22 01:20:14 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ObjectSpace.each_object([module]) {|obj| ... } => fixnum
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* Calls the block once for each living, nonimmediate object in this
|
|
|
|
* Ruby process. If <i>module</i> is specified, calls the block
|
|
|
|
* for only those classes or modules that match (or are a subclass of)
|
|
|
|
* <i>module</i>. Returns the number of objects found. Immediate
|
|
|
|
* objects (<code>Fixnum</code>s, <code>Symbol</code>s
|
|
|
|
* <code>true</code>, <code>false</code>, and <code>nil</code>) are
|
|
|
|
* never returned. In the example below, <code>each_object</code>
|
|
|
|
* returns both the numbers we defined and several constants defined in
|
|
|
|
* the <code>Math</code> module.
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* a = 102.7
|
|
|
|
* b = 95 # Won't be returned
|
|
|
|
* c = 12345678987654321
|
|
|
|
* count = ObjectSpace.each_object(Numeric) {|x| p x }
|
|
|
|
* puts "Total count: #{count}"
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* <em>produces:</em>
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* 12345678987654321
|
|
|
|
* 102.7
|
|
|
|
* 2.71828182845905
|
|
|
|
* 3.14159265358979
|
|
|
|
* 2.22044604925031e-16
|
|
|
|
* 1.7976931348623157e+308
|
|
|
|
* 2.2250738585072e-308
|
|
|
|
* Total count: 7
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
os_each_obj(int argc, VALUE *argv)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
VALUE of;
|
|
|
|
|
2003-03-26 02:01:14 -05:00
|
|
|
rb_secure(4);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (rb_scan_args(argc, argv, "01", &of) == 0) {
|
|
|
|
return os_live_obj();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return os_obj_of(of);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE finalizers;
|
|
|
|
|
2003-12-22 01:20:14 -05:00
|
|
|
/* deprecated
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
add_final(VALUE os, VALUE block)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-07-15 09:37:03 -04:00
|
|
|
rb_warn("ObjectSpace::add_finalizer is deprecated; use define_finalizer");
|
2003-06-07 11:34:31 -04:00
|
|
|
if (!rb_respond_to(block, rb_intern("call"))) {
|
|
|
|
rb_raise(rb_eArgError, "wrong type argument %s (should be callable)",
|
2003-06-06 05:44:22 -04:00
|
|
|
rb_obj_classname(block));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2003-06-06 05:44:22 -04:00
|
|
|
rb_ary_push(finalizers, block);
|
|
|
|
return block;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-22 01:20:14 -05:00
|
|
|
/*
|
|
|
|
* deprecated
|
|
|
|
*/
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rm_final(VALUE os, VALUE block)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-07-15 09:37:03 -04:00
|
|
|
rb_warn("ObjectSpace::remove_finalizer is deprecated; use undefine_finalizer");
|
2003-06-06 05:44:22 -04:00
|
|
|
rb_ary_delete(finalizers, block);
|
|
|
|
return block;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-22 01:20:14 -05:00
|
|
|
/*
|
|
|
|
* deprecated
|
|
|
|
*/
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
finals(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_warn("ObjectSpace::finalizers is deprecated");
|
1998-01-16 07:13:05 -05:00
|
|
|
return finalizers;
|
|
|
|
}
|
|
|
|
|
2003-12-22 01:20:14 -05:00
|
|
|
/*
|
|
|
|
* deprecated
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
call_final(VALUE os, VALUE obj)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2002-08-29 05:08:18 -04:00
|
|
|
rb_warn("ObjectSpace::call_finalizer is deprecated; use define_finalizer");
|
1998-01-16 07:13:05 -05:00
|
|
|
need_call_final = 1;
|
|
|
|
FL_SET(obj, FL_FINALIZE);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2003-12-22 01:20:14 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ObjectSpace.undefine_finalizer(obj)
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* Removes all finalizers for <i>obj</i>.
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
*/
|
|
|
|
|
2000-07-15 09:37:03 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
undefine_final(VALUE os, VALUE obj)
|
2000-07-15 09:37:03 -04:00
|
|
|
{
|
|
|
|
if (finalizer_table) {
|
2003-07-25 01:36:55 -04:00
|
|
|
st_delete(finalizer_table, (st_data_t*)&obj, 0);
|
2000-07-15 09:37:03 -04:00
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2003-12-22 01:20:14 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ObjectSpace.define_finalizer(obj, aProc=proc())
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
|
|
|
* Adds <i>aProc</i> as a finalizer, to be called after <i>obj</i>
|
|
|
|
* was destroyed.
|
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
*/
|
|
|
|
|
2000-07-15 09:37:03 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
define_final(int argc, VALUE *argv, VALUE os)
|
2000-07-15 09:37:03 -04:00
|
|
|
{
|
2003-06-06 05:44:22 -04:00
|
|
|
VALUE obj, block, table;
|
2000-07-15 09:37:03 -04:00
|
|
|
|
2003-06-06 05:44:22 -04:00
|
|
|
rb_scan_args(argc, argv, "11", &obj, &block);
|
2000-07-15 09:37:03 -04:00
|
|
|
if (argc == 1) {
|
2003-06-16 03:14:50 -04:00
|
|
|
block = rb_block_proc();
|
2000-07-15 09:37:03 -04:00
|
|
|
}
|
2003-06-07 11:34:31 -04:00
|
|
|
else if (!rb_respond_to(block, rb_intern("call"))) {
|
|
|
|
rb_raise(rb_eArgError, "wrong type argument %s (should be callable)",
|
2003-06-06 05:44:22 -04:00
|
|
|
rb_obj_classname(block));
|
2000-07-15 09:37:03 -04:00
|
|
|
}
|
|
|
|
need_call_final = 1;
|
|
|
|
FL_SET(obj, FL_FINALIZE);
|
|
|
|
|
2004-07-23 03:52:38 -04:00
|
|
|
block = rb_ary_new3(2, INT2FIX(ruby_safe_level), block);
|
2004-06-28 21:31:37 -04:00
|
|
|
|
2000-07-15 09:37:03 -04:00
|
|
|
if (!finalizer_table) {
|
|
|
|
finalizer_table = st_init_numtable();
|
|
|
|
}
|
|
|
|
if (st_lookup(finalizer_table, obj, &table)) {
|
2003-06-06 05:44:22 -04:00
|
|
|
rb_ary_push(table, block);
|
2000-07-15 09:37:03 -04:00
|
|
|
}
|
|
|
|
else {
|
2003-06-06 05:44:22 -04:00
|
|
|
st_add_direct(finalizer_table, obj, rb_ary_new3(1, block));
|
2000-07-15 09:37:03 -04:00
|
|
|
}
|
2003-06-06 05:44:22 -04:00
|
|
|
return block;
|
2000-07-15 09:37:03 -04:00
|
|
|
}
|
|
|
|
|
2002-12-04 02:39:32 -05:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_gc_copy_finalizer(VALUE dest, VALUE obj)
|
2002-12-04 02:39:32 -05:00
|
|
|
{
|
|
|
|
VALUE table;
|
|
|
|
|
|
|
|
if (!finalizer_table) return;
|
|
|
|
if (!FL_TEST(obj, FL_FINALIZE)) return;
|
|
|
|
if (st_lookup(finalizer_table, obj, &table)) {
|
|
|
|
st_insert(finalizer_table, dest, table);
|
|
|
|
}
|
2004-10-27 05:29:26 -04:00
|
|
|
FL_SET(dest, FL_FINALIZE);
|
2002-12-04 02:39:32 -05:00
|
|
|
}
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
run_single_final(VALUE *args)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
2004-06-28 21:31:37 -04:00
|
|
|
rb_eval_cmd(args[0], args[1], (int)args[2]);
|
1999-08-13 01:45:20 -04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
run_final(VALUE obj)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2002-08-21 11:47:54 -04:00
|
|
|
long i;
|
2003-07-24 03:50:36 -04:00
|
|
|
int status, critical_save = rb_thread_critical;
|
2005-06-19 01:16:36 -04:00
|
|
|
VALUE args[3], table, objid;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2005-06-19 01:09:32 -04:00
|
|
|
objid = rb_obj_id(obj); /* make obj into id */
|
2003-07-24 03:50:36 -04:00
|
|
|
rb_thread_critical = Qtrue;
|
2005-06-19 01:09:32 -04:00
|
|
|
args[1] = 0;
|
2004-06-28 21:31:37 -04:00
|
|
|
args[2] = (VALUE)ruby_safe_level;
|
2006-09-02 10:42:08 -04:00
|
|
|
for (i=0; i<RARRAY_LEN(finalizers); i++) {
|
|
|
|
args[0] = RARRAY_PTR(finalizers)[i];
|
2005-06-19 01:09:32 -04:00
|
|
|
if (!args[1]) args[1] = rb_ary_new3(1, objid);
|
2005-09-14 04:30:16 -04:00
|
|
|
rb_protect((VALUE(*)(VALUE))run_single_final, (VALUE)args, &status);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
2003-07-25 01:36:55 -04:00
|
|
|
if (finalizer_table && st_delete(finalizer_table, (st_data_t*)&obj, &table)) {
|
2006-09-02 10:42:08 -04:00
|
|
|
for (i=0; i<RARRAY_LEN(table); i++) {
|
|
|
|
VALUE final = RARRAY_PTR(table)[i];
|
|
|
|
args[0] = RARRAY_PTR(final)[1];
|
2005-06-19 01:09:32 -04:00
|
|
|
if (!args[1]) args[1] = rb_ary_new3(1, objid);
|
2006-09-02 10:42:08 -04:00
|
|
|
args[2] = FIX2INT(RARRAY_PTR(final)[0]);
|
2005-09-14 04:30:16 -04:00
|
|
|
rb_protect((VALUE(*)(VALUE))run_single_final, (VALUE)args, &status);
|
2000-07-15 09:37:03 -04:00
|
|
|
}
|
|
|
|
}
|
2003-07-24 03:50:36 -04:00
|
|
|
rb_thread_critical = critical_save;
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
2004-09-27 08:25:21 -04:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_gc_finalize_deferred(void)
|
2004-09-27 08:25:21 -04:00
|
|
|
{
|
|
|
|
RVALUE *p = deferred_final_list;
|
|
|
|
|
2006-02-12 23:53:22 -05:00
|
|
|
during_gc++;
|
2004-09-27 08:25:21 -04:00
|
|
|
deferred_final_list = 0;
|
|
|
|
if (p) {
|
|
|
|
finalize_list(p);
|
|
|
|
}
|
2005-08-12 04:13:28 -04:00
|
|
|
free_unused_heaps();
|
2006-02-12 23:53:22 -05:00
|
|
|
during_gc = 0;
|
2004-09-27 08:25:21 -04:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_gc_call_finalizer_at_exit(void)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
|
|
|
RVALUE *p, *pend;
|
|
|
|
int i;
|
|
|
|
|
2006-02-12 23:53:22 -05:00
|
|
|
/* finalizers are part of garbage collection */
|
|
|
|
during_gc++;
|
1999-01-19 23:59:39 -05:00
|
|
|
/* run finalizers */
|
2001-01-23 04:55:10 -05:00
|
|
|
if (need_call_final) {
|
2005-06-19 01:09:32 -04:00
|
|
|
p = deferred_final_list;
|
|
|
|
deferred_final_list = 0;
|
|
|
|
finalize_list(p);
|
2001-01-23 04:55:10 -05:00
|
|
|
for (i = 0; i < heaps_used; i++) {
|
2003-10-01 07:49:44 -04:00
|
|
|
p = heaps[i].slot; pend = p + heaps[i].limit;
|
2001-01-23 04:55:10 -05:00
|
|
|
while (p < pend) {
|
|
|
|
if (FL_TEST(p, FL_FINALIZE)) {
|
|
|
|
FL_UNSET(p, FL_FINALIZE);
|
|
|
|
p->as.basic.klass = 0;
|
|
|
|
run_final((VALUE)p);
|
|
|
|
}
|
|
|
|
p++;
|
2000-04-10 01:48:43 -04:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
}
|
2003-08-01 10:57:48 -04:00
|
|
|
/* run data object's finalizers */
|
2004-04-07 02:30:15 -04:00
|
|
|
for (i = 0; i < heaps_used; i++) {
|
2003-10-01 07:49:44 -04:00
|
|
|
p = heaps[i].slot; pend = p + heaps[i].limit;
|
1998-01-16 07:19:22 -05:00
|
|
|
while (p < pend) {
|
|
|
|
if (BUILTIN_TYPE(p) == T_DATA &&
|
2004-04-06 22:51:05 -04:00
|
|
|
DATA_PTR(p) && RANY(p)->as.data.dfree &&
|
|
|
|
RANY(p)->as.basic.klass != rb_cThread) {
|
2001-02-02 06:38:20 -05:00
|
|
|
p->as.free.flags = 0;
|
2003-03-23 05:55:39 -05:00
|
|
|
if ((long)RANY(p)->as.data.dfree == -1) {
|
|
|
|
RUBY_CRITICAL(free(DATA_PTR(p)));
|
|
|
|
}
|
|
|
|
else if (RANY(p)->as.data.dfree) {
|
|
|
|
(*RANY(p)->as.data.dfree)(DATA_PTR(p));
|
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
else if (BUILTIN_TYPE(p) == T_FILE) {
|
2004-04-06 22:51:05 -04:00
|
|
|
if (rb_io_fptr_finalize(RANY(p)->as.file.fptr)) {
|
|
|
|
p->as.free.flags = 0;
|
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
2006-02-12 23:53:22 -05:00
|
|
|
during_gc = 0;
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
2003-12-22 01:20:14 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ObjectSpace._id2ref(object_id) -> an_object
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* Converts an object id to a reference to the object. May not be
|
|
|
|
* called on an object id passed as a parameter to a finalizer.
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
* s = "I am a string" #=> "I am a string"
|
|
|
|
* r = ObjectSpace._id2ref(s.object_id) #=> "I am a string"
|
|
|
|
* r == s #=> true
|
2005-06-19 13:16:14 -04:00
|
|
|
*
|
2003-12-22 01:20:14 -05:00
|
|
|
*/
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
static VALUE
|
2006-03-02 00:22:30 -05:00
|
|
|
id2ref(VALUE obj, VALUE objid)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
2005-07-27 03:27:19 -04:00
|
|
|
#if SIZEOF_LONG == SIZEOF_VOIDP
|
|
|
|
#define NUM2PTR(x) NUM2ULONG(x)
|
|
|
|
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
|
|
|
|
#define NUM2PTR(x) NUM2ULL(x)
|
|
|
|
#endif
|
|
|
|
VALUE ptr;
|
|
|
|
void *p0;
|
1998-01-16 07:19:22 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_secure(4);
|
2006-03-02 00:22:30 -05:00
|
|
|
ptr = NUM2PTR(objid);
|
2005-07-27 03:27:19 -04:00
|
|
|
p0 = (void *)ptr;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (ptr == Qtrue) return Qtrue;
|
|
|
|
if (ptr == Qfalse) return Qfalse;
|
|
|
|
if (ptr == Qnil) return Qnil;
|
2001-03-20 22:41:45 -05:00
|
|
|
if (FIXNUM_P(ptr)) return (VALUE)ptr;
|
2006-03-04 01:28:51 -05:00
|
|
|
ptr = objid ^ FIXNUM_FLAG; /* unset FIXNUM_FLAG */
|
2006-03-02 00:22:30 -05:00
|
|
|
|
2006-03-04 01:28:51 -05:00
|
|
|
if ((ptr % sizeof(RVALUE)) == (4 << 2)) {
|
|
|
|
ID symid = ptr / sizeof(RVALUE);
|
2006-03-02 00:22:30 -05:00
|
|
|
if (rb_id2name(symid) == 0)
|
|
|
|
rb_raise(rb_eRangeError, "%p is not symbol id value", p0);
|
|
|
|
return ID2SYM(symid);
|
2001-03-20 22:41:45 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2004-03-10 02:05:19 -05:00
|
|
|
if (!is_pointer_to_heap((void *)ptr)|| BUILTIN_TYPE(ptr) >= T_BLOCK) {
|
2005-07-27 03:27:19 -04:00
|
|
|
rb_raise(rb_eRangeError, "%p is not id value", p0);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
2003-08-22 04:09:58 -04:00
|
|
|
if (BUILTIN_TYPE(ptr) == 0 || RBASIC(ptr)->klass == 0) {
|
2005-07-27 03:27:19 -04:00
|
|
|
rb_raise(rb_eRangeError, "%p is recycled object", p0);
|
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
|
|
|
}
|
|
|
|
|
2006-03-02 00:22:30 -05:00
|
|
|
/*
|
|
|
|
* Document-method: __id__
|
|
|
|
* Document-method: object_id
|
|
|
|
*
|
|
|
|
* call-seq:
|
|
|
|
* obj.__id__ => fixnum
|
|
|
|
* obj.object_id => fixnum
|
|
|
|
*
|
|
|
|
* Returns an integer identifier for <i>obj</i>. The same number will
|
|
|
|
* be returned on all calls to <code>id</code> for a given object, and
|
|
|
|
* no two active objects will share an id.
|
|
|
|
* <code>Object#object_id</code> is a different concept from the
|
|
|
|
* <code>:name</code> notation, which returns the symbol id of
|
|
|
|
* <code>name</code>. Replaces the deprecated <code>Object#id</code>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* obj.hash => fixnum
|
|
|
|
*
|
|
|
|
* Generates a <code>Fixnum</code> hash value for this object. This
|
|
|
|
* function must have the property that <code>a.eql?(b)</code> implies
|
|
|
|
* <code>a.hash == b.hash</code>. The hash value is used by class
|
|
|
|
* <code>Hash</code>. Any hash value that exceeds the capacity of a
|
|
|
|
* <code>Fixnum</code> will be truncated before being used.
|
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_obj_id(VALUE obj)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 32-bit VALUE space
|
|
|
|
* MSB ------------------------ LSB
|
|
|
|
* false 00000000000000000000000000000000
|
|
|
|
* true 00000000000000000000000000000010
|
|
|
|
* nil 00000000000000000000000000000100
|
|
|
|
* undef 00000000000000000000000000000110
|
|
|
|
* symbol ssssssssssssssssssssssss00001110
|
|
|
|
* object oooooooooooooooooooooooooooooo00 = 0 (mod sizeof(RVALUE))
|
|
|
|
* fixnum fffffffffffffffffffffffffffffff1
|
|
|
|
*
|
|
|
|
* object_id space
|
|
|
|
* LSB
|
|
|
|
* false 00000000000000000000000000000000
|
|
|
|
* true 00000000000000000000000000000010
|
|
|
|
* nil 00000000000000000000000000000100
|
|
|
|
* undef 00000000000000000000000000000110
|
|
|
|
* symbol 000SSSSSSSSSSSSSSSSSSSSSSSSSSS0 S...S % A = 4 (S...S = s...s * A + 4)
|
|
|
|
* object oooooooooooooooooooooooooooooo0 o...o % A = 0
|
|
|
|
* fixnum fffffffffffffffffffffffffffffff1 bignum if required
|
|
|
|
*
|
|
|
|
* where A = sizeof(RVALUE)/4
|
|
|
|
*
|
|
|
|
* sizeof(RVALUE) is
|
|
|
|
* 20 if 32-bit, double is 4-byte aligned
|
|
|
|
* 24 if 32-bit, double is 8-byte aligned
|
|
|
|
* 40 if 64-bit
|
|
|
|
*/
|
|
|
|
if (SPECIAL_CONST_P(obj)) {
|
|
|
|
return LONG2NUM((long)obj);
|
|
|
|
}
|
|
|
|
return (VALUE)((long)obj|FIXNUM_FLAG);
|
|
|
|
}
|
|
|
|
|
2003-12-22 01:20:14 -05:00
|
|
|
/*
|
|
|
|
* The <code>GC</code> module provides an interface to Ruby's mark and
|
|
|
|
* sweep garbage collection mechanism. Some of the underlying methods
|
|
|
|
* are also available via the <code>ObjectSpace</code> module.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
Init_GC(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE rb_mObSpace;
|
|
|
|
|
|
|
|
rb_mGC = rb_define_module("GC");
|
2001-01-29 00:10:42 -05:00
|
|
|
rb_define_singleton_method(rb_mGC, "start", rb_gc_start, 0);
|
|
|
|
rb_define_singleton_method(rb_mGC, "enable", rb_gc_enable, 0);
|
|
|
|
rb_define_singleton_method(rb_mGC, "disable", rb_gc_disable, 0);
|
2006-01-09 17:32:55 -05:00
|
|
|
rb_define_singleton_method(rb_mGC, "stress", gc_stress_get, 0);
|
|
|
|
rb_define_singleton_method(rb_mGC, "stress=", gc_stress_set, 1);
|
2001-01-29 00:10:42 -05:00
|
|
|
rb_define_method(rb_mGC, "garbage_collect", rb_gc_start, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
rb_mObSpace = rb_define_module("ObjectSpace");
|
|
|
|
rb_define_module_function(rb_mObSpace, "each_object", os_each_obj, -1);
|
2001-01-29 00:10:42 -05:00
|
|
|
rb_define_module_function(rb_mObSpace, "garbage_collect", rb_gc_start, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
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();
|
2002-03-07 06:19:37 -05:00
|
|
|
|
|
|
|
source_filenames = st_init_strtable();
|
2002-04-24 00:54:16 -04:00
|
|
|
|
|
|
|
rb_global_variable(&nomem_error);
|
2005-12-11 22:04:53 -05:00
|
|
|
nomem_error = rb_exc_new2(rb_eNoMemError, "failed to allocate memory");
|
2006-03-02 00:22:30 -05:00
|
|
|
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
rb_define_method(rb_cBasicObject, "__id__", rb_obj_id, 0);
|
|
|
|
rb_define_method(rb_cBasicObject, "object_id", rb_obj_id, 0);
|
2006-03-02 00:22:30 -05:00
|
|
|
rb_define_method(rb_mKernel, "hash", rb_obj_id, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|