Skip to content

Commit cc885e8

Browse files
committed
Setup indirect call for PythonBufferAccessLibrary.release
1 parent b227d9f commit cc885e8

28 files changed

+168
-91
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BinasciiModuleBuiltins.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ public static AsciiBufferConverter create() {
157157
@GenerateNodeFactory
158158
abstract static class A2bBase64Node extends PythonUnaryClinicBuiltinNode {
159159
@Specialization(limit = "3")
160-
PBytes doConvert(Object buffer,
160+
PBytes doConvert(VirtualFrame frame, Object buffer,
161161
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib) {
162162
try {
163163
return b64decode(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer));
164164
} finally {
165-
bufferLib.release(buffer);
165+
bufferLib.release(buffer, frame, this);
166166
}
167167
}
168168

@@ -189,12 +189,12 @@ protected ArgumentClinicProvider getArgumentClinic() {
189189
@GenerateNodeFactory
190190
abstract static class A2bHexNode extends PythonUnaryClinicBuiltinNode {
191191
@Specialization(limit = "3")
192-
PBytes a2b(Object buffer,
192+
PBytes a2b(VirtualFrame frame, Object buffer,
193193
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib) {
194194
try {
195195
return a2b(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer));
196196
} finally {
197-
bufferLib.release(buffer);
197+
bufferLib.release(buffer, frame, this);
198198
}
199199
}
200200

@@ -250,12 +250,12 @@ private PBytes b2a(byte[] data, int lenght, int newline) {
250250
}
251251

252252
@Specialization(limit = "3")
253-
PBytes b2aBuffer(Object buffer, int newline,
253+
PBytes b2aBuffer(VirtualFrame frame, Object buffer, int newline,
254254
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib) {
255255
try {
256256
return b2a(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer), newline);
257257
} finally {
258-
bufferLib.release(buffer);
258+
bufferLib.release(buffer, frame, this);
259259
}
260260
}
261261

@@ -274,7 +274,7 @@ abstract static class B2aHexNode extends PythonTernaryClinicBuiltinNode {
274274
@CompilationFinal(dimensions = 1) private static final byte[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
275275

276276
@Specialization(limit = "3")
277-
PBytes b2a(Object buffer, Object sep, int bytesPerSep,
277+
PBytes b2a(VirtualFrame frame, Object buffer, Object sep, int bytesPerSep,
278278
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib) {
279279
if (sep != PNone.NO_VALUE || bytesPerSep != 1) {
280280
// TODO implement sep and bytes_per_sep
@@ -283,7 +283,7 @@ PBytes b2a(Object buffer, Object sep, int bytesPerSep,
283283
try {
284284
return b2a(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer));
285285
} finally {
286-
bufferLib.release(buffer);
286+
bufferLib.release(buffer, frame, this);
287287
}
288288
}
289289

@@ -311,12 +311,12 @@ protected ArgumentClinicProvider getArgumentClinic() {
311311
abstract static class Crc32Node extends PythonBinaryClinicBuiltinNode {
312312
// TODO crc != NO_VALUE
313313
@Specialization(guards = "isNoValue(crc)", limit = "3")
314-
static long b2a(Object buffer, @SuppressWarnings("unused") PNone crc,
314+
long b2a(VirtualFrame frame, Object buffer, @SuppressWarnings("unused") PNone crc,
315315
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib) {
316316
try {
317317
return getCrcValue(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer));
318318
} finally {
319-
bufferLib.release(buffer);
319+
bufferLib.release(buffer, frame, this);
320320
}
321321
}
322322

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,15 +1375,17 @@ Object fail(Object cls, Object arg, Object base) {
13751375
Object createIntGeneric(VirtualFrame frame, Object cls, Object obj, @SuppressWarnings("unused") PNone base,
13761376
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary bufferAcquireLib,
13771377
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib) {
1378-
// This method (together with callInt and callIndex) reflects the logic of PyNumber_Long
1379-
// in CPython. We don't use PythonObjectLibrary here since the original CPython function
1380-
// does not use any of the conversion functions (such as _PyLong_AsInt or
1381-
// PyNumber_Index) either, but it reimplements the logic in a slightly different way
1382-
// (e.g. trying __int__ before __index__ whereas _PyLong_AsInt does it the other way)
1383-
// and also with specific exception messages which are expected by Python unittests.
1384-
// This unfortunately means that this method relies on the internal logic of NO_VALUE
1385-
// return values representing missing magic methods which should be ideally hidden
1386-
// by PythonObjectLibrary.
1378+
/*
1379+
* This method (together with callInt and callIndex) reflects the logic of PyNumber_Long
1380+
* in CPython. We don't use PythonObjectLibrary here since the original CPython function
1381+
* does not use any of the conversion functions (such as _PyLong_AsInt or
1382+
* PyNumber_Index) either, but it reimplements the logic in a slightly different way
1383+
* (e.g. trying __int__ before __index__ whereas _PyLong_AsInt does it the other way)
1384+
* and also with specific exception messages which are expected by Python unittests.
1385+
* This unfortunately means that this method relies on the internal logic of NO_VALUE
1386+
* return values representing missing magic methods which should be ideally hidden by
1387+
* PythonObjectLibrary.
1388+
*/
13871389
Object result = callInt(frame, obj);
13881390
if (result == PNone.NO_VALUE) {
13891391
result = callIndex(frame, obj);
@@ -1400,7 +1402,7 @@ Object createIntGeneric(VirtualFrame frame, Object cls, Object obj, @SuppressWar
14001402
String number = PythonUtils.newString(bufferLib.getInternalOrCopiedByteArray(buffer), 0, bufferLib.getBufferLength(buffer));
14011403
return stringToInt(frame, cls, number, 10, obj);
14021404
} finally {
1403-
bufferLib.release(buffer);
1405+
bufferLib.release(buffer, frame, this);
14041406
}
14051407
}
14061408
if (isIntegerType(truncResult)) {
@@ -1903,7 +1905,7 @@ Object doBuffer(VirtualFrame frame, Object strClass, Object obj, Object encoding
19031905
Object en = encoding == PNone.NO_VALUE ? "utf-8" : encoding;
19041906
return decodeBytes(frame, strClass, bytesObj, en, errors);
19051907
} finally {
1906-
bufferLib.release(buffer);
1908+
bufferLib.release(buffer, frame, this);
19071909
}
19081910
}
19091911

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ PCode generic(VirtualFrame frame, Object wSource, Object wFilename, Object wMode
854854
warnNode.warnFormat(frame, null, DeprecationWarning, 1, ErrorMessages.PATH_SHOULD_BE_STR_BYTES_PATHLIKE_NOT_P, wFilename);
855855
}
856856
} finally {
857-
bufferLib.release(filenameBuffer);
857+
bufferLib.release(filenameBuffer, frame, this);
858858
}
859859
} else {
860860
filename = asPath.execute(frame, wFilename);
@@ -942,8 +942,7 @@ String sourceAsString(VirtualFrame frame, Object source, String filename, Intero
942942
} catch (PythonFileDetector.InvalidEncodingException e) {
943943
throw raiseInvalidSyntax(filename, "encoding problem: %s", e.getEncodingName());
944944
} finally {
945-
bufferLib.release(buffer);
946-
945+
bufferLib.release(buffer, frame, this);
947946
}
948947
}
949948
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsModuleBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,13 @@ public final Object execute(@SuppressWarnings("unused") VirtualFrame frame, byte
638638
}
639639

640640
@Specialization(limit = "3")
641-
Object decode(Object buffer, String errors,
641+
Object decode(VirtualFrame frame, Object buffer, String errors,
642642
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib) {
643643
try {
644644
int len = bufferLib.getBufferLength(buffer);
645645
return decodeBytes(bufferLib.getInternalOrCopiedByteArray(buffer), len, errors);
646646
} finally {
647-
bufferLib.release(buffer);
647+
bufferLib.release(buffer, frame, this);
648648
}
649649
}
650650

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/JavaModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ Object doBuffer(VirtualFrame frame, Object object,
300300
try {
301301
return new InteropByteArray(bufferLib.getCopiedByteArray(object));
302302
} finally {
303-
bufferLib.release(buffer);
303+
bufferLib.release(buffer, frame, this);
304304
}
305305
}
306306
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ long doWrite(VirtualFrame frame, int fd, Object dataBuffer,
618618
errorProfile.enter();
619619
throw raiseOSErrorFromPosixException(frame, e);
620620
} finally {
621-
bufferLib.release(dataBuffer);
621+
bufferLib.release(dataBuffer, frame, this);
622622
}
623623
}
624624

@@ -2537,7 +2537,7 @@ PosixFileHandle doBuffer(VirtualFrame frame, Object value,
25372537
ErrorMessages.S_S_SHOULD_BE_S_NOT_P, functionNameWithColon, argumentName, getAllowedTypes(), value);
25382538
return new PosixPath(value, checkPath(posixLib.createPathFromBytes(getPosixSupport(), bufferLib.getCopiedByteArray(value))), true);
25392539
} finally {
2540-
bufferLib.release(buffer);
2540+
bufferLib.release(buffer, frame, getContext(), getLanguage(), this);
25412541
}
25422542
}
25432543

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ protected Source doGeneric(VirtualFrame frame, Object pattern, String flags,
146146
String patternStr = decodeLatin1(bytes, bytesLen);
147147
return constructRegexSource(options, patternStr, flags);
148148
} finally {
149-
bufferLib.release(buffer);
149+
bufferLib.release(buffer, frame, this);
150150
}
151151
}
152152
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SocketModuleBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ String doGeneric(VirtualFrame frame, Object addr,
736736
Object result = posixLib.inet_ntoa(getPosixSupport(), ByteArraySupport.bigEndian().getInt(bytes, 0));
737737
return posixLib.getPathAsString(getPosixSupport(), result);
738738
} finally {
739-
bufferLib.release(buffer);
739+
bufferLib.release(buffer, frame, this);
740740
}
741741
}
742742
}
@@ -796,7 +796,7 @@ String doGeneric(VirtualFrame frame, int family, Object obj,
796796
throw raiseOSErrorFromPosixException(frame, e);
797797
}
798798
} finally {
799-
bufferLib.release(buffer);
799+
bufferLib.release(buffer, frame, this);
800800
}
801801
}
802802

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOBaseBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Object readinto(VirtualFrame frame, Object self, Object buffer,
154154
bufferLib.readIntoBuffer(data, 0, buffer, 0, dataLen, bufferLib);
155155
return dataLen;
156156
} finally {
157-
bufferLib.release(buffer);
157+
bufferLib.release(buffer, frame, this);
158158
}
159159
}
160160

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedReaderMixinBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ Object bufferedReadintoGeneric(VirtualFrame frame, PBuffered self, Object buffer
572572
return written;
573573
} finally {
574574
BufferedIONodes.EnterBufferedNode.leave(self);
575-
bufferLib.release(buffer);
575+
bufferLib.release(buffer, frame, this);
576576
}
577577
}
578578

0 commit comments

Comments
 (0)