Skip to content

Commit 80410a9

Browse files
committed
Rename PythonObjectReference.idx to handleTableIndex (and similar in GraalPyObject)
1 parent 9ec03f5 commit 80410a9

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

graalpython/com.oracle.graal.python.cext/src/capi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ typedef struct {
105105

106106
typedef struct {
107107
PyObject_VAR_HEAD
108-
int32_t id;
108+
int32_t handle_table_index;
109109
} GraalPyObject;
110110

111111
typedef struct {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static void releaseNativeWrapper(PythonNativeWrapper nativeWrapper, CStructAcces
136136
private static boolean tableEntryRemoved(HandleContext context, PythonNativeWrapper nativeWrapper) {
137137
PythonObjectReference ref = nativeWrapper.ref;
138138
if (ref != null) {
139-
int id = ref.getId();
139+
int id = ref.getHandleTableIndex();
140140
return id <= 0 || CApiTransitions.nativeStubLookupGet(context, nativeWrapper.getNativePointer(), id) == null;
141141
}
142142
// there cannot be a table entry if the wrapper does not have a PythonObjectReference

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -197,22 +197,22 @@ public static final class PythonObjectReference extends IdReference<PythonNative
197197

198198
/**
199199
* The index in the lookup table, where this reference is stored. This duplicates the native
200-
* field {@link CFields#GraalPyObject__id} in order to save reading the native field if we
201-
* already have the reference object. The value may be {@code -1} in which case it means
202-
* that the reference's referent is a managed object and {@link #pointer} points into the
203-
* handle space.
200+
* field {@link CFields#GraalPyObject__handle_table_index} in order to save reading the
201+
* native field if we already have the reference object. The value may be {@code -1} in
202+
* which case it means that the reference's referent is a managed object and
203+
* {@link #pointer} points into the handle space.
204204
*/
205-
private final int idx;
205+
private final int handleTableIndex;
206206

207-
private PythonObjectReference(HandleContext handleContext, PythonNativeWrapper referent, boolean strong, long pointer, int idx) {
207+
private PythonObjectReference(HandleContext handleContext, PythonNativeWrapper referent, boolean strong, long pointer, int handleTableIndex) {
208208
super(handleContext, referent);
209209
this.pointer = pointer;
210210
this.strongReference = strong ? referent : null;
211211
if (LOGGER.isLoggable(Level.FINE)) {
212212
LOGGER.fine(PythonUtils.formatJString("new %s", toString()));
213213
}
214214
referent.ref = this;
215-
this.idx = idx;
215+
this.handleTableIndex = handleTableIndex;
216216
}
217217

218218
static PythonObjectReference create(HandleContext handleContext, PythonAbstractObjectNativeWrapper referent, boolean strong, long pointer, int idx) {
@@ -232,16 +232,16 @@ public void setStrongReference(PythonNativeWrapper wrapper) {
232232
strongReference = wrapper;
233233
}
234234

235-
public int getId() {
236-
return idx;
235+
public int getHandleTableIndex() {
236+
return handleTableIndex;
237237
}
238238

239239
@Override
240240
@TruffleBoundary
241241
public String toString() {
242242
String type = strongReference != null ? "strong" : "weak";
243243
PythonNativeWrapper referent = get();
244-
return String.format("PythonObjectReference<0x%x,%s,%s,id=%d>", pointer, type, referent != null ? referent : "freed", idx);
244+
return String.format("PythonObjectReference<0x%x,%s,%s,id=%d>", pointer, type, referent != null ? referent : "freed", handleTableIndex);
245245
}
246246
}
247247

@@ -365,7 +365,7 @@ public static void pollReferenceQueue() {
365365
if (entry instanceof PythonObjectReference reference) {
366366
LOGGER.fine(() -> PythonUtils.formatJString("releasing %s", reference.toString()));
367367
if (HandlePointerConverter.pointsToPyHandleSpace(reference.pointer)) {
368-
assert nativeStubLookupGet(context, reference.pointer, reference.idx) != null : Long.toHexString(reference.pointer);
368+
assert nativeStubLookupGet(context, reference.pointer, reference.handleTableIndex) != null : Long.toHexString(reference.pointer);
369369
nativeStubLookupRemove(context, reference);
370370
/*
371371
* We may only free native object stubs if their reference count is
@@ -385,7 +385,7 @@ public static void pollReferenceQueue() {
385385
* field because there may be referenced from managed in the future
386386
* and then we would incorrectly reuse the ID.
387387
*/
388-
CStructAccess.WriteIntNode.writeUncached(reference.pointer, CFields.GraalPyObject__id, 0);
388+
CStructAccess.WriteIntNode.writeUncached(reference.pointer, CFields.GraalPyObject__handle_table_index, 0);
389389
}
390390
} else {
391391
assert nativeLookupGet(context, reference.pointer) != null : Long.toHexString(reference.pointer);
@@ -550,8 +550,8 @@ private static int resizeNativeStubLookupTable(HandleContext context) {
550550
}
551551

552552
private static int nativeStubLookupPut(HandleContext context, PythonObjectReference value) {
553-
assert value.idx > 0;
554-
final int idx = value.idx - 1;
553+
assert value.handleTableIndex > 0;
554+
final int idx = value.handleTableIndex - 1;
555555
assert context.nativeStubLookup[idx] == null || context.nativeStubLookup[idx] == value;
556556
context.nativeStubLookup[idx] = value;
557557
if (PythonContext.DEBUG_CAPI) {
@@ -564,8 +564,8 @@ private static int nativeStubLookupPut(HandleContext context, PythonObjectRefere
564564
}
565565

566566
private static PythonObjectReference nativeStubLookupRemove(HandleContext context, PythonObjectReference ref) {
567-
assert ref.idx > 0;
568-
final int idx = ref.idx - 1;
567+
assert ref.handleTableIndex > 0;
568+
final int idx = ref.handleTableIndex - 1;
569569
PythonObjectReference result = context.nativeStubLookup[idx];
570570
context.nativeStubLookup[idx] = null;
571571
context.nativeStubLookupFreeStack.push(idx);
@@ -658,7 +658,7 @@ static long doGeneric(Node inliningTarget, PythonAbstractObjectNativeWrapper wra
658658
long stubPointer = coerceToLongNode.execute(inliningTarget, nativeObjectStub);
659659
long taggedPointer = HandlePointerConverter.stubToPointer(stubPointer);
660660
int idx = nativeStubLookupReserve(handleContext);
661-
writeIntNode.write(stubPointer, CFields.GraalPyObject__id, idx);
661+
writeIntNode.write(stubPointer, CFields.GraalPyObject__handle_table_index, idx);
662662
PythonObjectReference ref = PythonObjectReference.create(handleContext, wrapper, immortal, taggedPointer, idx);
663663
nativeStubLookupPut(handleContext, ref);
664664

@@ -790,7 +790,7 @@ static PythonNativeWrapper doGeneric(Node inliningTarget, long pointer,
790790
@Cached(inline = false) CStructAccess.ReadI32Node readI32Node,
791791
@Cached InlinedExactClassProfile profile) {
792792
HandleContext nativeContext = PythonContext.get(inliningTarget).nativeContext;
793-
int idx = readI32Node.read(HandlePointerConverter.pointerToStub(pointer), CFields.GraalPyObject__id);
793+
int idx = readI32Node.read(HandlePointerConverter.pointerToStub(pointer), CFields.GraalPyObject__handle_table_index);
794794
PythonObjectReference reference = nativeStubLookupGet(nativeContext, pointer, idx);
795795
PythonNativeWrapper wrapper = profile.profile(inliningTarget, reference.get());
796796
assert wrapper != null : "reference was collected: " + Long.toHexString(pointer);
@@ -1065,7 +1065,7 @@ Object doNonWrapper(Object value,
10651065
}
10661066
assert pythonContext.ownsGil();
10671067
if (isHandleSpaceProfile.profile(inliningTarget, HandlePointerConverter.pointsToPyHandleSpace(pointer))) {
1068-
int idx = readI32Node.read(HandlePointerConverter.pointerToStub(pointer), CFields.GraalPyObject__id);
1068+
int idx = readI32Node.read(HandlePointerConverter.pointerToStub(pointer), CFields.GraalPyObject__handle_table_index);
10691069
PythonObjectReference reference = nativeStubLookupGet(nativeContext, pointer, idx);
10701070
if (reference == null) {
10711071
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -1232,7 +1232,7 @@ Object doNonWrapper(long pointer, boolean stealing,
12321232
}
12331233
assert pythonContext.ownsGil();
12341234
if (isHandleSpaceProfile.profile(inliningTarget, HandlePointerConverter.pointsToPyHandleSpace(pointer))) {
1235-
int idx = readI32Node.read(HandlePointerConverter.pointerToStub(pointer), CFields.GraalPyObject__id);
1235+
int idx = readI32Node.read(HandlePointerConverter.pointerToStub(pointer), CFields.GraalPyObject__handle_table_index);
12361236
PythonObjectReference reference = nativeStubLookupGet(nativeContext, pointer, idx);
12371237
if (reference == null) {
12381238
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -1374,7 +1374,7 @@ static PythonNativeWrapper doNonWrapper(Object obj, boolean strict,
13741374
HandleContext nativeContext = pythonContext.nativeContext;
13751375
assert pythonContext.ownsGil();
13761376
if (isHandleSpaceProfile.profile(inliningTarget, HandlePointerConverter.pointsToPyHandleSpace(pointer))) {
1377-
int idx = readI32Node.read(HandlePointerConverter.pointerToStub(pointer), CFields.GraalPyObject__id);
1377+
int idx = readI32Node.read(HandlePointerConverter.pointerToStub(pointer), CFields.GraalPyObject__handle_table_index);
13781378
PythonObjectReference reference = nativeStubLookupGet(nativeContext, pointer, idx);
13791379
PythonNativeWrapper wrapper;
13801380
if (reference == null) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/structs/CFields.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public enum CFields {
116116

117117
PyVarObject__ob_size(Py_ssize_t),
118118

119-
GraalPyObject__id(Int),
119+
GraalPyObject__handle_table_index(Int),
120120
GraalPyVarObject__ob_item(PyObjectPtr),
121121

122122
PyModuleDef__m_name(ConstCharPtr),

0 commit comments

Comments
 (0)