Python function PyDict_SetItem
is used to insert a value val
into the dictionary with a key of key
. According to the API document, PyDict_SetItem
does not steal a reference to val
so that the caller of PyDict_SetItem
keeps an ownership of val
. Hence, a reference to val
must be decremented after it is added to the dictionary. But there is no mention about key
in the API document. What should we do for key
?
PyObject *dict = PyDict_New();
PyObject *key = PyUnicode_FromString("key");
PyObject *val = PyLong_FromLong(0L);
PyDict_SetItem(dict, key, val);