From 0fed227da78a251032d6e1080ea968b3c7b86203 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Fri, 9 Nov 2018 12:16:59 +0000 Subject: [PATCH] Consistently make keyword-lists be static and read-only. We had an exciting mix of static and automatic storage durations, and none were marked as `const'. Python isn't `const'-correct, so we have to cast away the `const'-ness: introduce a new macro `KWLIST' to do this. Also constify some other related tables, such as method names in `pgev_python'. --- catacomb-python.h | 2 ++ util.c | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/catacomb-python.h b/catacomb-python.h index 1989cd0..bbb5fac 100644 --- a/catacomb-python.h +++ b/catacomb-python.h @@ -231,6 +231,8 @@ MODULES(DO) return (d); \ } +#define KWLIST (/*unconst*/ char **)kwlist + struct nameval { const char *name; unsigned long value; }; extern void setconstants(PyObject *, const struct nameval *); diff --git a/util.c b/util.c index 7118bfb..2e6ee25 100644 --- a/util.c +++ b/util.c @@ -603,13 +603,15 @@ end: return (rc); } -static char *def_kwlist[] = { "key", "default", 0 }; +static const char *const def_kwlist[] = { "key", "default", 0 }; PyObject *gmapmeth_get(PyObject *me, PyObject *arg, PyObject *kw) { PyObject *k, *def = Py_None, *v; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO:get", def_kwlist, &k, &def)) + if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO:get", + (/*unconst*/ char **)def_kwlist, + &k, &def)) return (0); if ((v = PyObject_GetItem(me, k)) != 0) return (v); PyErr_Clear(); @@ -621,7 +623,8 @@ PyObject *gmapmeth_setdefault(PyObject *me, PyObject *arg, PyObject *kw) PyObject *k, *def = Py_None, *v; if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO:setdefault", - def_kwlist, &k, &def)) + (/*unconst*/ char **)def_kwlist, + &k, &def)) return (0); if ((v = PyObject_GetItem(me, k)) != 0) return (v); PyErr_Clear(); @@ -633,7 +636,9 @@ PyObject *gmapmeth_pop(PyObject *me, PyObject *arg, PyObject *kw) { PyObject *k, *def = 0, *v; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO:pop", def_kwlist, &k, &def)) + if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO:pop", + (/*unconst*/ char **)def_kwlist, + &k, &def)) return (0); if ((v = PyObject_GetItem(me, k)) != 0) { PyObject_DelItem(me, k); -- 2.11.0