Skip to content

Commit 48a2109

Browse files
committed
[GR-25324] [GR-24230] Get test_struct to pass.
PullRequest: graalpython/1157
2 parents 25463d8 + fd98d2b commit 48a2109

File tree

12 files changed

+414
-263
lines changed

12 files changed

+414
-263
lines changed

graalpython/com.oracle.graal.python.cext/src/capi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ void initialize_hashes();
295295
#define JWRAPPER_NE (polyglot_invoke(PY_TRUFFLE_CEXT, "METH_NE"))
296296
#define JWRAPPER_GT (polyglot_invoke(PY_TRUFFLE_CEXT, "METH_GT"))
297297
#define JWRAPPER_GE (polyglot_invoke(PY_TRUFFLE_CEXT, "METH_GE"))
298+
#define JWRAPPER_ITERNEXT (polyglot_invoke(PY_TRUFFLE_CEXT, "METH_ITERNEXT"))
298299

299300
#define TDEBUG __builtin_debugtrap()
300301
#define get_method_flags_wrapper(flags) \

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ int PyType_Ready(PyTypeObject* cls) {
534534
ADD_SLOT_CONV("__ge__", NULL, cls->tp_richcompare, -2, JWRAPPER_GE);
535535
}
536536
ADD_SLOT("__iter__", cls->tp_iter, -1);
537-
ADD_SLOT("__next__", cls->tp_iternext, -1);
537+
ADD_SLOT_CONV("__next__", NULL, cls->tp_iternext, -1, JWRAPPER_ITERNEXT);
538538
ADD_SLOT("__get__", cls->tp_descr_get, -3);
539539
ADD_SLOT_PRIMITIVE("__set__", cls->tp_descr_set, -3);
540540
ADD_SLOT_PRIMITIVE("__init__", cls->tp_init, METH_KEYWORDS | METH_VARARGS);

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_struct.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,5 @@
88
*graalpython.lib-python.3.test.test_struct.StructTest.test_boundary_error_message_with_negative_offset
99
*graalpython.lib-python.3.test.test_struct.StructTest.test_calcsize
1010
*graalpython.lib-python.3.test.test_struct.StructTest.test_consistence
11+
*graalpython.lib-python.3.test.test_struct.StructTest.test_count_overflow
1112
*graalpython.lib-python.3.test.test_struct.StructTest.test_format_attr
12-
*graalpython.lib-python.3.test.test_struct.StructTest.test_isbigendian
13-
*graalpython.lib-python.3.test.test_struct.StructTest.test_issue29802
14-
*graalpython.lib-python.3.test.test_struct.StructTest.test_nN_code
15-
*graalpython.lib-python.3.test.test_struct.StructTest.test_new_features
16-
*graalpython.lib-python.3.test.test_struct.StructTest.test_p_code
17-
*graalpython.lib-python.3.test.test_struct.StructTest.test_trailing_counter
18-
*graalpython.lib-python.3.test.test_struct.StructTest.test_transitiveness
19-
*graalpython.lib-python.3.test.test_struct.StructTest.test_unpack_from
20-
*graalpython.lib-python.3.test.test_struct.UnpackIteratorTest.test_construct
21-
*graalpython.lib-python.3.test.test_struct.UnpackIteratorTest.test_half_float

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

