X-Git-Url: https://git.distorted.org.uk/~mdw/pyke/blobdiff_plain/0b1eafbfd841149f61b47be54713a642f8538a6a..c0ddcbacacd1108395fce05c57db4ddd4d801888:/util.c diff --git a/util.c b/util.c index 89130cb..8fab0bf 100644 --- a/util.c +++ b/util.c @@ -1,7 +1,5 @@ /* -*-c-*- * - * $Id$ - * * Miscellaneous utilities (not Catacomb-specific) * * (c) 2005 Straylight/Edgeware @@ -30,6 +28,10 @@ #include "catacomb-python.h" +/*----- External values ---------------------------------------------------*/ + +static PyObject *modname = 0; + /*----- Conversions -------------------------------------------------------*/ PyObject *getulong(unsigned long w) @@ -58,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"); @@ -129,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 ------------------------------------------------------*/ @@ -165,16 +171,22 @@ void *newtype(PyTypeObject *metaty, ty->ht_name = PyString_FromString(ty->ht_type.tp_name); if (ty->ht_name) ty->ht_type.tp_name = PyString_AS_STRING(ty->ht_name); - PyObject_INIT(&ty->ht_type, metaty); + DISCARD(PyObject_INIT(&ty->ht_type, metaty)); Py_INCREF(metaty); return (ty); } +void typeready(PyTypeObject *ty) +{ + PyType_Ready(ty); + PyDict_SetItemString(ty->tp_dict, "__module__", modname); +} + PyTypeObject *inittype(PyTypeObject *tyskel) { PyTypeObject *ty = newtype(&PyType_Type, tyskel, 0); ty->tp_flags |= Py_TPFLAGS_HEAPTYPE; - PyType_Ready(ty); + typeready(ty); return (ty); } @@ -405,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; @@ -634,13 +646,14 @@ PyMethodDef gmap_pymethods[] = { /*----- Initialization ----------------------------------------------------*/ -void util_init(void) +void util_pyinit(void) { + modname = PyString_FromString("catacomb"); INITTYPE(itemiter, root); INITTYPE(valiter, root); } -void util_insert(PyObject *mod) +void util_pyinsert(PyObject *mod) { INSERT("ItemIter", itemiter_pytype); INSERT("ValueIter", valiter_pytype);