Skip to content

Commit fe256ae

Browse files
committed
make sure that PyTrue and PyFalse are unique
1 parent 947ab2e commit fe256ae

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

graalpython/com.oracle.graal.python.cext/src/abstract.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static PyObject* null_error(void) {
5454
}
5555

5656
int PyNumber_Check(PyObject *o) {
57-
PyObject *result = truffle_invoke(PY_TRUFFLE_CEXT, "PyNumber_Check", to_java(o));
57+
PyObject *result = to_sulong(truffle_invoke(PY_TRUFFLE_CEXT, "PyNumber_Check", to_java(o)));
5858
if(result == Py_True) {
5959
return 1;
6060
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,18 @@ public PythonNativeObject createNativeObjectWrapper(Object obj) {
201201
/*
202202
* Primitive types
203203
*/
204+
@CompilationFinal PInt pyTrue = null;
205+
@CompilationFinal PInt pyFalse = null;
204206

205207
public PInt createInt(boolean value) {
206-
return trace(new PInt(lookupClass(PythonBuiltinClassType.Boolean), value ? BigInteger.ONE : BigInteger.ZERO));
208+
if (value && pyTrue == null) {
209+
CompilerDirectives.transferToInterpreterAndInvalidate();
210+
pyTrue = new PInt(lookupClass(PythonBuiltinClassType.Boolean), BigInteger.ONE);
211+
} else if (!value && pyFalse == null) {
212+
CompilerDirectives.transferToInterpreterAndInvalidate();
213+
pyFalse = new PInt(lookupClass(PythonBuiltinClassType.Boolean), BigInteger.ZERO);
214+
}
215+
return value ? pyTrue : pyFalse;
207216
}
208217

209218
public PInt createInt(int value) {

0 commit comments

Comments
 (0)