Skip to content

Commit c970d6e

Browse files
committed
Fix: do correct check for uninitialized handle
1 parent 8f788f6 commit c970d6e

File tree

1 file changed

+15
-3
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy

1 file changed

+15
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyHandle.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,23 @@
6767
@ExportLibrary(value = NativeTypeLibrary.class, useForAOT = false)
6868
@ExportLibrary(PythonNativeWrapperLibrary.class)
6969
public final class GraalHPyHandle implements TruffleObject {
70+
public static final int UNINITIALIZED = Integer.MIN_VALUE;
7071

7172
public static final GraalHPyHandle NULL_HANDLE = new GraalHPyHandle();
7273
public static final String I = "_i";
7374

7475
private final Object delegate;
76+
/**
77+
* The ID of the handle if it was allocated in the handle table.
78+
* <p>
79+
* The value also encodes the state:<br/>
80+
* (1) If the value is {@link #UNINITIALIZED}, then the handle was never allocated in the handle
81+
* table.<br/>
82+
* (2) If the value is zero or positive then this is the index for the handle table. If the<br/>
83+
* (3) If the value is negative but not {@link #UNINITIALIZED} then the handle was already
84+
* closed (only used in HPy debug mode)<br/>
85+
* </p>
86+
*/
7587
private int id;
7688

7789
private GraalHPyHandle() {
@@ -82,7 +94,7 @@ private GraalHPyHandle() {
8294
GraalHPyHandle(Object delegate) {
8395
assert delegate != null : "HPy handles to Java null are not allowed";
8496
this.delegate = delegate;
85-
this.id = Integer.MIN_VALUE;
97+
this.id = UNINITIALIZED;
8698
}
8799

88100
/**
@@ -101,15 +113,15 @@ public int getId(GraalHPyContext context, ConditionProfile hasIdProfile) {
101113

102114
public int getIdDebug(GraalHPyContext context) {
103115
int result = id;
104-
if (id == -1) {
116+
if (id == UNINITIALIZED) {
105117
result = context.getHPyHandleForObject(this);
106118
id = result;
107119
}
108120
return result;
109121
}
110122

111123
int getDebugId() {
112-
if (id == Integer.MIN_VALUE) {
124+
if (id == UNINITIALIZED) {
113125
throw CompilerDirectives.shouldNotReachHere();
114126
}
115127
if (id >= 0) {

0 commit comments

Comments
 (0)