[前][次][番号順一覧][スレッド一覧]

ruby-changes:34869

From: normal <ko1@a...>
Date: Sat, 26 Jul 2014 06:35:04 +0900 (JST)
Subject: [ruby-changes:34869] normal:r46952 (trunk): introduce ZALLOC{, _N} to replace ALLOC{, _N}+MEMZERO use

normal	2014-07-26 06:34:35 +0900 (Sat, 26 Jul 2014)

  New Revision: 46952

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46952

  Log:
    introduce ZALLOC{,_N} to replace ALLOC{,_N}+MEMZERO use
    
    Using calloc where possible reduces code and binary sizes.
    
    * include/ruby/ruby.h (ZALLOC, ZALLOC_N): implement
      (Data_Make_Struct, TypedData_Make_Struct):
      ZALLOC replaces ALLOC+memset
    * compile.c (iseq_seq_sequence): ZALLOC_N replaces ALLOC_N+MEMZERO
    * cont.c (fiber_t_alloc): ZALLOC replaces ALLOC+MEMZERO
    * io.c (rb_io_reopen): ditto
    * iseq.c (prepare_iseq_build): ditto
    * parse.y (new_args_tail_gen, parser_new, ripper_s_allocate): ditto
    * re.c (match_alloc): ditto
    * variable.c (rb_const_set): ditto
    * ext/socket/raddrinfo.c (get_addrinfo): ditto
    * ext/strscan/strscan.c (strscan_s_allocate): ditto
    * gc.c (rb_objspace_alloc): calloc replaces malloc+MEMZERO

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/cont.c
    trunk/ext/socket/raddrinfo.c
    trunk/ext/strscan/strscan.c
    trunk/gc.c
    trunk/include/ruby/ruby.h
    trunk/io.c
    trunk/iseq.c
    trunk/parse.y
    trunk/re.c
    trunk/variable.c
Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 46951)
+++ include/ruby/ruby.h	(revision 46952)
@@ -1000,8 +1000,7 @@ void *rb_check_typeddata(VALUE, const rb https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1000
     rb_data_object_alloc((klass),(sval),(RUBY_DATA_FUNC)(mark),(RUBY_DATA_FUNC)(free))
 
 #define Data_Make_Struct(klass,type,mark,free,sval) (\
-    (sval) = ALLOC(type),\
-    memset((sval), 0, sizeof(type)),\
+    (sval) = ZALLOC(type),\
     Data_Wrap_Struct((klass),(mark),(free),(sval))\
 )
 
@@ -1009,8 +1008,7 @@ void *rb_check_typeddata(VALUE, const rb https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1008
   rb_data_typed_object_alloc((klass),(sval),(data_type))
 
 #define TypedData_Make_Struct(klass, type, data_type, sval) (\
-    (sval) = ALLOC(type),\
-    memset((sval), 0, sizeof(type)),\
+    (sval) = ZALLOC(type),\
     TypedData_Wrap_Struct((klass),(data_type),(sval))\
 )
 
@@ -1270,6 +1268,8 @@ rb_num2char_inline(VALUE x) https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1268
 
 #define ALLOC_N(type,n) ((type*)xmalloc2((n),sizeof(type)))
 #define ALLOC(type) ((type*)xmalloc(sizeof(type)))
+#define ZALLOC_N(type,n) ((type*)xcalloc((n),sizeof(type)))
+#define ZALLOC(type) (ZALLOC_N(type,1))
 #define REALLOC_N(var,type,n) ((var)=(type*)xrealloc2((char*)(var),(n),sizeof(type)))
 
 #define ALLOCA_N(type,n) ((type*)alloca(sizeof(type)*(n)))
Index: re.c
===================================================================
--- re.c	(revision 46951)
+++ re.c	(revision 46952)
@@ -872,8 +872,7 @@ match_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/re.c#L872
     match->str = 0;
     match->rmatch = 0;
     match->regexp = 0;
