Skip to content

Commit acb6d44

Browse files
committed
return type err from PyUnicode_Tailmatch if arg not string
1 parent 65e965b commit acb6d44

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ def _reference_as_unicode_escape_string(args):
132132

133133
def _reference_tailmatch(args):
134134
if not isinstance(args[0], str) or not isinstance(args[1], str):
135-
return -1;
135+
if sys.version_info.minor >= 6:
136+
raise SystemError
137+
else:
138+
raise TypeError
136139

137140
s = args[0]
138141
substr = args[1]
@@ -580,7 +583,7 @@ def compile_module(self, name):
580583
("abc", 1, 1, 0, 1),
581584
),
582585
resultspec="i",
583-
argspec='OOiii',
586+
argspec='OOnni',
584587
arguments=["PyObject* left", "PyObject* right", "Py_ssize_t start", "Py_ssize_t end", "int direction"],
585588
cmpfunc=unhandled_error_compare
586589
)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PythonCextBuiltins.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3427,8 +3427,9 @@ public int tailmatch(VirtualFrame frame, Object string, Object substring, long s
34273427
@Specialization(guards = {"!isAnyString(frame, string, getClassNode, isSubtypeNode) || !isAnyString(frame, substring, getClassNode, isSubtypeNode)"})
34283428
public Object find(VirtualFrame frame, Object string, Object substring, Object start, Object end, Object direction,
34293429
@Cached GetClassNode getClassNode,
3430-
@Cached IsSubtypeNode isSubtypeNode) {
3431-
return -1;
3430+
@Cached IsSubtypeNode isSubtypeNode,
3431+
@Cached PRaiseNativeNode raiseNativeNode) {
3432+
return raiseNativeNode.raiseInt(frame, -1, TypeError, ErrorMessages.MUST_BE_STR_NOT_P, string);
34323433
}
34333434

34343435
protected boolean isAnyString(VirtualFrame frame, Object obj, GetClassNode getClassNode, IsSubtypeNode isSubtypeNode) {

0 commit comments

Comments
 (0)