ruby-changes:40907
From: ko1 <ko1@a...>
Date: Wed, 9 Dec 2015 09:38:55 +0900 (JST)
Subject: [ruby-changes:40907] ko1:r52986 (trunk): * *.c (*_memsize): do not check ptr.
ko1 2015-12-09 09:38:32 +0900 (Wed, 09 Dec 2015) New Revision: 52986 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52986 Log: * *.c (*_memsize): do not check ptr. NULL checking is finished Before call of memsize functions. See r52979. Modified files: trunk/ChangeLog trunk/compile.c trunk/cont.c trunk/dir.c trunk/enumerator.c trunk/error.c trunk/file.c trunk/gc.c trunk/io.c trunk/parse.y trunk/proc.c trunk/random.c trunk/thread.c trunk/thread_sync.c trunk/transcode.c trunk/vm.c Index: thread_sync.c =================================================================== --- thread_sync.c (revision 52985) +++ thread_sync.c (revision 52986) @@ -68,7 +68,7 @@ mutex_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L68 static size_t mutex_memsize(const void *ptr) { - return ptr ? sizeof(rb_mutex_t) : 0; + return sizeof(rb_mutex_t); } static const rb_data_type_t mutex_data_type = { Index: ChangeLog =================================================================== --- ChangeLog (revision 52985) +++ ChangeLog (revision 52986) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Dec 9 09:34:41 2015 Koichi Sasada <ko1@a...> + + * *.c (*_memsize): do not check ptr. + NULL checking is finished Before call of memsize functions. + See r52979. + Wed Dec 9 09:25:29 2015 SHIBATA Hiroshi <hsbt@r...> * test/net/smtp/test_response.rb: use Test::Unit. We should use Test::Unit Index: enumerator.c =================================================================== --- enumerator.c (revision 52985) +++ enumerator.c (revision 52986) @@ -156,7 +156,7 @@ enumerator_mark(void *p) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L156 static size_t enumerator_memsize(const void *p) { - return p ? sizeof(struct enumerator) : 0; + return sizeof(struct enumerator); } static const rb_data_type_t enumerator_data_type = { @@ -1067,7 +1067,7 @@ yielder_mark(void *p) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L1067 static size_t yielder_memsize(const void *p) { - return p ? sizeof(struct yielder) : 0; + return sizeof(struct yielder); } static const rb_data_type_t yielder_data_type = { @@ -1174,7 +1174,7 @@ generator_mark(void *p) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L1174 static size_t generator_memsize(const void *p) { - return p ? sizeof(struct generator) : 0; + return sizeof(struct generator); } static const rb_data_type_t generator_data_type = { Index: io.c =================================================================== --- io.c (revision 52985) +++ io.c (revision 52986) @@ -7764,7 +7764,6 @@ argf_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/io.c#L7764 { const struct argf *p = ptr; size_t size = sizeof(*p); - if (!ptr) return 0; if (p->inplace) size += strlen(p->inplace) + 1; return size; } Index: compile.c =================================================================== --- compile.c (revision 52985) +++ compile.c (revision 52986) @@ -8054,16 +8054,11 @@ ibf_dump_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/compile.c#L8054 static size_t ibf_dump_memsize(const void *ptr) { - if (ptr) { - struct ibf_dump *dump = (struct ibf_dump *)ptr; - size_t size = sizeof(*dump); - if (dump->iseq_table) size += st_memsize(dump->iseq_table); - if (dump->id_table) size += st_memsize(dump->id_table); - return size; - } - else { - return 0; - } + struct ibf_dump *dump = (struct ibf_dump *)ptr; + size_t size = sizeof(*dump); + if (dump->iseq_table) size += st_memsize(dump->iseq_table); + if (dump->id_table) size += st_memsize(dump->id_table); + return size; } static const rb_data_type_t ibf_dump_type = { @@ -8253,13 +8248,8 @@ ibf_loader_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/compile.c#L8248 static size_t ibf_loader_memsize(const void *ptr) { - if (ptr) { - struct ibf_load *load = (struct ibf_load *)ptr; - return sizeof(struct ibf_load) + load->header->id_list_size * sizeof(ID); - } - else { - return 0; - } + struct ibf_load *load = (struct ibf_load *)ptr; + return sizeof(struct ibf_load) + load->header->id_list_size * sizeof(ID); } static const rb_data_type_t ibf_load_type = { Index: proc.c =================================================================== --- proc.c (revision 52985) +++ proc.c (revision 52986) @@ -269,7 +269,7 @@ binding_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/proc.c#L269 static size_t binding_memsize(const void *ptr) { - return ptr ? sizeof(rb_binding_t) : 0; + return sizeof(rb_binding_t); } const rb_data_type_t ruby_binding_data_type = { @@ -1203,7 +1203,7 @@ bm_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/proc.c#L1203 static size_t bm_memsize(const void *ptr) { - return ptr ? sizeof(struct METHOD) : 0; + return sizeof(struct METHOD); } static const rb_data_type_t method_data_type = { Index: thread.c =================================================================== --- thread.c (revision 52985) +++ thread.c (revision 52986) @@ -3983,7 +3983,7 @@ struct thgroup { https://github.com/ruby/ruby/blob/trunk/thread.c#L3983 static size_t thgroup_memsize(const void *ptr) { - return ptr ? sizeof(struct thgroup) : 0; + return sizeof(struct thgroup); } static const rb_data_type_t thgroup_data_type = { Index: dir.c =================================================================== --- dir.c (revision 52985) +++ dir.c (revision 52986) @@ -438,7 +438,7 @@ dir_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/dir.c#L438 static size_t dir_memsize(const void *ptr) { - return ptr ? sizeof(struct dir_data) : 0; + return sizeof(struct dir_data); } static const rb_data_type_t dir_data_type = { Index: gc.c =================================================================== --- gc.c (revision 52985) +++ gc.c (revision 52986) @@ -7948,7 +7948,6 @@ wmap_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/gc.c#L7948 { size_t size; const struct weakmap *w = ptr; - if (!w) return 0; size = sizeof(*w); size += st_memsize(w->obj2wmap); size += st_memsize(w->wmap2obj); Index: parse.y =================================================================== --- parse.y (revision 52985) +++ parse.y (revision 52986) @@ -10807,7 +10807,6 @@ parser_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/parse.y#L10807 struct local_vars *local; size_t size = sizeof(*parser); - if (!ptr) return 0; size += toksiz; for (local = lvtbl; local; local = local->prev) { size += sizeof(*local); Index: error.c =================================================================== --- error.c (revision 52985) +++ error.c (revision 52986) @@ -1196,7 +1196,7 @@ name_err_mesg_mark(void *p) https://github.com/ruby/ruby/blob/trunk/error.c#L1196 static size_t name_err_mesg_memsize(const void *p) { - return p ? (NAME_ERR_MESG_COUNT * sizeof(VALUE)) : 0; + return NAME_ERR_MESG_COUNT * sizeof(VALUE); } static const rb_data_type_t name_err_mesg_data_type = { Index: cont.c =================================================================== --- cont.c (revision 52985) +++ cont.c (revision 52986) @@ -280,26 +280,25 @@ cont_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/cont.c#L280 { const rb_context_t *cont = ptr; size_t size = 0; - if (cont) { - size = sizeof(*cont); - if (cont->vm_stack) { + + size = sizeof(*cont); + if (cont->vm_stack) { #ifdef CAPTURE_JUST_VALID_VM_STACK - size_t n = (cont->vm_stack_slen + cont->vm_stack_clen); + size_t n = (cont->vm_stack_slen + cont->vm_stack_clen); #else - size_t n = cont->saved_thread.stack_size; + size_t n = cont->saved_thread.stack_size; #endif - size += n * sizeof(*cont->vm_stack); - } + size += n * sizeof(*cont->vm_stack); + } - if (cont->machine.stack) { - size += cont->machine.stack_size * sizeof(*cont->machine.stack); - } + if (cont->machine.stack) { + size += cont->machine.stack_size * sizeof(*cont->machine.stack); + } #ifdef __ia64 - if (cont->machine.register_stack) { - size += cont->machine.register_stack_size * sizeof(*cont->machine.register_stack); - } -#endif + if (cont->machine.register_stack) { + size += cont->machine.register_stack_size * sizeof(*cont->machine.register_stack); } +#endif return size; } @@ -343,14 +342,13 @@ fiber_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/cont.c#L342 { const rb_fiber_t *fib = ptr; size_t size = 0; - if (ptr) { - size = sizeof(*fib); - if (fib->cont.type != ROOT_FIBER_CONTEXT && - fib->cont.saved_thread.local_storage != NULL) { - size += st_memsize(fib->cont.saved_thread.local_storage); - } - size += cont_memsize(&fib->cont); + + size = sizeof(*fib); + if (fib->cont.type != ROOT_FIBER_CONTEXT && + fib->cont.saved_thread.local_storage != NULL) { + size += st_memsize(fib->cont.saved_thread.local_storage); } + size += cont_memsize(&fib->cont); return size; } Index: vm.c =================================================================== --- vm.c (revision 52985) +++ vm.c (revision 52986) @@ -2047,20 +2047,15 @@ ruby_vm_destruct(rb_vm_t *vm) https://github.com/ruby/ruby/blob/trunk/vm.c#L2047 static size_t vm_memsize(const void *ptr) { - if (ptr) { - const rb_vm_t *vmobj = ptr; - size_t size = sizeof(rb_vm_t); + const rb_vm_t *vmobj = ptr; + size_t size = sizeof(rb_vm_t); - size += vmobj->living_thread_num * sizeof(rb_thread_t); + size += vmobj->living_thread_num * sizeof(rb_thread_t); - if (vmobj->defined_strings) { - size += DEFINED_EXPR * sizeof(VALUE); - } - return size; - } - else { - return 0; + if (vmobj->defined_strings) { + size += DEFINED_EXPR * sizeof(VALUE); } + return size; } static const rb_data_type_t vm_data_type = { @@ -2298,21 +2293,16 @@ thread_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L2293 static size_t thread_memsize(const void *ptr) { - if (ptr) { - const rb_thread_t *th = ptr; - size_t size = sizeof(rb_thread_t); + const rb_thread_t *th = ptr; + size_t size = sizeof(rb_thread_t); - if (!th->root_fiber) { - size += th->stack_size * sizeof(VALUE); - } - if (th->local_storage) { - size += st_memsize(th->local_storage); - } - return size; + if (!th->root_fiber) { + size += th->stack_size * sizeof(VALUE); } - else { - return 0; + if (th->local_storage) { + size += st_memsize(th->local_storage); } + return size; } #define thread_data_type ruby_threadptr_data_type Index: file.c =================================================================== --- file.c (revision 52985) +++ file.c (revision 52986) @@ -378,7 +378,7 @@ rb_file_path(VALUE obj) https://github.com/ruby/ruby/blob/trunk/file.c#L378 static size_t stat_memsize(const void *p) { - return p ? sizeof(struct stat) : 0; + return sizeof(struct stat); } static const rb_data_type_t stat_data_type = { Index: random.c =================================================================== --- random.c (revision 52985) +++ random.c (revision 52986) @@ -343,7 +343,7 @@ random_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/random.c#L343 static size_t random_memsize(const void *ptr) { - return ptr ? sizeof(rb_random_t) : 0; + return sizeof(rb_random_t); } static const rb_data_type_t random_data_type = { Index: transcode.c =================================================================== --- transcode.c (revision 52985) +++ transcode.c (revision 52986) @@ -2912,7 +2912,7 @@ econv_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/transcode.c#L2912 static size_t econv_memsize(const void *ptr) { - return ptr ? sizeof(rb_econv_t) : 0; + return sizeof(rb_econv_t); } static const rb_data_type_t econv_data_type = { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/