ruby-changes:4863
From: ko1@a...
Date: Sun, 11 May 2008 14:44:52 +0900 (JST)
Subject: [ruby-changes:4863] akr - Ruby:r16356 (trunk): * include/ruby/ruby.h (SIZET2NUM): new macro.
akr 2008-05-11 14:44:36 +0900 (Sun, 11 May 2008) New Revision: 16356 Modified files: trunk/ChangeLog trunk/gc.c trunk/include/ruby/ruby.h Log: * include/ruby/ruby.h (SIZET2NUM): new macro. (NUM2SIZET): new macro. * gc.c (struct rb_objspace): use size_t for increment, length and used for 64bit. (allocate_heaps): ditto. (assign_heap_slot): ditto. (set_heaps_increment): ditto. (gc_mark_all): ditto. (is_pointer_to_heap): ditto. (free_unused_heaps): ditto. (gc_sweep): ditto. (os_obj_of): ditto. (rb_gc_call_finalizer_at_exit): ditto. (count_objects): ditto. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/include/ruby/ruby.h?r1=16356&r2=16355&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16356&r2=16355&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/gc.c?r1=16356&r2=16355&diff_format=u Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 16355) +++ include/ruby/ruby.h (revision 16356) @@ -171,6 +171,14 @@ # define OFFT2NUM(v) INT2NUM(v) #endif +#if SIZEOF_SIZE_T > SIZEOF_LONG && defined(HAVE_LONG_LONG) +# define SIZET2NUM(v) ULL2NUM(v) +#elif SIZEOF_SIZE_T == SIZEOF_LONG +# define SIZET2NUM(v) ULONG2NUM(v) +#else +# define SIZET2NUM(v) UINT2NUM(v) +#endif + #ifndef PIDT2NUM #define PIDT2NUM(v) LONG2NUM(v) #endif @@ -364,6 +372,12 @@ # define NUM2OFFT(x) NUM2LONG(x) #endif +#if defined(HAVE_LONG_LONG) && SIZEOF_SIZE_T > SIZEOF_LONG +# define NUM2SIZET(x) ((size_t)NUM2ULL(x)) +#else +# define NUM2SIZET(x) NUM2ULONG(x) +#endif + double rb_num2dbl(VALUE); #define NUM2DBL(x) rb_num2dbl((VALUE)(x)) Index: ChangeLog =================================================================== --- ChangeLog (revision 16355) +++ ChangeLog (revision 16356) @@ -1,3 +1,21 @@ +Sun May 11 14:40:36 2008 Tanaka Akira <akr@f...> + + * include/ruby/ruby.h (SIZET2NUM): new macro. + (NUM2SIZET): new macro. + + * gc.c (struct rb_objspace): use size_t for increment, length and + used for 64bit. + (allocate_heaps): ditto. + (assign_heap_slot): ditto. + (set_heaps_increment): ditto. + (gc_mark_all): ditto. + (is_pointer_to_heap): ditto. + (free_unused_heaps): ditto. + (gc_sweep): ditto. + (os_obj_of): ditto. + (rb_gc_call_finalizer_at_exit): ditto. + (count_objects): ditto. + Sun May 11 13:14:09 2008 Tanaka Akira <akr@f...> * thread.c (thread_cleanup_func_before_exec): extracted from Index: gc.c =================================================================== --- gc.c (revision 16355) +++ gc.c (revision 16356) @@ -149,10 +149,10 @@ unsigned long increase; } params; struct { - long increment; + size_t increment; struct heaps_slot *ptr; - long length; - long used; + size_t length; + size_t used; RVALUE *freelist; RVALUE *range[2]; RVALUE *freed; @@ -517,30 +517,30 @@ static void -allocate_heaps(rb_objspace_t *objspace, int next_heaps_length) +allocate_heaps(rb_objspace_t *objspace, size_t next_heaps_length) { struct heaps_slot *p; - int length; + size_t size; - heaps_length = next_heaps_length; - length = heaps_length*sizeof(struct heaps_slot); + size = next_heaps_length*sizeof(struct heaps_slot); RUBY_CRITICAL( if (heaps_used > 0) { - p = (struct heaps_slot *)realloc(heaps, length); + p = (struct heaps_slot *)realloc(heaps, size); if (p) heaps = p; } else { - p = heaps = (struct heaps_slot *)malloc(length); + p = heaps = (struct heaps_slot *)malloc(size); } ); if (p == 0) rb_memerror(); + heaps_length = next_heaps_length; } static void assign_heap_slot(rb_objspace_t *objspace) { RVALUE *p, *pend, *membase; - long hi, lo, mid; + size_t hi, lo, mid; int objs; objs = HEAP_OBJ_LIMIT; @@ -596,7 +596,7 @@ static void init_heap(rb_objspace_t *objspace) { - int add, i; + size_t add, i; add = HEAP_MIN_SLOTS / HEAP_OBJ_LIMIT; @@ -614,10 +614,11 @@ static void set_heaps_increment(rb_objspace_t *objspace) { - heaps_inc = heaps_used * 1.8 - heaps_used; + size_t next_heaps_length = heaps_used * 1.8; + heaps_inc = next_heaps_length - heaps_used; - if ((heaps_used + heaps_inc) > heaps_length) { - allocate_heaps(objspace, heaps_used + heaps_inc); + if (next_heaps_length > heaps_length) { + allocate_heaps(objspace, next_heaps_length); } } @@ -818,7 +819,7 @@ gc_mark_all(rb_objspace_t *objspace) { RVALUE *p, *pend; - int i; + size_t i; init_mark_stack(objspace); for (i = 0; i < heaps_used; i++) { @@ -854,7 +855,7 @@ { register RVALUE *p = RANY(ptr); register struct heaps_slot *heap; - register long hi, lo, mid; + register size_t hi, lo, mid; if (p < lomem || p > himem) return Qfalse; if ((VALUE)p % sizeof(RVALUE) != 0) return Qfalse; @@ -1317,7 +1318,7 @@ static void free_unused_heaps(rb_objspace_t *objspace) { - int i, j; + size_t i, j; RVALUE *last = 0; for (i = j = 1; j < heaps_used; i++) { @@ -1354,9 +1355,9 @@ gc_sweep(rb_objspace_t *objspace) { RVALUE *p, *pend, *final_list; - int freed = 0; - int i; - unsigned long live = 0, free_min = 0, do_heap_free = 0; + size_t freed = 0; + size_t i; + size_t live = 0, free_min = 0, do_heap_free = 0; do_heap_free = (heaps_used * HEAP_OBJ_LIMIT) * 0.65; free_min = (heaps_used * HEAP_OBJ_LIMIT) * 0.2; @@ -1865,8 +1866,8 @@ static VALUE os_obj_of(rb_objspace_t *objspace, VALUE of) { - int i; - int n = 0; + size_t i; + size_t n = 0; for (i = 0; i < heaps_used; i++) { RVALUE *p, *pend; @@ -1893,7 +1894,7 @@ } } - return INT2FIX(n); + return SIZET2NUM(n); } /* @@ -2075,7 +2076,7 @@ { rb_objspace_t *objspace = &rb_objspace; RVALUE *p, *pend; - int i; + size_t i; /* finalizers are part of garbage collection */ during_gc++; @@ -2275,10 +2276,10 @@ count_objects(int argc, VALUE *argv, VALUE os) { rb_objspace_t *objspace = &rb_objspace; - long counts[T_MASK+1]; - long freed = 0; - long total = 0; - int i; + size_t counts[T_MASK+1]; + size_t freed = 0; + size_t total = 0; + size_t i; VALUE hash; if (rb_scan_args(argc, argv, "01", &hash) == 1) { @@ -2307,8 +2308,8 @@ if (hash == Qnil) hash = rb_hash_new(); - rb_hash_aset(hash, ID2SYM(rb_intern("TOTAL")), LONG2NUM(total)); - rb_hash_aset(hash, ID2SYM(rb_intern("FREE")), LONG2NUM(freed)); + rb_hash_aset(hash, ID2SYM(rb_intern("TOTAL")), SIZET2NUM(total)); + rb_hash_aset(hash, ID2SYM(rb_intern("FREE")), SIZET2NUM(freed)); for (i = 0; i <= T_MASK; i++) { VALUE type; switch (i) { @@ -2342,7 +2343,7 @@ default: type = INT2NUM(i); break; } if (counts[i]) - rb_hash_aset(hash, type, LONG2NUM(counts[i])); + rb_hash_aset(hash, type, SIZET2NUM(counts[i])); } return hash; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/