Skip to content

Commit 201fcff

Browse files
committed
Migrate ToByteArray users
1 parent 46249dc commit 201fcff

18 files changed

+131
-109
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ PBytes doCallBytes(VirtualFrame frame, Object cls, Object source, PNone encoding
325325
if (cls == PythonBuiltinClassType.PBytes) {
326326
return (PBytes) bytes;
327327
} else {
328-
return factory().createBytes(cls, toBytesNode.execute(bytes));
328+
return factory().createBytes(cls, toBytesNode.execute(frame, bytes));
329329
}
330330
} else {
331331
throw raise(TypeError, ErrorMessages.RETURNED_NONBYTES, __BYTES__, bytes);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Object doSequence(VirtualFrame frame, Object env,
165165
Object[] result = new Object[length];
166166
for (int i = 0; i < length; ++i) {
167167
Object o = getItem.execute(frame, env, i);
168-
byte[] bytes = toBytesNode.execute(o);
168+
byte[] bytes = toBytesNode.execute(frame, o);
169169
Object o1 = posixLib.createPathFromBytes(getContext().getPosixSupport(), bytes);
170170
if (o1 == null) {
171171
throw raise(ValueError, ErrorMessages.EMBEDDED_NULL_BYTE);
@@ -249,7 +249,7 @@ int forkExec(VirtualFrame frame, Object[] args, Object executableList, boolean c
249249
int length = sizeNode.execute(frame, executableList);
250250
Object[] executables = new Object[length];
251251
for (int i = 0; i < length; ++i) {
252-
byte[] bytes = toBytesNode.execute(getItem.execute(frame, executableList, i));
252+
byte[] bytes = toBytesNode.execute(frame, getItem.execute(frame, executableList, i));
253253
if (Arrays.equals(bytes, sysExecutable)) {
254254
if (length != 1) {
255255
throw raise(ValueError, ErrorMessages.UNSUPPORTED_USE_OF_SYS_EXECUTABLE);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,11 +2202,11 @@ abstract static class PyBytes_FromStringAndSize extends NativeBuiltin {
22022202
// PythonNativeObject)
22032203

22042204
@Specialization
2205-
Object doGeneric(@SuppressWarnings("unused") Object module, PythonNativeWrapper object, long size,
2205+
Object doGeneric(VirtualFrame frame, @SuppressWarnings("unused") Object module, PythonNativeWrapper object, long size,
22062206
@Cached AsPythonObjectNode asPythonObjectNode,
22072207
@Exclusive @Cached BytesNodes.ToBytesNode getByteArrayNode,
22082208
@Shared("toSulongNode") @Cached CExtNodes.ToSulongNode toSulongNode) {
2209-
byte[] ary = getByteArrayNode.execute(asPythonObjectNode.execute(object));
2209+
byte[] ary = getByteArrayNode.execute(frame, asPythonObjectNode.execute(object));
22102210
PBytes result;
22112211
if (size >= 0 && size < ary.length) {
22122212
// cast to int is guaranteed because of 'size < ary.length'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ Object getAddrInfo(VirtualFrame frame, Object hostObject, Object portObject, int
589589
} else if (PGuards.isString(portObjectProfiled)) {
590590
port = posixLib.createPathFromString(getPosixSupport(), castToString.execute(portObjectProfiled));
591591
} else if (PGuards.isBytes(portObjectProfiled)) {
592-
port = posixLib.createPathFromBytes(getPosixSupport(), toBytes.execute(portObjectProfiled));
592+
port = posixLib.createPathFromBytes(getPosixSupport(), toBytes.execute(frame, portObjectProfiled));
593593
} else if (portObject == PNone.NONE) {
594594
port = null;
595595
} else {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2CompressorBuiltins.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
7777
import com.oracle.truffle.api.dsl.NodeFactory;
7878
import com.oracle.truffle.api.dsl.Specialization;
79+
import com.oracle.truffle.api.frame.VirtualFrame;
7980
import com.oracle.truffle.api.profiles.ConditionProfile;
8081

8182
@CoreFunctions(extendClasses = BZ2Compressor)
@@ -138,10 +139,10 @@ PBytes doNativeBytes(BZ2Object.BZ2Compressor self, PBytesLike data,
138139
}
139140

140141
@Specialization(guards = {"!self.isFlushed()"})
141-
PBytes doNativeObject(BZ2Object.BZ2Compressor self, Object data,
142-
@Cached BytesNodes.ToBytesNode toBytes,
143-
@Shared("c") @Cached Bz2Nodes.Bz2NativeCompress compress) {
144-
byte[] bytes = toBytes.execute(data);
142+
PBytes doNativeObject(VirtualFrame frame, BZ2Object.BZ2Compressor self, Object data,
143+
@Cached BytesNodes.ToBytesNode toBytes,
144+
@Shared("c") @Cached Bz2Nodes.Bz2NativeCompress compress) {
145+
byte[] bytes = toBytes.execute(frame, data);
145146
int len = bytes.length;
146147
return factory().createBytes(compress.compress(self, PythonContext.get(this), bytes, len));
147148
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/bz2/BZ2DecompressorBuiltins.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
7171
import com.oracle.truffle.api.dsl.NodeFactory;
7272
import com.oracle.truffle.api.dsl.Specialization;
73+
import com.oracle.truffle.api.frame.VirtualFrame;
7374
import com.oracle.truffle.api.profiles.ConditionProfile;
7475

7576
@CoreFunctions(extendClasses = BZ2Decompressor)
@@ -122,11 +123,11 @@ PBytes doNativeBytes(BZ2Object.BZ2Decompressor self, PBytesLike data, int maxLen
122123
}
123124

124125
@Specialization(guards = {"!self.isEOF()"})
125-
PBytes doNativeObject(BZ2Object.BZ2Decompressor self, Object data, int maxLength,
126-
@Cached BytesNodes.ToBytesNode toBytes,
127-
@Shared("d") @Cached Bz2Nodes.Bz2NativeDecompress decompress) {
126+
PBytes doNativeObject(VirtualFrame frame, BZ2Object.BZ2Decompressor self, Object data, int maxLength,
127+
@Cached BytesNodes.ToBytesNode toBytes,
128+
@Shared("d") @Cached Bz2Nodes.Bz2NativeDecompress decompress) {
128129
synchronized (self) {
129-
byte[] bytes = toBytes.execute(data);
130+
byte[] bytes = toBytes.execute(frame, data);
130131
int len = bytes.length;
131132
return factory().createBytes(decompress.execute(self, bytes, len, maxLength));
132133
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CFieldBuiltins.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import com.oracle.graal.python.builtins.objects.PNone;
7070
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes.ToBytesNode;
7171
import com.oracle.graal.python.builtins.objects.bytes.BytesUtils;
72+
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
7273
import com.oracle.graal.python.builtins.objects.bytes.PBytesLike;
7374
import com.oracle.graal.python.builtins.objects.cext.PythonNativeVoidPtr;
7475
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.GetInternalByteArrayNode;
@@ -626,7 +627,7 @@ Object s_set(@SuppressWarnings("unused") FieldSet setfunc, PtrValue ptr, Object
626627
throw raise(TypeError, "expected bytes, %s found", getNameNode.execute(getClassNode.execute(value)));
627628
}
628629

629-
data = getBytes.execute(value); // a copy is expected.. no need for memcpy
630+
data = getBytes.execute((PBytes) value); // a copy is expected.. no need for memcpy
630631
size = data.length; /* XXX Why not Py_SIZE(value)? */
631632
if (size < length) {
632633
/*
@@ -643,7 +644,7 @@ Object s_set(@SuppressWarnings("unused") FieldSet setfunc, PtrValue ptr, Object
643644
}
644645

645646
@Specialization(guards = "setfunc == z_set")
646-
Object z_set(@SuppressWarnings("unused") FieldSet setfunc, PtrValue ptr, Object value, @SuppressWarnings("unused") int size,
647+
Object z_set(VirtualFrame frame, @SuppressWarnings("unused") FieldSet setfunc, PtrValue ptr, Object value, @SuppressWarnings("unused") int size,
647648
@Cached GetNameNode getNameNode,
648649
@Cached GetClassNode getClassNode,
649650
@Cached PyLongCheckNode longCheckNode,
@@ -653,10 +654,10 @@ Object z_set(@SuppressWarnings("unused") FieldSet setfunc, PtrValue ptr, Object
653654
return value;
654655
}
655656
if (PGuards.isPBytes(value)) {
656-
ptr.writeBytesArrayElement(getBytes.execute(value));
657+
ptr.writeBytesArrayElement(getBytes.execute((PBytes) value));
657658
return value;
658659
} else if (value instanceof PythonNativeVoidPtr) {
659-
ptr.writeBytesArrayElement(getBytes.execute(((PythonNativeVoidPtr) value).getPointerObject()));
660+
ptr.writeBytesArrayElement(getBytes.execute(frame, ((PythonNativeVoidPtr) value).getPointerObject()));
660661
return PNone.NONE;
661662
} else if (longCheckNode.execute(value)) {
662663
// *(char **)ptr = (char *)PyLong_AsUnsignedLongMask(value);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ Object write(VirtualFrame frame, PFileIO self, Object data,
675675
@Shared("e") @Cached BranchProfile errorProfile,
676676
@Shared("g") @Cached GilNode gil) {
677677
try {
678-
return posixWrite.write(self.getFD(), toBytes.execute(data), toBytes.execute(data).length, posixLib, errorProfile, gil);
678+
return posixWrite.write(self.getFD(), toBytes.execute(frame, data), toBytes.execute(frame, data).length, posixLib, errorProfile, gil);
679679
} catch (PosixSupportLibrary.PosixException e) {
680680
if (e.getErrorCode() == EAGAIN.getNumber()) {
681681
return PNone.NONE;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMACompressorBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ PBytes doBytes(LZMACompressor self, PBytesLike data,
173173
}
174174

175175
@Specialization(guards = {"!self.isFlushed()"})
176-
PBytes doObject(LZMACompressor self, Object data,
176+
PBytes doObject(VirtualFrame frame, LZMACompressor self, Object data,
177177
@Cached BytesNodes.ToBytesNode toBytes,
178178
@Shared("c") @Cached LZMANodes.CompressNode compress) {
179-
byte[] bytes = toBytes.execute(data);
179+
byte[] bytes = toBytes.execute(frame, data);
180180
int len = bytes.length;
181181
return factory().createBytes(compress.compress(self, PythonContext.get(this), bytes, len));
182182
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMADecompressorBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@ PBytes doBytes(LZMADecompressor self, PBytesLike data, int maxLength,
202202
}
203203

204204
@Specialization(guards = {"!self.isEOF()"})
205-
PBytes doObject(LZMADecompressor self, Object data, int maxLength,
205+
PBytes doObject(VirtualFrame frame, LZMADecompressor self, Object data, int maxLength,
206206
@Cached BytesNodes.ToBytesNode toBytes,
207207
@Shared("d") @Cached LZMANodes.DecompressNode decompress) {
208-
byte[] bytes = toBytes.execute(data);
208+
byte[] bytes = toBytes.execute(frame, data);
209209
int len = bytes.length;
210210
return factory().createBytes(decompress.execute(self, bytes, len, maxLength));
211211
}

0 commit comments

Comments
 (0)