From: Michael Tremer Date: Fri, 29 Dec 2017 12:02:21 +0000 (+0000) Subject: python: Create a global loc_ctx* context X-Git-Tag: 0.9.0~153 X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Flibloc.git;a=commitdiff_plain;h=62ffafdd53360511a7a9ac919b8e5d01bc146941 python: Create a global loc_ctx* context Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index ea82663..7061b05 100644 --- a/Makefile.am +++ b/Makefile.am @@ -85,6 +85,7 @@ pkgpyexec_LTLIBRARIES = \ src_python_location_la_SOURCES = \ src/python/locationmodule.c \ + src/python/locationmodule.h \ src/python/as.c \ src/python/as.h \ src/python/database.c \ diff --git a/src/python/locationmodule.c b/src/python/locationmodule.c index 39a7a1d..67f796d 100644 --- a/src/python/locationmodule.c +++ b/src/python/locationmodule.c @@ -16,11 +16,18 @@ #include +#include "locationmodule.h" #include "as.h" #include "database.h" PyMODINIT_FUNC PyInit_location(void); +static void location_free(void) { + // Release context + if (loc_ctx) + loc_unref(loc_ctx); +} + static PyMethodDef location_module_methods[] = { { NULL }, }; @@ -31,9 +38,15 @@ static struct PyModuleDef location_module = { .m_size = -1, .m_doc = "Python module for libloc", .m_methods = location_module_methods, + .m_free = (freefunc)location_free, }; PyMODINIT_FUNC PyInit_location(void) { + // Initialise loc context + int r = loc_new(&loc_ctx); + if (r) + return NULL; + PyObject* m = PyModule_Create(&location_module); if (!m) return NULL; diff --git a/src/python/locationmodule.h b/src/python/locationmodule.h new file mode 100644 index 0000000..2847366 --- /dev/null +++ b/src/python/locationmodule.h @@ -0,0 +1,25 @@ +/* + libloc - A library to determine the location of someone on the Internet + + Copyright (C) 2017 IPFire Development Team + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. +*/ + +#ifndef PYTHON_LOCATION_MODULE_H +#define PYTHON_LOCATION_MODULE_H + +#include +#include + +struct loc_ctx* loc_ctx; + +#endif /* PYTHON_LOCATION_MODULE_H */