mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-22 07:41:16 -05:00
- For multi Python module setups, clean previously parsed module
functions in __main__'s dictionary, if any, so that only current module functions are registered.
This commit is contained in:
parent
122dd6c11e
commit
e4510c76e5
2 changed files with 33 additions and 0 deletions
|
|
@ -5,6 +5,9 @@
|
||||||
- Expose the configured listening and outgoing interfaces, if any, as
|
- Expose the configured listening and outgoing interfaces, if any, as
|
||||||
a list of strings in the Python 'config_file' class instead of the
|
a list of strings in the Python 'config_file' class instead of the
|
||||||
current Swig object proxy; fixes #79.
|
current Swig object proxy; fixes #79.
|
||||||
|
- For multi Python module setups, clean previously parsed module
|
||||||
|
functions in __main__'s dictionary, if any, so that only current
|
||||||
|
module functions are registered.
|
||||||
|
|
||||||
13 October 2023: George
|
13 October 2023: George
|
||||||
- Better fix for infinite loop when reading multiple lines of input on
|
- Better fix for infinite loop when reading multiple lines of input on
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,34 @@ struct pythonmod_qstate {
|
||||||
PyObject* data;
|
PyObject* data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* The dict from __main__ could have remnants from a previous script
|
||||||
|
* invocation, in a multi python module setup. Usually this is fine since newer
|
||||||
|
* scripts will update their values. The obvious erroneous case is when mixing
|
||||||
|
* python scripts that make use of both 'init' and 'init_standard'. This
|
||||||
|
* results in 'init_standard' to persist on following scripts that don't use it
|
||||||
|
* (thus not replacing it). This is also problematic in case where a script
|
||||||
|
* does not define a required function but a previously loaded script did. The
|
||||||
|
* current solution is to make sure to clean offensive remnants that influence
|
||||||
|
* further parsing of the individual scripts.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
clean_python_function_objects(PyObject* dict) {
|
||||||
|
const char* function_names[] = {
|
||||||
|
"init",
|
||||||
|
"init_standard",
|
||||||
|
"deinit",
|
||||||
|
"operate",
|
||||||
|
"inform_super"
|
||||||
|
};
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for(i=0; i<sizeof(function_names)/sizeof(function_names[0]); i++) {
|
||||||
|
if(PyDict_GetItemString(dict, function_names[i]) != NULL) {
|
||||||
|
PyDict_DelItemString(dict, function_names[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/* Generated */
|
/* Generated */
|
||||||
#ifndef S_SPLINT_S
|
#ifndef S_SPLINT_S
|
||||||
#include "pythonmod/interface.h"
|
#include "pythonmod/interface.h"
|
||||||
|
|
@ -418,6 +446,8 @@ int pythonmod_init(struct module_env* env, int id)
|
||||||
Py_XINCREF(pe->module);
|
Py_XINCREF(pe->module);
|
||||||
pe->dict = PyModule_GetDict(pe->module);
|
pe->dict = PyModule_GetDict(pe->module);
|
||||||
Py_XINCREF(pe->dict);
|
Py_XINCREF(pe->dict);
|
||||||
|
clean_python_function_objects(pe->dict);
|
||||||
|
|
||||||
pe->data = PyDict_New();
|
pe->data = PyDict_New();
|
||||||
/* add the script filename to the global "mod_env" for trivial access */
|
/* add the script filename to the global "mod_env" for trivial access */
|
||||||
fname = PyString_FromString(pe->fname);
|
fname = PyString_FromString(pe->fname);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue