summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-17 19:59:56 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-17 19:59:56 +0000
commitcad4591086b285fa5c8fb61f19692b9a521dcea7 (patch)
treed5cced02e3e1a3e9a89ff0862f83ee5bdb35f658
parent3a55e8a4360fbcd1c8db05eba4d8e7e365dd4547 (diff)
remove branches in dmark and dfree GC callbacks
dmark and dfree callbacks are never called in gc.c for NULL DATA_PTR values, not even for zombie objects. * compile.c (ibf_loader_mark): remove branch for pointer validity * compile.c (ibf_loader_free): ditto * cont.c (cont_free): ditto * cont.c (fiber_free): ditto * dir.c (dir_free): ditto * ext/stringio/stringio.c (strio_mark): ditto * proc.c (binding_free): ditto * thread_sync.c (mutex_free): ditto * vm.c (thread_free): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--compile.c18
-rw-r--r--cont.c85
-rw-r--r--dir.c5
-rw-r--r--ext/stringio/stringio.c5
-rw-r--r--proc.c8
-rw-r--r--thread_sync.c16
-rw-r--r--vm.c51
7 files changed, 86 insertions, 102 deletions
diff --git a/compile.c b/compile.c
index 7bfca53..e3d66b6 100644
--- a/compile.c
+++ b/compile.c
@@ -8631,22 +8631,18 @@ ibf_load_setup(struct ibf_load *load, VALUE loader_obj, VALUE str)
static void
ibf_loader_mark(void *ptr)
{
- if (ptr) {
- struct ibf_load *load = (struct ibf_load *)ptr;
- rb_gc_mark(load->str);
- rb_gc_mark(load->iseq_list);
- rb_gc_mark(load->obj_list);
- }
+ struct ibf_load *load = (struct ibf_load *)ptr;
+ rb_gc_mark(load->str);
+ rb_gc_mark(load->iseq_list);
+ rb_gc_mark(load->obj_list);
}
static void
ibf_loader_free(void *ptr)
{
- if (ptr) {
- struct ibf_load *load = (struct ibf_load *)ptr;
- ruby_xfree(load->id_list);
- ruby_xfree(load);
- }
+ struct ibf_load *load = (struct ibf_load *)ptr;
+ ruby_xfree(load->id_list);
+ ruby_xfree(load);
}
static size_t
diff --git a/cont.c b/cont.c
index 7787530..3355ad3 100644
--- a/cont.c
+++ b/cont.c
@@ -218,55 +218,54 @@ cont_mark(void *ptr)
static void
cont_free(void *ptr)
{
+ rb_context_t *cont = ptr;
+
RUBY_FREE_ENTER("cont");
- if (ptr) {
- rb_context_t *cont = ptr;
- RUBY_FREE_UNLESS_NULL(cont->saved_thread.stack);
+ RUBY_FREE_UNLESS_NULL(cont->saved_thread.stack);
#if FIBER_USE_NATIVE
- if (cont->type == CONTINUATION_CONTEXT) {
- /* cont */
- ruby_xfree(cont->ensure_array);
- RUBY_FREE_UNLESS_NULL(cont->machine.stack);
- }
- else {
- /* fiber */
- rb_fiber_t *fib = (rb_fiber_t*)cont;
- const rb_thread_t *const th = GET_THREAD();
+ if (cont->type == CONTINUATION_CONTEXT) {
+ /* cont */
+ ruby_xfree(cont->ensure_array);
+ RUBY_FREE_UNLESS_NULL(cont->machine.stack);
+ }
+ else {
+ /* fiber */
+ rb_fiber_t *fib = (rb_fiber_t*)cont;
+ const rb_thread_t *const th = GET_THREAD();
#ifdef _WIN32
- if (th && th->fiber != fib && cont->type != ROOT_FIBER_CONTEXT) {
- /* don't delete root fiber handle */
- if (fib->fib_handle) {
- DeleteFiber(fib->fib_handle);
- }
+ if (th && th->fiber != fib && cont->type != ROOT_FIBER_CONTEXT) {
+ /* don't delete root fiber handle */
+ if (fib->fib_handle) {
+ DeleteFiber(fib->fib_handle);
}
+ }
#else /* not WIN32 */
- if (th && th->fiber != fib) {
- if (fib->ss_sp) {
- if (cont->type == ROOT_FIBER_CONTEXT) {
- rb_bug("Illegal root fiber parameter");
- }
- munmap((void*)fib->ss_sp, fib->ss_size);
+ if (th && th->fiber != fib) {
+ if (fib->ss_sp) {
+ if (cont->type == ROOT_FIBER_CONTEXT) {
+ rb_bug("Illegal root fiber parameter");
}
+ munmap((void*)fib->ss_sp, fib->ss_size);
}
- else {
- /* It may reached here when finalize */
- /* TODO examine whether it is a bug */
- /* rb_bug("cont_free: release self"); */
- }
-#endif
}
+ else {
+ /* It may reached here when finalize */
+ /* TODO examine whether it is a bug */
+ /* rb_bug("cont_free: release self"); */
+ }
+#endif
+ }
#else /* not FIBER_USE_NATIVE */
- ruby_xfree(cont->ensure_array);
- RUBY_FREE_UNLESS_NULL(cont->machine.stack);
+ ruby_xfree(cont->ensure_array);
+ RUBY_FREE_UNLESS_NULL(cont->machine.stack);
#endif
#ifdef __ia64
- RUBY_FREE_UNLESS_NULL(cont->machine.register_stack);
+ RUBY_FREE_UNLESS_NULL(cont->machine.register_stack);
#endif
- RUBY_FREE_UNLESS_NULL(cont->vm_stack);
+ RUBY_FREE_UNLESS_NULL(cont->vm_stack);
- /* free rb_cont_t or rb_fiber_t */
- ruby_xfree(ptr);
- }
+ /* free rb_cont_t or rb_fiber_t */
+ ruby_xfree(ptr);
RUBY_FREE_LEAVE("cont");
}
@@ -317,16 +316,14 @@ fiber_mark(void *ptr)
static void
fiber_free(void *ptr)
{
+ rb_fiber_t *fib = ptr;
RUBY_FREE_ENTER("fiber");
- if (ptr) {
- rb_fiber_t *fib = ptr;
- if (fib->cont.type != ROOT_FIBER_CONTEXT &&
- fib->cont.saved_thread.local_storage) {
- st_free_table(fib->cont.saved_thread.local_storage);
- }
-
- cont_free(&fib->cont);
+ if (fib->cont.type != ROOT_FIBER_CONTEXT &&
+ fib->cont.saved_thread.local_storage) {
+ st_free_table(fib->cont.saved_thread.local_storage);
}
+
+ cont_free(&fib->cont);
RUBY_FREE_LEAVE("fiber");
}
diff --git a/dir.c b/dir.c
index 365f059..9fc5597 100644
--- a/dir.c
+++ b/dir.c
@@ -436,9 +436,8 @@ static void
dir_free(void *ptr)
{
struct dir_data *dir = ptr;
- if (dir) {
- if (dir->dir) closedir(dir->dir);
- }
+
+ if (dir->dir) closedir(dir->dir);
xfree(dir);
}
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index fb2edda..ba65123 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -52,9 +52,8 @@ static void
strio_mark(void *p)
{
struct StringIO *ptr = p;
- if (ptr) {
- rb_gc_mark(ptr->string);
- }
+
+ rb_gc_mark(ptr->string);
}
static void
diff --git a/proc.c b/proc.c
index dd571f7..58d33b1 100644
--- a/proc.c
+++ b/proc.c
@@ -265,12 +265,10 @@ rb_proc_lambda_p(VALUE procval)
static void
binding_free(void *ptr)
{
- rb_binding_t *bind;
RUBY_FREE_ENTER("binding");
- if (ptr) {
- bind = ptr;
- ruby_xfree(bind);
- }
+
+ ruby_xfree(ptr);
+
RUBY_FREE_LEAVE("binding");
}
diff --git a/thread_sync.c b/thread_sync.c
index 152995f..c3311da 100644
--- a/thread_sync.c
+++ b/thread_sync.c
@@ -54,16 +54,14 @@ static const char* rb_mutex_unlock_th(rb_mutex_t *mutex, rb_thread_t volatile *t
static void
mutex_free(void *ptr)
{
- if (ptr) {
- rb_mutex_t *mutex = ptr;
- if (mutex->th) {
- /* rb_warn("free locked mutex"); */
- const char *err = rb_mutex_unlock_th(mutex, mutex->th);
- if (err) rb_bug("%s", err);
- }
- native_mutex_destroy(&mutex->lock);
- native_cond_destroy(&mutex->cond);
+ rb_mutex_t *mutex = ptr;
+ if (mutex->th) {
+ /* rb_warn("free locked mutex"); */
+ const char *err = rb_mutex_unlock_th(mutex, mutex->th);
+ if (err) rb_bug("%s", err);
}
+ native_mutex_destroy(&mutex->lock);
+ native_cond_destroy(&mutex->cond);
ruby_xfree(ptr);
}
diff --git a/vm.c b/vm.c
index f336c55..70df670 100644
--- a/vm.c
+++ b/vm.c
@@ -2346,41 +2346,38 @@ rb_thread_mark(void *ptr)
static void
thread_free(void *ptr)
{
- rb_thread_t *th;
+ rb_thread_t *th = ptr;
RUBY_FREE_ENTER("thread");
- if (ptr) {
- th = ptr;
-
- if (!th->root_fiber) {
- RUBY_FREE_UNLESS_NULL(th->stack);
- }
+ if (!th->root_fiber) {
+ RUBY_FREE_UNLESS_NULL(th->stack);
+ }
- if (th->locking_mutex != Qfalse) {
- rb_bug("thread_free: locking_mutex must be NULL (%p:%p)", (void *)th, (void *)th->locking_mutex);
- }
- if (th->keeping_mutexes != NULL) {
- rb_bug("thread_free: keeping_mutexes must be NULL (%p:%p)", (void *)th, (void *)th->keeping_mutexes);
- }
+ if (th->locking_mutex != Qfalse) {
+ rb_bug("thread_free: locking_mutex must be NULL (%p:%p)", (void *)th, (void *)th->locking_mutex);
+ }
+ if (th->keeping_mutexes != NULL) {
+ rb_bug("thread_free: keeping_mutexes must be NULL (%p:%p)", (void *)th, (void *)th->keeping_mutexes);
+ }
- if (th->local_storage) {
- st_free_table(th->local_storage);
- }
+ if (th->local_storage) {
+ st_free_table(th->local_storage);
+ }
- if (th->vm && th->vm->main_thread == th) {
- RUBY_GC_INFO("main thread\n");
- }
- else {
+ if (th->vm && th->vm->main_thread == th) {
+ RUBY_GC_INFO("main thread\n");
+ }
+ else {
#ifdef USE_SIGALTSTACK
- if (th->altstack) {
- free(th->altstack);
- }
-#endif
- ruby_xfree(ptr);
+ if (th->altstack) {
+ free(th->altstack);
}
- if (ruby_current_thread == th)
- ruby_current_thread = NULL;
+#endif
+ ruby_xfree(ptr);
}
+ if (ruby_current_thread == th)
+ ruby_current_thread = NULL;
+
RUBY_FREE_LEAVE("thread");
}