6262import com .oracle .graal .python .builtins .PythonBuiltins ;
6363import com .oracle .graal .python .builtins .objects .PNone ;
6464import com .oracle .graal .python .builtins .objects .buffer .PythonBufferAccessLibrary ;
65- import com .oracle .graal .python .builtins .objects .buffer .PythonBufferAcquireLibrary ;
6665import com .oracle .graal .python .builtins .objects .bytes .PBytes ;
6766import com .oracle .graal .python .builtins .objects .str .PString ;
67+ import com .oracle .graal .python .lib .PyBufferRelease ;
68+ import com .oracle .graal .python .lib .PyObjectCheckBuffer ;
69+ import com .oracle .graal .python .lib .PyObjectGetBuffer ;
6870import com .oracle .graal .python .nodes .ErrorMessages ;
6971import com .oracle .graal .python .nodes .PRaiseNode ;
7072import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
7577import com .oracle .graal .python .nodes .function .builtins .clinic .ArgumentCastNode ;
7678import com .oracle .graal .python .nodes .function .builtins .clinic .ArgumentClinicProvider ;
7779import com .oracle .graal .python .nodes .util .CastToTruffleStringNode ;
78- import com .oracle .graal .python .runtime .IndirectCallData .InteropCallData ;
79- import com .oracle .graal .python .runtime .PythonContext ;
8080import com .oracle .graal .python .runtime .object .PFactory ;
8181import com .oracle .graal .python .runtime .sequence .storage .ByteSequenceStorage ;
8282import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
@@ -107,13 +107,11 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
107107 }
108108
109109 abstract static class AsciiBufferConverter extends ArgumentCastNode {
110- @ Specialization (guards = "acquireLib.hasBuffer (value)" , limit = "getCallSiteInlineCacheMaxDepth() " )
110+ @ Specialization (guards = "checkBufferNode.execute (value)" , limit = "1 " )
111111 static Object doObject (VirtualFrame frame , Object value ,
112- @ Bind Node inliningTarget ,
113- @ Bind PythonContext context ,
114- @ Cached ("createFor($node)" ) InteropCallData callData ,
115- @ CachedLibrary ("value" ) PythonBufferAcquireLibrary acquireLib ) {
116- return acquireLib .acquireReadonly (value , frame , context , context .getLanguage (inliningTarget ), callData );
112+ @ Cached PyObjectCheckBuffer checkBufferNode ,
113+ @ Cached PyObjectGetBuffer getBuffer ) {
114+ return getBuffer .executeReadonly (frame , value );
117115 }
118116
119117 @ ExportLibrary (PythonBufferAccessLibrary .class )
@@ -193,14 +191,14 @@ public static AsciiBufferConverter create() {
193191 abstract static class A2bBase64Node extends PythonBinaryClinicBuiltinNode {
194192 @ Specialization (limit = "3" )
195193 PBytes doConvert (VirtualFrame frame , Object buffer , boolean strictMode ,
196- @ Cached ("createFor($node)" ) InteropCallData callData ,
197194 @ CachedLibrary ("buffer" ) PythonBufferAccessLibrary bufferLib ,
198- @ Bind PythonLanguage language ) {
195+ @ Bind PythonLanguage language ,
196+ @ Cached PyBufferRelease releaseBuffer ) {
199197 try {
200198 ByteSequenceStorage storage = b64decode (bufferLib .getInternalOrCopiedByteArray (buffer ), bufferLib .getBufferLength (buffer ), strictMode );
201199 return PFactory .createBytes (language , storage );
202200 } finally {
203- bufferLib . release ( buffer , frame , callData );
201+ releaseBuffer . execute ( frame , buffer );
204202 }
205203 }
206204
@@ -278,14 +276,14 @@ protected ArgumentClinicProvider getArgumentClinic() {
278276 abstract static class A2bHexNode extends PythonUnaryClinicBuiltinNode {
279277 @ Specialization (limit = "3" )
280278 PBytes a2b (VirtualFrame frame , Object buffer ,
281- @ Cached ("createFor($node)" ) InteropCallData callData ,
282279 @ CachedLibrary ("buffer" ) PythonBufferAccessLibrary bufferLib ,
283- @ Bind PythonLanguage language ) {
280+ @ Bind PythonLanguage language ,
281+ @ Cached PyBufferRelease releaseBuffer ) {
284282 try {
285283 byte [] bytes = a2b (bufferLib .getInternalOrCopiedByteArray (buffer ), bufferLib .getBufferLength (buffer ));
286284 return PFactory .createBytes (language , bytes );
287285 } finally {
288- bufferLib . release ( buffer , frame , callData );
286+ releaseBuffer . execute ( frame , buffer );
289287 }
290288 }
291289
@@ -342,13 +340,13 @@ private PBytes b2a(byte[] data, int lenght, boolean newline, PythonLanguage lang
342340
343341 @ Specialization (limit = "3" )
344342 PBytes b2aBuffer (VirtualFrame frame , Object buffer , boolean newline ,
345- @ Cached ("createFor($node)" ) InteropCallData callData ,
346343 @ CachedLibrary ("buffer" ) PythonBufferAccessLibrary bufferLib ,
347- @ Bind PythonLanguage language ) {
344+ @ Bind PythonLanguage language ,
345+ @ Cached PyBufferRelease releaseBuffer ) {
348346 try {
349347 return b2a (bufferLib .getInternalOrCopiedByteArray (buffer ), bufferLib .getBufferLength (buffer ), newline , language );
350348 } finally {
351- bufferLib . release ( buffer , frame , callData );
349+ releaseBuffer . execute ( frame , buffer );
352350 }
353351 }
354352
@@ -369,18 +367,18 @@ abstract static class B2aHexNode extends PythonTernaryClinicBuiltinNode {
369367 @ Specialization (limit = "3" )
370368 static PBytes b2a (VirtualFrame frame , Object buffer , Object sep , int bytesPerSep ,
371369 @ Bind Node inliningTarget ,
372- @ Cached ("createFor($node)" ) InteropCallData callData ,
373370 @ CachedLibrary ("buffer" ) PythonBufferAccessLibrary bufferLib ,
374371 @ Bind PythonLanguage language ,
375- @ Cached PRaiseNode raiseNode ) {
372+ @ Cached PRaiseNode raiseNode ,
373+ @ Cached PyBufferRelease releaseBuffer ) {
376374 if (sep != PNone .NO_VALUE || bytesPerSep != 1 ) {
377375 // TODO implement sep and bytes_per_sep
378376 throw raiseNode .raise (inliningTarget , NotImplementedError );
379377 }
380378 try {
381379 return b2a (bufferLib .getInternalOrCopiedByteArray (buffer ), bufferLib .getBufferLength (buffer ), language );
382380 } finally {
383- bufferLib . release ( buffer , frame , callData );
381+ releaseBuffer . execute ( frame , buffer );
384382 }
385383 }
386384
@@ -410,12 +408,12 @@ abstract static class Crc32Node extends PythonBinaryClinicBuiltinNode {
410408 @ Specialization (limit = "3" )
411409 static long b2a (VirtualFrame frame , Object buffer , long crc ,
412410 @ Bind Node inliningTarget ,
413- @ Cached ( "createFor($node) " ) InteropCallData callData ,
414- @ CachedLibrary ( "buffer" ) PythonBufferAccessLibrary bufferLib ) {
411+ @ CachedLibrary ( "buffer " ) PythonBufferAccessLibrary bufferLib ,
412+ @ Cached PyBufferRelease releaseBuffer ) {
415413 try {
416414 return crc32 (inliningTarget , (int ) crc , bufferLib .getInternalOrCopiedByteArray (buffer ), 0 , bufferLib .getBufferLength (buffer ));
417415 } finally {
418- bufferLib . release ( buffer , frame , callData );
416+ releaseBuffer . execute ( frame , buffer );
419417 }
420418 }
421419
@@ -434,12 +432,12 @@ abstract static class CrcHqxNode extends PythonBinaryClinicBuiltinNode {
434432 @ Specialization (limit = "3" )
435433 static long b2a (VirtualFrame frame , Object buffer , long crc ,
436434 @ Bind Node inliningTarget ,
437- @ Cached ( "createFor($node) " ) InteropCallData callData ,
438- @ CachedLibrary ( "buffer" ) PythonBufferAccessLibrary bufferLib ) {
435+ @ CachedLibrary ( "buffer " ) PythonBufferAccessLibrary bufferLib ,
436+ @ Cached PyBufferRelease releaseBuffer ) {
439437 try {
440438 return crcHqx (inliningTarget , (int ) crc , bufferLib .getInternalOrCopiedByteArray (buffer ), 0 , bufferLib .getBufferLength (buffer ));
441439 } finally {
442- bufferLib . release ( buffer , frame , callData );
440+ releaseBuffer . execute ( frame , buffer );
443441 }
444442 }
445443
0 commit comments