Skip to content

Commit 875129c

Browse files
committed
fix(oss): Update cython to be compatible with OSS 3.1.3
1 parent 5c1928a commit 875129c

File tree

8 files changed

+119
-36
lines changed

8 files changed

+119
-36
lines changed

thrift/lib/python/server/python_async_processor.pxd

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
cimport cython
1516
from cpython.ref cimport PyObject
1617
from libcpp cimport bool as cbool
1718
from libcpp.map cimport map as cmap
@@ -20,21 +21,40 @@ from libcpp.pair cimport pair
2021
from libcpp.string cimport string
2122
from libcpp.vector cimport vector as cvector
2223

24+
from folly cimport cFollyPromise, cFollyUnit, c_unit
2325
from folly.executor cimport cAsyncioExecutor
2426
from folly.iobuf cimport cIOBuf
2527

26-
from thrift.python.exceptions cimport cException
28+
from thrift.py3.stream cimport (
29+
cResponseAndServerStream,
30+
cServerStream,
31+
ServerStream,
32+
)
33+
from thrift.python.exceptions cimport (
34+
cException,
35+
cTApplicationException,
36+
)
2737
from thrift.python.protocol cimport RpcKind
2838
from thrift.python.server_impl.async_processor cimport (
2939
cAsyncProcessorFactory,
3040
AsyncProcessorFactory,
3141
)
42+
from thrift.python.streaming.py_promise cimport Promise_Py
43+
from thrift.python.streaming.python_user_exception cimport cPythonUserException
44+
from thrift.python.streaming.sink cimport (
45+
cResponseAndSinkConsumer,
46+
cSinkConsumer,
47+
)
3248
from thrift.python.types cimport ServiceInterface as cServiceInterface
3349

50+
3451
# cython doesn't support * in template parameters
3552
# Make a typedef to workaround this.
3653
ctypedef PyObject* PyObjPtr
3754

55+
ctypedef unique_ptr[cIOBuf] UniqueIOBuf
56+
ctypedef cResponseAndSinkConsumer[UniqueIOBuf, UniqueIOBuf, UniqueIOBuf] SinkResponse
57+
ctypedef cResponseAndServerStream[UniqueIOBuf, UniqueIOBuf] StreamResponse
3858

3959

4060
cdef extern from "thrift/lib/python/server/PythonAsyncProcessorFactory.h" namespace "::apache::thrift::python":
@@ -60,3 +80,58 @@ cdef class PythonAsyncProcessorFactory(AsyncProcessorFactory):
6080

6181
@staticmethod
6282
cdef PythonAsyncProcessorFactory create(cServiceInterface server)
83+
84+
cdef class Promise_cFollyUnit(Promise_Py):
85+
cdef cFollyPromise[cFollyUnit]* cPromise
86+
87+
cdef error_ta(Promise_cFollyUnit self, cTApplicationException err)
88+
cdef error_py(Promise_cFollyUnit self, cPythonUserException err)
89+
cdef complete(Promise_cFollyUnit self, object _)
90+
91+
@staticmethod
92+
cdef create(cFollyPromise[cFollyUnit] cPromise)
93+
94+
cdef class Promise_Sink(Promise_Py):
95+
cdef cFollyPromise[SinkResponse]* _cPromise
96+
97+
cdef error_ta(Promise_Sink self, cTApplicationException err)
98+
cdef error_py(Promise_Sink self, cPythonUserException err)
99+
cdef complete(Promise_Sink self, object pyobj)
100+
101+
@staticmethod
102+
cdef create(cFollyPromise[SinkResponse] promise)
103+
104+
cdef class Promise_Stream(Promise_Py):
105+
cdef cFollyPromise[StreamResponse]* cPromise
106+
107+
cdef error_ta(Promise_Stream self, cTApplicationException err)
108+
cdef error_py(Promise_Stream self, cPythonUserException err)
109+
cdef complete(Promise_Stream self, object pyobj)
110+
111+
@staticmethod
112+
cdef create(cFollyPromise[StreamResponse] cPromise)
113+
114+
cdef class ResponseAndServerStream:
115+
cdef unique_ptr[StreamResponse] cResponseStream
116+
117+
@staticmethod
118+
cdef _fbthrift_create(object val, object stream)
119+
120+
cdef class ResponseAndSinkConsumer:
121+
cdef unique_ptr[SinkResponse] _cResponseSink
122+
123+
@staticmethod
124+
cdef _fbthrift_create(object val, object sink)
125+
126+
@cython.final
127+
cdef class ServerSink_IOBuf:
128+
cdef unique_ptr[cSinkConsumer[UniqueIOBuf, UniqueIOBuf]] _cSink
129+
130+
@staticmethod
131+
cdef _fbthrift_create(object sink_callback)
132+
133+
cdef class ServerStream_IOBuf(ServerStream):
134+
cdef unique_ptr[cServerStream[UniqueIOBuf]] cStream
135+
136+
@staticmethod
137+
cdef _fbthrift_create(object stream)

