Skip to content

Commit eee20e9

Browse files
committed
Flip endianness argument
1 parent 2ed1e95 commit eee20e9

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextLongBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static Object convert(Object charPtr, long size, int littleEndian, int signed,
480480
throw raiseNode.get(inliningTarget).raise(OverflowError, ErrorMessages.BYTE_ARRAY_TOO_LONG_TO_CONVERT_TO_INT);
481481
}
482482
byte[] bytes = readByteNode.readByteArray(charPtr, (int) size);
483-
return fromByteArray.execute(inliningTarget, bytes, littleEndian == 0, signed != 0);
483+
return fromByteArray.execute(inliningTarget, bytes, littleEndian != 0, signed != 0);
484484
}
485485
}
486486
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteIncrementalEncoderBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static Object getstate(MultibyteIncrementalEncoderObject self,
286286
// for the encoder object.
287287
// memcpy(statebytes + statesize, self.state.c, MULTIBYTECODECSTATE);
288288
// statesize += MULTIBYTECODECSTATE;
289-
Object stateobj = fromByteArray.execute(inliningTarget, statebytes, false, true);
289+
Object stateobj = fromByteArray.execute(inliningTarget, statebytes, true, true);
290290
assert (stateobj instanceof PInt); // since statebytes.length > 8, we will get a PInt
291291
writeHiddenAttrNode.execute(inliningTarget, (PInt) stateobj, HiddenAttr.ENCODER_OBJECT, self.state);
292292
return stateobj;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ public static Object build(CookieType cookie) {
421421
SERIALIZE.putInt(buffer, Long.BYTES + Integer.BYTES, cookie.bytesToFeed);
422422
SERIALIZE.putInt(buffer, Long.BYTES + Integer.BYTES * 2, cookie.charsToSkip);
423423
SERIALIZE.putByte(buffer, Long.BYTES + Integer.BYTES * 3, cookie.needEOF);
424-
return IntNodes.PyLongFromByteArray.executeUncached(buffer, false, false);
424+
return IntNodes.PyLongFromByteArray.executeUncached(buffer, true, false);
425425
}
426426

427427
public static CookieType parse(long v, Node inliningTarget, InlinedConditionProfile overflow, PRaiseNode.Lazy raise) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/pickle/PUnpickler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,12 +696,12 @@ protected HashingStorageAddAllToOther ensureHashingStorageAddAllToOther() {
696696
return addAllToOther;
697697
}
698698

699-
protected Object longFromBytes(byte[] data, boolean bigEndian) {
699+
protected Object longFromBytes(byte[] data, boolean littleEndian) {
700700
if (pyLongFromByteArray == null) {
701701
CompilerDirectives.transferToInterpreterAndInvalidate();
702702
pyLongFromByteArray = insert(IntNodesFactory.PyLongFromByteArrayNodeGen.create());
703703
}
704-
return pyLongFromByteArray.executeCached(data, bigEndian, true);
704+
return pyLongFromByteArray.executeCached(data, littleEndian, true);
705705
}
706706

707707
protected void setAttribute(VirtualFrame frame, Object object, Object key, Object value) {
@@ -910,7 +910,7 @@ private void loadCountedLong(VirtualFrame frame, PUnpickler self, int n) {
910910
} else {
911911
// Read the raw little-endian bytes and convert.
912912
final ByteArrayView pdata = read(frame, self, size);
913-
value = longFromBytes(pdata.getBytes(size), false);
913+
value = longFromBytes(pdata.getBytes(size), true);
914914
}
915915
pDataPush(self, value);
916916
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,11 +2841,11 @@ static Object fromObject(VirtualFrame frame, Object cl, Object object, TruffleSt
28412841
@Cached IntNodes.PyLongFromByteArray fromByteArray,
28422842
@Cached CallNode callCtor,
28432843
@Cached PRaiseNode.Lazy raiseNode) {
2844-
boolean bigEndian;
2844+
boolean littleEndian;
28452845
if (equalNode.execute(byteorder, T_BIG, TS_ENCODING)) {
2846-
bigEndian = true;
2846+
littleEndian = false;
28472847
} else if (equalNode.execute(byteorder, T_LITTLE, TS_ENCODING)) {
2848-
bigEndian = false;
2848+
littleEndian = true;
28492849
} else {
28502850
throw raiseNode.get(inliningTarget).raise(PythonErrorType.ValueError, ErrorMessages.BYTEORDER_MUST_BE_LITTLE_OR_BIG);
28512851
}
@@ -2860,7 +2860,7 @@ static Object fromObject(VirtualFrame frame, Object cl, Object object, TruffleSt
28602860
} else {
28612861
bytes = bytesFromObject.execute(frame, object);
28622862
}
2863-
Object result = fromByteArray.execute(inliningTarget, bytes, bigEndian, signed);
2863+
Object result = fromByteArray.execute(inliningTarget, bytes, littleEndian, signed);
28642864
if (isBuiltinIntProfile.profileClass(inliningTarget, cl, PythonBuiltinClassType.PInt)) {
28652865
return result;
28662866
} else {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntNodes.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,26 +180,26 @@ static byte[] doPInt(Node inliningTarget, PInt value, int size, boolean bigEndia
180180
@GenerateInline(inlineByDefault = true)
181181
@GenerateUncached
182182
public abstract static class PyLongFromByteArray extends Node {
183-
public abstract Object execute(Node inliningTarget, byte[] data, boolean bigEndian, boolean signed);
183+
public abstract Object execute(Node inliningTarget, byte[] data, boolean littleEndian, boolean signed);
184184

185-
public final Object executeCached(byte[] data, boolean bigEndian, boolean signed) {
186-
return execute(this, data, bigEndian, signed);
185+
public final Object executeCached(byte[] data, boolean littleEndian, boolean signed) {
186+
return execute(this, data, littleEndian, signed);
187187
}
188188

189-
public static Object executeUncached(byte[] data, boolean bigEndian, boolean signed) {
190-
return IntNodesFactory.PyLongFromByteArrayNodeGen.getUncached().execute(null, data, bigEndian, signed);
189+
public static Object executeUncached(byte[] data, boolean littleEndian, boolean signed) {
190+
return IntNodesFactory.PyLongFromByteArrayNodeGen.getUncached().execute(null, data, littleEndian, signed);
191191
}
192192

193193
@Specialization
194-
static Object doOther(Node inliningTarget, byte[] data, boolean bigEndian, boolean signed,
194+
static Object doOther(Node inliningTarget, byte[] data, boolean littleEndian, boolean signed,
195195
@Cached InlinedBranchProfile fastPath1,
196196
@Cached InlinedBranchProfile fastPath2,
197197
@Cached InlinedBranchProfile fastPath4,
198198
@Cached InlinedBranchProfile fastPath8,
199199
@Cached InlinedBranchProfile generic,
200200
@Cached(inline = false) PythonObjectFactory factory,
201201
@Cached PRaiseNode.Lazy raiseNode) {
202-
NumericSupport support = bigEndian ? NumericSupport.bigEndian() : NumericSupport.littleEndian();
202+
NumericSupport support = littleEndian ? NumericSupport.littleEndian() : NumericSupport.bigEndian();
203203
if (signed) {
204204
switch (data.length) {
205205
case 1 -> {

0 commit comments

Comments
 (0)