Lines changed: 70 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import com.oracle.graal.python.builtins.modules.ExternalFunctionNodesFactory.MaterializePrimitiveNodeGen;
4747
import com.oracle.graal.python.builtins.modules.ExternalFunctionNodesFactory.ReleaseNativeWrapperNodeGen;
4848
import com.oracle.graal.python.builtins.modules.PythonCextBuiltins.CheckFunctionResultNode;
49+
import com.oracle.graal.python.builtins.modules.PythonCextBuiltins.PExternalFunctionWrapper;
50+
import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.DefaultCheckFunctionResultNodeGen;
4951
import com.oracle.graal.python.builtins.objects.PNone;
5052
import com.oracle.graal.python.builtins.objects.cext.CApiGuards;
5153
import com.oracle.graal.python.builtins.objects.cext.CExtNodes;
@@ -192,7 +194,7 @@ public static MethDirectRoot create(PythonLanguage lang, String name, Object cal
192194
*/
193195
static final class ExternalFunctionInvokeNode extends PNodeWithContext implements IndirectCallNode {
194196
@Child private CExtNodes.ConvertArgsToSulongNode toSulongNode;
195-
@Child private CheckFunctionResultNode checkResultNode = CheckFunctionResultNode.create();
197+
@Child private CheckFunctionResultNode checkResultNode;
196198
@Child private PForeignToPTypeNode fromForeign = PForeignToPTypeNode.create();
197199
@Child private ToJavaStealingNode asPythonObjectNode = ToJavaStealingNodeGen.create();
198200
@Child private InteropLibrary lib;
@@ -220,12 +222,18 @@ public Node copy() {
220222
return node;
221223
}
222224

225+
@TruffleBoundary
223226
ExternalFunctionInvokeNode() {
224227
this.toSulongNode = CExtNodes.AllToSulongNode.create();
228+
this.checkResultNode = DefaultCheckFunctionResultNodeGen.create();
225229
}
226230

227-
ExternalFunctionInvokeNode(ConvertArgsToSulongNode convertArgsNode) {
231+
@TruffleBoundary
232+
ExternalFunctionInvokeNode(PExternalFunctionWrapper provider) {
233+
ConvertArgsToSulongNode convertArgsNode = provider.createConvertArgsToSulongNode();
228234
this.toSulongNode = convertArgsNode != null ? convertArgsNode : CExtNodes.AllToSulongNode.create();
235+
CheckFunctionResultNode checkFunctionResultNode = provider.getCheckFunctionResultNode();
236+
this.checkResultNode = checkFunctionResultNode != null ? checkFunctionResultNode : DefaultCheckFunctionResultNodeGen.create();
229237
}
230238

231239
public Object execute(VirtualFrame frame, String name, Object callable, Object[] frameArgs, int argsOffset) {
@@ -283,8 +291,8 @@ public static ExternalFunctionInvokeNode create() {
283291
return new ExternalFunctionInvokeNode();
284292
}
285293

286-
public static ExternalFunctionInvokeNode create(ConvertArgsToSulongNode convertArgsNode) {
287-
return new ExternalFunctionInvokeNode(convertArgsNode);
294+
public static ExternalFunctionInvokeNode create(PExternalFunctionWrapper provider) {
295+
return new ExternalFunctionInvokeNode(provider);
288296
}
289297
}
290298

@@ -369,12 +377,12 @@ abstract static class MethodDescriptorRoot extends PRootNode {
369377
}
370378

371379
@TruffleBoundary
372-
MethodDescriptorRoot(PythonLanguage language, String name, Object callable, ConvertArgsToSulongNode convertArgsToSulongNode) {
380+
MethodDescriptorRoot(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider) {
373381
super(language);
374382
this.name = name;
375383
this.callable = callable;
376-
if (convertArgsToSulongNode != null) {
377-
this.externalInvokeNode = ExternalFunctionInvokeNode.create(convertArgsToSulongNode);
384+
if (provider != null) {
385+
this.externalInvokeNode = ExternalFunctionInvokeNode.create(provider);
378386
} else {
379387
this.invokeNode = CallVarargsMethodNode.create();
380388
}
@@ -476,8 +484,8 @@ public MethKeywordsRoot(PythonLanguage language, String name, Object callable) {
476484
super(language, name, callable);
477485
}
478486

479-
public MethKeywordsRoot(PythonLanguage language, String name, Object callable, ConvertArgsToSulongNode convertArgsToSulongNode) {
480-
super(language, name, callable, convertArgsToSulongNode);
487+
public MethKeywordsRoot(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider) {
488+
super(language, name, callable, provider);
481489
this.factory = PythonObjectFactory.create();
482490
this.readVarargsNode = ReadVarArgsNode.create(1, true);
483491
this.readKwargsNode = ReadVarKeywordsNode.create(new String[0]);
@@ -523,8 +531,8 @@ public MethVarargsRoot(PythonLanguage language, String name, Object callable) {
523531
super(language, name, callable);
524532
}
525533

526-
public MethVarargsRoot(PythonLanguage language, String name, Object callable, ConvertArgsToSulongNode convertArgsToSulongNode) {
527-
super(language, name, callable, convertArgsToSulongNode);
534+
public MethVarargsRoot(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider) {
535+
super(language, name, callable, provider);
528536
this.factory = PythonObjectFactory.create();
529537
this.readVarargsNode = ReadVarArgsNode.create(1, true);
530538
this.createArgsTupleNode = CreateArgsTupleNodeGen.create();
@@ -564,8 +572,8 @@ public MethNoargsRoot(PythonLanguage language, String name, Object callable) {
564572
super(language, name, callable);
565573
}
566574

567-
public MethNoargsRoot(PythonLanguage language, String name, Object callable, ConvertArgsToSulongNode convertArgsToSulongNode) {
568-
super(language, name, callable, convertArgsToSulongNode);
575+
public MethNoargsRoot(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider) {
576+
super(language, name, callable, provider);
569577
}
570578

571579
@Override
@@ -588,8 +596,8 @@ public MethORoot(PythonLanguage language, String name, Object callable) {
588596
super(language, name, callable);
589597
}
590598

591-
public MethORoot(PythonLanguage language, String name, Object callable, ConvertArgsToSulongNode convertArgsToSulongNode) {
592-
super(language, name, callable, convertArgsToSulongNode);
599+
public MethORoot(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider) {
600+
super(language, name, callable, provider);
593601
this.readArgNode = ReadIndexedArgumentNode.create(1);
594602
}
595603

@@ -616,8 +624,8 @@ public MethFastcallWithKeywordsRoot(PythonLanguage language, String name, Object
616624
super(language, name, callable);
617625
}
618626

619-
public MethFastcallWithKeywordsRoot(PythonLanguage language, String name, Object callable, ConvertArgsToSulongNode convertArgsToSulongNode) {
620-
super(language, name, callable, convertArgsToSulongNode);
627+
public MethFastcallWithKeywordsRoot(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider) {
628+
super(language, name, callable, provider);
621629
this.factory = PythonObjectFactory.create();
622630
this.readVarargsNode = ReadVarArgsNode.create(1, true);
623631
this.readKwargsNode = ReadVarKeywordsNode.create(new String[0]);
@@ -653,8 +661,8 @@ public MethFastcallRoot(PythonLanguage language, String name, Object callable) {
653661
super(language, name, callable);
654662
}
655663

656-
public MethFastcallRoot(PythonLanguage language, String name, Object callable, ConvertArgsToSulongNode convertArgsToSulongNode) {
657-
super(language, name, callable, convertArgsToSulongNode);
664+
public MethFastcallRoot(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider) {
665+
super(language, name, callable, provider);
658666
this.factory = PythonObjectFactory.create();
659667
this.readVarargsNode = ReadVarArgsNode.create(1, true);
660668
}
@@ -684,8 +692,8 @@ static class AllocFuncRootNode extends MethodDescriptorRoot {
684692
super(language, name, callable);
685693
}
686694

687-
AllocFuncRootNode(PythonLanguage language, String name, Object callable, ConvertArgsToSulongNode convertArgsToSulongNode) {
688-
super(language, name, callable, convertArgsToSulongNode);
695+
AllocFuncRootNode(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider) {
696+
super(language, name, callable, provider);
689697
this.readArgNode = ReadIndexedArgumentNode.create(1);
690698
this.asSsizeTNode = ConvertPIntToPrimitiveNodeGen.create();
691699
}
@@ -720,8 +728,8 @@ static final class GetAttrFuncRootNode extends MethodDescriptorRoot {
720728
super(language, name, callable);
721729
}
722730

723-
GetAttrFuncRootNode(PythonLanguage language, String name, Object callable, ConvertArgsToSulongNode convertArgsToSulongNode) {
724-
super(language, name, callable, convertArgsToSulongNode);
731+
GetAttrFuncRootNode(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider) {
732+
super(language, name, callable, provider);
725733
this.readArgNode = ReadIndexedArgumentNode.create(1);
726734
this.asCharPointerNode = CExtNodes.AsCharPointerNode.create();
727735
}
@@ -754,8 +762,8 @@ static final class SetAttrFuncRootNode extends MethodDescriptorRoot {
754762
super(language, name, callable);
755763
}
756764

757-
SetAttrFuncRootNode(PythonLanguage language, String name, Object callable, ConvertArgsToSulongNode convertArgsToSulongNode) {
758-
super(language, name, callable, convertArgsToSulongNode);
765+
SetAttrFuncRootNode(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider) {
766+
super(language, name, callable, provider);
759767
this.readArg1Node = ReadIndexedArgumentNode.create(1);
760768
this.readArg2Node = ReadIndexedArgumentNode.create(2);
761769
this.asCharPointerNode = CExtNodes.AsCharPointerNode.create();
@@ -790,8 +798,8 @@ static final class RichCmpFuncRootNode extends MethodDescriptorRoot {
790798
super(language, name, callable);
791799
}
792800

793-
RichCmpFuncRootNode(PythonLanguage language, String name, Object callable, ConvertArgsToSulongNode convertArgsToSulongNode) {
794-
super(language, name, callable, convertArgsToSulongNode);
801+
RichCmpFuncRootNode(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider) {
802+
super(language, name, callable, provider);
795803
this.readArg1Node = ReadIndexedArgumentNode.create(1);
796804
this.readArg2Node = ReadIndexedArgumentNode.create(2);
797805
this.asSsizeTNode = ConvertPIntToPrimitiveNodeGen.create();
@@ -829,8 +837,8 @@ static final class SSizeObjArgProcRootNode extends MethodDescriptorRoot {
829837
super(language, name, callable);
830838
}
831839

832-
SSizeObjArgProcRootNode(PythonLanguage language, String name, Object callable, ConvertArgsToSulongNode convertArgsToSulongNode) {
833-
super(language, name, callable, convertArgsToSulongNode);
840+
SSizeObjArgProcRootNode(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider) {
841+
super(language, name, callable, provider);
834842
this.readArg1Node = ReadIndexedArgumentNode.create(1);
835843
this.readArg2Node = ReadIndexedArgumentNode.create(2);
836844
this.asSsizeTNode = ConvertPIntToPrimitiveNodeGen.create();
@@ -869,8 +877,8 @@ static final class MethReverseRootNode extends MethodDescriptorRoot {
869877
this.readArg1Node = ReadIndexedArgumentNode.create(1);
870878
}
871879

872-
MethReverseRootNode(PythonLanguage language, String name, Object callable, ConvertArgsToSulongNode convertArgsToSulongNode) {
873-
super(language, name, callable, convertArgsToSulongNode);
880+
MethReverseRootNode(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider) {
881+
super(language, name, callable, provider);
874882
this.readArg0Node = ReadIndexedArgumentNode.create(0);
875883
this.readArg1Node = ReadIndexedArgumentNode.create(1);
876884
}
@@ -910,8 +918,8 @@ static class MethPowRootNode extends MethodDescriptorRoot {
910918
this.profile = null;
911919
}
912920

913-
MethPowRootNode(PythonLanguage language, String name, Object callable, ConvertArgsToSulongNode convertArgsToSulongNode) {
914-
super(language, name, callable, convertArgsToSulongNode);
921+
MethPowRootNode(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider) {
922+
super(language, name, callable, provider);
915923
this.readVarargsNode = ReadVarArgsNode.create(1, true);
916924
this.profile = ConditionProfile.createBinaryProfile();
917925
}
@@ -944,8 +952,8 @@ static final class MethRPowRootNode extends MethPowRootNode {
944952
super(language, name, callable);
945953
}
946954

947-
MethRPowRootNode(PythonLanguage language, String name, Object callable, ConvertArgsToSulongNode convertArgsToSulongNode) {
948-
super(language, name, callable, convertArgsToSulongNode);
955+
MethRPowRootNode(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider) {
956+
super(language, name, callable, provider);
949957
}
950958

951959
@Override
@@ -969,8 +977,8 @@ static final class MethRichcmpOpRootNode extends MethodDescriptorRoot {
969977
this.op = op;
970978
}
971979

972-
MethRichcmpOpRootNode(PythonLanguage language, String name, Object callable, ConvertArgsToSulongNode convertArgsToSulongNode, int op) {
973-
super(language, name, callable, convertArgsToSulongNode);
980+
MethRichcmpOpRootNode(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider, int op) {
981+
super(language, name, callable, provider);
974982
this.readArgNode = ReadIndexedArgumentNode.create(1);
975983
this.op = op;
976984
}
@@ -995,6 +1003,31 @@ public Signature getSignature() {
9951003
}
9961004
}
9971005

1006+
/**
1007+
* Wrapper root node for C function type {@code iternextfunc}.
1008+
*/
1009+
static class IterNextFuncRootNode extends MethodDescriptorRoot {
1010+
1011+
IterNextFuncRootNode(PythonLanguage language, String name, Object callable) {
1012+
super(language, name, callable);
1013+
}
1014+
1015+
IterNextFuncRootNode(PythonLanguage language, String name, Object callable, PExternalFunctionWrapper provider) {
1016+
super(language, name, callable, provider);
1017+
}
1018+
1019+
@Override
1020+
protected Object[] prepareCArguments(VirtualFrame frame) {
1021+
return new Object[]{readSelfNode.execute(frame)};
1022+
}
1023+
1024+
@Override
1025+
public Signature getSignature() {
1026+
// same signature as a method without arguments (just the self)
1027+
return MethNoargsRoot.SIGNATURE;
1028+
}
1029+
}
1030+
9981031
/**
9991032
* We need to inflate all primitives in order to avoid memory leaks. Explanation: Primitives
10001033
* would currently be wrapped into a PrimitiveNativeWrapper. If any of those will receive a

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import com.oracle.graal.python.builtins.CoreFunctions;
5757
import com.oracle.graal.python.builtins.PythonBuiltins;
5858
import com.oracle.graal.python.builtins.modules.PythonCextBuiltins.CheckFunctionResultNode;
59+
import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.DefaultCheckFunctionResultNodeGen;
5960
import com.oracle.graal.python.builtins.objects.PNone;
6061
import com.oracle.graal.python.builtins.objects.PythonAbstractObjectFactory.PInteropGetAttributeNodeGen;
6162
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
@@ -419,7 +420,7 @@ private SetItemNode getSetItemNode() {
419420
private CheckFunctionResultNode getCheckResultNode() {
420421
if (checkResultNode == null) {
421422
CompilerDirectives.transferToInterpreterAndInvalidate();
422-
checkResultNode = insert(CheckFunctionResultNode.create());
423+
checkResultNode = insert(DefaultCheckFunctionResultNodeGen.create());
423424
}
424425
return checkResultNode;
425426
}

0 commit comments

Comments
 (0)