summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-04-24 04:54:16 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-04-24 04:54:16 +0000
commite3a8c626308cb8546baaf75e6133df304142f0c8 (patch)
tree4fb40e7eab065c70d5b2cdb44eb16bea01b12c15 /gc.c
parentb596fbbc375ea58aa2b869cb6025b2bb101f96b9 (diff)
* io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
* io.c (rb_io_mode_modenum): ditto. * gc.c (rb_memerror): rename from mem_error, and exported. * gc.c (Init_GC): pre-allocate NoMemoryError instance. * object.c (convert_type): error message changed from "failed to convert" to "cannot convert", since it does not try to convert if an object does not respond to the converting method. * eval.c (block_pass): convert Method to Proc using rb_check_convert_type(). * object.c (rb_check_convert_type): always convert T_DATA * eval.c (rb_thread_cleanup): should not terminate main_thread by Fatal error. * regex.c (is_in_list): need to not exclude NUL and NEWLINE. * re.c (rb_reg_expr_str): wrong backslash escapement. * re.c (rb_reg_expr_str): do not escape embedded space characters. * marshal.c (w_object): T_DATA process patch from Joel VanderWerf <vjoel@PATH.Berkeley.EDU>. This is temporary hack; it remains undocumented, and it will be removed when marshaling is re-designed. * marshal.c (r_object): ditto. * numeric.c (num_step): Integer#step is moved to Numeric#step; Fixnum#step is merged into this method. * numeric.c (int_dotimes): Fixnum#times is merged. * numeric.c (int_upto): Fixnum#upto is merged. * numeric.c (int_downto): Fixnum#downto is merged. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2401 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c40
1 files changed, 16 insertions, 24 deletions
diff --git a/gc.c b/gc.c
index e95f38e6b3..6cd0222f2f 100644
--- a/gc.c
+++ b/gc.c
@@ -66,22 +66,19 @@ static void run_final();
#endif
static unsigned long malloc_memories = 0;
+static VALUE nomem_error;
-static void
-mem_error(mesg)
- char *mesg;
+void
+rb_memerror()
{
static int recurse = 0;
- if (rb_safe_level() >= 4) {
- rb_raise(rb_eNoMemError, mesg);
+ if (recurse > 0 && rb_safe_level() < 4) {
+ fprintf(stderr, "[FATAL] failed to allocate memory\n");
+ exit(1);
}
- if (recurse == 0) {
- recurse++;
- rb_fatal(mesg);
- }
- fprintf(stderr, "[FATAL] failed to allocate memory\n");
- exit(1);
+ recurse++;
+ rb_exc_raise(nomem_error);
}
void *
@@ -104,10 +101,7 @@ ruby_xmalloc(size)
rb_gc();
RUBY_CRITICAL(mem = malloc(size));
if (!mem) {
- if (size >= 10 * 1024 * 1024) {
- mem_error("tried to allocate too big memory");
- }
- mem_error("failed to allocate memory");
+ rb_memerror();
}
}
@@ -144,10 +138,7 @@ ruby_xrealloc(ptr, size)
rb_gc();
RUBY_CRITICAL(mem = realloc(ptr, size));
if (!mem) {
- if (size >= 10 * 1024 * 1024) {
- rb_raise(rb_eNoMemError, "tried to re-allocate too big memory");
- }
- mem_error("failed to allocate memory(realloc)");
+ rb_memerror();
}
}
@@ -287,11 +278,11 @@ add_heap()
RUBY_CRITICAL(heaps = (heaps_used>0)?
(RVALUE**)realloc(heaps, heaps_length*sizeof(RVALUE*)):
(RVALUE**)malloc(heaps_length*sizeof(RVALUE*)));
- if (heaps == 0) mem_error("heaps: can't alloc memory");
+ if (heaps == 0) rb_memerror();
RUBY_CRITICAL(heaps_limits = (heaps_used>0)?
(int*)realloc(heaps_limits, heaps_length*sizeof(int)):
(int*)malloc(heaps_length*sizeof(int)));
- if (heaps_limits == 0) mem_error("heaps_limits: can't alloc memory");
+ if (heaps_limits == 0) rb_memerror();
}
for (;;) {
@@ -299,7 +290,7 @@ add_heap()
heaps_limits[heaps_used] = heap_slots;
if (p == 0) {
if (heap_slots == HEAP_MIN_SLOTS) {
- mem_error("add_heap: can't alloc memory");
+ rb_memerror();
}
heap_slots = HEAP_MIN_SLOTS;
continue;
@@ -396,8 +387,6 @@ int
ruby_stack_length(p)
VALUE **p;
{
- int ret;
-
SET_STACK_END;
if (p) *p = STACK_END;
return STACK_LENGTH;
@@ -1558,4 +1547,7 @@ Init_GC()
finalizers = rb_ary_new();
source_filenames = st_init_strtable();
+
+ nomem_error = rb_exc_new(rb_eNoMemError, "failed to allocate memory");
+ rb_global_variable(&nomem_error);
}