thrift/lib/python/server/python_async_processor.pyx

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from thrift.python.server_impl.python_async_processor cimport SerializedRequest
16+
1517
import asyncio
1618
import sys
1719
import traceback
@@ -20,16 +22,17 @@ from cpython.ref cimport PyObject
2022
cimport cython
2123
from cython.operator cimport dereference
2224
from libcpp.map cimport map as cmap
23-
from libcpp.memory cimport make_unique, make_shared, static_pointer_cast
25+
from libcpp.memory cimport make_unique, make_shared, static_pointer_cast, unique_ptr
2426
from libcpp.optional cimport optional
2527
from libcpp.pair cimport pair
28+
from libcpp.string cimport string
2629
from libcpp.unordered_set cimport unordered_set
2730
from libcpp.utility cimport move as cmove
2831
from libcpp.vector cimport vector as cvector
2932

3033
from folly cimport cFollyPromise, cFollyUnit, c_unit
3134
from folly.executor cimport get_executor
32-
from folly.iobuf cimport IOBuf, from_unique_ptr
35+
from folly.iobuf cimport IOBuf, cIOBuf, from_unique_ptr
3336

3437
from thrift.py3.stream cimport (
3538
cServerStream,
@@ -43,13 +46,12 @@ from thrift.python.exceptions cimport (
4346
cTApplicationException,
4447
cTApplicationExceptionType__UNKNOWN,
4548
)
46-
from thrift.python.protocol cimport Protocol
49+
from thrift.python.protocol cimport Protocol, RpcKind
4750
from thrift.python.serializer import serialize_iobuf
4851
from thrift.python.server_impl.request_context cimport (
4952
Cpp2RequestContext,
5053
handleAddressCallback,
5154
RequestContext,
52-
SocketAddress,
5355
THRIFT_REQUEST_CONTEXT,
5456
)
5557
from thrift.python.streaming.py_promise cimport (
@@ -71,14 +73,8 @@ from thrift.python.streaming.sink cimport (
7173
from thrift.python.types cimport ServiceInterface as cServiceInterface
7274

7375

74-
ctypedef unique_ptr[cIOBuf] UniqueIOBuf
75-
ctypedef cResponseAndServerStream[UniqueIOBuf, UniqueIOBuf] StreamResponse
76-
ctypedef cResponseAndSinkConsumer[UniqueIOBuf, UniqueIOBuf, UniqueIOBuf] SinkResponse
77-
7876
@cython.final
7977
cdef class ServerSink_IOBuf:
80-
cdef unique_ptr[cSinkConsumer[UniqueIOBuf, UniqueIOBuf]] _cSink
81-
8278
@staticmethod
8379
cdef _fbthrift_create(object sink_callback):
8480
cdef ServerSink_IOBuf inst = ServerSink_IOBuf.__new__(ServerSink_IOBuf)
@@ -88,8 +84,6 @@ cdef class ServerSink_IOBuf:
8884
return inst
8985

9086
cdef class ResponseAndSinkConsumer:
91-
cdef unique_ptr[SinkResponse] _cResponseSink
92-
9387
@staticmethod
9488
cdef _fbthrift_create(object val, object sink):
9589
cdef ResponseAndSinkConsumer inst = ResponseAndSinkConsumer.__new__(ResponseAndSinkConsumer)
@@ -103,8 +97,6 @@ cdef class ResponseAndSinkConsumer:
10397

10498

10599
cdef class Promise_Sink(Promise_Py):
106-
cdef cFollyPromise[SinkResponse]* _cPromise
107-
108100
def __cinit__(self):
109101
self._cPromise = new cFollyPromise[SinkResponse](cFollyPromise[SinkResponse].makeEmpty())
110102

@@ -129,8 +121,6 @@ cdef class Promise_Sink(Promise_Py):
129121
return inst
130122

131123
cdef class Promise_Stream(Promise_Py):
132-
cdef cFollyPromise[StreamResponse]* cPromise
133-
134124
def __cinit__(self):
135125
self.cPromise = new cFollyPromise[StreamResponse](cFollyPromise[StreamResponse].makeEmpty())
136126

@@ -154,8 +144,6 @@ cdef class Promise_Stream(Promise_Py):
154144

155145

156146
cdef class Promise_cFollyUnit(Promise_Py):
157-
cdef cFollyPromise[cFollyUnit]* cPromise
158-
159147
def __cinit__(self):
160148
self.cPromise = new cFollyPromise[cFollyUnit](cFollyPromise[cFollyUnit].makeEmpty())
161149

@@ -178,8 +166,6 @@ cdef class Promise_cFollyUnit(Promise_Py):
178166
return inst
179167

180168
cdef class ServerStream_IOBuf(ServerStream):
181-
cdef unique_ptr[cServerStream[UniqueIOBuf]] cStream
182-
183169
@staticmethod
184170
cdef _fbthrift_create(object stream):
185171
cdef ServerStream_IOBuf inst = ServerStream_IOBuf.__new__(ServerStream_IOBuf)
@@ -193,8 +179,6 @@ cdef class ServerStream_IOBuf(ServerStream):
193179
return inst
194180

195181
cdef class ResponseAndServerStream:
196-
cdef unique_ptr[StreamResponse] cResponseStream
197-
198182
@staticmethod
199183
cdef _fbthrift_create(object val, object stream):
200184
cdef ResponseAndServerStream inst = ResponseAndServerStream.__new__(ResponseAndServerStream)

thrift/lib/python/streaming/py_promise.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ cdef class Promise_IOBuf(Promise_Py):
4949

5050

5151
cdef void genNextStreamValue(object generator, cFollyPromise[optional[unique_ptr[cIOBuf]]] promise) noexcept
52-
cdef void genNextSinkValue(object generator, cFollyPromise[optional[unique_ptr[cIOBuf]]] promise) noexcept
52+
cdef api void genNextSinkValue(object generator, cFollyPromise[optional[unique_ptr[cIOBuf]]] promise) noexcept

thrift/lib/python/streaming/py_promise.pyx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,25 @@ import sys
1818

1919
from cpython cimport bool as pbool
2020
from cython.operator cimport dereference
21+
from libcpp.memory cimport unique_ptr
22+
from libcpp.optional cimport optional
2123
from libcpp.utility cimport move as cmove
2224

23-
from folly.iobuf cimport IOBuf
25+
from folly cimport cFollyPromise
26+
from folly.iobuf cimport (
27+
IOBuf,
28+
cIOBuf,
29+
)
2430

2531
from thrift.python.exceptions cimport (
2632
ApplicationError,
33+
cTApplicationException,
2734
cTApplicationExceptionType__UNKNOWN,
2835
)
29-
from thrift.python.streaming.python_user_exception cimport PythonUserException
36+
from thrift.python.streaming.python_user_exception cimport (
37+
PythonUserException,
38+
cPythonUserException,
39+
)
3040

3141

3242
cdef class Promise_Py:
@@ -146,7 +156,7 @@ cdef void genNextStreamValue(object generator, cFollyPromise[optional[unique_ptr
146156
)
147157
)
148158

149-
cdef void genNextSinkValue(object generator, cFollyPromise[optional[unique_ptr[cIOBuf]]] promise) noexcept:
159+
cdef api void genNextSinkValue(object generator, cFollyPromise[optional[unique_ptr[cIOBuf]]] promise) noexcept:
150160
cdef Promise_Optional_IOBuf __promise = Promise_Optional_IOBuf.create(cmove(promise))
151161
asyncio.get_event_loop().create_task(
152162
runGenerator(

thrift/lib/python/streaming/python_user_exception.pyx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from thrift.python.streaming.python_user_exception cimport cPythonUserException
16+
1517
from cython.operator cimport dereference as deref
16-
from libcpp.memory cimport make_unique
18+
from libcpp.memory cimport make_unique, unique_ptr
1719
from libcpp.string cimport string
1820
from libcpp.utility cimport move as cmove
1921

20-
from folly.iobuf cimport from_unique_ptr
22+
from folly cimport cFollyExceptionWrapper
23+
from folly.iobuf cimport IOBuf, cIOBuf, from_unique_ptr
2124

2225

2326
cdef class PythonUserException(Exception):

thrift/lib/python/streaming/sink.pxd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ cdef class ResponseAndBidirectionalStream:
129129
cdef class ResponseAndClientSink:
130130
pass
131131

132+
cdef class ServerSinkGenerator:
133+
cdef cIOBufSinkGenerator _cpp_gen
134+
cdef cFollyExecutor* _executor
135+
136+
@staticmethod
137+
cdef _fbthrift_create(
138+
cIOBufSinkGenerator cpp_gen,
139+
cFollyExecutor* executor,
140+
)
141+
132142
cdef api void cancelAsyncGenerator(object generator)
133143

134144
cdef api int invoke_server_sink_callback(

thrift/lib/python/streaming/sink.pyx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import traceback
1818

1919
from cython.operator import dereference
2020
from cpython.ref cimport PyObject
21-
from libcpp.memory cimport make_shared, make_unique, shared_ptr
21+
from libcpp.memory cimport make_shared, make_unique, shared_ptr, unique_ptr
2222
from libcpp.utility cimport move as cmove
2323

2424
from folly cimport cFollyPromise, cFollyTry
@@ -41,6 +41,7 @@ from thrift.python.mutable_serializer import (
4141
deserialize as deserialize_mutable,
4242
)
4343
from thrift.python.mutable_types import MutableStruct
44+
from thrift.python.protocol cimport Protocol
4445
from thrift.python.serializer import deserialize
4546
from thrift.python.streaming.py_promise cimport (
4647
genNextSinkValue,
@@ -51,10 +52,10 @@ from thrift.python.streaming.python_user_exception cimport (
5152
extractPyUserExceptionIOBuf,
5253
PythonUserException,
5354
)
55+
from thrift.python.streaming.sink cimport cIOBufClientSink, cIOBufSinkGenerator
5456
from thrift.python.streaming.stream cimport cIOBufClientBufferedStream
5557
from thrift.python.types import Struct
5658

57-
5859
cdef class ClientSink:
5960
@staticmethod
6061
cdef _fbthrift_create(
@@ -215,7 +216,7 @@ cdef raise_first_exception_field(response_struct):
215216
cdef void sink_final_resp_callback(
216217
cFollyTry[unique_ptr[cIOBuf]]&& res,
217218
PyObject* user_data,
218-
):
219+
) noexcept:
219220
future, final_resp_cls, sink_elem_cls, protocol = <object> user_data
220221
try:
221222
if res.hasException():
@@ -310,9 +311,6 @@ async def invokeCallbackWithGenerator(
310311

311312

312313
cdef class ServerSinkGenerator:
313-
cdef cIOBufSinkGenerator _cpp_gen
314-
cdef cFollyExecutor* _executor
315-
316314
@staticmethod
317315
cdef _fbthrift_create(
318316
cIOBufSinkGenerator cpp_gen,

thrift/lib/python/streaming/stream.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ from libcpp.utility cimport move as cmove
2222
from folly cimport cFollyTry
2323
from folly.coro cimport bridgeCoroTaskWith
2424
from folly.executor cimport get_executor
25-
from folly.iobuf cimport from_unique_ptr
25+
from folly.iobuf cimport cIOBuf, from_unique_ptr
2626
from folly.optional cimport cOptional
2727

2828
from thrift.python.exceptions cimport create_py_exception
29+
from thrift.python.protocol cimport Protocol
2930
from thrift.python.serializer import deserialize
3031

32+
from thrift.python.streaming.stream cimport cIOBufClientBufferedStream
33+
3134

3235
cdef void client_stream_callback(
3336
cFollyTry[cOptional[unique_ptr[cIOBuf]]]&& result,

0 commit comments

Comments
 (0)