Skip to content

Commit df240db

Browse files
committed
Improve implementation of 'PySequence_Fast'.
1 parent 5330dae commit df240db

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

graalpython/com.oracle.graal.python.cext/src/abstract.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,26 @@ PyObject* PySequence_Tuple(PyObject *v) {
256256
return UPCALL_CEXT_O(_jls_PySequence_Tuple, native_to_java(v));
257257
}
258258

259-
UPCALL_ID(PySequence_Fast);
259+
UPCALL_ID(PySequence_List);
260+
PyObject* PySequence_List(PyObject *v) {
261+
return UPCALL_CEXT_O(_jls_PySequence_List, native_to_java(v));
262+
}
263+
260264
PyObject * PySequence_Fast(PyObject *v, const char *m) {
261-
return UPCALL_CEXT_O(_jls_PySequence_Fast, native_to_java(v), polyglot_from_string(m, SRC_CS));
265+
if (v == NULL) {
266+
return null_error();
267+
}
268+
269+
if (PyList_CheckExact(v) || PyTuple_CheckExact(v)) {
270+
Py_INCREF(v);
271+
return v;
272+
}
273+
274+
PyObject* result = UPCALL_CEXT_O(_jls_PySequence_List, native_to_java(v));
275+
if (result == NULL) {
276+
PyErr_SetString(PyExc_TypeError, m);
277+
}
278+
return result;
262279
}
263280

264281
UPCALL_ID(PyObject_GetItem);

graalpython/lib-graalpython/python_cext.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,8 @@ def PySequence_Tuple(obj):
517517

518518

519519
@may_raise
520-
def PySequence_Fast(obj, msg):
521-
if isinstance(obj, tuple) or isinstance(obj, list):
522-
return obj
523-
try:
524-
return list(obj)
525-
except TypeError:
526-
raise TypeError(msg)
520+
def PySequence_List(obj):
521+
return list(obj)
527522

528523

529524
def PySequence_Check(obj):

0 commit comments

Comments
 (0)