Skip to content
Closed
Next Next commit
Add private _PyModule_StealObject API.
  • Loading branch information
brandtbucher committed Nov 20, 2019
commit a59525cc69bc2bc2f0c40e4bf86674aa5906eeef
13 changes: 13 additions & 0 deletions Python/modsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,19 @@ PyModule_AddObject(PyObject *m, const char *name, PyObject *o)
return 0;
}

/* Like PyModule_AddObject, but steals o on success AND failure.
This is probably what you want! */

int
_PyModule_StealObject(PyObject *m, const char *name, PyObject *o)
{
if (PyModule_AddObject(m, name, o) < 0) {
Py_XDECREF(o);
return -1;
}
return 0;
}

int
PyModule_AddIntConstant(PyObject *m, const char *name, long value)
{
Expand Down