Skip to content

Commit 8b5b0c2

Browse files
committed
Don't reference cython genexp from core modules
Fixes a not-well-understood issue that would cause segfualts when building with Cython < 0.22
1 parent 03781ec commit 8b5b0c2

3 files changed

Lines changed: 8 additions & 13 deletions

File tree

cassandra/cluster.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from __future__ import absolute_import
2020

2121
import atexit
22-
from collections import defaultdict
22+
from collections import defaultdict, Mapping
2323
from concurrent.futures import ThreadPoolExecutor
2424
import logging
2525
from random import random
@@ -61,7 +61,7 @@
6161
BatchMessage, RESULT_KIND_PREPARED,
6262
RESULT_KIND_SET_KEYSPACE, RESULT_KIND_ROWS,
6363
RESULT_KIND_SCHEMA_CHANGE, MIN_SUPPORTED_VERSION,
64-
ProtocolHandler, _RESULT_SEQUENCE_TYPES)
64+
ProtocolHandler)
6565
from cassandra.metadata import Metadata, protect_name, murmur3
6666
from cassandra.policies import (TokenAwarePolicy, DCAwareRoundRobinPolicy, SimpleConvictionPolicy,
6767
ExponentialReconnectionPolicy, HostDistance,
@@ -3348,9 +3348,13 @@ def fetch_next_page(self):
33483348
self._current_rows = []
33493349

33503350
def _set_current_rows(self, result):
3351-
if isinstance(result, _RESULT_SEQUENCE_TYPES):
3351+
if isinstance(result, Mapping):
3352+
self._current_rows = [result] if result else []
3353+
return
3354+
try:
3355+
iter(result) # can't check directly for generator types because cython generators are different
33523356
self._current_rows = result
3353-
else:
3357+
except TypeError:
33543358
self._current_rows = [result] if result else []
33553359

33563360
def _fetch_all(self):

cassandra/obj_parser.pyx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,13 @@ cdef class LazyParser(ColumnParser):
3838
# supported in cpdef methods
3939
return parse_rows_lazy(reader, desc)
4040

41-
cpdef get_cython_generator_type(self):
42-
return get_cython_generator_type()
4341

4442
def parse_rows_lazy(BytesIOReader reader, ParseDesc desc):
4543
cdef Py_ssize_t i, rowcount
4644
rowcount = read_int(reader)
4745
cdef RowParser rowparser = TupleRowParser()
4846
return (rowparser.unpack_row(reader, desc) for i in range(rowcount))
4947

50-
def get_cython_generator_type():
51-
return type((i for i in range(0)))
5248

5349
cdef class TupleRowParser(RowParser):
5450
"""

cassandra/protocol.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,8 +1000,6 @@ def decode_message(cls, protocol_version, user_type_map, stream_id, flags, opcod
10001000

10011001
return msg
10021002

1003-
_RESULT_SEQUENCE_TYPES = (list, tuple) # types retuned by ResultMessages
1004-
10051003
def cython_protocol_handler(colparser):
10061004
"""
10071005
Given a column parser to deserialize ResultMessages, return a suitable
@@ -1046,9 +1044,6 @@ class CythonProtocolHandler(ProtocolHandler):
10461044
if HAVE_CYTHON:
10471045
from cassandra.obj_parser import ListParser, LazyParser
10481046
ProtocolHandler = cython_protocol_handler(ListParser())
1049-
1050-
lazy_parser = LazyParser()
1051-
_RESULT_SEQUENCE_TYPES += (lazy_parser.get_cython_generator_type(),)
10521047
LazyProtocolHandler = cython_protocol_handler(LazyParser())
10531048
else:
10541049
# Use Python-based ProtocolHandler

0 commit comments

Comments
 (0)