plugins/python/sudo_python_module.c: use IntEnums instead of constants
It is a bit more code, but it is more "pythonic" and easier to debug as the enum values also know their names. It is also an API break, eg. sudo.RC_OK becomes sudo.RC.OK as sudo.RC will be the "type" of the enum, but I guess that is acceptable before the initial release.
This commit is contained in:

committed by
Todd C. Miller

parent
67ab6fd5d6
commit
21c02e1732
@@ -243,6 +243,15 @@ _python_plugin_register_plugin_in_py_ctx(void)
|
||||
PyImport_AppendInittab("sudo", sudo_module_init);
|
||||
Py_InitializeEx(0);
|
||||
py_ctx.py_main_interpreter = PyThreadState_Get();
|
||||
|
||||
// This ensures we import "sudo" module in the main interpreter,
|
||||
// each subinterpreter will have a shallow copy.
|
||||
// (This makes the C sudo module able to eg. import other modules.)
|
||||
PyObject *py_sudo = NULL;
|
||||
if ((py_sudo = PyImport_ImportModule("sudo")) == NULL) {
|
||||
debug_return_int(SUDO_RC_ERROR);
|
||||
}
|
||||
Py_CLEAR(py_sudo);
|
||||
} else {
|
||||
PyThreadState_Swap(py_ctx.py_main_interpreter);
|
||||
}
|
||||
|
Reference in New Issue
Block a user