summaryrefslogtreecommitdiff
path: root/gpsclient.c
diff options
context:
space:
mode:
authorFred Wright <fw@fwright.net>2016-04-08 10:07:42 -0700
committerEric S. Raymond <esr@thyrsus.com>2016-04-09 04:39:15 -0400
commit97be9754e1eb6fb83e114af1b2286e287793f693 (patch)
treeddf288e79d4208498b7aaa039b230bdbfe292be9 /gpsclient.c
parent90413f5f16d66b69da2f8d5cd8d989aabb12514b (diff)
downloadgpsd-97be9754e1eb6fb83e114af1b2286e287793f693.tar.gz
Fixes Python C extensions for Python 3 compatibility.
These are necessary, but not sufficient, changes to make the C extensions work "polyglot". These are believed to be complete as far as the C code is concerned, and don't break Python 2 compatibility. This puts all the stuff that needs to differ between Python 2 and Python 3 into conditionally-defined macros in a new header file python_compatibility.h. The definitions assume Python 2.6 or later. In addition to the things requiring conditionals, the Lexer object was using the deprecated tp_getattr entry, with a function based on Py_FindMethod, which is gone in Python 3. However, the newer tp_getattro entry can be pointed directly to PyObject_GenericGetAttr, which works in Python 2 and 3. Packet data returned by the Lexer is now 'bytes' in Python 3, which is appropriate given that it may contain binary data. However, it means that packet data can't be passed directly to anything expecting a 'str'. In Python 2, the data is just a 'str' as usual. TESTED: Ran "scons build-all check" and xgps (using Python 2.7). Also ran the daemon and maidenhead-locator tests with Python 2.6.
Diffstat (limited to 'gpsclient.c')
-rw-r--r--gpsclient.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/gpsclient.c b/gpsclient.c
index 276900e3..7b04ddc0 100644
--- a/gpsclient.c
+++ b/gpsclient.c
@@ -10,6 +10,7 @@
#include "gps.h"
#include "gpsdclient.h"
#include "compiler.h" /* for UNUSED */
+#include "python_compatibility.h"
/*
* Client utility functions
@@ -83,13 +84,16 @@ PyDoc_STRVAR(module_doc,
/* banishes a pointless compiler warning */
extern PyMODINIT_FUNC initclienthelpers(void);
-PyMODINIT_FUNC
// cppcheck-suppress unusedFunction
-initclienthelpers(void)
+GPSD_PY_MODULE_INIT(clienthelpers)
{
PyObject *m;
- m = Py_InitModule3("gps.clienthelpers", gpsclient_methods, module_doc);
+ /* Create the module and add the functions */
+ GPSD_PY_MODULE_DEF(m, "clienthelpers", module_doc, gpsclient_methods)
+
+ if (m == NULL)
+ return GPSD_PY_MODULE_ERROR_VAL;
PyModule_AddIntConstant(m, "deg_dd", deg_dd);
PyModule_AddIntConstant(m, "deg_ddmm", deg_ddmm);
@@ -99,5 +103,6 @@ initclienthelpers(void)
PyModule_AddIntConstant(m, "imperial", imperial);
PyModule_AddIntConstant(m, "nautical", nautical);
PyModule_AddIntConstant(m, "metric", metric);
-}
+ return GPSD_PY_MODULE_SUCCESS_VAL(m);
+}