*.c: Use Python macros rather than functions where possible.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 24 Nov 2019 12:35:45 +0000 (12:35 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 10 Apr 2020 21:42:39 +0000 (22:42 +0100)
algorithms.c
catacomb.c
group.c
mp.c
pgen.c

index 31bd95b..886c159 100644 (file)
@@ -193,9 +193,9 @@ static PyObject *ksget_min(PyObject *me, void *hunoz)
 {
   PyObject *set = ((keyszset_pyobj *)me)->set;
   int i, n, y, x = -1;
-  n = PyTuple_Size(set);
+  n = PyTuple_GET_SIZE(set);
   for (i = 0; i < n; i++) {
-    y = PyInt_AsLong(PyTuple_GetItem(set, i));
+    y = PyInt_AS_LONG(PyTuple_GET_ITEM(set, i));
     if (x == -1 || y < x) x = y;
   }
   return (PyInt_FromLong(x));
@@ -205,9 +205,9 @@ static PyObject *ksget_max(PyObject *me, void *hunoz)
 {
   PyObject *set = ((keyszset_pyobj *)me)->set;
   int i, n, y, x = -1;
-  n = PyTuple_Size(set);
+  n = PyTuple_GET_SIZE(set);
   for (i = 0; i < n; i++) {
-    y = PyInt_AsLong(PyTuple_GetItem(set, i));
+    y = PyInt_AS_LONG(PyTuple_GET_ITEM(set, i));
     if (y > x) x = y;
   }
   return (PyInt_FromLong(x));
index e868f0f..f02d39e 100644 (file)
@@ -74,8 +74,8 @@ PyObject *mexp_common(PyObject *me, PyObject *arg,
   PyObject *qq, *x, *y, *z = 0;
   char *v = 0, *vv;
 
-  if (PyTuple_Size(arg) == 1)
-    arg = PyTuple_GetItem(arg, 0);
+  if (PyTuple_GET_SIZE(arg) == 1)
+    arg = PyTuple_GET_ITEM(arg, 0);
   Py_INCREF(arg);
   if (!PySequence_Check(arg)) TYERR("not a sequence");
   n = PySequence_Size(arg); if (n < 0) goto end;
@@ -135,7 +135,7 @@ static PyObject *smallprimes(void)
   int i;
 
   for (i = 0; i < NPRIME; i++)
-    PyList_SetItem(v, i, PyInt_FromLong(primetab[i]));
+    PyList_SET_ITEM(v, i, PyInt_FromLong(primetab[i]));
   return (v);
 }
 
diff --git a/group.c b/group.c
index 439ec42..5d7c34b 100644 (file)
--- a/group.c
+++ b/group.c
@@ -154,7 +154,7 @@ static PyObject *meth__DHInfo_genlimlee(PyObject *me,
     PGENERR(&exc);
   vec = PyList_New(nf);
   for (i = 0; i < nf; i++)
-    PyList_SetItem(vec, i, mp_pywrap(v[i]));
+    PyList_SET_ITEM(vec, i, mp_pywrap(v[i]));
   xfree(v);
   rc = Py_BuildValue("(NN)", fginfo_pywrap(&dp, dhinfo_pytype), vec);
 end:
diff --git a/mp.c b/mp.c
index 31eec24..fc49eca 100644 (file)
--- a/mp.c
+++ b/mp.c
@@ -1011,10 +1011,10 @@ static PyObject *mmmeth_factor(PyObject *me, PyObject *arg)
   mp *x;
 
   if (!MPMUL_LIVEP(me)) VALERR("MPMul object invalid");
-  if (PyTuple_Size(arg) != 1)
+  if (PyTuple_GET_SIZE(arg) != 1)
     i = PyObject_GetIter(arg);
   else {
-    if ((q = PyTuple_GetItem(arg, 0)) == 0) goto end;
+    if ((q = PyTuple_GET_ITEM(arg, 0)) == 0) goto end;
     if ((i = PyObject_GetIter(q)) == 0) {
       PyErr_Clear(); /* that's ok */
       i = PyObject_GetIter(arg);
@@ -1683,7 +1683,7 @@ static PyObject *mcmeth_solve(PyObject *me, PyObject *arg)
   Py_ssize_t i = 0, n = c->k;
 
   Py_INCREF(me);
-  if (PyTuple_Size(arg) == n)
+  if (PyTuple_GET_SIZE(arg) == n)
     q = arg;
   else if (!PyArg_ParseTuple(arg, "O:solve", &q))
     goto end;
@@ -1727,7 +1727,7 @@ static PyObject *mpcrt_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
   mpmul mm;
   mpcrt_pyobj *c = 0;
 
-  if (PyTuple_Size(arg) > 1)
+  if (PyTuple_GET_SIZE(arg) > 1)
     q = arg;
   else if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:new", KWLIST, &q))
     goto end;
@@ -1780,7 +1780,7 @@ static PyObject *mcget_moduli(PyObject *me, void *hunoz)
 
   if ((q = PyList_New(c->k)) == 0) return (0);
   for (i = 0; i < c->k; i++)
-    PyList_SetItem(q, i, mp_pywrap(c->v[i].m));
+    PyList_SET_ITEM(q, i, mp_pywrap(c->v[i].m));
   return (q);
 }
 
diff --git a/pgen.c b/pgen.c
index 9f9e1a2..6444225 100644 (file)
--- a/pgen.c
+++ b/pgen.c
@@ -1039,7 +1039,7 @@ static PyObject *meth_limlee(PyObject *me, PyObject *arg, PyObject *kw)
     PGENERR(&exc);;
   vec = PyList_New(nf);
   for (i = 0; i < nf; i++)
-    PyList_SetItem(vec, i, mp_pywrap(v[i]));
+    PyList_SET_ITEM(vec, i, mp_pywrap(v[i]));
   xfree(v);
   rc = Py_BuildValue("(NN)", mp_pywrap(x), vec);
 end: