Skip to content

Commit 65e965b

Browse files
committed
fixed err msg in PyUnicode_AsUnicodeEscapeString and PyUnicode_AsEncodedString
1 parent 8e1be30 commit 65e965b

File tree

2 files changed

+22
-33
lines changed

2 files changed

+22
-33
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ def _reference_compare(args):
114114

115115
def _reference_as_encoded_string(args):
116116
if not isinstance(args[0], str):
117-
if sys.version_info.minor >= 6:
118-
raise SystemError
119-
else:
120-
raise TypeError
117+
raise TypeError
121118

122119
s = args[0]
123120
encoding = args[1]
@@ -127,10 +124,7 @@ def _reference_as_encoded_string(args):
127124
_codecs_module = None
128125
def _reference_as_unicode_escape_string(args):
129126
if not isinstance(args[0], str):
130-
if sys.version_info.minor >= 6:
131-
raise SystemError
132-
else:
133-
raise TypeError
127+
raise TypeError
134128
global _codecs_module
135129
if not _codecs_module:
136130
import _codecs as _codecs_module

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

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import static com.oracle.graal.python.nodes.ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC_S;
4949
import static com.oracle.graal.python.nodes.ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P;
5050
import static com.oracle.graal.python.nodes.ErrorMessages.BASE_MUST_BE;
51+
import static com.oracle.graal.python.nodes.ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP;
5152
import static com.oracle.graal.python.nodes.ErrorMessages.CANNOT_CONVERT_P_OBJ_TO_S;
5253
import static com.oracle.graal.python.nodes.ErrorMessages.HASH_MISMATCH;
5354
import static com.oracle.graal.python.nodes.ErrorMessages.LIST_INDEX_OUT_OF_RANGE;
@@ -61,13 +62,11 @@
6162
import static com.oracle.graal.python.nodes.SpecialMethodNames.KEYS;
6263
import static com.oracle.graal.python.nodes.SpecialMethodNames.VALUES;
6364
import static com.oracle.graal.python.nodes.SpecialMethodNames.__FLOAT__;
64-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__ITER__;
65-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__NEW__;
6665
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETITEM__;
67-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__NEW__;
6866
import static com.oracle.graal.python.nodes.SpecialMethodNames.__IADD__;
69-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__ITER__;
7067
import static com.oracle.graal.python.nodes.SpecialMethodNames.__IMUL__;
68+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__ITER__;
69+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__NEW__;
7170
import static com.oracle.graal.python.nodes.SpecialMethodNames.__SETITEM__;
7271
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
7372
import static com.oracle.graal.python.util.PythonUtils.EMPTY_BYTE_ARRAY;
@@ -111,14 +110,12 @@
111110
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.TupleNode;
112111
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.ChrNode;
113112
import com.oracle.graal.python.builtins.modules.CodecsModuleBuiltins.CodecsEncodeNode;
114-
import com.oracle.graal.python.builtins.modules.CodecsModuleBuiltins.DecodeNode;
115113
import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.CreateFunctionNodeGen;
116114
import com.oracle.graal.python.builtins.modules.SysModuleBuiltins.InternNode;
117115
import com.oracle.graal.python.builtins.objects.PNone;
118116
import com.oracle.graal.python.builtins.objects.PNotImplemented;
119117
import com.oracle.graal.python.builtins.objects.bytes.BytesBuiltins;
120-
import com.oracle.graal.python.builtins.objects.bytes.BytesBuiltins.AddNode;
121-
import com.oracle.graal.python.builtins.objects.bytes.BytesBuiltins.JoinNode;
118+
import com.oracle.graal.python.builtins.objects.bytes.BytesBuiltins.DecodeNode;
122119
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
123120
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
124121
import com.oracle.graal.python.builtins.objects.bytes.PBytesLike;
@@ -1666,7 +1663,7 @@ public Object check(VirtualFrame frame, Object obj,
16661663
public abstract static class PyBytesConcatNode extends PythonBinaryBuiltinNode {
16671664
@Specialization
16681665
public Object concat(VirtualFrame frame, PBytes original, Object newPart,
1669-
@Cached AddNode addNode,
1666+
@Cached BytesBuiltins.AddNode addNode,
16701667
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
16711668
@Cached GetNativeNullNode getNativeNullNode) {
16721669
try {
@@ -1706,7 +1703,7 @@ protected boolean isBytesSubtype(VirtualFrame frame, Object obj, GetClassNode ge
17061703
public abstract static class PyBytesJoinNode extends PythonBinaryBuiltinNode {
17071704
@Specialization
17081705
public Object join(VirtualFrame frame, PBytes original, Object newPart,
1709-
@Cached JoinNode joinNode,
1706+
@Cached BytesBuiltins.JoinNode joinNode,
17101707
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
17111708
@Cached GetNativeNullNode getNativeNullNode) {
17121709
try {
@@ -2902,7 +2899,7 @@ abstract static class PySequenceConcatNode extends PythonBinaryBuiltinNode {
29022899
@Specialization(guards = {"checkNode.execute(s1)", "checkNode.execute(s1)"})
29032900
Object concat(VirtualFrame frame, Object s1, Object s2,
29042901
@SuppressWarnings("unused") @Cached PySequenceCheckNode checkNode,
2905-
@Cached("createAdd()") com.oracle.graal.python.nodes.expression.BinaryArithmetic.AddNode addNode,
2902+
@Cached("createAdd()") BinaryArithmetic.AddNode addNode,
29062903
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
29072904
@Cached GetNativeNullNode getNativeNullNode) {
29082905
try {
@@ -2921,8 +2918,8 @@ protected Object cantConcat(VirtualFrame frame, Object s1, @SuppressWarnings("un
29212918
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), TypeError, ErrorMessages.OBJ_CANT_BE_CONCATENATED, s1);
29222919
}
29232920

2924-
protected com.oracle.graal.python.nodes.expression.BinaryArithmetic.AddNode createAdd() {
2925-
return (com.oracle.graal.python.nodes.expression.BinaryArithmetic.AddNode) BinaryArithmetic.Add.create();
2921+
protected BinaryArithmetic.AddNode createAdd() {
2922+
return (BinaryArithmetic.AddNode) BinaryArithmetic.Add.create();
29262923
}
29272924
}
29282925

@@ -2934,7 +2931,7 @@ abstract static class PySequenceInPlaceConcatNode extends PythonBinaryBuiltinNod
29342931
Object concat(VirtualFrame frame, Object s1, Object s2,
29352932
@Cached PyObjectLookupAttr lookupNode,
29362933
@Cached CallNode callNode,
2937-
@Cached("createAdd()") com.oracle.graal.python.nodes.expression.BinaryArithmetic.AddNode addNode,
2934+
@Cached("createAdd()") BinaryArithmetic.AddNode addNode,
29382935
@SuppressWarnings("unused") @Cached PySequenceCheckNode checkNode,
29392936
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
29402937
@Cached GetNativeNullNode getNativeNullNode) {
@@ -2958,8 +2955,8 @@ protected Object concat(VirtualFrame frame, Object s1, @SuppressWarnings("unused
29582955
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), TypeError, ErrorMessages.OBJ_CANT_BE_CONCATENATED, s1);
29592956
}
29602957

2961-
protected com.oracle.graal.python.nodes.expression.BinaryArithmetic.AddNode createAdd() {
2962-
return (com.oracle.graal.python.nodes.expression.BinaryArithmetic.AddNode) BinaryArithmetic.Add.create();
2958+
protected BinaryArithmetic.AddNode createAdd() {
2959+
return (BinaryArithmetic.AddNode) BinaryArithmetic.Add.create();
29632960
}
29642961
}
29652962

@@ -3087,7 +3084,7 @@ public abstract static class PyUnicodeConcatNode extends PythonBinaryBuiltinNode
30873084

30883085
@Specialization(guards = {"isString(left) || isStringSubtype(frame, left, getClassNode, isSubtypeNode)", "isString(right) || isStringSubtype(frame, right, getClassNode, isSubtypeNode)"})
30893086
public Object concat(VirtualFrame frame, Object left, Object right,
3090-
@Cached com.oracle.graal.python.builtins.objects.str.StringBuiltins.AddNode addNode,
3087+
@Cached StringBuiltins.AddNode addNode,
30913088
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
30923089
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
30933090
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
@@ -3321,7 +3318,7 @@ protected boolean isStringSubtype(VirtualFrame frame, Object obj, GetClassNode g
33213318
public abstract static class PyUnicodeJoinNode extends PythonBinaryBuiltinNode {
33223319
@Specialization(guards = {"isString(separator) || isStringSubtype(frame, separator, getClassNode, isSubtypeNode)"})
33233320
public Object find(VirtualFrame frame, Object separator, Object seq,
3324-
@Cached com.oracle.graal.python.builtins.objects.str.StringBuiltins.JoinNode joinNode,
3321+
@Cached StringBuiltins.JoinNode joinNode,
33253322
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
33263323
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
33273324
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
@@ -3389,7 +3386,7 @@ private static boolean isStringSubtype(VirtualFrame frame, Object obj, GetClassN
33893386
@GenerateNodeFactory
33903387
public abstract static class PyUnicodeTailmatchNode extends PythonBuiltinNode {
33913388
@Specialization(guards = {"isAnyString(frame, string, getClassNode, isSubtypeNode)", "isAnyString(frame, substring, getClassNode, isSubtypeNode)", "direction > 0"})
3392-
public Object tailmatch(VirtualFrame frame, Object string, Object substring, long start, long end, @SuppressWarnings("unused") long direction,
3389+
public int tailmatch(VirtualFrame frame, Object string, Object substring, long start, long end, @SuppressWarnings("unused") long direction,
33933390
@Cached PyObjectLookupAttr lookupAttrNode,
33943391
@Cached SliceLiteralNode sliceNode,
33953392
@Cached CallNode callNode,
@@ -3408,7 +3405,7 @@ public Object tailmatch(VirtualFrame frame, Object string, Object substring, lon
34083405
}
34093406

34103407
@Specialization(guards = {"isAnyString(frame, string, getClassNode, isSubtypeNode)", "isAnyString(frame, substring, getClassNode, isSubtypeNode)", "direction <= 0"})
3411-
public Object tailmatch(VirtualFrame frame, Object string, Object substring, long start, long end, @SuppressWarnings("unused") long direction,
3408+
public int tailmatch(VirtualFrame frame, Object string, Object substring, long start, long end, @SuppressWarnings("unused") long direction,
34123409
@Cached PyObjectLookupAttr lookupAttrNode,
34133410
@Cached SliceLiteralNode sliceNode,
34143411
@Cached CallNode callNode,
@@ -3462,13 +3459,12 @@ public Object encode(VirtualFrame frame, Object obj, String encoding, String err
34623459
}
34633460

34643461
@Specialization(guards = {"!isString(obj)", "!isStringSubtype(frame, obj, getClassNode, isSubtypeNode)"})
3465-
public Object encode(VirtualFrame frame, Object obj, @SuppressWarnings("unused") String encoding, @SuppressWarnings("unused") String errors,
3466-
@Cached StrNode strNode,
3462+
public Object encode(VirtualFrame frame, @SuppressWarnings("unused") Object obj, @SuppressWarnings("unused") String encoding, @SuppressWarnings("unused") String errors,
34673463
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
34683464
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
34693465
@Cached PRaiseNativeNode raiseNativeNode,
34703466
@Cached GetNativeNullNode getNativeNullNode) {
3471-
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(frame, obj), obj);
3467+
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), TypeError, BAD_ARG_TYPE_FOR_BUILTIN_OP);
34723468
}
34733469

34743470
protected static boolean isStringSubtype(VirtualFrame frame, Object obj, GetClassNode getClassNode, IsSubtypeNode isSubtypeNode) {
@@ -3553,13 +3549,12 @@ public Object escape(VirtualFrame frame, Object s,
35533549
}
35543550

35553551
@Specialization(guards = {"!isString(obj)", "!isStringSubtype(frame, obj, getClassNode, isSubtypeNode)"})
3556-
public Object escape(VirtualFrame frame, Object obj,
3552+
public Object escape(VirtualFrame frame, @SuppressWarnings("unused") Object obj,
35573553
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
35583554
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
3559-
@Cached StrNode strNode,
35603555
@Cached PRaiseNativeNode raiseNativeNode,
35613556
@Cached GetNativeNullNode getNativeNullNode) {
3562-
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(frame, obj), obj);
3557+
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), TypeError, BAD_ARG_TYPE_FOR_BUILTIN_OP);
35633558
}
35643559

35653560
protected static boolean isStringSubtype(VirtualFrame frame, Object obj, GetClassNode getClassNode, IsSubtypeNode isSubtypeNode) {

0 commit comments

Comments
 (0)