Skip to content

Commit c329a10

Browse files
committed
ObjectNodes.GetStateNode use PyObjectLookupAttribute node instead of the PythonObjectLibrary
1 parent e7d5aab commit c329a10

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@
5252
import com.oracle.truffle.api.nodes.Node;
5353

5454
/**
55-
* Namespace containing equivalent nodes of {@code _Pylong_XXX} private function from {@code longobject.c}
55+
* Namespace containing equivalent nodes of {@code _Pylong_XXX} private function from
56+
* {@code longobject.c}
5657
*/
5758
public abstract class IntNodes {
5859
/**
59-
* Equivalent of CPython's {@code _PyLong_Sign}.
60-
* Return 0 if v is 0, -1 if v < 0, +1 if v > 0.
60+
* Equivalent of CPython's {@code _PyLong_Sign}. Return 0 if v is 0, -1 if v < 0, +1 if v > 0.
6161
*/
6262
public abstract static class PyLongSign extends Node {
6363
public abstract int execute(Object value);
@@ -79,8 +79,8 @@ static int doPInt(PInt value) {
7979
}
8080

8181
/**
82-
* Equivalent to CPython's {@code _PyLong_NumBits}.
83-
* Return the number of bits needed to represent the absolute value of a long.
82+
* Equivalent to CPython's {@code _PyLong_NumBits}. Return the number of bits needed to
83+
* represent the absolute value of a long.
8484
*/
8585
public abstract static class PyLongNumBits extends Node {
8686
public abstract int execute(Object value);
@@ -102,8 +102,8 @@ static int doPInt(PInt value) {
102102
}
103103

104104
/**
105-
* Equivalent to CPython's {@code _PyLong_AsByteArray}.
106-
* Convert the least-significant 8*n bits of long v to a base-256 integer, stored in array bytes.
105+
* Equivalent to CPython's {@code _PyLong_AsByteArray}. Convert the least-significant 8*n bits
106+
* of long v to a base-256 integer, stored in array bytes.
107107
*/
108108
public abstract static class PyLongAsByteArray extends Node {
109109
public abstract byte[] execute(Object value, int size, boolean bigEndian);
@@ -118,7 +118,7 @@ static byte[] doLong(long value, int size, boolean bigEndian) {
118118

119119
@Specialization
120120
static byte[] doPInt(PInt value, int size, boolean bigEndian,
121-
@Cached PRaiseNode raiseNode) {
121+
@Cached PRaiseNode raiseNode) {
122122
final byte[] bytes = new byte[size];
123123
NumericSupport support = bigEndian ? NumericSupport.bigEndian() : NumericSupport.littleEndian();
124124
try {
@@ -131,8 +131,8 @@ static byte[] doPInt(PInt value, int size, boolean bigEndian,
131131
}
132132

133133
/**
134-
* Equivalent to CPython's {@code _PyLong_FromByteArray}.
135-
* View the n unsigned bytes as a binary integer in base 256, and return a Python int with the same numeric value.
134+
* Equivalent to CPython's {@code _PyLong_FromByteArray}. View the n unsigned bytes as a binary
135+
* integer in base 256, and return a Python int with the same numeric value.
136136
*/
137137
public abstract static class PyLongFromByteArray extends Node {
138138
public abstract Object execute(byte[] data, boolean bigEndian);
@@ -149,7 +149,7 @@ static Object doLong(byte[] data, boolean bigEndian) {
149149

150150
@Specialization(guards = "!fitsInLong(data)")
151151
static Object doPInt(byte[] data, boolean bigEndian,
152-
@Cached PythonObjectFactory factory) {
152+
@Cached PythonObjectFactory factory) {
153153
NumericSupport support = bigEndian ? NumericSupport.bigEndian() : NumericSupport.littleEndian();
154154
return factory.createInt(support.getBigInteger(data, 0));
155155
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectNodes.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
101101
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
102102
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
103+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
103104
import com.oracle.graal.python.lib.PyObjectSizeNode;
104105
import com.oracle.graal.python.nodes.BuiltinNames;
105106
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -596,15 +597,15 @@ Object getStateFromSlots(VirtualFrame frame, Object obj, boolean required, Objec
596597
@Cached GetSlotNamesNode getSlotNamesNode,
597598
@Cached GetClassNode getClassNode,
598599
@Cached PyObjectSizeNode sizeNode,
599-
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary pol,
600+
@Cached PyObjectLookupAttr lookupAttr,
600601
@CachedLibrary(limit = "1") HashingStorageLibrary hlib) {
601602
Object state;
602603
Object type = getClassNode.execute(obj);
603604
if (required && getItemsizeNode.execute(type) != 0) {
604605
throw raise(TypeError, CANNOT_PICKLE_OBJECT_TYPE, obj);
605606
}
606607

607-
Object dict = pol.lookupAttribute(obj, frame, __DICT__);
608+
Object dict = lookupAttr.execute(frame, obj, __DICT__);
608609
if (!PGuards.isNoValue(dict) && sizeNode.execute(frame, dict) > 0) {
609610
state = dict;
610611
} else {
@@ -624,7 +625,7 @@ Object getStateFromSlots(VirtualFrame frame, Object obj, boolean required, Objec
624625
for (Object o : names) {
625626
try {
626627
String name = toJavaStringNode.execute(o);
627-
Object value = pol.lookupAttribute(obj, frame, name);
628+
Object value = lookupAttr.execute(frame, obj, name);
628629
if (!PGuards.isNoValue(value)) {
629630
hlib.setItem(slotsStorage, name, value);
630631
haveSlots = true;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongCheckNode.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@
5454
import com.oracle.truffle.api.library.CachedLibrary;
5555

5656
/**
57-
* Check if the object is a long or subclass of. Equivalent of CPython's
58-
* {@code PyLong_Check}.
57+
* Check if the object is a long or subclass of. Equivalent of CPython's {@code PyLong_Check}.
5958
*/
6059
@ImportStatic(SpecialMethodNames.class)
6160
@GenerateUncached
@@ -84,9 +83,9 @@ static boolean doPInt(@SuppressWarnings("unused") PInt object) {
8483

8584
@Specialization
8685
static boolean doGeneric(Object object,
87-
@Cached GetClassNode getClassNode,
88-
@Cached IsSubtypeNode isSubtypeNode,
89-
@CachedLibrary(limit = "3") InteropLibrary interopLibrary) {
86+
@Cached GetClassNode getClassNode,
87+
@Cached IsSubtypeNode isSubtypeNode,
88+
@CachedLibrary(limit = "3") InteropLibrary interopLibrary) {
9089
Object type = getClassNode.execute(object);
9190
if (isSubtypeNode.execute(type, PythonBuiltinClassType.PInt)) {
9291
return true;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/NumericSupport.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
import com.oracle.truffle.api.memory.ByteArraySupport;
1616

1717
public final class NumericSupport {
18-
private static final long NEG_ZERO_RAWBITS = Double.doubleToRawLongBits(-0.0);
18+
private static final long NEG_ZERO_RAWBITS = Double.doubleToRawLongBits(-0.0);
1919
private static final double EPSILON = .00000000000000001;
2020
private final ByteArraySupport support;
2121
private final boolean bigEndian;
2222

2323
private NumericSupport(boolean bigEndian) {
24-
this.support = bigEndian ? ByteArraySupport.bigEndian(): ByteArraySupport.littleEndian();
24+
this.support = bigEndian ? ByteArraySupport.bigEndian() : ByteArraySupport.littleEndian();
2525
this.bigEndian = bigEndian;
2626
}
2727

@@ -253,7 +253,7 @@ public BigInteger getBigInteger(byte[] buffer, int index) {
253253
}
254254

255255
@TruffleBoundary
256-
public BigInteger getBigInteger(byte[] buffer, int index, int numBytes) throws IndexOutOfBoundsException{
256+
public BigInteger getBigInteger(byte[] buffer, int index, int numBytes) throws IndexOutOfBoundsException {
257257
assert numBytes <= buffer.length - index;
258258
final byte[] bytes;
259259
if (index == 0 && numBytes == buffer.length) {
@@ -354,7 +354,7 @@ public void putDouble(PNodeWithRaise node, byte[] buffer, int index, double valu
354354
}
355355

356356
public static short asUnsigned(byte value) {
357-
return (short)(value & 0x00ff);
357+
return (short) (value & 0x00ff);
358358
}
359359

360360
public static int asUnsigned(short value) {
@@ -374,8 +374,7 @@ public static BigInteger asUnsigned(long value) {
374374
int lower = (int) value;
375375

376376
// return (upper << 32) + lower
377-
return (BigInteger.valueOf(Integer.toUnsignedLong(upper))).shiftLeft(32).
378-
add(BigInteger.valueOf(Integer.toUnsignedLong(lower)));
377+
return (BigInteger.valueOf(Integer.toUnsignedLong(upper))).shiftLeft(32).add(BigInteger.valueOf(Integer.toUnsignedLong(lower)));
379378
}
380379
}
381380
}

0 commit comments

Comments
 (0)