Skip to content

Commit 16fdf43

Browse files
committed
Properly decref items when removing from native storage
1 parent 5ec1892 commit 16fdf43

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,10 @@ void PyTruffle_ObjectArrayFree(PyObject** array, int32_t size) {
907907
free(array);
908908
}
909909

910+
void PyTruffle_SetStorageItem(PyObject** ptr, int32_t index, PyObject* newitem) {
911+
Py_XSETREF(ptr[index], newitem);
912+
}
913+
910914
PyAPI_FUNC(Py_ssize_t) PyTruffle_Object_Size(PyObject *op) {
911915
return ((PyVarObject*)op)->ob_size;
912916
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public enum NativeCAPISymbol implements NativeCExtSymbol {
157157
FUN_PY_TRUFFLE_OBJECT_ARRAY_REALLOC("PyTruffle_ObjectArrayRealloc"),
158158
FUN_PY_TRUFFLE_PRIMITIVE_ARRAY_FREE("PyTruffle_PrimitiveArrayFree"),
159159
FUN_PY_TRUFFLE_OBJECT_ARRAY_FREE("PyTruffle_ObjectArrayFree"),
160+
FUN_PY_TRUFFLE_SET_STORAGE_ITEM("PyTruffle_SetStorageItem"),
160161
FUN_PY_TRUFFLE_NATIVE_TUPLE_ITEMS("PyTruffle_NativeTupleItems"),
161162
FUN_PY_OBJECT_GENERIC_GET_DICT("_PyObject_GenericGetDict"),
162163
FUN_PY_OBJECT_NEW("PyTruffle_Object_New"),

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_PY_TRUFFLE_LONG_ARRAY_TO_NATIVE;
3636
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_PY_TRUFFLE_OBJECT_ARRAY_REALLOC;
3737
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_PY_TRUFFLE_OBJECT_ARRAY_TO_NATIVE;
38+
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_PY_TRUFFLE_SET_STORAGE_ITEM;
3839
import static com.oracle.graal.python.builtins.objects.iterator.IteratorBuiltins.NextNode.STOP_MARKER;
3940
import static com.oracle.graal.python.runtime.exception.PythonErrorType.IndexError;
4041
import static com.oracle.graal.python.runtime.exception.PythonErrorType.MemoryError;
@@ -1284,14 +1285,9 @@ protected static void doNativeByte(NativeSequenceStorage storage, int idx, Objec
12841285

12851286
@Specialization(guards = "isObjectStorage(storage)")
12861287
protected static void doNativeObject(NativeSequenceStorage storage, int idx, Object value,
1287-
@Shared("lib") @CachedLibrary(limit = "1") InteropLibrary lib,
1288+
@Cached PCallCapiFunction call,
12881289
@Cached ToNewRefNode toSulongNode) {
1289-
// TODO xdecref previous value
1290-
try {
1291-
lib.writeArrayElement(storage.getPtr(), idx, toSulongNode.execute(value));
1292-
} catch (UnsupportedMessageException | UnsupportedTypeException | InvalidArrayIndexException e) {
1293-
throw CompilerDirectives.shouldNotReachHere(e);
1294-
}
1290+
call.call(FUN_PY_TRUFFLE_SET_STORAGE_ITEM, storage.getPtr(), idx, toSulongNode.execute(value));
12951291
}
12961292

12971293
@Fallback

0 commit comments

Comments
 (0)