mirror of
https://github.com/NLnetLabs/unbound.git
synced 2026-08-17 21:25:50 +02:00
- Fix for python module on Windows, fix fopen.
git-svn-id: file:///svn/unbound/trunk@5125 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
+12
-1
@@ -247,6 +247,9 @@ int pythonmod_init(struct module_env* env, int id)
|
||||
PyObject* py_init_arg, *res;
|
||||
PyGILState_STATE gil;
|
||||
int init_standard = 1;
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject* PyFileObject = NULL;
|
||||
#endif
|
||||
|
||||
struct pythonmod_env* pe = (struct pythonmod_env*)calloc(1, sizeof(struct pythonmod_env));
|
||||
if (!pe)
|
||||
@@ -307,7 +310,15 @@ int pythonmod_init(struct module_env* env, int id)
|
||||
}
|
||||
|
||||
/* Check Python file load */
|
||||
if ((script_py = fopen(pe->fname, "r")) == NULL)
|
||||
/* uses python to open the file, this works on other platforms,
|
||||
* eg. Windows, to open the file in the correct mode for python */
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject* PyFileObject = PyFile_FromString(pe->fname, "r");
|
||||
script_py = PyFile_AsFile(PyFileObject, pe->fname, 1);
|
||||
#else
|
||||
script_py = _Py_fopen(pe->fname, "r");
|
||||
#endif
|
||||
if (script_py == NULL)
|
||||
{
|
||||
log_err("pythonmod: can't open file %s for reading", pe->fname);
|
||||
PyGILState_Release(gil);
|
||||
|
||||
Reference in New Issue
Block a user