| 1 |
From c637a9f82bc43f7380b04baa96df243f157939d4 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Stan Hu <[email protected]> |
| 3 |
Date: Mon, 22 Jan 2024 13:11:28 -0800 |
| 4 |
Subject: [PATCH] [ruby] Fix compilation errors on clang 16 (#34481) |
| 5 |
|
| 6 |
As announced in https://discourse.llvm.org/t/clang-16-notice-of-potentially-breaking-changes/65562, clang 16 defaults `-Wincompatible-function-pointer-types` to be on. This causes a number of hard errors due to implicit conversions between `void *` and `void`, such as: |
| 7 |
|
| 8 |
``` |
| 9 |
../../../../src/ruby/ext/grpc/rb_channel.c:770:47: error: incompatible function pointer types passing 'VALUE (VALUE)' (aka 'unsigned long (unsigned long)') to parameter of type 'VALUE (*)(void *)' (aka 'unsigned long (*)(void *)') [-Wincompatible-function-pointer-types] |
| 10 |
g_channel_polling_thread = rb_thread_create(run_poll_channels_loop, NULL); |
| 11 |
^~~~~~~~~~~~~~~~~~~~~~ |
| 12 |
/root/.rbenv/versions/3.1.4/include/ruby-3.1.0/ruby/internal/intern/thread.h:190:32: note: passing argument to parameter 'f' here |
| 13 |
VALUE rb_thread_create(VALUE (*f)(void *g), void *g); |
| 14 |
^ |
| 15 |
../../../../src/ruby/ext/grpc/rb_channel.c:780:41: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes] |
| 16 |
void grpc_rb_channel_polling_thread_stop() { |
| 17 |
^ |
| 18 |
void |
| 19 |
../../../../src/ruby/ext/grpc/rb_channel.c:786:30: error: incompatible function pointer types passing 'void (void *)' to parameter of type 'void *(*)(void *)' [-Wincompatible-function-pointer-types] |
| 20 |
rb_thread_call_without_gvl(run_poll_channels_loop_unblocking_func, NULL, NULL, |
| 21 |
``` |
| 22 |
|
| 23 |
This commit fixes these pointer types using wrapper functions where necessary. |
| 24 |
|
| 25 |
This issue was also raised on the FreeBSD port of the grpc gem: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=271540 |
| 26 |
|
| 27 |
<!-- |
| 28 |
|
| 29 |
If you know who should review your pull request, please assign it to that |
| 30 |
person, otherwise the pull request would get assigned randomly. |
| 31 |
|
| 32 |
If your pull request is for a specific language, please add the appropriate |
| 33 |
lang label. |
| 34 |
|
| 35 |
--> |
| 36 |
|
| 37 |
Closes #34481 |
| 38 |
|
| 39 |
COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/34481 from stanhu:sh-ruby-fix-clang-16 63c7424ad0c93f7a7aa1ce0e84ea7916c4cbdc5f |
| 40 |
PiperOrigin-RevId: 600548467 |
| 41 |
--- |
| 42 |
src/ruby/ext/grpc/rb_channel.c | 16 +++++++++++----- |
| 43 |
src/ruby/ext/grpc/rb_event_thread.c | 12 +++++++++--- |
| 44 |
2 files changed, 20 insertions(+), 8 deletions(-) |
| 45 |
|
| 46 |
Bug-Upstream: https://github.com/grpc/grpc/pull/34481 |
| 47 |
--- a/src/ruby/ext/grpc/rb_channel.c |
| 48 |
+++ b/src/ruby/ext/grpc/rb_channel.c |
| 49 |
@@ -115,6 +115,7 @@ |
| 50 |
grpc_channel* channel); |
| 51 |
static void bg_watched_channel_list_free_and_remove(bg_watched_channel* bg); |
| 52 |
static void run_poll_channels_loop_unblocking_func(void* arg); |
| 53 |
+static void* run_poll_channels_loop_unblocking_func_wrapper(void* arg); |
| 54 |
|
| 55 |
// Needs to be called under global_connection_polling_mu |
| 56 |
static void grpc_rb_channel_watch_connection_state_op_complete( |
| 57 |
@@ -659,8 +660,12 @@ |
| 58 |
return NULL; |
| 59 |
} |
| 60 |
|
| 61 |
-// Notify the channel polling loop to cleanup and shutdown. |
| 62 |
static void run_poll_channels_loop_unblocking_func(void* arg) { |
| 63 |
+ run_poll_channels_loop_unblocking_func_wrapper(arg); |
| 64 |
+} |
| 65 |
+ |
| 66 |
+// Notify the channel polling loop to cleanup and shutdown. |
| 67 |
+static void* run_poll_channels_loop_unblocking_func_wrapper(void* arg) { |
| 68 |
bg_watched_channel* bg = NULL; |
| 69 |
(void)arg; |
| 70 |
|
| 71 |
@@ -671,7 +676,7 @@ |
| 72 |
// early out after first time through |
| 73 |
if (abort_channel_polling) { |
| 74 |
gpr_mu_unlock(&global_connection_polling_mu); |
| 75 |
- return; |
| 76 |
+ return NULL; |
| 77 |
} |
| 78 |
abort_channel_polling = 1; |
| 79 |
|
| 80 |
@@ -691,10 +696,11 @@ |
| 81 |
gpr_log(GPR_DEBUG, |
| 82 |
"GRPC_RUBY: run_poll_channels_loop_unblocking_func - end aborting " |
| 83 |
"connection polling"); |
| 84 |
+ return NULL; |
| 85 |
} |
| 86 |
|
| 87 |
// Poll channel connectivity states in background thread without the GIL. |
| 88 |
-static VALUE run_poll_channels_loop(VALUE arg) { |
| 89 |
+static VALUE run_poll_channels_loop(void* arg) { |
| 90 |
(void)arg; |
| 91 |
gpr_log( |
| 92 |
GPR_DEBUG, |
| 93 |
--- a/src/ruby/ext/grpc/rb_event_thread.c |
| 94 |
+++ b/src/ruby/ext/grpc/rb_event_thread.c |
| 95 |
@@ -104,17 +104,22 @@ |
| 96 |
return NULL; |
| 97 |
} |
| 98 |
|
| 99 |
-static void grpc_rb_event_unblocking_func(void* arg) { |
| 100 |
+static void* grpc_rb_event_unblocking_func_wrapper(void* arg) { |
| 101 |
(void)arg; |
| 102 |
gpr_mu_lock(&event_queue.mu); |
| 103 |
event_queue.abort = true; |
| 104 |
gpr_cv_signal(&event_queue.cv); |
| 105 |
gpr_mu_unlock(&event_queue.mu); |
| 106 |
+ return NULL; |
| 107 |
+} |
| 108 |
+ |
| 109 |
+static void grpc_rb_event_unblocking_func(void* arg) { |
| 110 |
+ grpc_rb_event_unblocking_func_wrapper(arg); |
| 111 |
} |
| 112 |
|
| 113 |
/* This is the implementation of the thread that handles auth metadata plugin |
| 114 |
* events */ |
| 115 |
-static VALUE grpc_rb_event_thread(VALUE arg) { |
| 116 |
+static VALUE grpc_rb_event_thread(void* arg) { |
| 117 |
grpc_rb_event* event; |
| 118 |
(void)arg; |
| 119 |
grpc_ruby_init(); |