Skip to content

Commit f714188

Browse files
committed
intrinsified python_cext PySequence_XXX
1 parent 8f3669f commit f714188

File tree

8 files changed

+365
-71
lines changed

8 files changed

+365
-71
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ PyObject* PySequence_Concat(PyObject *s, PyObject *o) {
549549

550550
UPCALL_ID(PySequence_InPlaceRepeat);
551551
PyObject* PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count) {
552-
return UPCALL_CEXT_O(_jls_PySequence_Repeat, native_to_java(o), count);
552+
return UPCALL_CEXT_O(_jls_PySequence_InPlaceRepeat, native_to_java(o), count);
553553
}
554554

555555
UPCALL_ID(PySequence_InPlaceConcat);

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_abstract.py

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ def _reference_fast(args):
139139
return obj
140140
return list(obj)
141141

142+
def _wrap_slice_fun(fun, since=0, default=None):
143+
def wrapped_fun(args):
144+
if not isinstance(args[0], list) and not isinstance(args[0], set) and not isinstance(args[0], tuple) and not isinstance(args[0], str):
145+
if sys.version_info.minor >= since:
146+
raise SystemError("expected list type")
147+
else:
148+
return default
149+
return fun(args)
150+
return wrapped_fun
142151

143152
class NoNumber():
144153
pass
@@ -733,6 +742,7 @@ def compile_module(self, name):
733742
({'a':0, 'b':1},),
734743
(DummySequence(),),
735744
(DummyListSubclass(),),
745+
('hello',),
736746
),
737747
resultspec="i",
738748
argspec='O',
@@ -750,6 +760,7 @@ def compile_module(self, name):
750760
([None],),
751761
(set(),),
752762
(DummyListSubclass(),),
763+
('hello',),
753764
),
754765
resultspec="n",
755766
argspec='O',
@@ -772,13 +783,58 @@ def compile_module(self, name):
772783
(set(), 0),
773784
({'a', 'b'}, 0),
774785
(DummyListSubclass(), 1),
786+
('hello', 1),
775787
),
776788
resultspec="O",
777789
argspec='On',
778790
arguments=["PyObject* sequence", "Py_ssize_t idx"],
779791
cmpfunc=unhandled_error_compare
780792
)
781-
793+
794+
test_PySequence_GetSlice = CPyExtFunction(
795+
_wrap_slice_fun(lambda args: args[0][args[1]:args[2]]),
796+
lambda: (
797+
(tuple(), 0, 1),
798+
((1, 2, 3), 1, 2),
799+
((None,), 1, 2),
800+
([], 0, 1),
801+
(['a', 'b', 'c'], 1, 2),
802+
([None], 0, 1),
803+
(set(), 0, 1),
804+
({'a', 'b'}, 1, 2),
805+
(DummyListSubclass(), 0, 1),
806+
('hello', 0, 1),
807+
),
808+
resultspec="O",
809+
argspec='Onn',
810+
arguments=["PyObject* sequence", "Py_ssize_t ilow", "Py_ssize_t ihigh"],
811+
cmpfunc=unhandled_error_compare
812+
)
813+
814+
test_PySequence_Contains = CPyExtFunction(
815+
lambda args: args[1] in args[0],
816+
lambda: (
817+
(tuple(), 1),
818+
((1, 2, 3), 1),
819+
((1, 2, 3), 4),
820+
((None,), 1),
821+
([], 1),
822+
(['a', 'b', 'c'], 'a'),
823+
(['a', 'b', 'c'], 'd'),
824+
([None], 1),
825+
(set(), 1),
826+
({'a', 'b'}, 'a'),
827+
({'a', 'b'}, 'c'),
828+
(DummyListSubclass(), 1),
829+
('hello', 'e'),
830+
('hello', 'x'),
831+
),
832+
resultspec="i",
833+
argspec='OO',
834+
arguments=["PyObject* haystack", "PyObject* needle"],
835+
cmpfunc=unhandled_error_compare
836+
)
837+
782838
test_PySequence_ITEM = CPyExtFunction(
783839
_reference_getitem,
784840
lambda: (
@@ -788,6 +844,7 @@ def compile_module(self, name):
788844
([], 10),
789845
(['a', 'b', 'c'], 2),
790846
([None], 0),
847+
('hello', 0),
791848
),
792849
resultspec="O",
793850
argspec='On',
@@ -803,6 +860,7 @@ def compile_module(self, name):
803860
((None,), 1, None),
804861
([], 10, 1),
805862
(['a', 'b', 'c'], 2, 'z'),
863+
('hello', 2, 'z'),
806864
),
807865
code=''' PyObject* wrap_PySequence_SetItem(PyObject* sequence, Py_ssize_t idx, PyObject* value) {
808866
if (PySequence_SetItem(sequence, idx, value) < 0) {
@@ -830,6 +888,27 @@ def compile_module(self, name):
830888
({'a': 0, 'b': 1, 'c': 2},),
831889
(None,),
832890
(0,),
891+
('hello',),
892+
),
893+
resultspec="O",
894+
argspec='O',
895+
arguments=["PyObject* sequence"],
896+
cmpfunc=unhandled_error_compare
897+
)
898+
899+
test_PySequence_List = CPyExtFunction(
900+
lambda args: list(args[0]),
901+
lambda: (
902+
(list(),),
903+
((1, 2, 3),),
904+
((None,),),
905+
([],),
906+
(['a', 'b', 'c'],),
907+
({'a', 'b', 'c'},),
908+
({'a': 0, 'b': 1, 'c': 2},),
909+
(None,),
910+
(0,),
911+
('hello',),
833912
),
834913
resultspec="O",
835914
argspec='O',

0 commit comments

Comments
 (0)