@@ -2293,16 +2293,16 @@ static Object strOneArg(VirtualFrame frame, Object cls, Object obj, @SuppressWar
2293
2293
@ Specialization (guards = {"!needsNativeAllocationNode.execute(inliningTarget, cls)" , "!isNoValue(encoding) || !isNoValue(errors)" }, limit = "3" )
2294
2294
static Object doBuffer (VirtualFrame frame , Object cls , Object obj , Object encoding , Object errors ,
2295
2295
@ Bind ("this" ) Node inliningTarget ,
2296
- @ Cached ("createFor(this)" ) IndirectCallData indirectCallData ,
2296
+ @ Exclusive @ Cached ("createFor(this)" ) IndirectCallData indirectCallData ,
2297
2297
@ SuppressWarnings ("unused" ) @ Exclusive @ Cached TypeNodes .NeedsNativeAllocationNode needsNativeAllocationNode ,
2298
2298
@ Exclusive @ Cached IsBuiltinClassExactProfile isPrimitiveProfile ,
2299
2299
@ Exclusive @ Cached InlinedConditionProfile isStringProfile ,
2300
2300
@ Exclusive @ Cached InlinedConditionProfile isPStringProfile ,
2301
- @ CachedLibrary ("obj" ) PythonBufferAcquireLibrary acquireLib ,
2302
- @ CachedLibrary (limit = "1" ) PythonBufferAccessLibrary bufferLib ,
2303
- @ Cached ("create(T_DECODE)" ) LookupAndCallTernaryNode callDecodeNode ,
2301
+ @ Exclusive @ CachedLibrary ("obj" ) PythonBufferAcquireLibrary acquireLib ,
2302
+ @ Exclusive @ CachedLibrary (limit = "1" ) PythonBufferAccessLibrary bufferLib ,
2303
+ @ Exclusive @ Cached ("create(T_DECODE)" ) LookupAndCallTernaryNode callDecodeNode ,
2304
2304
@ Shared @ Cached PythonObjectFactory factory ,
2305
- @ Cached PRaiseNode .Lazy raiseNode ) {
2305
+ @ Exclusive @ Cached PRaiseNode .Lazy raiseNode ) {
2306
2306
Object buffer ;
2307
2307
try {
2308
2308
buffer = acquireLib .acquireReadonly (obj , frame , indirectCallData );
@@ -2337,16 +2337,53 @@ static Object doBuffer(VirtualFrame frame, Object cls, Object obj, Object encodi
2337
2337
static Object doNativeSubclass (VirtualFrame frame , Object cls , Object obj , @ SuppressWarnings ("unused" ) Object encoding , @ SuppressWarnings ("unused" ) Object errors ,
2338
2338
@ SuppressWarnings ("unused" ) @ Bind ("this" ) Node inliningTarget ,
2339
2339
@ SuppressWarnings ("unused" ) @ Exclusive @ Cached TypeNodes .NeedsNativeAllocationNode needsNativeAllocationNode ,
2340
- @ Cached @ SuppressWarnings ("unused" ) IsSubtypeNode isSubtype ,
2340
+ @ Shared @ Cached @ SuppressWarnings ("unused" ) IsSubtypeNode isSubtype ,
2341
2341
@ Exclusive @ Cached PyObjectStrAsObjectNode strNode ,
2342
- @ Cached CExtNodes .StringSubtypeNew subtypeNew ) {
2342
+ @ Shared @ Cached ( neverDefault = true ) CExtNodes .StringSubtypeNew subtypeNew ) {
2343
2343
if (obj == PNone .NO_VALUE ) {
2344
2344
return subtypeNew .call (cls , T_EMPTY_STRING );
2345
2345
} else {
2346
2346
return subtypeNew .call (cls , strNode .execute (frame , inliningTarget , obj ));
2347
2347
}
2348
2348
}
2349
2349
2350
+ @ Specialization (guards = {"needsNativeAllocationNode.execute(inliningTarget, cls)" , "isSubtypeOfString(frame, isSubtype, cls)" , //
2351
+ "!isNoValue(encoding) || !isNoValue(errors)" }, limit = "1" )
2352
+ static Object doNativeSubclassEncodeErr (VirtualFrame frame , Object cls , Object obj , @ SuppressWarnings ("unused" ) Object encoding , @ SuppressWarnings ("unused" ) Object errors ,
2353
+ @ SuppressWarnings ("unused" ) @ Bind ("this" ) Node inliningTarget ,
2354
+ @ Exclusive @ Cached ("createFor(this)" ) IndirectCallData indirectCallData ,
2355
+ @ SuppressWarnings ("unused" ) @ Exclusive @ Cached TypeNodes .NeedsNativeAllocationNode needsNativeAllocationNode ,
2356
+ @ Shared @ Cached @ SuppressWarnings ("unused" ) IsSubtypeNode isSubtype ,
2357
+ @ Exclusive @ Cached IsBuiltinClassExactProfile isPrimitiveProfile ,
2358
+ @ Exclusive @ Cached InlinedConditionProfile isStringProfile ,
2359
+ @ Exclusive @ Cached InlinedConditionProfile isPStringProfile ,
2360
+ @ Exclusive @ CachedLibrary ("obj" ) PythonBufferAcquireLibrary acquireLib ,
2361
+ @ Exclusive @ CachedLibrary (limit = "1" ) PythonBufferAccessLibrary bufferLib ,
2362
+ @ Exclusive @ Cached ("create(T_DECODE)" ) LookupAndCallTernaryNode callDecodeNode ,
2363
+ @ Shared @ Cached (neverDefault = true ) CExtNodes .StringSubtypeNew subtypeNew ,
2364
+ @ Shared @ Cached PythonObjectFactory factory ,
2365
+ @ Exclusive @ Cached PRaiseNode .Lazy raiseNode ) {
2366
+ Object buffer ;
2367
+ try {
2368
+ buffer = acquireLib .acquireReadonly (obj , frame , indirectCallData );
2369
+ } catch (PException e ) {
2370
+ throw raiseNode .get (inliningTarget ).raise (TypeError , ErrorMessages .NEED_BYTELIKE_OBJ , obj );
2371
+ }
2372
+ try {
2373
+ PBytes bytesObj = factory .createBytes (bufferLib .getCopiedByteArray (buffer ));
2374
+ Object en = encoding == PNone .NO_VALUE ? T_UTF8 : encoding ;
2375
+ Object result = assertNoJavaString (callDecodeNode .execute (frame , bytesObj , en , errors ));
2376
+ if (isStringProfile .profile (inliningTarget , result instanceof TruffleString )) {
2377
+ return subtypeNew .call (cls , asPString (cls , (TruffleString ) result , inliningTarget , isPrimitiveProfile , factory ));
2378
+ } else if (isPStringProfile .profile (inliningTarget , result instanceof PString )) {
2379
+ return subtypeNew .call (cls , result );
2380
+ }
2381
+ throw raiseNode .get (inliningTarget ).raise (TypeError , ErrorMessages .P_S_RETURNED_NON_STRING , bytesObj , "decode" , result );
2382
+ } finally {
2383
+ bufferLib .release (buffer , frame , indirectCallData );
2384
+ }
2385
+ }
2386
+
2350
2387
protected static boolean isSubtypeOfString (VirtualFrame frame , IsSubtypeNode isSubtypeNode , Object cls ) {
2351
2388
return isSubtypeNode .execute (frame , cls , PythonBuiltinClassType .PString );
2352
2389
}
0 commit comments