46
46
import com .oracle .graal .python .builtins .modules .ExternalFunctionNodesFactory .MaterializePrimitiveNodeGen ;
47
47
import com .oracle .graal .python .builtins .modules .ExternalFunctionNodesFactory .ReleaseNativeWrapperNodeGen ;
48
48
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 ;
49
51
import com .oracle .graal .python .builtins .objects .PNone ;
50
52
import com .oracle .graal .python .builtins .objects .cext .CApiGuards ;
51
53
import com .oracle .graal .python .builtins .objects .cext .CExtNodes ;
@@ -192,7 +194,7 @@ public static MethDirectRoot create(PythonLanguage lang, String name, Object cal
192
194
*/
193
195
static final class ExternalFunctionInvokeNode extends PNodeWithContext implements IndirectCallNode {
194
196
@ Child private CExtNodes .ConvertArgsToSulongNode toSulongNode ;
195
- @ Child private CheckFunctionResultNode checkResultNode = CheckFunctionResultNode . create () ;
197
+ @ Child private CheckFunctionResultNode checkResultNode ;
196
198
@ Child private PForeignToPTypeNode fromForeign = PForeignToPTypeNode .create ();
197
199
@ Child private ToJavaStealingNode asPythonObjectNode = ToJavaStealingNodeGen .create ();
198
200
@ Child private InteropLibrary lib ;
@@ -220,12 +222,18 @@ public Node copy() {
220
222
return node ;
221
223
}
222
224
225
+ @ TruffleBoundary
223
226
ExternalFunctionInvokeNode () {
224
227
this .toSulongNode = CExtNodes .AllToSulongNode .create ();
228
+ this .checkResultNode = DefaultCheckFunctionResultNodeGen .create ();
225
229
}
226
230
227
- ExternalFunctionInvokeNode (ConvertArgsToSulongNode convertArgsNode ) {
231
+ @ TruffleBoundary
232
+ ExternalFunctionInvokeNode (PExternalFunctionWrapper provider ) {
233
+ ConvertArgsToSulongNode convertArgsNode = provider .createConvertArgsToSulongNode ();
228
234
this .toSulongNode = convertArgsNode != null ? convertArgsNode : CExtNodes .AllToSulongNode .create ();
235
+ CheckFunctionResultNode checkFunctionResultNode = provider .getCheckFunctionResultNode ();
236
+ this .checkResultNode = checkFunctionResultNode != null ? checkFunctionResultNode : DefaultCheckFunctionResultNodeGen .create ();
229
237
}
230
238
231
239
public Object execute (VirtualFrame frame , String name , Object callable , Object [] frameArgs , int argsOffset ) {
@@ -283,8 +291,8 @@ public static ExternalFunctionInvokeNode create() {
283
291
return new ExternalFunctionInvokeNode ();
284
292
}
285
293
286
- public static ExternalFunctionInvokeNode create (ConvertArgsToSulongNode convertArgsNode ) {
287
- return new ExternalFunctionInvokeNode (convertArgsNode );
294
+ public static ExternalFunctionInvokeNode create (PExternalFunctionWrapper provider ) {
295
+ return new ExternalFunctionInvokeNode (provider );
288
296
}
289
297
}
290
298
@@ -369,12 +377,12 @@ abstract static class MethodDescriptorRoot extends PRootNode {
369
377
}
370
378
371
379
@ TruffleBoundary
372
- MethodDescriptorRoot (PythonLanguage language , String name , Object callable , ConvertArgsToSulongNode convertArgsToSulongNode ) {
380
+ MethodDescriptorRoot (PythonLanguage language , String name , Object callable , PExternalFunctionWrapper provider ) {
373
381
super (language );
374
382
this .name = name ;
375
383
this .callable = callable ;
376
- if (convertArgsToSulongNode != null ) {
377
- this .externalInvokeNode = ExternalFunctionInvokeNode .create (convertArgsToSulongNode );
384
+ if (provider != null ) {
385
+ this .externalInvokeNode = ExternalFunctionInvokeNode .create (provider );
378
386
} else {
379
387
this .invokeNode = CallVarargsMethodNode .create ();
380
388
}
@@ -476,8 +484,8 @@ public MethKeywordsRoot(PythonLanguage language, String name, Object callable) {
476
484
super (language , name , callable );
477
485
}
478
486
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 );
481
489
this .factory = PythonObjectFactory .create ();
482
490
this .readVarargsNode = ReadVarArgsNode .create (1 , true );
483
491
this .readKwargsNode = ReadVarKeywordsNode .create (new String [0 ]);
@@ -523,8 +531,8 @@ public MethVarargsRoot(PythonLanguage language, String name, Object callable) {
523
531
super (language , name , callable );
524
532
}
525
533
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 );
528
536
this .factory = PythonObjectFactory .create ();
529
537
this .readVarargsNode = ReadVarArgsNode .create (1 , true );
530
538
this .createArgsTupleNode = CreateArgsTupleNodeGen .create ();
@@ -564,8 +572,8 @@ public MethNoargsRoot(PythonLanguage language, String name, Object callable) {
564
572
super (language , name , callable );
565
573
}
566
574
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 );
569
577
}
570
578
571
579
@ Override
@@ -588,8 +596,8 @@ public MethORoot(PythonLanguage language, String name, Object callable) {
588
596
super (language , name , callable );
589
597
}
590
598
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 );
593
601
this .readArgNode = ReadIndexedArgumentNode .create (1 );
594
602
}
595
603
@@ -616,8 +624,8 @@ public MethFastcallWithKeywordsRoot(PythonLanguage language, String name, Object
616
624
super (language , name , callable );
617
625
}
618
626
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 );
621
629
this .factory = PythonObjectFactory .create ();
622
630
this .readVarargsNode = ReadVarArgsNode .create (1 , true );
623
631
this .readKwargsNode = ReadVarKeywordsNode .create (new String [0 ]);
@@ -653,8 +661,8 @@ public MethFastcallRoot(PythonLanguage language, String name, Object callable) {
653
661
super (language , name , callable );
654
662
}
655
663
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 );
658
666
this .factory = PythonObjectFactory .create ();
659
667
this .readVarargsNode = ReadVarArgsNode .create (1 , true );
660
668
}
@@ -684,8 +692,8 @@ static class AllocFuncRootNode extends MethodDescriptorRoot {
684
692
super (language , name , callable );
685
693
}
686
694
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 );
689
697
this .readArgNode = ReadIndexedArgumentNode .create (1 );
690
698
this .asSsizeTNode = ConvertPIntToPrimitiveNodeGen .create ();
691
699
}
@@ -720,8 +728,8 @@ static final class GetAttrFuncRootNode extends MethodDescriptorRoot {
720
728
super (language , name , callable );
721
729
}
722
730
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 );
725
733
this .readArgNode = ReadIndexedArgumentNode .create (1 );
726
734
this .asCharPointerNode = CExtNodes .AsCharPointerNode .create ();
727
735
}
@@ -754,8 +762,8 @@ static final class SetAttrFuncRootNode extends MethodDescriptorRoot {
754
762
super (language , name , callable );
755
763
}
756
764
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 );
759
767
this .readArg1Node = ReadIndexedArgumentNode .create (1 );
760
768
this .readArg2Node = ReadIndexedArgumentNode .create (2 );
761
769
this .asCharPointerNode = CExtNodes .AsCharPointerNode .create ();
@@ -790,8 +798,8 @@ static final class RichCmpFuncRootNode extends MethodDescriptorRoot {
790
798
super (language , name , callable );
791
799
}
792
800
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 );
795
803
this .readArg1Node = ReadIndexedArgumentNode .create (1 );
796
804
this .readArg2Node = ReadIndexedArgumentNode .create (2 );
797
805
this .asSsizeTNode = ConvertPIntToPrimitiveNodeGen .create ();
@@ -829,8 +837,8 @@ static final class SSizeObjArgProcRootNode extends MethodDescriptorRoot {
829
837
super (language , name , callable );
830
838
}
831
839
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 );
834
842
this .readArg1Node = ReadIndexedArgumentNode .create (1 );
835
843
this .readArg2Node = ReadIndexedArgumentNode .create (2 );
836
844
this .asSsizeTNode = ConvertPIntToPrimitiveNodeGen .create ();
@@ -869,8 +877,8 @@ static final class MethReverseRootNode extends MethodDescriptorRoot {
869
877
this .readArg1Node = ReadIndexedArgumentNode .create (1 );
870
878
}
871
879
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 );
874
882
this .readArg0Node = ReadIndexedArgumentNode .create (0 );
875
883
this .readArg1Node = ReadIndexedArgumentNode .create (1 );
876
884
}
@@ -910,8 +918,8 @@ static class MethPowRootNode extends MethodDescriptorRoot {
910
918
this .profile = null ;
911
919
}
912
920
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 );
915
923
this .readVarargsNode = ReadVarArgsNode .create (1 , true );
916
924
this .profile = ConditionProfile .createBinaryProfile ();
917
925
}
@@ -944,8 +952,8 @@ static final class MethRPowRootNode extends MethPowRootNode {
944
952
super (language , name , callable );
945
953
}
946
954
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 );
949
957
}
950
958
951
959
@ Override
@@ -969,8 +977,8 @@ static final class MethRichcmpOpRootNode extends MethodDescriptorRoot {
969
977
this .op = op ;
970
978
}
971
979
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 );
974
982
this .readArgNode = ReadIndexedArgumentNode .create (1 );
975
983
this .op = op ;
976
984
}
@@ -995,6 +1003,31 @@ public Signature getSignature() {
995
1003
}
996
1004
}
997
1005
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
+
998
1031
/**
999
1032
* We need to inflate all primitives in order to avoid memory leaks. Explanation: Primitives
1000
1033
* would currently be wrapped into a PrimitiveNativeWrapper. If any of those will receive a
0 commit comments