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

ruby-changes:35490

From: normal <ko1@a...>
Date: Sat, 13 Sep 2014 14:14:59 +0900 (JST)
Subject: [ruby-changes:35490] normal:r47572 (trunk): simplify some trivial rb_data_type_t callbacks

normal	2014-09-13 14:14:51 +0900 (Sat, 13 Sep 2014)

  New Revision: 47572

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

  Log:
    simplify some trivial rb_data_type_t callbacks
    
    * process.c (free_exec_arg): remove
      (memsize_exec_arg): ptr is never NULL
      (exec_arg_data_type): use RUBY_TYPED_DEFAULT_FREE
    
    * variable.c (autoload_i_free): remove
      (autoload_data_i_type): use RUBY_TYPED_DEFAULT_FREE
      (autoload_memsize): ptr is never NULL
    
    * vm_backtrace.c (location_free): remove
      (location_mark): ptr is never NULL
      (location_data_type): use RUBY_TYPED_DEFAULT_FREE
      (backtrace_mark): ditto
      (backtrace_free): ditto

  Modified files:
    trunk/ChangeLog
    trunk/process.c
    trunk/variable.c
    trunk/vm_backtrace.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47571)
+++ ChangeLog	(revision 47572)
@@ -1,3 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Sep 13 14:14:00 2014  Eric Wong  <e@8...>
+
+	* process.c (free_exec_arg): remove
+	  (memsize_exec_arg): ptr is never NULL
+	  (exec_arg_data_type): use RUBY_TYPED_DEFAULT_FREE
+
+	* variable.c (autoload_i_free): remove
+	  (autoload_data_i_type): use RUBY_TYPED_DEFAULT_FREE
+	  (autoload_memsize): ptr is never NULL
+
+	* vm_backtrace.c (location_free): remove
+	  (location_mark): ptr is never NULL
+	  (location_data_type): use RUBY_TYPED_DEFAULT_FREE
+	  (backtrace_mark): ditto
+	  (backtrace_free): ditto
+
 Sat Sep 13 13:43:07 2014  Eric Wong  <e@8...>
 
 	* doc/NEWS-2.0.0: fix typo for default RUBY_FIBER_MACHINE_STACK_SIZE
Index: variable.c
===================================================================
--- variable.c	(revision 47571)
+++ variable.c	(revision 47572)
@@ -1543,7 +1543,7 @@ static size_t https://github.com/ruby/ruby/blob/trunk/variable.c#L1543
 autoload_memsize(const void *ptr)
 {
     const st_table *tbl = ptr;
-    return tbl ? st_memsize(tbl) : 0;
+    return st_memsize(tbl);
 }
 
 static const rb_data_type_t autoload_data_type = {
@@ -1584,13 +1584,6 @@ autoload_i_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/variable.c#L1584
     rb_gc_mark(p->value);
 }
 
-static void
-autoload_i_free(void *ptr)
-{
-    struct autoload_data_i *p = ptr;
-    xfree(p);
-}
-
 static size_t
 autoload_i_memsize(const void *ptr)
 {
@@ -1599,7 +1592,7 @@ autoload_i_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/variable.c#L1592
 
 static const rb_data_type_t autoload_data_i_type = {
     "autoload_i",
-    {autoload_i_mark, autoload_i_free, autoload_i_memsize,},
+    {autoload_i_mark, RUBY_TYPED_DEFAULT_FREE, autoload_i_memsize,},
     NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
Index: vm_backtrace.c
===================================================================
--- vm_backtrace.c	(revision 47571)
+++ vm_backtrace.c	(revision 47572)
@@ -72,10 +72,8 @@ struct valued_frame_info { https://github.com/ruby/ruby/blob/trunk/vm_backtrace.c#L72
 static void
 location_mark(void *ptr)
 {
-    if (ptr) {
-	struct valued_frame_info *vfi = (struct valued_frame_info *)ptr;
-	rb_gc_mark(vfi->btobj);
-    }
+    struct valued_frame_info *vfi = (struct valued_frame_info *)ptr;
+    rb_gc_mark(vfi->btobj);
 }
 
 static void
@@ -93,15 +91,6 @@ location_mark_entry(rb_backtrace_locatio https://github.com/ruby/ruby/blob/trunk/vm_backtrace.c#L91
     }
 }
 
-static void
-location_free(void *ptr)
-{
-    if (ptr) {
-	rb_backtrace_location_t *fi = (rb_backtrace_location_t *)ptr;
-	ruby_xfree(fi);
-    }
-}
-
 static size_t
 location_memsize(const void *ptr)
 {
@@ -111,7 +100,7 @@ location_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/vm_backtrace.c#L100
 
 static const rb_data_type_t location_data_type = {
     "frame_info",
-    {location_mark, location_free, location_memsize,},
+    {location_mark, RUBY_TYPED_DEFAULT_FREE, location_memsize,},
     NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
@@ -378,26 +367,22 @@ typedef struct rb_backtrace_struct { https://github.com/ruby/ruby/blob/trunk/vm_backtrace.c#L367
 static void
 backtrace_mark(void *ptr)
 {
-    if (ptr) {
-	rb_backtrace_t *bt = (rb_backtrace_t *)ptr;
-	size_t i, s = bt->backtrace_size;
+    rb_backtrace_t *bt = (rb_backtrace_t *)ptr;
+    size_t i, s = bt->backtrace_size;
 
-	for (i=0; i<s; i++) {
-	    location_mark_entry(&bt->backtrace[i]);
-	}
-	rb_gc_mark(bt->strary);
-	rb_gc_mark(bt->locary);
+    for (i=0; i<s; i++) {
+	location_mark_entry(&bt->backtrace[i]);
     }
+    rb_gc_mark(bt->strary);
+    rb_gc_mark(bt->locary);
 }
 
 static void
 backtrace_free(void *ptr)
 {
-   if (ptr) {
-       rb_backtrace_t *bt = (rb_backtrace_t *)ptr;
-       if (bt->backtrace) ruby_xfree(bt->backtrace_base);
-       ruby_xfree(bt);
-   }
+   rb_backtrace_t *bt = (rb_backtrace_t *)ptr;
+   if (bt->backtrace) ruby_xfree(bt->backtrace_base);
+   ruby_xfree(bt);
 }
 
 static size_t
Index: process.c
===================================================================
--- process.c	(revision 47571)
+++ process.c	(revision 47572)
@@ -1348,21 +1348,15 @@ mark_exec_arg(void *ptr) https://github.com/ruby/ruby/blob/trunk/process.c#L1348
     rb_gc_mark(eargp->chdir_dir);
 }
 
-static void
-free_exec_arg(void *ptr)
-{
-    xfree(ptr);
-}
-
 static size_t
 memsize_exec_arg(const void *ptr)
 {
-    return ptr ? sizeof(struct rb_execarg) : 0;
+    return sizeof(struct rb_execarg);
 }
 
 static const rb_data_type_t exec_arg_data_type = {
     "exec_arg",
-    {mark_exec_arg, free_exec_arg, memsize_exec_arg},
+    {mark_exec_arg, RUBY_TYPED_DEFAULT_FREE, memsize_exec_arg},
     NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
 };
 

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

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