Skip to content

Commit

Permalink
hookify functions in moduleobject.c
Browse files Browse the repository at this point in the history
Summary: Adds hooks around `PyStrictModule_Check` for use in `_add_methods_to_object` and `PyModule_SetDocString`.

Reviewed By: carljm

Differential Revision: D51405031

fbshipit-source-id: c3fbb5b30a8d22fe3864873d97d555eeefd09c16
  • Loading branch information
pilleye authored and facebook-github-bot committed Nov 20, 2023
1 parent b5e078b commit 5f70b2d
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,14 @@ _add_methods_to_object(PyObject *module, PyObject *name, PyMethodDef *functions)
if (func == NULL) {
return -1;
}
#ifdef ENABLE_CINDERX
if (PyStrictModule_Check(module)) {
if (Ci_hook_PyStrictModule_Check && Ci_hook_PyStrictModule_Check(module)) {
PyObject *globals = ((PyStrictModuleObject *)module)->globals;
if (PyDict_SetItemString(globals, fdef->ml_name, func) != 0) {
Py_DECREF(func);
return -1;
}
}
else
#endif
if (PyObject_SetAttrString(module, fdef->ml_name, func) != 0) {
else if (PyObject_SetAttrString(module, fdef->ml_name, func) != 0) {
Py_DECREF(func);
return -1;
}
Expand Down Expand Up @@ -470,14 +467,12 @@ PyModule_SetDocString(PyObject *m, const char *doc)
if (v == NULL) {
Py_XDECREF(v);
return -1;
#ifdef ENABLE_CINDERX
} else if (PyStrictModule_Check(m)) {
} else if (Ci_hook_PyStrictModule_Check && Ci_hook_PyStrictModule_Check(m)) {
PyObject *globals = ((PyStrictModuleObject*)m)->globals;
if (_PyDict_SetItemId(globals, &PyId___doc__, v) != 0) {
Py_DECREF(v);
return -1;
}
#endif
} else if(_PyObject_SetAttrId(m, &PyId___doc__, v) != 0) {
Py_XDECREF(v);
return -1;
Expand Down

0 comments on commit 5f70b2d

Please sign in to comment.