-    match->rmatch = ALLOC(struct rmatch);
-    MEMZERO(match->rmatch, struct rmatch, 1);
+    match->rmatch = ZALLOC(struct rmatch);
 
     return (VALUE)match;
 }
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46951)
+++ ChangeLog	(revision 46952)
@@ -1,3 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jul 26 05:58:35 2014  Eric Wong  <e@8...>
+
+	* include/ruby/ruby.h (ZALLOC, ZALLOC_N): implement
+	  (Data_Make_Struct, TypedData_Make_Struct):
+	  ZALLOC replaces ALLOC+memset
+	* compile.c (iseq_seq_sequence): ZALLOC_N replaces ALLOC_N+MEMZERO
+	* cont.c (fiber_t_alloc): ZALLOC replaces ALLOC+MEMZERO
+	* io.c (rb_io_reopen): ditto
+	* iseq.c (prepare_iseq_build): ditto
+	* parse.y (new_args_tail_gen, parser_new, ripper_s_allocate): ditto
+	* re.c (match_alloc): ditto
+	* variable.c (rb_const_set): ditto
+	* ext/socket/raddrinfo.c (get_addrinfo): ditto
+	* ext/strscan/strscan.c (strscan_s_allocate): ditto
+	* gc.c (rb_objspace_alloc): calloc replaces malloc+MEMZERO
+
 Sat Jul 26 05:54:54 2014  Eric Wong  <e@8...>
 
 	* symbol.c (dsymbol_check): remove unneeded semi-colon
