Skip to content

Commit 089f31d

Browse files
committed
Upgrade to Cython 0.28.2
Start using the new @cython.iterable_coroutine decorator. This allows us to stop patching the generated C code to get compatibility with generator-based coroutines.
1 parent fca41a6 commit 089f31d

File tree

3 files changed

+12
-72
lines changed

3 files changed

+12
-72
lines changed

asyncpg/protocol/protocol.pyx

+11
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ cdef class BaseProtocol(CoreProtocol):
147147
self.is_reading = False
148148
self.transport.pause_reading()
149149

150+
@cython.iterable_coroutine
150151
async def prepare(self, stmt_name, query, timeout,
151152
PreparedStatementState state=None):
152153
if self.cancel_waiter is not None:
@@ -171,6 +172,7 @@ cdef class BaseProtocol(CoreProtocol):
171172
finally:
172173
return await waiter
173174

175+
@cython.iterable_coroutine
174176
async def bind_execute(self, PreparedStatementState state, args,
175177
str portal_name, int limit, return_extra,
176178
timeout):
@@ -203,6 +205,7 @@ cdef class BaseProtocol(CoreProtocol):
203205
finally:
204206
return await waiter
205207

208+
@cython.iterable_coroutine
206209
async def bind_execute_many(self, PreparedStatementState state, args,
207210
str portal_name, timeout):
208211

@@ -238,6 +241,7 @@ cdef class BaseProtocol(CoreProtocol):
238241
finally:
239242
return await waiter
240243

244+
@cython.iterable_coroutine
241245
async def bind(self, PreparedStatementState state, args,
242246
str portal_name, timeout):
243247

@@ -266,6 +270,7 @@ cdef class BaseProtocol(CoreProtocol):
266270
finally:
267271
return await waiter
268272

273+
@cython.iterable_coroutine
269274
async def execute(self, PreparedStatementState state,
270275
str portal_name, int limit, return_extra,
271276
timeout):
@@ -295,6 +300,7 @@ cdef class BaseProtocol(CoreProtocol):
295300
finally:
296301
return await waiter
297302

303+
@cython.iterable_coroutine
298304
async def query(self, query, timeout):
299305
if self.cancel_waiter is not None:
300306
await self.cancel_waiter
@@ -319,6 +325,7 @@ cdef class BaseProtocol(CoreProtocol):
319325
finally:
320326
return await waiter
321327

328+
@cython.iterable_coroutine
322329
async def copy_out(self, copy_stmt, sink, timeout):
323330
if self.cancel_waiter is not None:
324331
await self.cancel_waiter
@@ -373,6 +380,7 @@ cdef class BaseProtocol(CoreProtocol):
373380

374381
return status_msg
375382

383+
@cython.iterable_coroutine
376384
async def copy_in(self, copy_stmt, reader, data,
377385
records, PreparedStatementState record_stmt, timeout):
378386
cdef:
@@ -491,6 +499,7 @@ cdef class BaseProtocol(CoreProtocol):
491499

492500
return status_msg
493501

502+
@cython.iterable_coroutine
494503
async def close_statement(self, PreparedStatementState state, timeout):
495504
if self.cancel_waiter is not None:
496505
await self.cancel_waiter
@@ -530,6 +539,7 @@ cdef class BaseProtocol(CoreProtocol):
530539
self._terminate()
531540
self.transport.abort()
532541

542+
@cython.iterable_coroutine
533543
async def close(self, timeout):
534544
if self.closing:
535545
return
@@ -651,6 +661,7 @@ cdef class BaseProtocol(CoreProtocol):
651661
self.cancel_sent_waiter is not None
652662
)
653663

664+
@cython.iterable_coroutine
654665
async def _wait_for_cancellation(self):
655666
if self.cancel_sent_waiter is not None:
656667
await self.cancel_sent_waiter

requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Cython>=0.25.2
1+
Cython>=0.28.2
22
flake8>=3.4.1
33
pytest>=3.0.7
44
uvloop>=0.8.0

setup.py

-71
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import os
99
import os.path
1010
import platform
11-
import re
1211
import sys
1312

1413
import setuptools
@@ -101,78 +100,8 @@ def finalize_options(self):
101100
compiler_directives=directives,
102101
annotate=self.cython_annotate)
103102

104-
for cfile, timestamp in cfiles.items():
105-
if os.path.getmtime(cfile) != timestamp:
106-
# The file was recompiled, patch
107-
self._patch_cfile(cfile)
108-
109103
super(build_ext, self).finalize_options()
110104

111-
def _patch_cfile(self, cfile):
112-
# Script to patch Cython 'async def' coroutines to have a 'tp_iter'
113-
# slot, which makes them compatible with 'yield from' without the
114-
# `asyncio.coroutine` decorator.
115-
116-
with open(cfile, 'rt') as f:
117-
src = f.read()
118-
119-
src = re.sub(
120-
r'''
121-
\s* offsetof\(__pyx_CoroutineObject,\s*gi_weakreflist\),
122-
\s* 0,
123-
\s* 0,
124-
\s* __pyx_Coroutine_methods,
125-
\s* __pyx_Coroutine_memberlist,
126-
\s* __pyx_Coroutine_getsets,
127-
''',
128-
129-
r'''
130-
offsetof(__pyx_CoroutineObject, gi_weakreflist),
131-
__Pyx_Coroutine_await, /* tp_iter */
132-
(iternextfunc) __Pyx_Generator_Next, /* tp_iternext */
133-
__pyx_Coroutine_methods,
134-
__pyx_Coroutine_memberlist,
135-
__pyx_Coroutine_getsets,
136-
''',
137-
138-
src, flags=re.X)
139-
140-
# Fix a segfault in Cython.
141-
src = re.sub(
142-
r'''
143-
\s* __Pyx_Coroutine_get_qualname\(__pyx_CoroutineObject\s+\*self\)
144-
\s* {
145-
\s* Py_INCREF\(self->gi_qualname\);
146-
''',
147-
148-
r'''
149-
__Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self)
150-
{
151-
if (self->gi_qualname == NULL) { return __pyx_empty_unicode; }
152-
Py_INCREF(self->gi_qualname);
153-
''',
154-
155-
src, flags=re.X)
156-
157-
src = re.sub(
158-
r'''
159-
\s* __Pyx_Coroutine_get_name\(__pyx_CoroutineObject\s+\*self\)
160-
\s* {
161-
\s* Py_INCREF\(self->gi_name\);
162-
''',
163-
164-
r'''
165-
__Pyx_Coroutine_get_name(__pyx_CoroutineObject *self)
166-
{
167-
if (self->gi_name == NULL) { return __pyx_empty_unicode; }
168-
Py_INCREF(self->gi_name);
169-
''',
170-
171-
src, flags=re.X)
172-
173-
with open(cfile, 'wt') as f:
174-
f.write(src)
175-
176105

177106
with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as f:
178107
readme = f.read()

0 commit comments

Comments
 (0)