| 1 |
From 4bea12353c2f0f5a52746821f1e3f961592c7ca0 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Atri Bhattacharya <[email protected]> |
| 3 |
Date: Tue, 2 Apr 2024 10:05:04 -0700 |
| 4 |
Subject: [PATCH] [python] Cython 3 compatibility: declare functions noexcept. |
| 5 |
(#35995) |
| 6 |
|
| 7 |
In Cython 3, cdef functions that really will not raise exceptions must be declared as `noexcept`. Fixed by this commit. |
| 8 |
|
| 9 |
Update requirements to `cython >= 3.0` in requirements*.txt and setup.py. |
| 10 |
|
| 11 |
Fixes issue #33918. |
| 12 |
|
| 13 |
<!-- |
| 14 |
|
| 15 |
If you know who should review your pull request, please assign it to that |
| 16 |
person, otherwise the pull request would get assigned randomly. |
| 17 |
|
| 18 |
If your pull request is for a specific language, please add the appropriate |
| 19 |
lang label. |
| 20 |
|
| 21 |
--> |
| 22 |
|
| 23 |
Closes #35995 |
| 24 |
|
| 25 |
COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/35995 from badshah400:master b3277bac1585ddee88a170b0a95c260d909cce9c |
| 26 |
PiperOrigin-RevId: 621214091 |
| 27 |
--- |
| 28 |
requirements.bazel.txt | 2 +- |
| 29 |
requirements.txt | 2 +- |
| 30 |
setup.py | 2 +- |
| 31 |
.../grpcio/grpc/_cython/_cygrpc/aio/callback_common.pxd.pxi | 2 +- |
| 32 |
.../grpcio/grpc/_cython/_cygrpc/aio/callback_common.pyx.pxi | 2 +- |
| 33 |
src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi | 2 +- |
| 34 |
src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pxd.pxi | 6 +++--- |
| 35 |
src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pyx.pxi | 6 +++--- |
| 36 |
src/python/grpcio/grpc/_cython/_cygrpc/vtable.pyx.pxi | 6 +++--- |
| 37 |
9 files changed, 15 insertions(+), 15 deletions(-) |
| 38 |
|
| 39 |
Origin: upstream, https://github.com/grpc/grpc/commit/4bea12353c2f0f5a52746821f1e3f961592c7ca0 |
| 40 |
Bug-upstream: https://github.com/grpc/grpc/issues/33918 |
| 41 |
--- a/requirements.bazel.txt |
| 42 |
+++ b/requirements.bazel.txt |
| 43 |
@@ -1,6 +1,6 @@ |
| 44 |
# GRPC Python setup requirements |
| 45 |
coverage==4.5.4 |
| 46 |
-cython==0.29.21 |
| 47 |
+cython==3.0.0 |
| 48 |
protobuf>=3.5.0.post1, < 4.0dev |
| 49 |
wheel==0.36.2 |
| 50 |
google-auth==1.24.0 |
| 51 |
--- a/requirements.txt |
| 52 |
+++ b/requirements.txt |
| 53 |
@@ -1,5 +1,5 @@ |
| 54 |
# GRPC Python setup requirements |
| 55 |
coverage>=4.0 |
| 56 |
-cython>=0.29.8 |
| 57 |
+cython>=3.0.0 |
| 58 |
protobuf>=4.21.3,<5.0dev |
| 59 |
wheel>=0.29 |
| 60 |
--- a/setup.py |
| 61 |
+++ b/setup.py |
| 62 |
@@ -502,7 +502,7 @@ |
| 63 |
elif need_cython: |
| 64 |
sys.stderr.write( |
| 65 |
'We could not find Cython. Setup may take 10-20 minutes.\n') |
| 66 |
- SETUP_REQUIRES += ('cython>=0.23',) |
| 67 |
+ SETUP_REQUIRES += ('cython>=3.0.0',) |
| 68 |
|
| 69 |
COMMAND_CLASS = { |
| 70 |
'doc': commands.SphinxDocumentation, |
| 71 |
--- a/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pxd.pxi |
| 72 |
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pxd.pxi |
| 73 |
@@ -48,7 +48,7 @@ |
| 74 |
@staticmethod |
| 75 |
cdef void functor_run( |
| 76 |
grpc_completion_queue_functor* functor, |
| 77 |
- int succeed) |
| 78 |
+ int succeed) noexcept |
| 79 |
|
| 80 |
cdef grpc_completion_queue_functor *c_functor(self) |
| 81 |
|
| 82 |
--- a/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pyx.pxi |
| 83 |
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pyx.pxi |
| 84 |
@@ -50,7 +50,7 @@ |
| 85 |
@staticmethod |
| 86 |
cdef void functor_run( |
| 87 |
grpc_completion_queue_functor* functor, |
| 88 |
- int success): |
| 89 |
+ int success) noexcept: |
| 90 |
cdef CallbackContext *context = <CallbackContext *>functor |
| 91 |
cdef object waiter = <object>context.waiter |
| 92 |
if not waiter.cancelled(): |
| 93 |
--- a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi |
| 94 |
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi |
| 95 |
@@ -314,7 +314,7 @@ |
| 96 |
return credentials |
| 97 |
|
| 98 |
cdef grpc_ssl_certificate_config_reload_status _server_cert_config_fetcher_wrapper( |
| 99 |
- void* user_data, grpc_ssl_server_certificate_config **config) with gil: |
| 100 |
+ void* user_data, grpc_ssl_server_certificate_config **config) noexcept with gil: |
| 101 |
# This is a credentials.ServerCertificateConfig |
| 102 |
cdef ServerCertificateConfig cert_config = None |
| 103 |
if not user_data: |
| 104 |
--- a/src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pxd.pxi |
| 105 |
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pxd.pxi |
| 106 |
@@ -20,10 +20,10 @@ |
| 107 |
void (*child)() nogil) |
| 108 |
|
| 109 |
|
| 110 |
-cdef void __prefork() nogil |
| 111 |
+cdef void __prefork() noexcept nogil |
| 112 |
|
| 113 |
|
| 114 |
-cdef void __postfork_parent() nogil |
| 115 |
+cdef void __postfork_parent() noexcept nogil |
| 116 |
|
| 117 |
|
| 118 |
-cdef void __postfork_child() nogil |
| 119 |
\ No newline at end of file |
| 120 |
+cdef void __postfork_child() noexcept nogil |
| 121 |
--- a/src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pyx.pxi |
| 122 |
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pyx.pxi |
| 123 |
@@ -34,7 +34,7 @@ |
| 124 |
|
| 125 |
_fork_handler_failed = False |
| 126 |
|
| 127 |
-cdef void __prefork() nogil: |
| 128 |
+cdef void __prefork() noexcept nogil: |
| 129 |
with gil: |
| 130 |
global _fork_handler_failed |
| 131 |
_fork_handler_failed = False |
| 132 |
@@ -48,14 +48,14 @@ |
| 133 |
_fork_handler_failed = True |
| 134 |
|
| 135 |
|
| 136 |
-cdef void __postfork_parent() nogil: |
| 137 |
+cdef void __postfork_parent() noexcept nogil: |
| 138 |
with gil: |
| 139 |
with _fork_state.fork_in_progress_condition: |
| 140 |
_fork_state.fork_in_progress = False |
| 141 |
_fork_state.fork_in_progress_condition.notify_all() |
| 142 |
|
| 143 |
|
| 144 |
-cdef void __postfork_child() nogil: |
| 145 |
+cdef void __postfork_child() noexcept nogil: |
| 146 |
with gil: |
| 147 |
try: |
| 148 |
if _fork_handler_failed: |
| 149 |
--- a/src/python/grpcio/grpc/_cython/_cygrpc/vtable.pyx.pxi |
| 150 |
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/vtable.pyx.pxi |
| 151 |
@@ -13,16 +13,16 @@ |
| 152 |
# limitations under the License. |
| 153 |
|
| 154 |
# TODO(https://github.com/grpc/grpc/issues/15662): Reform this. |
| 155 |
-cdef void* _copy_pointer(void* pointer): |
| 156 |
+cdef void* _copy_pointer(void* pointer) noexcept: |
| 157 |
return pointer |
| 158 |
|
| 159 |
|
| 160 |
# TODO(https://github.com/grpc/grpc/issues/15662): Reform this. |
| 161 |
-cdef void _destroy_pointer(void* pointer): |
| 162 |
+cdef void _destroy_pointer(void* pointer) noexcept: |
| 163 |
pass |
| 164 |
|
| 165 |
|
| 166 |
-cdef int _compare_pointer(void* first_pointer, void* second_pointer): |
| 167 |
+cdef int _compare_pointer(void* first_pointer, void* second_pointer) noexcept: |
| 168 |
if first_pointer < second_pointer: |
| 169 |
return -1 |
| 170 |
elif first_pointer > second_pointer: |