ruby-changes:50103
From: shyouhei <ko1@a...>
Date: Mon, 5 Feb 2018 13:17:50 +0900 (JST)
Subject: [ruby-changes:50103] shyouhei:r62221 (trunk): assigning void* to a function pointer is a POSIXism
shyouhei 2018-02-05 13:17:44 +0900 (Mon, 05 Feb 2018) New Revision: 62221 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62221 Log: assigning void* to a function pointer is a POSIXism No implicit cast is defined between these types. Should be explicit. Also, NULL is defined to be ((void*)0) so not usable as a function pointer value. Modified files: trunk/mjit.c trunk/thread_pthread.c trunk/vm_core.h Index: thread_pthread.c =================================================================== --- thread_pthread.c (revision 62220) +++ thread_pthread.c (revision 62221) @@ -1777,7 +1777,7 @@ rb_nativethread_self(void) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1777 static void * mjit_worker(void *arg) { - void (*worker_func)(void) = arg; + void (*worker_func)(void) = (void(*)(void))arg; if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0) { fprintf(stderr, "Cannot enable cancelation in MJIT worker\n"); @@ -1791,7 +1791,7 @@ mjit_worker(void *arg) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1791 /* Launch MJIT thread. Returns FALSE if it fails to create thread. */ int -rb_thread_create_mjit_thread(void (*child_hook)(void), void (*worker_func)(void)) +rb_thread_create_mjit_thread(void (*child_hook)(void), void *worker_func) { pthread_attr_t attr; pthread_t worker_pid; Index: vm_core.h =================================================================== --- vm_core.h (revision 62220) +++ vm_core.h (revision 62221) @@ -292,8 +292,9 @@ pathobj_realpath(VALUE pathobj) https://github.com/ruby/ruby/blob/trunk/vm_core.h#L292 } } -/* A forward declaration */ +/* Forward declarations */ struct rb_mjit_unit; +struct rb_execution_context_struct; struct rb_iseq_constant_body { enum iseq_type { @@ -419,7 +420,8 @@ struct rb_iseq_constant_body { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L420 unsigned int stack_max; /* for stack overflow check */ /* The following fields are MJIT related info. */ - void *jit_func; /* function pointer for loaded native code */ + VALUE (*jit_func)(struct rb_execution_context_struct *, + struct rb_control_frame_struct *); /* function pointer for loaded native code */ long unsigned total_calls; /* number of total calls with `mjit_exec()` */ struct rb_mjit_unit *jit_unit; }; Index: mjit.c =================================================================== --- mjit.c (revision 62220) +++ mjit.c (revision 62221) @@ -440,7 +440,7 @@ static void https://github.com/ruby/ruby/blob/trunk/mjit.c#L440 free_unit(struct rb_mjit_unit *unit) { if (unit->iseq) /* ISeq is not GCed */ - unit->iseq->body->jit_func = NULL; + unit->iseq->body->jit_func = 0; if (unit->handle) /* handle is NULL if it's in queue */ dlclose(unit->handle); xfree(unit); @@ -682,7 +682,7 @@ load_func_from_so(const char *so_file, c https://github.com/ruby/ruby/blob/trunk/mjit.c#L682 /* Compile ISeq in UNIT and return function pointer of JIT-ed code. It may return NOT_COMPILABLE_JIT_ISEQ_FUNC if something went wrong. */ -static void * +static mjit_func_t convert_unit_to_func(struct rb_mjit_unit *unit) { char c_file[70], so_file[70], funcname[35]; @@ -744,7 +744,7 @@ convert_unit_to_func(struct rb_mjit_unit https://github.com/ruby/ruby/blob/trunk/mjit.c#L744 if (!success) { if (!mjit_opts.save_temps) remove(c_file); - return (void *)NOT_COMPILABLE_JIT_ISEQ_FUNC; + return (mjit_func_t)NOT_COMPILABLE_JIT_ISEQ_FUNC; } start_time = real_ms_time(); @@ -755,7 +755,7 @@ convert_unit_to_func(struct rb_mjit_unit https://github.com/ruby/ruby/blob/trunk/mjit.c#L755 remove(c_file); if (!success) { verbose(2, "Failed to generate so: %s", so_file); - return (void *)NOT_COMPILABLE_JIT_ISEQ_FUNC; + return (mjit_func_t)NOT_COMPILABLE_JIT_ISEQ_FUNC; } func = load_func_from_so(so_file, funcname, unit); @@ -771,7 +771,7 @@ convert_unit_to_func(struct rb_mjit_unit https://github.com/ruby/ruby/blob/trunk/mjit.c#L771 RSTRING_PTR(rb_iseq_path(unit->iseq)), FIX2INT(unit->iseq->body->location.first_lineno), c_file); CRITICAL_SECTION_FINISH(3, "end of jit"); } - return func; + return (mjit_func_t)func; } /* Set to TRUE to finish worker. */ @@ -810,7 +810,7 @@ worker(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L810 CRITICAL_SECTION_FINISH(3, "in worker dequeue"); if (node) { - void *func = convert_unit_to_func(node->unit); + mjit_func_t func = convert_unit_to_func(node->unit); CRITICAL_SECTION_START(3, "in jit func replace"); if (node->unit->iseq) { /* Check whether GCed or not */ @@ -985,7 +985,7 @@ unload_units(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L985 /* Unload the worst node. */ verbose(2, "Unloading unit %d (calls=%lu)", worst_node->unit->id, worst_node->unit->iseq->body->total_calls); unit = worst_node->unit; - unit->iseq->body->jit_func = (void *)NOT_READY_JIT_ISEQ_FUNC; + unit->iseq->body->jit_func = (mjit_func_t)NOT_READY_JIT_ISEQ_FUNC; remove_from_list(worst_node, &active_units); assert(unit->handle != NULL); @@ -1005,7 +1005,7 @@ mjit_add_iseq_to_process(const rb_iseq_t https://github.com/ruby/ruby/blob/trunk/mjit.c#L1005 if (!mjit_init_p) return; - iseq->body->jit_func = (void *)NOT_READY_JIT_ISEQ_FUNC; + iseq->body->jit_func = (mjit_func_t)NOT_READY_JIT_ISEQ_FUNC; create_unit(iseq); if (iseq->body->jit_unit == NULL) /* Failure in creating the unit. */ @@ -1177,7 +1177,7 @@ mjit_init(struct mjit_options *opts) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1177 /* Initialize worker thread */ finish_worker_p = FALSE; worker_finished = FALSE; - if (rb_thread_create_mjit_thread(child_after_fork, worker) == FALSE) { + if (rb_thread_create_mjit_thread(child_after_fork, (void *)worker) == FALSE) { mjit_init_p = FALSE; rb_native_mutex_destroy(&mjit_engine_mutex); rb_native_cond_destroy(&mjit_pch_wakeup); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/