From 2d3c15397384ea55a7a632a4302d6b4d432ad4ac Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 28 Mar 2020 10:00:09 +0000 Subject: [PATCH] pyke/mapping.c: Export `gmap_pyupdate' as a separately useful thing. It adds all of the things in a Python mapping into a gmappish object. What's not to like? --- pyke/mapping.c | 7 ++++--- pyke/pyke.h | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pyke/mapping.c b/pyke/mapping.c index ad02d25..b108178 100644 --- a/pyke/mapping.c +++ b/pyke/mapping.c @@ -848,7 +848,7 @@ end: return (rc); } -static int update_core(PyObject *me, PyObject *map) +int gmap_pyupdate(PyObject *me, PyObject *map) { const gmap_ops *gmops = GMAP_OPS(me); PyObject *i = 0, *item = 0, *k = 0, *v = 0; @@ -856,6 +856,7 @@ static int update_core(PyObject *me, PyObject *map) unsigned foundp; int rc = -1; + if (!map) return (0); v = PyObject_CallMethod(map, PY23("iteritems", "items"), 0); #ifdef PY3 if (v) { i = PyObject_GetIter(v); Py_DECREF(v); v = 0; } @@ -899,8 +900,8 @@ PyObject *gmapmeth_update(PyObject *me, PyObject *arg, PyObject *kw) PyObject *map = 0; if (!PyArg_ParseTuple(arg, "|O:update", &map)) return (0); - if (map && update_core(me, map)) return (0); - if (kw && update_core(me, kw)) return (0); + if (gmap_pyupdate(me, map)) return (0); + if (gmap_pyupdate(me, kw)) return (0); RETURN_ME; } diff --git a/pyke/pyke.h b/pyke/pyke.h index a60fd76..ada47fc 100644 --- a/pyke/pyke.h +++ b/pyke/pyke.h @@ -687,6 +687,7 @@ extern PyObject *gmap_pyiter(PyObject *); /* for `tp_iter' */ extern PyObject *gmap_pylookup(PyObject *, PyObject *); /* for `mp_subscript' */ extern int gmap_pystore(PyObject *, PyObject *, PyObject *); /* for `mp_ass_subscript' */ extern int gmap_pyhaskey(PyObject *, PyObject *); /* for `sq_contains' */ +extern int gmap_pyupdate(PyObject *me, PyObject *map); extern const PySequenceMethods gmap_pysequence; /* for `tp_as_sequence' */ extern const PyMethodDef gmapro_pymethods[]; /* read-only methods */ extern const PyMethodDef gmap_pymethods[]; /* all the standard methods */ -- 2.11.0