Skip to content

Commit a0ab80a

Browse files
committed
Use POL buffer messages in bytes builtins
1 parent 5681c6c commit a0ab80a

File tree

12 files changed

+217
-233
lines changed

12 files changed

+217
-233
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public PBytes hasBytesAttr(VirtualFrame frame, Object cls, Object source, @Suppr
304304
if (isBytes.profile(bytes instanceof PBytes && isClassProfile.profileIsAnyBuiltinClass(cls))) {
305305
return (PBytes) bytes;
306306
}
307-
return factory().createBytes(cls, toBytesNode.execute(frame, bytes));
307+
return factory().createBytes(cls, toBytesNode.execute(bytes));
308308
}
309309

310310
@Specialization(guards = {"!isNone(source)", "!canUseByteAttr(frame, source, lib, encoding, errors)"}, limit = "3")
@@ -899,7 +899,7 @@ Object floatFromString(VirtualFrame frame, Object cls, String arg) {
899899
}
900900

901901
private double convertBytesToDouble(VirtualFrame frame, PBytesLike arg) {
902-
return convertStringToDouble(frame, PythonUtils.newString(getByteArray(frame, arg)), arg);
902+
return convertStringToDouble(frame, PythonUtils.newString(getByteArray(arg)), arg);
903903
}
904904

