28
28
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .UnicodeEncodeError ;
29
29
import static com .oracle .graal .python .builtins .objects .cext .capi .NativeCAPISymbol .FUN_ADD_NATIVE_SLOTS ;
30
30
import static com .oracle .graal .python .builtins .objects .cext .capi .NativeCAPISymbol .FUN_PY_OBJECT_NEW ;
31
- import static com .oracle .graal .python .builtins .objects .cext .capi .NativeCAPISymbol .FUN_PY_TRUFFLE_MEMORYVIEW_FROM_OBJECT ;
32
31
import static com .oracle .graal .python .builtins .objects .str .StringUtils .canEncodeUTF8 ;
33
32
import static com .oracle .graal .python .builtins .objects .str .StringUtils .containsNullCharacter ;
34
33
import static com .oracle .graal .python .builtins .objects .type .TypeBuiltins .TYPE_ITEMSIZE ;
108
107
import com .oracle .graal .python .annotations .ArgumentClinic ;
109
108
import com .oracle .graal .python .builtins .Builtin ;
110
109
import com .oracle .graal .python .builtins .CoreFunctions ;
110
+ import com .oracle .graal .python .builtins .Python3Core ;
111
111
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
112
112
import com .oracle .graal .python .builtins .PythonBuiltins ;
113
113
import com .oracle .graal .python .builtins .modules .WarningsModuleBuiltins .WarnNode ;
116
116
import com .oracle .graal .python .builtins .objects .PNotImplemented ;
117
117
import com .oracle .graal .python .builtins .objects .array .PArray ;
118
118
import com .oracle .graal .python .builtins .objects .bytes .BytesNodes ;
119
+ import com .oracle .graal .python .builtins .objects .bytes .BytesNodes .GetManagedBufferNode ;
119
120
import com .oracle .graal .python .builtins .objects .bytes .PByteArray ;
120
121
import com .oracle .graal .python .builtins .objects .bytes .PBytes ;
121
122
import com .oracle .graal .python .builtins .objects .bytes .PBytesLike ;
242
243
import com .oracle .graal .python .nodes .util .SplitArgsNode ;
243
244
import com .oracle .graal .python .parser .PythonSSTNodeFactory ;
244
245
import com .oracle .graal .python .runtime .ExecutionContext .IndirectCallContext ;
245
- import com .oracle .graal .python .runtime .PythonContext ;
246
- import com .oracle .graal .python .builtins .Python3Core ;
247
246
import com .oracle .graal .python .runtime .exception .PException ;
248
247
import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
249
248
import com .oracle .graal .python .runtime .sequence .storage .ObjectSequenceStorage ;
@@ -308,6 +307,7 @@ PBytes doEmpty(VirtualFrame frame, Object cls, PNone source, PNone encoding, PNo
308
307
309
308
@ Specialization (guards = "!isNoValue(source)" )
310
309
PBytes doCallBytes (VirtualFrame frame , Object cls , Object source , PNone encoding , PNone errors ,
310
+ @ Cached GetManagedBufferNode getManagedBufferNode ,
311
311
@ Cached GetClassNode getClassNode ,
312
312
@ Cached ConditionProfile hasBytes ,
313
313
@ Cached ("create(__BYTES__)" ) LookupSpecialMethodNode lookupBytes ,
@@ -328,13 +328,16 @@ PBytes doCallBytes(VirtualFrame frame, Object cls, Object source, PNone encoding
328
328
throw raise (TypeError , ErrorMessages .RETURNED_NONBYTES , __BYTES__ , bytes );
329
329
}
330
330
}
331
- return factory ().createBytes (cls , bytesInitNode .execute (frame , source , encoding , errors ));
331
+ Object s = getManagedBufferNode .getBuffer (frame , getContext (), source );
332
+ return factory ().createBytes (cls , bytesInitNode .execute (frame , s , encoding , errors ));
332
333
}
333
334
334
335
@ Specialization (guards = {"isNoValue(source) || (!isNoValue(encoding) || !isNoValue(errors))" })
335
336
PBytes dontCallBytes (VirtualFrame frame , Object cls , Object source , Object encoding , Object errors ,
337
+ @ Cached GetManagedBufferNode getManagedBufferNode ,
336
338
@ Cached BytesNodes .BytesInitNode bytesInitNode ) {
337
- return factory ().createBytes (cls , bytesInitNode .execute (frame , source , encoding , errors ));
339
+ Object s = getManagedBufferNode .getBuffer (frame , getContext (), source );
340
+ return factory ().createBytes (cls , bytesInitNode .execute (frame , s , encoding , errors ));
338
341
}
339
342
}
340
343
@@ -2167,14 +2170,16 @@ Object typeNew(VirtualFrame frame, Object cls, Object wName, PTuple bases, PDict
2167
2170
@ Cached GetMroStorageNode getMroStorageNode ) {
2168
2171
// Determine the proper metatype to deal with this
2169
2172
String name = castStr .execute (wName );
2170
- Object metaclass = calculate_metaclass (frame , cls , bases , getClassNode , lib );
2171
- if (metaclass != cls ) {
2172
- Object newFunc = getNewFuncNode .execute (metaclass );
2173
+ Object metaclass = cls ;
2174
+ Object winner = calculateMetaclass (frame , metaclass , bases , getClassNode , lib );
2175
+ if (winner != metaclass ) {
2176
+ Object newFunc = getNewFuncNode .execute (winner );
2173
2177
if (newFunc instanceof PBuiltinFunction && (((PBuiltinFunction ) newFunc ).getFunctionRootNode () == getRootNode ())) {
2178
+ metaclass = winner ;
2174
2179
// the new metaclass has the same __new__ function as we are in, continue
2175
2180
} else {
2176
2181
// Pass it to the winner
2177
- callNewFuncNode .execute (frame , newFunc , new Object []{metaclass , name , bases , namespaceOrig }, kwds );
2182
+ return callNewFuncNode .execute (frame , newFunc , new Object []{winner , name , bases , namespaceOrig }, kwds );
2178
2183
}
2179
2184
}
2180
2185
@@ -2710,7 +2715,7 @@ private PythonAbstractClass[] getMro(PythonAbstractClass pythonClass) {
2710
2715
return getMroNode .execute (pythonClass );
2711
2716
}
2712
2717
2713
- private Object calculate_metaclass (VirtualFrame frame , Object cls , PTuple bases , GetClassNode getClassNode , PythonObjectLibrary lib ) {
2718
+ private Object calculateMetaclass (VirtualFrame frame , Object cls , PTuple bases , GetClassNode getClassNode , PythonObjectLibrary lib ) {
2714
2719
Object winner = cls ;
2715
2720
for (Object base : ensureGetObjectArrayNode ().execute (bases )) {
2716
2721
if (lib .lookupAttributeOnType (base , __MRO_ENTRIES__ ) != PNone .NO_VALUE ) {
@@ -3381,20 +3386,8 @@ PMemoryView fromMemoryView(@SuppressWarnings("unused") Object cls, PMemoryView o
3381
3386
3382
3387
@ Specialization
3383
3388
PMemoryView fromNative (VirtualFrame frame , @ SuppressWarnings ("unused" ) Object cls , PythonAbstractNativeObject object ,
3384
- @ CachedLanguage PythonLanguage language ,
3385
- @ Cached CExtNodes .ToSulongNode toSulongNode ,
3386
- @ Cached CExtNodes .AsPythonObjectNode asPythonObjectNode ,
3387
- @ Cached PCallCapiFunction callCapiFunction ,
3388
- @ Cached PythonCextBuiltins .DefaultCheckFunctionResultNode checkFunctionResultNode ) {
3389
- PythonContext context = getContext ();
3390
- Object state = IndirectCallContext .enter (frame , language , context , this );
3391
- try {
3392
- Object result = callCapiFunction .call (FUN_PY_TRUFFLE_MEMORYVIEW_FROM_OBJECT , toSulongNode .execute (object ));
3393
- checkFunctionResultNode .execute (context , FUN_PY_TRUFFLE_MEMORYVIEW_FROM_OBJECT .getName (), result );
3394
- return (PMemoryView ) asPythonObjectNode .execute (result );
3395
- } finally {
3396
- IndirectCallContext .exit (frame , language , getContextRef (), state );
3397
- }
3389
+ @ Cached GetManagedBufferNode getManagedBufferNode ) {
3390
+ return getManagedBufferNode .getMemoryView (frame , getContext (), object );
3398
3391
}
3399
3392
3400
3393
@ Fallback
0 commit comments