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 ;
117
116
import com .oracle .graal .python .builtins .objects .PNotImplemented ;
118
117
import com .oracle .graal .python .builtins .objects .array .PArray ;
119
118
import com .oracle .graal .python .builtins .objects .bytes .BytesNodes ;
119
+ import com .oracle .graal .python .builtins .objects .bytes .BytesNodes .GetManagedBufferNode ;
120
120
import com .oracle .graal .python .builtins .objects .bytes .PByteArray ;
121
121
import com .oracle .graal .python .builtins .objects .bytes .PBytes ;
122
122
import com .oracle .graal .python .builtins .objects .bytes .PBytesLike ;
248
248
import com .oracle .graal .python .nodes .util .SplitArgsNode ;
249
249
import com .oracle .graal .python .parser .PythonSSTNodeFactory ;
250
250
import com .oracle .graal .python .runtime .ExecutionContext .IndirectCallContext ;
251
- import com .oracle .graal .python .runtime .PythonContext ;
252
251
import com .oracle .graal .python .runtime .exception .PException ;
253
252
import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
254
253
import com .oracle .graal .python .runtime .sequence .storage .ObjectSequenceStorage ;
@@ -314,6 +313,7 @@ PBytes doEmpty(VirtualFrame frame, Object cls, PNone source, PNone encoding, PNo
314
313
315
314
@ Specialization (guards = "!isNoValue(source)" )
316
315
PBytes doCallBytes (VirtualFrame frame , Object cls , Object source , PNone encoding , PNone errors ,
316
+ @ Cached GetManagedBufferNode getManagedBufferNode ,
317
317
@ Cached GetClassNode getClassNode ,
318
318
@ Cached ConditionProfile hasBytes ,
319
319
@ Cached ("create(__BYTES__)" ) LookupSpecialMethodNode lookupBytes ,
@@ -334,13 +334,16 @@ PBytes doCallBytes(VirtualFrame frame, Object cls, Object source, PNone encoding
334
334
throw raise (TypeError , ErrorMessages .RETURNED_NONBYTES , __BYTES__ , bytes );
335
335
}
336
336
}
337
- return factory ().createBytes (cls , bytesInitNode .execute (frame , source , encoding , errors ));
337
+ Object s = getManagedBufferNode .getBuffer (frame , getContext (), source );
338
+ return factory ().createBytes (cls , bytesInitNode .execute (frame , s , encoding , errors ));
338
339
}
339
340
340
341
@ Specialization (guards = {"isNoValue(source) || (!isNoValue(encoding) || !isNoValue(errors))" })
341
342
PBytes dontCallBytes (VirtualFrame frame , Object cls , Object source , Object encoding , Object errors ,
343
+ @ Cached GetManagedBufferNode getManagedBufferNode ,
342
344
@ Cached BytesNodes .BytesInitNode bytesInitNode ) {
343
- return factory ().createBytes (cls , bytesInitNode .execute (frame , source , encoding , errors ));
345
+ Object s = getManagedBufferNode .getBuffer (frame , getContext (), source );
346
+ return factory ().createBytes (cls , bytesInitNode .execute (frame , s , encoding , errors ));
344
347
}
345
348
}
346
349
@@ -2173,14 +2176,16 @@ Object typeNew(VirtualFrame frame, Object cls, Object wName, PTuple bases, PDict
2173
2176
@ Cached GetMroStorageNode getMroStorageNode ) {
2174
2177
// Determine the proper metatype to deal with this
2175
2178
String name = castStr .execute (wName );
2176
- Object metaclass = calculate_metaclass (frame , cls , bases , getClassNode , lib );
2177
- if (metaclass != cls ) {
2178
- Object newFunc = getNewFuncNode .execute (metaclass );
2179
+ Object metaclass = cls ;
2180
+ Object winner = calculateMetaclass (frame , metaclass , bases , getClassNode , lib );
2181
+ if (winner != metaclass ) {
2182
+ Object newFunc = getNewFuncNode .execute (winner );
2179
2183
if (newFunc instanceof PBuiltinFunction && (((PBuiltinFunction ) newFunc ).getFunctionRootNode () == getRootNode ())) {
2184
+ metaclass = winner ;
2180
2185
// the new metaclass has the same __new__ function as we are in, continue
2181
2186
} else {
2182
2187
// Pass it to the winner
2183
- callNewFuncNode .execute (frame , newFunc , new Object []{metaclass , name , bases , namespaceOrig }, kwds );
2188
+ return callNewFuncNode .execute (frame , newFunc , new Object []{winner , name , bases , namespaceOrig }, kwds );
2184
2189
}
2185
2190
}
2186
2191
@@ -2716,7 +2721,7 @@ private PythonAbstractClass[] getMro(PythonAbstractClass pythonClass) {
2716
2721
return getMroNode .execute (pythonClass );
2717
2722
}
2718
2723
2719
- private Object calculate_metaclass (VirtualFrame frame , Object cls , PTuple bases , GetClassNode getClassNode , PythonObjectLibrary lib ) {
2724
+ private Object calculateMetaclass (VirtualFrame frame , Object cls , PTuple bases , GetClassNode getClassNode , PythonObjectLibrary lib ) {
2720
2725
Object winner = cls ;
2721
2726
for (Object base : ensureGetObjectArrayNode ().execute (bases )) {
2722
2727
if (lib .lookupAttributeOnType (base , __MRO_ENTRIES__ ) != PNone .NO_VALUE ) {
@@ -3388,20 +3393,8 @@ PMemoryView fromMemoryView(@SuppressWarnings("unused") Object cls, PMemoryView o
3388
3393
3389
3394
@ Specialization
3390
3395
PMemoryView fromNative (VirtualFrame frame , @ SuppressWarnings ("unused" ) Object cls , PythonAbstractNativeObject object ,
3391
- @ CachedLanguage PythonLanguage language ,
3392
- @ Cached CExtNodes .ToSulongNode toSulongNode ,
3393
- @ Cached CExtNodes .AsPythonObjectNode asPythonObjectNode ,
3394
- @ Cached PCallCapiFunction callCapiFunction ,
3395
- @ Cached PythonCextBuiltins .DefaultCheckFunctionResultNode checkFunctionResultNode ) {
3396
- PythonContext context = getContext ();
3397
- Object state = IndirectCallContext .enter (frame , language , context , this );
3398
- try {
3399
- Object result = callCapiFunction .call (FUN_PY_TRUFFLE_MEMORYVIEW_FROM_OBJECT , toSulongNode .execute (object ));
3400
- checkFunctionResultNode .execute (context , FUN_PY_TRUFFLE_MEMORYVIEW_FROM_OBJECT .getName (), result );
3401
- return (PMemoryView ) asPythonObjectNode .execute (result );
3402
- } finally {
3403
- IndirectCallContext .exit (frame , language , getContextRef (), state );
3404
- }
3396
+ @ Cached GetManagedBufferNode getManagedBufferNode ) {
3397
+ return getManagedBufferNode .getMemoryView (frame , getContext (), object );
3405
3398
}
3406
3399
3407
3400
@ Specialization (guards = "isFallbackCase(object)" )
0 commit comments