905905
private double convertStringToDouble(VirtualFrame frame, String src, Object origObj) {
@@ -1026,12 +1026,12 @@ protected static boolean isSubtypeOfFloat(VirtualFrame frame, IsSubtypeNode isSu
10261026
return isSubtypeNode.execute(frame, cls, PythonBuiltinClassType.PFloat);
10271027
}
10281028

1029-
private byte[] getByteArray(VirtualFrame frame, PBytesLike pByteArray) {
1029+
private byte[] getByteArray(PBytesLike pByteArray) {
10301030
if (toByteArrayNode == null) {
10311031
CompilerDirectives.transferToInterpreterAndInvalidate();
10321032
toByteArrayNode = insert(BytesNodes.ToBytesNode.create());
10331033
}
1034-
return toByteArrayNode.execute(frame, pByteArray);
1034+
return toByteArrayNode.execute(pByteArray);
10351035
}
10361036
}
10371037

@@ -1365,7 +1365,7 @@ Object createIntError(VirtualFrame frame, Object cls, String number, Object base
13651365
@Specialization
13661366
Object parseBytesError(VirtualFrame frame, Object cls, PBytesLike arg, int base) {
13671367
checkBase(base);
1368-
return stringToInt(frame, cls, toString(frame, arg), base, arg);
1368+
return stringToInt(frame, cls, toString(arg), base, arg);
13691369
}
13701370

13711371
@Specialization(guards = "isNoValue(base)")
@@ -1517,12 +1517,12 @@ private Object callTrunc(VirtualFrame frame, Object obj) {
15171517
return callTruncNode.executeObject(frame, obj);
15181518
}
15191519

1520-
private String toString(VirtualFrame frame, PBytesLike pByteArray) {
1520+
private String toString(PBytesLike pByteArray) {
15211521
if (toByteArrayNode == null) {
15221522
CompilerDirectives.transferToInterpreterAndInvalidate();
15231523
toByteArrayNode = insert(BytesNodes.ToBytesNode.create());
15241524
}
1525-
return toString(toByteArrayNode.execute(frame, pByteArray));
1525+
return toString(toByteArrayNode.execute(pByteArray));
15261526
}
15271527

15281528
@TruffleBoundary

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ Object doExecuteInternal(PythonModule thisModule, String path, PSequence args) t
357357
ProcessBuilder builder = new ProcessBuilder(cmd);
358358
Map<String, String> environment = builder.environment();
359359
environ.entries().forEach(entry -> {
360-
environment.put(new String(toBytes.execute(null, entry.key)), new String(toBytes.execute(null, entry.value)));
360+
environment.put(new String(toBytes.execute(entry.key)), new String(toBytes.execute(entry.value)));
361361
});
362362
Process pr = builder.start();
363363
BufferedReader bfr = new BufferedReader(new InputStreamReader(pr.getInputStream()));

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,10 +1361,10 @@ byte[] doCArrayWrapper(CByteArrayWrapper o, long n,
13611361
}
13621362

13631363
@Specialization(limit = "1")
1364-
byte[] doSequenceArrayWrapper(VirtualFrame frame, PySequenceArrayWrapper obj, long n,
1364+
byte[] doSequenceArrayWrapper(PySequenceArrayWrapper obj, long n,
13651365
@CachedLibrary(value = "obj") PythonNativeWrapperLibrary lib,
13661366
@Cached BytesNodes.ToBytesNode toBytesNode) {
1367-
return subRangeIfNeeded(toBytesNode.execute(frame, lib.getDelegate(obj)), n);
1367+
return subRangeIfNeeded(toBytesNode.execute(lib.getDelegate(obj)), n);
13681368
}
13691369

13701370
@Specialization(limit = "5")
@@ -2638,11 +2638,11 @@ abstract static class PyBytes_FromStringAndSize extends NativeBuiltin {
26382638
// PythonNativeObject)
26392639

26402640
@Specialization
2641-
Object doGeneric(VirtualFrame frame, @SuppressWarnings("unused") Object module, PythonNativeWrapper object, long size,
2641+
Object doGeneric(@SuppressWarnings("unused") Object module, PythonNativeWrapper object, long size,
26422642
@Cached AsPythonObjectNode asPythonObjectNode,
26432643
@Exclusive @Cached BytesNodes.ToBytesNode getByteArrayNode,
26442644
@Shared("toSulongNode") @Cached CExtNodes.ToSulongNode toSulongNode) {
2645-
byte[] ary = getByteArrayNode.execute(frame, asPythonObjectNode.execute(object));
2645+
byte[] ary = getByteArrayNode.execute(asPythonObjectNode.execute(object));
26462646
PBytes result;
26472647
if (size >= 0 && size < ary.length) {
26482648
// cast to int is guaranteed because of 'size < ary.length'

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import com.oracle.graal.python.builtins.CoreFunctions;
5252
import com.oracle.graal.python.builtins.PythonBuiltins;
5353
import com.oracle.graal.python.builtins.objects.PNone;
54-
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
5554
import com.oracle.graal.python.builtins.objects.bytes.BytesUtils;
5655
import com.oracle.graal.python.builtins.objects.bytes.PBytesLike;
5756
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
@@ -133,7 +132,6 @@ Object run(String code,
133132
abstract static class ProcessEscapeSequences extends PythonUnaryBuiltinNode {
134133

135134
@Child private SequenceStorageNodes.ToByteArrayNode toByteArrayNode;
136-
@Child private BytesNodes.ToBytesNode toBytesNode;
137135

138136
@Specialization
139137
Object run(PString str) {
@@ -196,14 +194,6 @@ private SequenceStorageNodes.ToByteArrayNode getToByteArrayNode() {
196194
}
197195
return toByteArrayNode;
198196
}
199-
200-
private BytesNodes.ToBytesNode getToBytesNode() {
201-
if (toBytesNode == null) {
202-
CompilerDirectives.transferToInterpreterAndInvalidate();
203-
toBytesNode = insert(BytesNodes.ToBytesNode.create());
204-
}
205-
return toBytesNode;
206-
}
207197
}
208198

209199
@Builtin(name = "tregex_call_compile", minNumOfPositionalArgs = 3)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,9 @@ private static long parseUnsigned(String valueIn) throws NumberFormatException {
760760
@GenerateNodeFactory
761761
abstract static class InetNtoANode extends PythonUnaryBuiltinNode {
762762
@Specialization
763-
String doGeneric(VirtualFrame frame, Object obj,
763+
String doGeneric(Object obj,
764764
@Cached("createToBytes()") BytesNodes.ToBytesNode toBytesNode) {
765-
return ntoa(toBytesNode.execute(frame, obj));
765+
return ntoa(toBytesNode.execute(obj));
766766
}
767767

768768
@TruffleBoundary
@@ -776,7 +776,7 @@ private String ntoa(byte[] bytes) {
776776
}
777777

778778
static BytesNodes.ToBytesNode createToBytes() {
779-
return BytesNodes.ToBytesNode.create(true, PythonBuiltinClassType.TypeError, "a bytes-like object is required, not '%p'");
779+
return BytesNodes.ToBytesNode.create(PythonBuiltinClassType.TypeError, "a bytes-like object is required, not '%p'");
780780
}
781781
}
782782

@@ -822,9 +822,9 @@ PBytes doError(@SuppressWarnings("unused") Object addrFamily, Object obj) {
822822
@GenerateNodeFactory
823823
abstract static class InetNtoPNode extends PythonBinaryBuiltinNode {
824824
@Specialization
825-
String doGeneric(VirtualFrame frame, int addrFamily, Object obj,
825+
String doGeneric(int addrFamily, Object obj,
826826
@Cached("createToBytes()") BytesNodes.ToBytesNode toBytesNode) {
827-
return ntoa(addrFamily, toBytesNode.execute(frame, obj));
827+
return ntoa(addrFamily, toBytesNode.execute(obj));
828828
}
829829

830830
@TruffleBoundary
@@ -848,7 +848,7 @@ private String ntoa(int addrFamily, byte[] bytes) {
848848
}
849849

850850
static BytesNodes.ToBytesNode createToBytes() {
851-
return BytesNodes.ToBytesNode.create(true, PythonBuiltinClassType.TypeError, "a bytes-like object is required, not '%p'");
851+
return BytesNodes.ToBytesNode.create(PythonBuiltinClassType.TypeError, "a bytes-like object is required, not '%p'");
852852
}
853853
}
854854

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ private static int computeCRC32(byte[] bytes, int value) {
222222
}
223223

224224
@Specialization
225-
public long doitNone(VirtualFrame frame, Object data, @SuppressWarnings("unused") PNone value,
225+
static long doitNone(Object data, @SuppressWarnings("unused") PNone value,
226226
@Cached ToBytesNode toBytesNode) {
227-
return doCRC32(toBytesNode.execute(frame, data));
227+
return doCRC32(toBytesNode.execute(data));
228228
}
229229

230230
@TruffleBoundary
@@ -235,20 +235,20 @@ private static long doCRC32(byte[] data) {
235235
}
236236

237237
@Specialization
238-
public long doitLong(VirtualFrame frame, Object data, long value,
238+
static long doitLong(Object data, long value,
239239
@Cached ToBytesNode toBytesNode) {
240240
// lost magnitude is ok here.
241241
int initValue = (int) value;
242-
byte[] array = toBytesNode.execute(frame, data);
242+
byte[] array = toBytesNode.execute(data);
243243
return computeCRC32(array, initValue) & 0xFFFFFFFFL;
244244
}
245245

246246
@Specialization
247-
public long doPInt(VirtualFrame frame, Object data, PInt value,
247+
static long doPInt(Object data, PInt value,
248248
@Cached ToBytesNode toBytesNode) {
249249
// lost magnitude is ok here.
250250
int initValue = value.intValue();
251-
byte[] array = toBytesNode.execute(frame, data);
251+
byte[] array = toBytesNode.execute(data);
252252
return computeCRC32(array, initValue) & 0xFFFFFFFFL;
253253
}
254254

@@ -303,26 +303,26 @@ private static long doAdler32(byte[] data) {
303303
}
304304

305305
@Specialization
306-
public long doitNone(VirtualFrame frame, Object data, @SuppressWarnings("unused") PNone value,
306+
static long doitNone(Object data, @SuppressWarnings("unused") PNone value,
307307
@Cached ToBytesNode toBytesNode) {
308-
return doAdler32(toBytesNode.execute(frame, data));
308+
return doAdler32(toBytesNode.execute(data));
309309
}
310310

311311
@Specialization
312-
public long doitLong(VirtualFrame frame, Object data, long value,
312+
static long doitLong(Object data, long value,
313313
@Cached ToBytesNode toBytesNode) {
314314
// lost magnitude is ok here.
315315
int initValue = (int) value;
316-
byte[] array = toBytesNode.execute(frame, data);
316+
byte[] array = toBytesNode.execute(data);
317317
return computeAdler32(array, initValue) & 0xFFFFFFFFL;
318318
}
319319

320320
@Specialization
321-
public long doPInt(VirtualFrame frame, Object data, PInt value,
321+
static long doPInt(Object data, PInt value,
322322
@Cached ToBytesNode toBytesNode) {
323323
// lost magnitude is ok here.
324324
int initValue = value.intValue();
325-
byte[] array = toBytesNode.execute(frame, data);
325+
byte[] array = toBytesNode.execute(data);
326326
return computeAdler32(array, initValue) & 0xFFFFFFFFL;
327327
}
328328

@@ -390,8 +390,8 @@ abstract static class DeflateCompress extends PythonTernaryBuiltinNode {
390390
@Child private ToBytesNode toBytes = ToBytesNode.create();
391391

392392
@Specialization
393-
Object deflateCompress(VirtualFrame frame, DeflaterWrapper stream, Object pb, int mode) {
394-
byte[] data = toBytes.execute(frame, pb);
393+
Object deflateCompress(DeflaterWrapper stream, Object pb, int mode) {
394+
byte[] data = toBytes.execute(pb);
395395
byte[] result = new byte[DEF_BUF_SIZE];
396396
return factory().createBytes(deflate(stream, mode, data, result));
397397
}
@@ -425,8 +425,8 @@ abstract static class InflateInitNode extends PythonBinaryBuiltinNode {
425425
@Child private ToBytesNode toBytes = ToBytesNode.create();
426426

427427
@Specialization
428-
Object init(VirtualFrame frame, int wbits, PBytes zdict) {
429-
byte[] bytes = toBytes.execute(frame, zdict);
428+
Object init(int wbits, PBytes zdict) {
429+
byte[] bytes = toBytes.execute(zdict);
430430
return new InflaterWrapper(inflate(wbits, bytes));
431431
}
432432

@@ -473,11 +473,11 @@ abstract static class InflaterDecompress extends PythonTernaryBuiltinNode {
473473
@Child private ToBytesNode toBytes = ToBytesNode.create();
474474

475475
@Specialization
476-
Object decompress(VirtualFrame frame, InflaterWrapper stream, PBytesLike pb, int maxLen) {
476+
Object decompress(InflaterWrapper stream, PBytesLike pb, int maxLen) {
477477
int maxLength = maxLen == 0 ? Integer.MAX_VALUE : maxLen;
478478

479479
ByteArrayOutputStream baos = new ByteArrayOutputStream();
480-
byte[] data = toBytes.execute(frame, pb);
480+
byte[] data = toBytes.execute(pb);
481481
byte[] result = new byte[Math.min(maxLen, DEF_BUF_SIZE)];
482482
byte[] decompressed = decompress(stream, maxLength, baos, data, result);
483483

@@ -489,9 +489,9 @@ Object decompress(VirtualFrame frame, InflaterWrapper stream, PBytesLike pb, int
489489
}
490490

491491
@Specialization
492-
Object decompress(VirtualFrame frame, InflaterWrapper stream, PBytesLike pb, long maxLen,
492+
Object decompress(InflaterWrapper stream, PBytesLike pb, long maxLen,
493493
@Cached CastToJavaIntExactNode castInt) {
494-
return decompress(frame, stream, pb, castInt.execute(maxLen));
494+
return decompress(stream, pb, castInt.execute(maxLen));
495495
}
496496

497497
@TruffleBoundary

0 commit comments

Comments
 (0)