debian/control: Add Build-Depends for `dh-python'.
[mLib-python] / array.c
diff --git a/array.c b/array.c
index 6f8048a..d83f64e 100644 (file)
--- a/array.c
+++ b/array.c
@@ -1,13 +1,11 @@
 /* -*-c-*-
  *
- * $Id$
- *
  * Double-ended arrays
  *
  * (c) 2005 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of the Python interface to mLib.
  *
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * mLib/Python 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 General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with mLib/Python; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -28,6 +26,8 @@
 
 /*----- Header files ------------------------------------------------------*/
 
+#define PY_SSIZE_T_CLEAN
+
 #include <Python.h>
 
 #include <string.h>
@@ -119,7 +119,7 @@ static void daiter_pydealloc(PyObject *me)
 
 PyTypeObject daiter_pytype = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "array.ArrayIter",                   /* @tp_name@ */
+  "mLib.ArrayIter",                    /* @tp_name@ */
   sizeof(daiter_pyobj),                        /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
@@ -218,7 +218,7 @@ static int da_insert(PyObject *me, PyObject *seq, int start, int end)
 {
   PyObject **items;
   size_t n;
-  
+
   if (0 > start || start > end || end > DA_LEN(DA_V(me))) {
     PyErr_SetString(PyExc_IndexError, "bad slice");
     return (-1);
@@ -259,7 +259,7 @@ static void da_pydealloc(PyObject *me)
   DA_DESTROY(DA_V(me));
 }
 
-static int da_pylength(PyObject *me)
+static Py_ssize_t da_pylength(PyObject *me)
   { return (DA_LEN(DA_V(me))); }
 
 static int da_pytraverse(PyObject *me, visitproc proc, void *arg)
@@ -297,12 +297,12 @@ static PyObject *da_pyconcat(PyObject *me, PyObject *other)
   return (x);
 }
 
-static PyObject *da_pyrepeat(PyObject *me, int times)
+static PyObject *da_pyrepeat(PyObject *me, Py_ssize_t times)
 {
   PyObject *x = da_new(&da_pytype);
   PyObject **items = DA(DA_V(me)), **dest;
   size_t n = DA_LEN(DA_V(me));
-  int i;
+  Py_ssize_t i;
 
   DA_ENSURE(DA_V(x), n * times);
   DA_UNSAFE_EXTEND(DA_V(x), n * times);
@@ -312,7 +312,7 @@ static PyObject *da_pyrepeat(PyObject *me, int times)
   return (x);
 }
 
-static PyObject *da_pygetitem(PyObject *me, int i)
+static PyObject *da_pygetitem(PyObject *me, Py_ssize_t i)
 {
   PyObject *o;
 
@@ -325,7 +325,7 @@ static PyObject *da_pygetitem(PyObject *me, int i)
   return (o);
 }
 
-static PyObject *da_pygetslice(PyObject *me, int i, int j)
+static PyObject *da_pygetslice(PyObject *me, Py_ssize_t i, Py_ssize_t j)
 {
   PyObject *x;
 
@@ -338,10 +338,10 @@ static PyObject *da_pygetslice(PyObject *me, int i, int j)
   return (x);
 }
 
-static int da_pyputitem(PyObject *me, int i, PyObject *x)
+static int da_pyputitem(PyObject *me, Py_ssize_t i, PyObject *x)
 {
   PyObject **p;
-  
+
   if (i < 0 || i >= DA_LEN(DA_V(me))) {
     PyErr_SetString(PyExc_IndexError, "index out of range");
     return (-1);
@@ -353,7 +353,8 @@ static int da_pyputitem(PyObject *me, int i, PyObject *x)
   return (0);
 }
 
-static int da_pyputslice(PyObject *me, int i, int j, PyObject *x)
+static int da_pyputslice(PyObject *me, Py_ssize_t i, Py_ssize_t j,
+                        PyObject *x)
   { return (da_insert(me, x, i, j)); }
 
 static int da_pycontainsp(PyObject *me, PyObject *x)
@@ -377,13 +378,13 @@ static PyObject *da_pyrepr(PyObject *me)
   dstr d = DSTR_INIT;
   PyObject *s, *rc = 0;
   char *p;
-  int n;
+  Py_ssize_t n;
   size_t i;
 
   dstr_puts(&d, "Array([");
   for (i = 0; i < DA_LEN(DA_V(me)); i++) {
     if ((s = PyObject_Repr(DA(DA_V(me))[i])) == 0 ||
-        PyString_AsStringAndSize(s, &p, &n)) {
+       PyString_AsStringAndSize(s, &p, &n)) {
       Py_XDECREF(s);
       goto done;
     }
@@ -405,11 +406,11 @@ static PyObject *da_pyappend(PyObject *me, PyObject *seq)
   RETURN_ME;
 }
 
-static PyObject *da_pyiprepeat(PyObject *me, int times)
+static PyObject *da_pyiprepeat(PyObject *me, Py_ssize_t times)
 {
   PyObject **items, **dest;
   size_t n = DA_LEN(DA_V(me));
-  int i;
+  Py_ssize_t i;
 
   if (times < 0) {
     PyErr_SetString(PyExc_ValueError, "multiplier must be nonnegative");
@@ -434,7 +435,7 @@ static PyObject *da_pyiprepeat(PyObject *me, int times)
 static PyObject *da_pyget(PyObject *me, PyObject *index)
 {
   if (PySlice_Check(index)) {
-    int start, stop, step, len;
+    Py_ssize_t start, stop, step, len;
     PyObject *v;
     PyObject **ww;
     PyObject **vv;
@@ -465,7 +466,7 @@ static PyObject *da_pyget(PyObject *me, PyObject *index)
 static int da_pyput(PyObject *me, PyObject *index, PyObject *x)
 {
   if (PySlice_Check(index)) {
-    int start, stop, step, len;
+    Py_ssize_t start, stop, step, len;
     size_t n;
     PyObject **ww;
     PyObject **vv;
@@ -520,7 +521,7 @@ static PyObject *dameth_push(PyObject *me, PyObject *arg)
 
 static PyObject *dameth_pop(PyObject *me, PyObject *arg)
 {
-  PyObject *x;
+  PyObject *x = Py_None;
 
   if (!PyArg_ParseTuple(arg, ":pop")) return (0);
   TRY
@@ -547,7 +548,7 @@ static PyObject *dameth_unshift(PyObject *me, PyObject *arg)
 
 static PyObject *dameth_shift(PyObject *me, PyObject *arg)
 {
-  PyObject *x;
+  PyObject *x = Py_None;
 
   if (!PyArg_ParseTuple(arg, ":shift")) return (0);
   TRY
@@ -601,7 +602,7 @@ static PyMappingMethods da_pymapping = {
 
 PyTypeObject da_pytype = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "array.Array",                       /* @tp_name@ */
+  "mLib.Array",                                /* @tp_name@ */
   sizeof(da_pyobj),                    /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */