diff --git a/src/raylib.cc b/src/raylib.cc index c727e67d4..87ca0d787 100644 --- a/src/raylib.cc +++ b/src/raylib.cc @@ -183,6 +183,20 @@ void TaskCapsule_Destructor(PyObject* capsule) { delete obj; } +// Helper methods + +// Pass ownership of both the key and the value to the PyDict. +// This is only required for PyDicts, not for PyLists or PyTuples, compare +// https://docs.python.org/2/c-api/dict.html +// https://docs.python.org/2/c-api/list.html +// https://docs.python.org/2/c-api/tuple.html + +void set_dict_item_and_transfer_ownership(PyObject* dict, PyObject* key, PyObject* val) { + PyDict_SetItem(dict, key, val); + Py_XDECREF(key); + Py_XDECREF(val); +} + // Serialization // serialize will serialize the python object val into the protocol buffer @@ -364,7 +378,9 @@ PyObject* deserialize(PyObject* worker_capsule, const Obj& obj, std::vector