X-Git-Url: https://git.distorted.org.uk/~mdw/mLib-python/blobdiff_plain/20bce5e92b01cd928f26b61be78215117039c561..d65a9a847e500ae144e31040454acba1a7333aaf:/array.c diff --git a/array.c b/array.c index 37850d9..724f16b 100644 --- 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. * @@ -15,12 +13,12 @@ * 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. @@ -36,6 +34,7 @@ #include #include +#include "array.h" #include "grim.h" /*----- Data structures ---------------------------------------------------*/ @@ -58,8 +57,6 @@ typedef struct daiter_pyobj { #define DAITER_V(obj) DA_V(DAITER_DA(obj)) #define DAITER_I(obj) (((daiter_pyobj *)(obj))->i) -static PyTypeObject da_pytype, daiter_pytype; - static int getseq(PyObject **pseq, PyObject ***v, size_t *n) { PyObject *seq = *pseq; @@ -118,9 +115,9 @@ static PyObject *daiter_pynext(PyObject *me) static void daiter_pydealloc(PyObject *me) { Py_DECREF(DAITER_DA(me)); PyObject_DEL(me); } -static PyTypeObject daiter_pytype = { +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@ */ @@ -219,7 +216,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); @@ -342,7 +339,7 @@ static PyObject *da_pygetslice(PyObject *me, int i, int j) static int da_pyputitem(PyObject *me, int i, PyObject *x) { PyObject **p; - + if (i < 0 || i >= DA_LEN(DA_V(me))) { PyErr_SetString(PyExc_IndexError, "index out of range"); return (-1); @@ -384,7 +381,7 @@ static PyObject *da_pyrepr(PyObject *me) 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; } @@ -521,7 +518,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 @@ -548,7 +545,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 @@ -600,9 +597,9 @@ static PyMappingMethods da_pymapping = { da_pyput /* @mp_ass_subscript@ */ }; -static PyTypeObject da_pytype = { +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@ */ @@ -650,14 +647,7 @@ static PyTypeObject da_pytype = { /*----- Initialization ----------------------------------------------------*/ -static PyMethodDef emptymethods[] = { { 0 } }; - -void initarray(void) -{ - PyObject *mod = Py_InitModule("array", emptymethods); - PyType_Ready(&da_pytype); PyType_Ready(&daiter_pytype); - PyModule_AddObject(mod, "Array", (PyObject *)&da_pytype); - PyModule_AddObject(mod, "ArrayIter", (PyObject *)&daiter_pytype); -} +void da_pysetup(void) + { PyType_Ready(&da_pytype); PyType_Ready(&daiter_pytype); } /*----- That's all, folks -------------------------------------------------*/