Index: variable.c
===================================================================
--- variable.c	(revision 46951)
+++ variable.c	(revision 46952)
@@ -2213,8 +2213,7 @@ rb_const_set(VALUE klass, ID id, VALUE v https://github.com/ruby/ruby/blob/trunk/variable.c#L2213
     rb_clear_constant_cache();
 
 
-    ce = ALLOC(rb_const_entry_t);
-    MEMZERO(ce, rb_const_entry_t, 1);
+    ce = ZALLOC(rb_const_entry_t);
     ce->flag = visibility;
     ce->line = rb_sourceline();
     st_insert(RCLASS_CONST_TBL(klass), (st_data_t)id, (st_data_t)ce);
Index: iseq.c
===================================================================
--- iseq.c	(revision 46951)
+++ iseq.c	(revision 46952)
@@ -286,8 +286,7 @@ prepare_iseq_build(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/iseq.c#L286
      * iseq->cached_special_block = 0;
      */
 
-    iseq->compile_data = ALLOC(struct iseq_compile_data);
-    MEMZERO(iseq->compile_data, struct iseq_compile_data, 1);
+    iseq->compile_data = ZALLOC(struct iseq_compile_data);
     RB_OBJ_WRITE(iseq->self, &iseq->compile_data->err_info, Qnil);
     RB_OBJ_WRITE(iseq->self, &iseq->compile_data->mark_ary, rb_ary_tmp_new(3));
 
Index: io.c
===================================================================
--- io.c	(revision 46951)
+++ io.c	(revision 46952)
@@ -6725,8 +6725,7 @@ rb_io_reopen(int argc, VALUE *argv, VALU https://github.com/ruby/ruby/blob/trunk/io.c#L6725
     rb_io_taint_check(file);
     fptr = RFILE(file)->fptr;
     if (!fptr) {
-	fptr = RFILE(file)->fptr = ALLOC(rb_io_t);
-	MEMZERO(fptr, rb_io_t, 1);
+	fptr = RFILE(file)->fptr = ZALLOC(rb_io_t);
     }
 
     if (!NIL_P(nmode) || !NIL_P(opt)) {
Index: compile.c
===================================================================
--- compile.c	(revision 46951)
+++ compile.c	(revision 46952)
@@ -1441,8 +1441,7 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L1441
     /* make instruction sequence */
     generated_iseq = ALLOC_N(VALUE, pos);
     line_info_table = ALLOC_N(struct iseq_line_info_entry, k);
-    iseq->is_entries = ALLOC_N(union iseq_inline_storage_entry, iseq->is_size);
-    MEMZERO(iseq->is_entries, union iseq_inline_storage_entry, iseq->is_size);
+    iseq->is_entries = ZALLOC_N(union iseq_inline_storage_entry, iseq->is_size);
     iseq->callinfo_entries = ALLOC_N(rb_call_info_t, iseq->callinfo_size);
     /* MEMZERO(iseq->callinfo_entries, rb_call_info_t, iseq->callinfo_size); */
 
Index: gc.c
===================================================================
--- gc.c	(revision 46951)
+++ gc.c	(revision 46952)
@@ -920,8 +920,7 @@ RVALUE_DEMOTE_FROM_OLD(rb_objspace_t *ob https://github.com/ruby/ruby/blob/trunk/gc.c#L920
 rb_objspace_t *
 rb_objspace_alloc(void)
 {
-    rb_objspace_t *objspace = malloc(sizeof(rb_objspace_t));
-    memset(objspace, 0, sizeof(*objspace));
+    rb_objspace_t *objspace = calloc(1, sizeof(rb_objspace_t));
     ruby_gc_stress = ruby_initial_gc_stress;
 
     malloc_limit = gc_params.malloc_limit_min;
@@ -1087,13 +1086,12 @@ heap_page_allocate(rb_objspace_t *objspa https://github.com/ruby/ruby/blob/trunk/gc.c#L1086
     }
 
     /* assign heap_page entry */
-    page = (struct heap_page *)malloc(sizeof(struct heap_page));
+    page = (struct heap_page *)calloc(1, sizeof(struct heap_page));
     if (page == 0) {
 	aligned_free(page_body);
 	during_gc = 0;
 	rb_memerror();
     }
-    MEMZERO((void*)page, struct heap_page, 1);
 
     page->body = page_body;
 
Index: parse.y
===================================================================
--- parse.y	(revision 46951)
+++ parse.y	(revision 46952)
@@ -9511,8 +9511,7 @@ new_args_tail_gen(struct parser_params * https://github.com/ruby/ruby/blob/trunk/parse.y#L9511
     NODE *node;
     int check = 0;
 
-    args = ALLOC(struct rb_args_info);
-    MEMZERO(args, struct rb_args_info, 1);
+    args = ZALLOC(struct rb_args_info);
     node = NEW_NODE(NODE_ARGS, 0, 0, args);
 
     args->block_arg      = b;
@@ -10244,8 +10243,7 @@ parser_new(void) https://github.com/ruby/ruby/blob/trunk/parse.y#L10243
 {
     struct parser_params *p;
 
-    p = ALLOC_N(struct parser_params, 1);
-    MEMZERO(p, struct parser_params, 1);
+    p = ZALLOC(struct parser_params);
     parser_initialize(p);
     return p;
 }
@@ -10665,8 +10663,7 @@ ripper_s_allocate(VALUE klass) https://github.com/ruby/ruby/blob/trunk/parse.y#L10663
     struct parser_params *p;
     VALUE self;
 
-    p = ALLOC_N(struct parser_params, 1);
-    MEMZERO(p, struct parser_params, 1);
+    p = ZALLOC(struct parser_params);
     self = TypedData_Wrap_Struct(klass, &parser_data_type, p);
     p->value = self;
     return self;
Index: ext/socket/raddrinfo.c
===================================================================
--- ext/socket/raddrinfo.c	(revision 46951)
+++ ext/socket/raddrinfo.c	(revision 46952)
@@ -718,8 +718,7 @@ get_addrinfo(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L718
 static rb_addrinfo_t *
 alloc_addrinfo()
 {
-    rb_addrinfo_t *rai = ALLOC(rb_addrinfo_t);
-    memset(rai, 0, sizeof(rb_addrinfo_t));
+    rb_addrinfo_t *rai = ZALLOC(rb_addrinfo_t);
     rai->inspectname = Qnil;
     rai->canonname = Qnil;
     return rai;
Index: ext/strscan/strscan.c
===================================================================
--- ext/strscan/strscan.c	(revision 46951)
+++ ext/strscan/strscan.c	(revision 46952)
@@ -199,8 +199,7 @@ strscan_s_allocate(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/strscan/strscan.c#L199
 {
     struct strscanner *p;
 
-    p = ALLOC(struct strscanner);
-    MEMZERO(p, struct strscanner, 1);
+    p = ZALLOC(struct strscanner);
     CLEAR_MATCH_STATUS(p);
     onig_region_init(&(p->regs));
     p->str = Qnil;
Index: cont.c
===================================================================
--- cont.c	(revision 46951)
+++ cont.c	(revision 46952)
@@ -1162,8 +1162,7 @@ fiber_t_alloc(VALUE fibval) https://github.com/ruby/ruby/blob/trunk/cont.c#L1162
     }
 
     THREAD_MUST_BE_RUNNING(th);
-    fib = ALLOC(rb_fiber_t);
-    memset(fib, 0, sizeof(rb_fiber_t));
+    fib = ZALLOC(rb_fiber_t);
     fib->cont.self = fibval;
     fib->cont.type = FIBER_CONTEXT;
     cont_init(&fib->cont, th);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]