1

Does PySys_SetObject steal the reference to the object v or should I decrement its reference counter?

PyObject *my_obj = PyUnicode_FromString("my_string_path");
int ret = PySys_SetObject("path", my_obj);
Py_XDECREF(my_obj);  // Should I decref it?

Should I just assume that whenever the docs don't specify that the function steals the reference I should always decrement its reference counter?

The same question for PyList_Append (PyList_SetItem specifies the stealing behavior).

dalmago
  • 106
  • 6

1 Answers1

1

Should I just assume that whenever the docs don't specify that the function steals the reference I should always decrement its reference counter?

Apparently yes. When calling PySys_SetObject("name", v) it does increment v reference counter. It also decrements the reference counter of whichever object there is in the sys module named "name", if it exists.

dalmago
  • 106
  • 6