Skip to content

Commit 52eee60

Browse files
committed
Avoid possible creation of multiple references to the same capsule
1 parent 79de24d commit 52eee60

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/capsule/PyCapsule.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public Object getDestructor() {
7777
}
7878

7979
private final CapsuleData data;
80+
private CApiTransitions.PyCapsuleReference reference;
8081

8182
/**
8283
* (mq) We are forcing all PyCapsule objects to be of a builtin type
@@ -122,8 +123,8 @@ public Object getDestructor() {
122123

123124
public void registerDestructor(Object destructor) {
124125
assert destructor == null || !InteropLibrary.getUncached().isNull(destructor);
125-
if (data.destructor == null && destructor != null) {
126-
CApiTransitions.registerPyCapsuleDestructor(this);
126+
if (reference == null && destructor != null) {
127+
reference = CApiTransitions.registerPyCapsuleDestructor(this);
127128
}
128129
data.destructor = destructor;
129130
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,12 @@ public String toString() {
377377
}
378378

379379
@TruffleBoundary
380-
public static void registerPyCapsuleDestructor(PyCapsule capsule) {
380+
public static PyCapsuleReference registerPyCapsuleDestructor(PyCapsule capsule) {
381381
assert PythonContext.get(null).ownsGil();
382382
HandleContext handleContext = getContext();
383383
PyCapsuleReference ref = new PyCapsuleReference(handleContext, capsule);
384384
handleContext.pyCapsuleReferences.add(ref);
385+
return ref;
385386
}
386387

387388
@TruffleBoundary

0 commit comments

Comments
 (0)