diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2019-06-30 14:56:56 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2019-06-30 14:56:56 +0000 |
commit | 4713c21a1ac91081e50e474d11fcec002b43a562 (patch) | |
tree | 3dee8846d50565e925146b25f6b761ceb1ea7b07 /pythonmod | |
parent | 9c9d011eed674ddd7e4a0a148691887afb9e75cd (diff) |
Notes
Diffstat (limited to 'pythonmod')
-rw-r--r-- | pythonmod/interface.i | 22 | ||||
-rw-r--r-- | pythonmod/pythonmod.c | 23 |
2 files changed, 40 insertions, 5 deletions
diff --git a/pythonmod/interface.i b/pythonmod/interface.i index 5f2559bacffa8..f9fd07b513d65 100644 --- a/pythonmod/interface.i +++ b/pythonmod/interface.i @@ -1,19 +1,37 @@ /* * interface.i: unbound python module */ +%begin %{ +/* store state of warning output, restored at later pop */ +#pragma GCC diagnostic push +/* ignore gcc8 METH_NOARGS function cast warnings for swig function pointers */ +#pragma GCC diagnostic ignored "-Wcast-function-type" +%} %module unboundmodule %{ +/* restore state of warning output, remove the functioncast ignore */ +#pragma GCC diagnostic pop /** * \file * This is the interface between the unbound server and a python module * called to perform operations on queries. */ #include <sys/types.h> + #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> + #endif + #ifdef HAVE_NETINET_IN_H #include <netinet/in.h> + #endif + #ifdef HAVE_ARPA_INET_H #include <arpa/inet.h> + #endif + #ifdef HAVE_NETDB_H #include <netdb.h> + #endif + #ifdef HAVE_SYS_UN_H #include <sys/un.h> + #endif #include <stdarg.h> #include "config.h" #include "util/log.h" @@ -449,7 +467,9 @@ struct sockaddr_storage {}; switch (ss->ss_family) { case AF_INET: return sizeof(struct sockaddr_in); case AF_INET6: return sizeof(struct sockaddr_in6); +#ifdef HAVE_SYS_UN_H case AF_UNIX: return sizeof(struct sockaddr_un); +#endif default: return 0; } @@ -515,10 +535,12 @@ struct sockaddr_storage {}; return PyBytes_FromStringAndSize((const char *)raw, sizeof(*raw)); } +#ifdef HAVE_SYS_UN_H if (ss->ss_family == AF_UNIX) { const struct sockaddr_un *sa = (struct sockaddr_un *)ss; return PyBytes_FromString(sa->sun_path); } +#endif return Py_None; } diff --git a/pythonmod/pythonmod.c b/pythonmod/pythonmod.c index a668ecc23cc70..9009a28daaa06 100644 --- a/pythonmod/pythonmod.c +++ b/pythonmod/pythonmod.c @@ -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 + PyFileObject = PyFile_FromString((char*)pe->fname, "r"); + script_py = PyFile_AsFile(PyFileObject); +#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); @@ -343,7 +354,11 @@ int pythonmod_init(struct module_env* env, int id) PyGILState_Release(gil); return 0; } +#if PY_MAJOR_VERSION < 3 + Py_XDECREF(PyFileObject); +#else fclose(script_py); +#endif if ((pe->func_init = PyDict_GetItemString(pe->dict, "init_standard")) == NULL) { @@ -517,8 +532,7 @@ void pythonmod_clear(struct module_qstate* qstate, int id) return; pq = (struct pythonmod_qstate*)qstate->minfo[id]; - verbose(VERB_ALGO, "pythonmod: clear, id: %d, pq:%lX", id, - (unsigned long int)pq); + verbose(VERB_ALGO, "pythonmod: clear, id: %d, pq:%p", id, pq); if(pq != NULL) { PyGILState_STATE gil = PyGILState_Ensure(); @@ -534,8 +548,7 @@ void pythonmod_clear(struct module_qstate* qstate, int id) size_t pythonmod_get_mem(struct module_env* env, int id) { struct pythonmod_env* pe = (struct pythonmod_env*)env->modinfo[id]; - verbose(VERB_ALGO, "pythonmod: get_mem, id: %d, pe:%lX", id, - (unsigned long int)pe); + verbose(VERB_ALGO, "pythonmod: get_mem, id: %d, pe:%p", id, pe); if(!pe) return 0; return sizeof(*pe); |