X-Git-Url: https://git.distorted.org.uk/~mdw/pyke/blobdiff_plain/35ac67cc37668d5a0b1b46b18f93df5bb9b99272..c0ddcbacacd1108395fce05c57db4ddd4d801888:/util.c diff --git a/util.c b/util.c index 717c3d9..8fab0bf 100644 --- a/util.c +++ b/util.c @@ -28,6 +28,10 @@ #include "catacomb-python.h" +/*----- External values ---------------------------------------------------*/ + +static PyObject *modname = 0; + /*----- Conversions -------------------------------------------------------*/ PyObject *getulong(unsigned long w) @@ -56,6 +60,7 @@ int convulong(PyObject *o, void *pp) unsigned long *p = pp; PyObject *t; + if (!o) VALERR("can't delete"); if (PyInt_Check(o)) { i = PyInt_AS_LONG(o); if (i < 0) VALERR("must be nonnegative"); @@ -127,8 +132,11 @@ end: int convbool(PyObject *o, void *pp) { + if (!o) VALERR("can't delete"); *(int *)pp = PyObject_IsTrue(o); return (1); +end: + return (0); } /*----- Type messing ------------------------------------------------------*/ @@ -168,14 +176,17 @@ void *newtype(PyTypeObject *metaty, return (ty); } +void typeready(PyTypeObject *ty) +{ + PyType_Ready(ty); + PyDict_SetItemString(ty->tp_dict, "__module__", modname); +} + PyTypeObject *inittype(PyTypeObject *tyskel) { - static PyObject *modname = 0; PyTypeObject *ty = newtype(&PyType_Type, tyskel, 0); - if (!modname) modname = PyString_FromString("catacomb"); ty->tp_flags |= Py_TPFLAGS_HEAPTYPE; - PyType_Ready(ty); - PyDict_SetItemString(ty->tp_dict, "__module__", modname); + typeready(ty); return (ty); } @@ -406,7 +417,7 @@ PySequenceMethods gmap_pysequence = { 0 /* @sq_inplace_repeat@ */ }; -int gmap_pysize(PyObject *me) +Py_ssize_t gmap_pysize(PyObject *me) { PyObject *i = 0, *x = 0; int rc = -1; @@ -637,6 +648,7 @@ PyMethodDef gmap_pymethods[] = { void util_pyinit(void) { + modname = PyString_FromString("catacomb"); INITTYPE(itemiter, root); INITTYPE(valiter, root); }