Skip to content

Commit 310102c

Browse files
committed
Support native member ob_size for Boolean
1 parent a329457 commit 310102c

File tree

2 files changed

+11
-7
lines changed
  • graalpython
    • com.oracle.graal.python.test/src/tests/cpyext
    • com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi

2 files changed

+11
-7
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_object.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,8 @@ def compile_module(self, name):
694694
lambda: (
695695
(0, 0),
696696
(1, 1),
697+
(False, 0),
698+
(True, 1),
697699
(-1, -1),
698700
(1, 1),
699701
(1<<29, 1),

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
import com.oracle.truffle.api.dsl.Cached;
186186
import com.oracle.truffle.api.dsl.Cached.Exclusive;
187187
import com.oracle.truffle.api.dsl.Cached.Shared;
188+
import com.oracle.truffle.api.dsl.Fallback;
188189
import com.oracle.truffle.api.dsl.GenerateUncached;
189190
import com.oracle.truffle.api.dsl.ImportStatic;
190191
import com.oracle.truffle.api.dsl.Specialization;
@@ -3187,12 +3188,17 @@ abstract static class ObSizeNode extends PNodeWithContext {
31873188
public abstract long execute(Object object);
31883189

31893190
@Specialization
3190-
long doInteger(@SuppressWarnings("unused") int object) {
3191+
static long doBoolean(boolean object) {
3192+
return object ? 1 : 0;
3193+
}
3194+
3195+
@Specialization
3196+
long doInteger(int object) {
31913197
return doLong(object);
31923198
}
31933199

31943200
@Specialization
3195-
long doLong(@SuppressWarnings("unused") long object) {
3201+
long doLong(long object) {
31963202
long t = PInt.abs(object);
31973203
int sign = object < 0 ? -1 : 1;
31983204
int size = 0;
@@ -3213,7 +3219,7 @@ long doPythonNativeVoidPtr(@SuppressWarnings("unused") PythonNativeVoidPtr objec
32133219
return ((Long.SIZE - 1) / getContext().getCApiContext().getPyLongBitsInDigit() + 1);
32143220
}
32153221

3216-
@Specialization(guards = "isFallback(object)")
3222+
@Fallback
32173223
static long doOther(Object object,
32183224
@Cached PyObjectSizeNode sizeNode) {
32193225
try {
@@ -3222,10 +3228,6 @@ static long doOther(Object object,
32223228
return -1;
32233229
}
32243230
}
3225-
3226-
static boolean isFallback(Object object) {
3227-
return !(object instanceof PInt || object instanceof Integer || object instanceof Long || object instanceof PythonNativeVoidPtr);
3228-
}
32293231
}
32303232

32313233
@GenerateUncached

0 commit comments

Comments
 (0)