56
56
import com .oracle .graal .python .builtins .modules .cext .PythonCextBuiltins .PromoteBorrowedValue ;
57
57
import com .oracle .graal .python .builtins .objects .PNone ;
58
58
import com .oracle .graal .python .builtins .objects .cext .PythonAbstractNativeObject ;
59
+ import com .oracle .graal .python .builtins .objects .cext .structs .CStructAccess ;
59
60
import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes ;
60
61
import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes .GetItemNode ;
61
62
import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes .GetItemScalarNode ;
62
63
import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes .ListGeneralizationNode ;
63
64
import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes .SetItemScalarNode ;
64
- import com .oracle .graal .python .builtins .objects .ints .PInt ;
65
65
import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
66
66
import com .oracle .graal .python .lib .PySliceNew ;
67
67
import com .oracle .graal .python .lib .PyTupleSizeNode ;
68
68
import com .oracle .graal .python .nodes .ErrorMessages ;
69
69
import com .oracle .graal .python .nodes .PRaiseNode ;
70
70
import com .oracle .graal .python .nodes .builtins .TupleNodes .GetNativeTupleStorage ;
71
71
import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
72
+ import com .oracle .graal .python .runtime .sequence .storage .NativeObjectSequenceStorage ;
72
73
import com .oracle .graal .python .runtime .sequence .storage .SequenceStorage ;
73
- import com .oracle .graal .python .util .PythonUtils ;
74
74
import com .oracle .truffle .api .dsl .Bind ;
75
75
import com .oracle .truffle .api .dsl .Cached ;
76
76
import com .oracle .truffle .api .dsl .Cached .Shared ;
@@ -84,22 +84,22 @@ public final class PythonCextTupleBuiltins {
84
84
abstract static class PyTuple_New extends CApiUnaryBuiltinNode {
85
85
86
86
@ Specialization
87
- static PTuple doGeneric (long size ,
87
+ static PTuple doGeneric (long longSize ,
88
88
@ Bind ("this" ) Node inliningTarget ,
89
89
@ Cached PythonObjectFactory factory ,
90
- @ Cached PRaiseNode .Lazy raiseNode ) {
91
- if (!PInt .isIntRange (size )) {
90
+ @ Cached PRaiseNode .Lazy raiseNode ,
91
+ @ Cached CStructAccess .AllocateNode alloc ) {
92
+ int size = (int ) longSize ;
93
+ if (longSize != size ) {
92
94
throw raiseNode .get (inliningTarget ).raise (PythonBuiltinClassType .MemoryError );
93
95
}
94
- Object [] data = new Object [(int ) size ];
95
96
/*
96
- * We need to fill the empty object array with 'PNone.NO_VALUE' because it may be that
97
- * the tuple is accessed with 'PyTuple_GET_ITEM' before all elements are initialized and
98
- * the corresponding storage-to-native transition would then fail because of the Java
99
- * nulls.
97
+ * Already allocate the tuple with native memory, since it has to be populated from the
98
+ * native side
100
99
*/
101
- PythonUtils .fill (data , 0 , data .length , PNone .NO_VALUE );
102
- return factory .createTuple (data );
100
+ Object mem = alloc .alloc ((longSize + 1 ) * CStructAccess .POINTER_SIZE );
101
+ NativeObjectSequenceStorage storage = NativeObjectSequenceStorage .create (mem , size , size , true );
102
+ return factory .createTuple (storage );
103
103
}
104
104
}
105
105
0 commit comments