chiark / gitweb /
Various other little bits.
[catacomb-python] / algorithms.c
index 6eda8029c92a3e7d5201924dc27824b8c4301a98..0a36f910740dcc0cd0ab83e2038479c5291b9f94 100644 (file)
@@ -236,7 +236,7 @@ static PyTypeObject keysz_pytype_skel = {
   sizeof(keysz_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
-  _PyObject_Del,                       /* @tp_dealloc@ */
+  0,                                   /* @tp_dealloc@ */
   0,                                   /* @tp_print@ */
   0,                                   /* @tp_getattr@ */
   0,                                   /* @tp_setattr@ */
@@ -274,7 +274,7 @@ static PyTypeObject keysz_pytype_skel = {
   0,                                   /* @tp_init@ */
   PyType_GenericAlloc,                 /* @tp_alloc@ */
   abstract_pynew,                      /* @tp_new@ */
-  _PyObject_Del,                       /* @tp_free@ */
+  0,                                   /* @tp_free@ */
   0                                    /* @tp_is_gc@ */
 };
 
@@ -284,7 +284,7 @@ static PyTypeObject keyszany_pytype_skel = {
   sizeof(keysz_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
-  _PyObject_Del,                       /* @tp_dealloc@ */
+  0,                                   /* @tp_dealloc@ */
   0,                                   /* @tp_print@ */
   0,                                   /* @tp_getattr@ */
   0,                                   /* @tp_setattr@ */
@@ -322,7 +322,7 @@ static PyTypeObject keyszany_pytype_skel = {
   0,                                   /* @tp_init@ */
   PyType_GenericAlloc,                 /* @tp_alloc@ */
   keyszany_pynew,                      /* @tp_new@ */
-  _PyObject_Del,                       /* @tp_free@ */
+  0,                                   /* @tp_free@ */
   0                                    /* @tp_is_gc@ */
 };
 
@@ -332,7 +332,7 @@ static PyTypeObject keyszrange_pytype_skel = {
   sizeof(keyszrange_pyobj),            /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
-  _PyObject_Del,                       /* @tp_dealloc@ */
+  0,                                   /* @tp_dealloc@ */
   0,                                   /* @tp_print@ */
   0,                                   /* @tp_getattr@ */
   0,                                   /* @tp_setattr@ */
@@ -371,7 +371,7 @@ sizes, and requires the key length to be a multiple of some value.",
   0,                                   /* @tp_init@ */
   PyType_GenericAlloc,                 /* @tp_alloc@ */
   keyszrange_pynew,                    /* @tp_new@ */
-  _PyObject_Del,                       /* @tp_free@ */
+  0,                                   /* @tp_free@ */
   0                                    /* @tp_is_gc@ */
 };
 
@@ -381,7 +381,7 @@ static PyTypeObject keyszset_pytype_skel = {
   sizeof(keyszset_pyobj),              /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
-  _PyObject_Del,                       /* @tp_dealloc@ */
+  0,                                   /* @tp_dealloc@ */
   0,                                   /* @tp_print@ */
   0,                                   /* @tp_getattr@ */
   0,                                   /* @tp_setattr@ */
@@ -420,7 +420,7 @@ few listed sizes.",
   0,                                   /* @tp_init@ */
   PyType_GenericAlloc,                 /* @tp_alloc@ */
   keyszset_pynew,                      /* @tp_new@ */
-  _PyObject_Del,                       /* @tp_free@ */
+  0,                                   /* @tp_free@ */
   0                                    /* @tp_is_gc@ */
 };
 
@@ -460,19 +460,18 @@ end:
 
 PyObject *gccipher_pywrap(gccipher *cc)
 {
-  gccipher_pyobj *g = newtype(gccipher_pytype, 0);
+  gccipher_pyobj *g = newtype(gccipher_pytype, 0, cc->name);
   g->cc = cc;
-  g->ty.tp_name = (/*unconst*/ char *)cc->name;
-  g->ty.tp_basicsize = sizeof(gcipher_pyobj);
-  g->ty.tp_base = gcipher_pytype;
+  g->ty.type.tp_basicsize = sizeof(gcipher_pyobj);
+  g->ty.type.tp_base = gcipher_pytype;
   Py_INCREF(gcipher_pytype);
-  g->ty.tp_flags = (Py_TPFLAGS_DEFAULT |
-                   Py_TPFLAGS_BASETYPE |
-                   Py_TPFLAGS_HEAPTYPE);
-  g->ty.tp_alloc = PyType_GenericAlloc;
-  g->ty.tp_free = _PyObject_Del;
-  g->ty.tp_new = gcipher_pynew;
-  PyType_Ready(&g->ty);
+  g->ty.type.tp_flags = (Py_TPFLAGS_DEFAULT |
+                        Py_TPFLAGS_BASETYPE |
+                        Py_TPFLAGS_HEAPTYPE);
+  g->ty.type.tp_alloc = PyType_GenericAlloc;
+  g->ty.type.tp_free = 0;
+  g->ty.type.tp_new = gcipher_pynew;
+  PyType_Ready(&g->ty.type);
   return ((PyObject *)g);
 }
 
@@ -481,7 +480,7 @@ static void gcipher_pydealloc(PyObject *me)
   if (GCIPHER_F(me) & f_freeme)
     GC_DESTROY(GCIPHER_C(me));
   Py_DECREF(me->ob_type);
-  PyObject_DEL(me);
+  FREEOBJ(me);
 }
 
 static PyObject *gccget_name(PyObject *me, void *hunoz)
@@ -634,7 +633,7 @@ static PyTypeObject gccipher_pytype_skel = {
   0,                                   /* @tp_init@ */
   PyType_GenericAlloc,                 /* @tp_alloc@ */
   abstract_pynew,                      /* @tp_new@ */
-  _PyObject_Del,                       /* @tp_free@ */
+  0,                                   /* @tp_free@ */
   0                                    /* @tp_is_gc@ */
 };
 
@@ -682,7 +681,7 @@ static PyTypeObject gcipher_pytype_skel = {
   0,                                   /* @tp_init@ */
   PyType_GenericAlloc,                 /* @tp_alloc@ */
   abstract_pynew,                      /* @tp_new@ */
-  _PyObject_Del,                       /* @tp_free@ */
+  0,                                   /* @tp_free@ */
   0                                    /* @tp_is_gc@ */
 };
 
@@ -705,19 +704,18 @@ end:
 
 PyObject *gchash_pywrap(gchash *ch)
 {
-  gchash_pyobj *g = newtype(gchash_pytype, 0);
+  gchash_pyobj *g = newtype(gchash_pytype, 0, ch->name);
   g->ch = ch;
-  g->ty.tp_name = (/*unconst*/ char *)ch->name;
-  g->ty.tp_basicsize = sizeof(ghash_pyobj);
-  g->ty.tp_base = ghash_pytype;
+  g->ty.type.tp_basicsize = sizeof(ghash_pyobj);
+  g->ty.type.tp_base = ghash_pytype;
   Py_INCREF(ghash_pytype);
-  g->ty.tp_flags = (Py_TPFLAGS_DEFAULT |
-                   Py_TPFLAGS_BASETYPE |
-                   Py_TPFLAGS_HEAPTYPE);
-  g->ty.tp_alloc = PyType_GenericAlloc;
-  g->ty.tp_free = _PyObject_Del;
-  g->ty.tp_new = ghash_pynew;
-  PyType_Ready(&g->ty);
+  g->ty.type.tp_flags = (Py_TPFLAGS_DEFAULT |
+                        Py_TPFLAGS_BASETYPE |
+                        Py_TPFLAGS_HEAPTYPE);
+  g->ty.type.tp_alloc = PyType_GenericAlloc;
+  g->ty.type.tp_free = 0;
+  g->ty.type.tp_new = ghash_pynew;
+  PyType_Ready(&g->ty.type);
   return ((PyObject *)g);
 }
 
@@ -737,7 +735,7 @@ static void ghash_pydealloc(PyObject *me)
   if (GHASH_F(me) & f_freeme)
     GH_DESTROY(GHASH_H(me));
   Py_DECREF(me->ob_type);
-  PyObject_DEL(me);
+  FREEOBJ(me);
 }
 
 static PyObject *gchget_name(PyObject *me, void *hunoz)
@@ -831,7 +829,7 @@ static PyTypeObject gchash_pytype_skel = {
   0,                                   /* @tp_init@ */
   PyType_GenericAlloc,                 /* @tp_alloc@ */
   abstract_pynew,                      /* @tp_new@ */
-  _PyObject_Del,                       /* @tp_free@ */
+  0,                                   /* @tp_free@ */
   0                                    /* @tp_is_gc@ */
 };
 
@@ -879,7 +877,7 @@ static PyTypeObject ghash_pytype_skel = {
   0,                                   /* @tp_init@ */
   PyType_GenericAlloc,                 /* @tp_alloc@ */
   abstract_pynew,                      /* @tp_new@ */
-  _PyObject_Del,                       /* @tp_free@ */
+  0,                                   /* @tp_free@ */
   0                                    /* @tp_is_gc@ */
 };
 
@@ -922,19 +920,18 @@ static PyObject *gmhash_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
 
 PyObject *gcmac_pywrap(gcmac *cm)
 {
-  gcmac_pyobj *g = newtype(gcmac_pytype, 0);
+  gcmac_pyobj *g = newtype(gcmac_pytype, 0, cm->name);
   g->cm = cm;
-  g->ty.tp_name = (/*unconst*/ char *)cm->name;
-  g->ty.tp_basicsize = sizeof(gmac_pyobj);
-  g->ty.tp_base = gmac_pytype;
+  g->ty.type.tp_basicsize = sizeof(gmac_pyobj);
+  g->ty.type.tp_base = gmac_pytype;
   Py_INCREF(gmac_pytype);
-  g->ty.tp_flags = (Py_TPFLAGS_DEFAULT |
+  g->ty.type.tp_flags = (Py_TPFLAGS_DEFAULT |
                    Py_TPFLAGS_BASETYPE |
                    Py_TPFLAGS_HEAPTYPE);
-  g->ty.tp_alloc = PyType_GenericAlloc;
-  g->ty.tp_free = _PyObject_Del;
-  g->ty.tp_new = gmac_pynew;
-  PyType_Ready(&g->ty);
+  g->ty.type.tp_alloc = PyType_GenericAlloc;
+  g->ty.type.tp_free = 0;
+  g->ty.type.tp_new = gmac_pynew;
+  PyType_Ready(&g->ty.type);
   return ((PyObject *)g);
 }
 
@@ -943,18 +940,18 @@ PyObject *gmac_pywrap(PyObject *cobj, gmac *m, unsigned f)
   gmac_pyobj *g;
   if (!cobj) cobj = gcmac_pywrap((/*unconst*/ gcmac *)GM_CLASS(m));
   else Py_INCREF(cobj);
-  g = newtype((PyTypeObject *)cobj, 0);
-  g->nameobj = PyString_FromFormat("%s(keyed)", m->ops->c->name);
-  g->ty.tp_name = PyString_AS_STRING(g->nameobj);
-  g->ty.tp_base = gmhash_pytype;
+  g = newtype((PyTypeObject *)cobj, 0, 0);
+  g->ty.name = PyString_FromFormat("%s(keyed)", m->ops->c->name);
+  g->ty.type.tp_name = PyString_AS_STRING(g->ty.name);
+  g->ty.type.tp_base = gmhash_pytype;
   Py_INCREF(gmac_pytype);
-  g->ty.tp_flags = (Py_TPFLAGS_DEFAULT |
-                   Py_TPFLAGS_BASETYPE |
-                   Py_TPFLAGS_HEAPTYPE);
-  g->ty.tp_alloc = PyType_GenericAlloc;
-  g->ty.tp_free = _PyObject_Del;
-  g->ty.tp_new = gmhash_pynew;
-  PyType_Ready(&g->ty);
+  g->ty.type.tp_flags = (Py_TPFLAGS_DEFAULT |
+                        Py_TPFLAGS_BASETYPE |
+                        Py_TPFLAGS_HEAPTYPE);
+  g->ty.type.tp_alloc = PyType_GenericAlloc;
+  g->ty.type.tp_free = 0;
+  g->ty.type.tp_new = gmhash_pynew;
+  PyType_Ready(&g->ty.type);
   g->m = m;
   g->f = f;
   return ((PyObject *)g);  
@@ -965,7 +962,6 @@ static void gmac_pydealloc(PyObject *me)
   if (GMAC_F(me) & f_freeme)
     GM_DESTROY(GMAC_M(me));
   Py_DECREF(me->ob_type);
-  Py_DECREF(GMAC_NAMEOBJ(me));
   PyType_Type.tp_dealloc(me);
 }
 
@@ -1031,7 +1027,7 @@ static PyTypeObject gcmac_pytype_skel = {
   0,                                   /* @tp_init@ */
   PyType_GenericAlloc,                 /* @tp_alloc@ */
   abstract_pynew,                      /* @tp_new@ */
-  _PyObject_Del,                       /* @tp_free@ */
+  0,                                   /* @tp_free@ */
   0                                    /* @tp_is_gc@ */
 };
 
@@ -1079,7 +1075,7 @@ static PyTypeObject gmac_pytype_skel = {
   0,                                   /* @tp_init@ */
   PyType_GenericAlloc,                 /* @tp_alloc@ */
   abstract_pynew,                      /* @tp_new@ */
-  _PyObject_Del,                       /* @tp_free@ */
+  0,                                   /* @tp_free@ */
   0                                    /* @tp_is_gc@ */
 };
 
@@ -1127,7 +1123,7 @@ static PyTypeObject gmhash_pytype_skel = {
   0,                                   /* @tp_init@ */
   PyType_GenericAlloc,                 /* @tp_alloc@ */
   abstract_pynew,                      /* @tp_new@ */
-  _PyObject_Del,                       /* @tp_free@ */
+  0,                                   /* @tp_free@ */
   0                                    /* @tp_is_gc@ */
 };