Skip to content

Commit b2d07c6

Browse files
committed
get rid of PythonArithmeticTypes string downcasts in cext builtins
1 parent 9322572 commit b2d07c6

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

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

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import java.util.logging.Level;
6868

6969
import com.oracle.graal.python.PythonLanguage;
70+
import com.oracle.graal.python.annotations.ArgumentClinic;
7071
import com.oracle.graal.python.builtins.Builtin;
7172
import com.oracle.graal.python.builtins.CoreFunctions;
7273
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -91,7 +92,6 @@
9192
import com.oracle.graal.python.builtins.modules.ExternalFunctionNodes.SetAttrFuncRootNode;
9293
import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.CheckInquiryResultNodeGen;
9394
import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.CheckIterNextResultNodeGen;
94-
import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.CreateFunctionNodeFactory;
9595
import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.DefaultCheckFunctionResultNodeGen;
9696
import com.oracle.graal.python.builtins.objects.PNone;
9797
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
@@ -233,11 +233,12 @@
233233
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
234234
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
235235
import com.oracle.graal.python.nodes.function.builtins.PythonQuaternaryBuiltinNode;
236+
import com.oracle.graal.python.nodes.function.builtins.PythonQuaternaryClinicBuiltinNode;
236237
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
237238
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
238239
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
240+
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
239241
import com.oracle.graal.python.nodes.object.GetClassNode;
240-
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
241242
import com.oracle.graal.python.nodes.truffle.PythonTypes;
242243
import com.oracle.graal.python.nodes.util.CannotCastException;
243244
import com.oracle.graal.python.nodes.util.CastToByteNode;
@@ -412,7 +413,6 @@ Object run(Object obj,
412413

413414
@Builtin(name = "PyTruffle_Type", minNumOfPositionalArgs = 1)
414415
@GenerateNodeFactory
415-
@TypeSystemReference(PythonArithmeticTypes.class)
416416
abstract static class PyTruffle_Type extends NativeBuiltin {
417417

418418
private static final String[] LOOKUP_MODULES = new String[]{
@@ -423,7 +423,8 @@ abstract static class PyTruffle_Type extends NativeBuiltin {
423423

424424
@Specialization
425425
@TruffleBoundary
426-
Object doI(String typeName) {
426+
Object doI(Object typeNameObject) {
427+
String typeName = CastToJavaStringNode.getUncached().execute(typeNameObject);
427428
PythonCore core = getCore();
428429
for (PythonBuiltinClassType type : PythonBuiltinClassType.VALUES) {
429430
if (type.getName().equals(typeName)) {
@@ -499,7 +500,6 @@ protected static SequenceStorageNodes.SetItemNode createSetItem() {
499500

500501
@Builtin(name = "CreateBuiltinMethod", minNumOfPositionalArgs = 2)
501502
@GenerateNodeFactory
502-
@TypeSystemReference(PythonArithmeticTypes.class)
503503
abstract static class CreateBuiltinMethodNode extends PythonBuiltinNode {
504504
@Specialization
505505
@TruffleBoundary
@@ -508,10 +508,14 @@ Object runWithoutCWrapper(PBuiltinFunction descriptor, Object self) {
508508
}
509509
}
510510

511-
@Builtin(name = "CreateFunction", minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 4)
511+
@Builtin(name = "CreateFunction", minNumOfPositionalArgs = 2, parameterNames = {"name", "callable", "wrapper", "type"})
512+
@ArgumentClinic(name = "name", conversion = ArgumentClinic.ClinicConversion.String)
512513
@GenerateNodeFactory
513-
@TypeSystemReference(PythonArithmeticTypes.class)
514-
abstract static class CreateFunctionNode extends PythonBuiltinNode {
514+
abstract static class CreateFunctionNode extends PythonQuaternaryClinicBuiltinNode {
515+
@Override
516+
protected ArgumentClinicProvider getArgumentClinic() {
517+
return PythonCextBuiltinsClinicProviders.CreateFunctionNodeClinicProviderGen.INSTANCE;
518+
}
515519

516520
abstract Object execute(String name, Object callable, Object wrapper, Object type);
517521

@@ -612,11 +616,6 @@ static boolean isNativeWrapper(Object obj) {
612616
static boolean isDecoratedManagedFunction(Object obj) {
613617
return obj instanceof PyCFunctionDecorator && CApiGuards.isNativeWrapper(((PyCFunctionDecorator) obj).getNativeFunction());
614618
}
615-
616-
public static CreateFunctionNode create() {
617-
return CreateFunctionNodeFactory.create(null);
618-
}
619-
620619
}
621620

622621
@Builtin(name = "PyErr_Restore", minNumOfPositionalArgs = 3)
@@ -1419,24 +1418,25 @@ private String decodeUTF32(byte[] data, int size, String errors, int byteorder)
14191418

14201419
@Builtin(name = "PyTruffle_Unicode_AsWideChar", minNumOfPositionalArgs = 4)
14211420
@GenerateNodeFactory
1422-
@TypeSystemReference(PythonArithmeticTypes.class)
14231421
abstract static class PyTruffle_Unicode_AsWideChar extends NativeUnicodeBuiltin {
14241422
@Child private UnicodeAsWideCharNode asWideCharNode;
14251423

14261424
@Specialization
1427-
Object doUnicode(VirtualFrame frame, String s, long elementSize, @SuppressWarnings("unused") PNone elements, Object errorMarker) {
1428-
return doUnicode(frame, s, elementSize, -1, errorMarker);
1425+
Object doUnicode(VirtualFrame frame, Object s, long elementSize, @SuppressWarnings("unused") PNone elements, Object errorMarker,
1426+
@Shared("castStr") @Cached CastToJavaStringNode castStr) {
1427+
return doUnicode(frame, s, elementSize, -1, errorMarker, castStr);
14291428
}
14301429

14311430
@Specialization
1432-
Object doUnicode(VirtualFrame frame, String s, long elementSize, long elements, Object errorMarker) {
1431+
Object doUnicode(VirtualFrame frame, Object s, long elementSize, long elements, Object errorMarker,
1432+
@Shared("castStr") @Cached CastToJavaStringNode castStr) {
14331433
try {
14341434
if (asWideCharNode == null) {
14351435
CompilerDirectives.transferToInterpreterAndInvalidate();
14361436
asWideCharNode = insert(UnicodeAsWideCharNodeGen.create());
14371437
}
14381438

1439-
PBytes wchars = asWideCharNode.executeLittleEndian(s, elementSize, elements);
1439+
PBytes wchars = asWideCharNode.executeLittleEndian(castStr.execute(s), elementSize, elements);
14401440
if (wchars != null) {
14411441
return wchars;
14421442
} else {
@@ -1449,18 +1449,20 @@ Object doUnicode(VirtualFrame frame, String s, long elementSize, long elements,
14491449
}
14501450

14511451
@Specialization
1452-
Object doUnicode(VirtualFrame frame, String s, PInt elementSize, @SuppressWarnings("unused") PNone elements, Object errorMarker) {
1452+
Object doUnicode(VirtualFrame frame, String s, PInt elementSize, @SuppressWarnings("unused") PNone elements, Object errorMarker,
1453+
@Shared("castStr") @Cached CastToJavaStringNode castStr) {
14531454
try {
1454-
return doUnicode(frame, s, elementSize.longValueExact(), -1, errorMarker);
1455+
return doUnicode(frame, s, elementSize.longValueExact(), -1, errorMarker, castStr);
14551456
} catch (OverflowException e) {
14561457
return raiseNative(frame, errorMarker, PythonErrorType.ValueError, ErrorMessages.INVALID_PARAMS);
14571458
}
14581459
}
14591460

14601461
@Specialization
1461-
Object doUnicode(VirtualFrame frame, String s, PInt elementSize, PInt elements, Object errorMarker) {
1462+
Object doUnicode(VirtualFrame frame, String s, PInt elementSize, PInt elements, Object errorMarker,
1463+
@Shared("castStr") @Cached CastToJavaStringNode castStr) {
14621464
try {
1463-
return doUnicode(frame, s, elementSize.longValueExact(), elements.longValueExact(), errorMarker);
1465+
return doUnicode(frame, s, elementSize.longValueExact(), elements.longValueExact(), errorMarker, castStr);
14641466
} catch (OverflowException e) {
14651467
return raiseNative(frame, errorMarker, PythonErrorType.ValueError, ErrorMessages.INVALID_PARAMS);
14661468
}

0 commit comments

Comments
 (0)