]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix for python module on Windows, fix fopen.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Wed, 27 Feb 2019 14:14:08 +0000 (14:14 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Wed, 27 Feb 2019 14:14:08 +0000 (14:14 +0000)
git-svn-id: file:///svn/unbound/trunk@5125 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
pythonmod/pythonmod.c

index 65faf7420b058816278d0ab03a620d403076d0fe..6e5b5966236d1c61d3346dc41578cd1aacbfae16 100644 (file)
@@ -3,6 +3,7 @@
          order and local zone tags, and elements in views.
        - Fix #14: contrib/unbound.init: Fix wrong comparison judgment
          before copying.
+       - Fix for python module on Windows, fix fopen.
 
 25 February 2019: Wouter
        - Fix #4227: pair event del and add for libevent for tcp_req_info.
index 2f5bdf3b7b906cabc3adc08bc859a47ac006bc73..25e1bc08a1bfd2dd97045c465ad6a6bc8ca57a7d 100644 (file)
@@ -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);