Skip to content

Commit e5f1ff2

Browse files
committed
Minor cleanups
1 parent cc885e8 commit e5f1ff2

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentCastNode.ArgumentCastNodeWithRaiseAndIndirectCall;
7272
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
7373
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
74+
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
7475
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
7576
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
7677
import com.oracle.truffle.api.dsl.Cached;
@@ -160,21 +161,22 @@ abstract static class A2bBase64Node extends PythonUnaryClinicBuiltinNode {
160161
PBytes doConvert(VirtualFrame frame, Object buffer,
161162
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib) {
162163
try {
163-
return b64decode(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer));
164+
ByteSequenceStorage storage = b64decode(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer));
165+
return factory().createBytes(storage);
164166
} finally {
165167
bufferLib.release(buffer, frame, this);
166168
}
167169
}
168170

169171
@TruffleBoundary
170-
private PBytes b64decode(byte[] data, int dataLen) {
172+
private ByteSequenceStorage b64decode(byte[] data, int dataLen) {
171173
try {
172174
// Using MIME decoder because that one skips over anything that is not the alphabet,
173175
// just like CPython does
174176
ByteBuffer result = Base64.getMimeDecoder().decode(ByteBuffer.wrap(data, 0, dataLen));
175-
return factory().createBytes(result.array(), result.limit());
177+
return new ByteSequenceStorage(result.array(), result.limit());
176178
} catch (IllegalArgumentException e) {
177-
throw raise(BinasciiError, e);
179+
throw PRaiseNode.raiseUncached(this, BinasciiError, e);
178180
}
179181
}
180182

@@ -192,22 +194,23 @@ abstract static class A2bHexNode extends PythonUnaryClinicBuiltinNode {
192194
PBytes a2b(VirtualFrame frame, Object buffer,
193195
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib) {
194196
try {
195-
return a2b(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer));
197+
byte[] bytes = a2b(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer));
198+
return factory().createBytes(bytes);
196199
} finally {
197200
bufferLib.release(buffer, frame, this);
198201
}
199202
}
200203

201204
@TruffleBoundary
202-
private PBytes a2b(byte[] bytes, int length) {
205+
private byte[] a2b(byte[] bytes, int length) {
203206
if (length % 2 != 0) {
204-
throw raise(BinasciiError, ErrorMessages.ODD_LENGTH_STRING);
207+
throw PRaiseNode.raiseUncached(this, BinasciiError, ErrorMessages.ODD_LENGTH_STRING);
205208
}
206209
byte[] output = new byte[length / 2];
207210
for (int i = 0; i < length / 2; i++) {
208211
output[i] = (byte) (digitValue((char) bytes[i * 2]) * 16 + digitValue((char) bytes[i * 2 + 1]));
209212
}
210-
return factory().createBytes(output);
213+
return output;
211214
}
212215

213216
private int digitValue(char b) {
@@ -218,7 +221,7 @@ private int digitValue(char b) {
218221
} else if (b >= 'A' && b <= 'F') {
219222
return b - 'A' + 10;
220223
} else {
221-
throw raise(BinasciiError, ErrorMessages.NON_HEX_DIGIT_FOUND);
224+
throw PRaiseNode.raiseUncached(this, BinasciiError, ErrorMessages.NON_HEX_DIGIT_FOUND);
222225
}
223226
}
224227

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import com.oracle.graal.python.lib.PyObjectLookupAttr;
8383
import com.oracle.graal.python.lib.PyObjectRichCompareBool;
8484
import com.oracle.graal.python.lib.PyObjectSizeNode;
85+
import com.oracle.graal.python.nodes.PRaiseNode;
8586
import com.oracle.graal.python.nodes.builtins.ListNodes;
8687
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
8788
import com.oracle.graal.python.nodes.control.GetNextNode;
@@ -943,7 +944,7 @@ Object frombytes(VirtualFrame frame, PArray self, Object buffer,
943944
bufferLib.readIntoByteArray(buffer, 0, self.getBuffer(), oldSize * itemsize, bufferLength);
944945
} catch (OverflowException e) {
945946
CompilerDirectives.transferToInterpreterAndInvalidate();
946-
throw raise(MemoryError);
947+
throw PRaiseNode.raiseUncached(this, MemoryError);
947948
}
948949
return PNone.NONE;
949950
} finally {

0 commit comments

Comments
 (0)