chiark / gitweb /
algorithms.c, knock-on: Eliminate `f_freeme' flags.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 9 Nov 2018 12:22:16 +0000 (12:22 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 10 Nov 2018 01:30:59 +0000 (01:30 +0000)
These were being carefully set and checked on ciphers, hashes, and MACs,
for no good reason because the flag was always set.  Abolish it.

The flag still exists for `grand' objects because they get injected into
Python through the `pgen' event-handling machinery, and Python mustn't
destroy them just because it loses its reference.  (It also mustn't try
to hang onto them, so there's a longstanding bug in there.)

algorithms.c
catacomb-python.h
pubkey.c

index 033176ba1d5825d09739fad1e445c104a149861d..8eced246a1594183c384b49355a07b2a501fbdb2 100644 (file)
@@ -457,14 +457,13 @@ PyTypeObject *gccipher_pytype, *gcipher_pytype;
 CONVFUNC(gccipher, gccipher *, GCCIPHER_CC)
 CONVFUNC(gcipher, gcipher *, GCIPHER_C)
 
-PyObject *gcipher_pywrap(PyObject *cobj, gcipher *c, unsigned f)
+PyObject *gcipher_pywrap(PyObject *cobj, gcipher *c)
 {
   gcipher_pyobj *g;
   if (!cobj) cobj = gccipher_pywrap((/*unconst*/ gccipher *)GC_CLASS(c));
   else Py_INCREF(cobj);
   g = PyObject_NEW(gcipher_pyobj, (PyTypeObject *)cobj);
   g->c = c;
-  g->f = f;
   return ((PyObject *)g);
 }
 
@@ -478,8 +477,7 @@ static PyObject *gcipher_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
     goto end;
   if (keysz(sz, GCCIPHER_CC(ty)->keysz) != sz) VALERR("bad key length");
   return (gcipher_pywrap((PyObject *)ty,
-                        GC_INIT(GCCIPHER_CC(ty), k, sz),
-                        f_freeme));
+                        GC_INIT(GCCIPHER_CC(ty), k, sz)));
 end:
   return (0);
 }
@@ -503,8 +501,7 @@ PyObject *gccipher_pywrap(gccipher *cc)
 
 static void gcipher_pydealloc(PyObject *me)
 {
-  if (GCIPHER_F(me) & f_freeme)
-    GC_DESTROY(GCIPHER_C(me));
+  GC_DESTROY(GCIPHER_C(me));
   Py_DECREF(me->ob_type);
   FREEOBJ(me);
 }
@@ -725,7 +722,7 @@ static PyObject *ghash_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
   static const char *const kwlist[] = { 0 };
   if (!PyArg_ParseTupleAndKeywords(arg, kw, ":new", KWLIST))
     goto end;
-  return (ghash_pywrap((PyObject *)ty, GH_INIT(GCHASH_CH(ty)), f_freeme));
+  return (ghash_pywrap((PyObject *)ty, GH_INIT(GCHASH_CH(ty))));
 end:
   return (0);
 }
@@ -747,21 +744,19 @@ PyObject *gchash_pywrap(gchash *ch)
   return ((PyObject *)g);
 }
 
-PyObject *ghash_pywrap(PyObject *cobj, ghash *h, unsigned f)
+PyObject *ghash_pywrap(PyObject *cobj, ghash *h)
 {
   ghash_pyobj *g;
   if (!cobj) cobj = gchash_pywrap((/*unconst*/ gchash *)GH_CLASS(h));
   else Py_INCREF(cobj);
   g = PyObject_NEW(ghash_pyobj, (PyTypeObject *)cobj);
   g->h = h;
-  g->f = f;
   return ((PyObject *)g);
 }
 
 static void ghash_pydealloc(PyObject *me)
 {
-  if (GHASH_F(me) & f_freeme)
-    GH_DESTROY(GHASH_H(me));
+  GH_DESTROY(GHASH_H(me));
   Py_DECREF(me->ob_type);
   FREEOBJ(me);
 }
@@ -966,8 +961,7 @@ static PyObject *gmac_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
     goto end;
   if (keysz(sz, GCMAC_CM(ty)->keysz) != sz) VALERR("bad key length");
   return (gmac_pywrap((PyObject *)ty,
-                     GM_KEY(GCMAC_CM(ty), k, sz),
-                     f_freeme));
+                     GM_KEY(GCMAC_CM(ty), k, sz)));
 end:
   return (0);
 }
@@ -980,7 +974,6 @@ static PyObject *gmhash_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
   if (!PyArg_ParseTupleAndKeywords(arg, kw, ":new", KWLIST)) return (0);
   g = PyObject_NEW(ghash_pyobj, ty);
   g->h = GM_INIT(GMAC_M(ty));
-  g->f = f_freeme;
   Py_INCREF(ty);
   return ((PyObject *)g);
 }
@@ -1002,7 +995,7 @@ PyObject *gcmac_pywrap(gcmac *cm)
   return ((PyObject *)g);
 }
 
-PyObject *gmac_pywrap(PyObject *cobj, gmac *m, unsigned f)
+PyObject *gmac_pywrap(PyObject *cobj, gmac *m)
 {
   gmac_pyobj *g;
   if (!cobj) cobj = gcmac_pywrap((/*unconst*/ gcmac *)GM_CLASS(m));
@@ -1021,14 +1014,12 @@ PyObject *gmac_pywrap(PyObject *cobj, gmac *m, unsigned f)
   g->ty.ht_type.tp_new = gmhash_pynew;
   typeready(&g->ty.ht_type);
   g->m = m;
-  g->f = f;
   return ((PyObject *)g);
 }
 
 static void gmac_pydealloc(PyObject *me)
 {
-  if (GMAC_F(me) & f_freeme)
-    GM_DESTROY(GMAC_M(me));
+  GM_DESTROY(GMAC_M(me));
   Py_DECREF(me->ob_type);
   PyType_Type.tp_dealloc(me);
 }
index 364a3c9ad8c159239b9cb9991c66ba6d012084a4..d68026d2f71f7230058b4eb057948a4a0dd0c0a4 100644 (file)
@@ -503,21 +503,18 @@ typedef struct gccipher_pyobj {
 extern PyTypeObject *gccipher_pytype;
 #define GCCIPHER_PYCHECK(o) PyObject_TypeCheck((o), gccipher_pytype)
 #define GCCIPHER_CC(o) (((gccipher_pyobj *)(o))->cc)
-#define GCCIPHER_F(o) (((gccipher_pyobj *)(o))->f)
 extern PyObject *gccipher_pywrap(gccipher *);
 extern int convgccipher(PyObject *, void *);
 
 typedef struct gcipher_pyobj {
   PyObject_HEAD
-  unsigned f;
   gcipher *c;
 } gcipher_pyobj;
 
 extern PyTypeObject *gcipher_pytype;
 #define GCIPHER_PYCHECK(o) PyObject_TypeCheck((o), gcipher_pytype)
 #define GCIPHER_C(o) (((gcipher_pyobj *)(o))->c)
-#define GCIPHER_F(o) (((gcipher_pyobj *)(o))->f)
-extern PyObject *gcipher_pywrap(PyObject *, gcipher *, unsigned);
+extern PyObject *gcipher_pywrap(PyObject *, gcipher *);
 extern int convgcipher(PyObject *, void *);
 
 typedef struct gchash_pyobj {
@@ -528,13 +525,11 @@ typedef struct gchash_pyobj {
 extern PyTypeObject *gchash_pytype;
 #define GCHASH_PYCHECK(o) PyObject_TypeCheck((o), gchash_pytype)
 #define GCHASH_CH(o) (((gchash_pyobj *)(o))->ch)
-#define GCHASH_F(o) (((gchash_pyobj *)(o))->f)
 extern PyObject *gchash_pywrap(gchash *);
 extern int convgchash(PyObject *, void *);
 
 typedef struct ghash_pyobj {
   PyObject_HEAD
-  unsigned f;
   ghash *h;
 } ghash_pyobj;
 
@@ -542,8 +537,7 @@ extern PyTypeObject *ghash_pytype, *gmhash_pytype;
 extern PyObject *sha_pyobj, *has160_pyobj;
 #define GHASH_PYCHECK(o) PyObject_TypeCheck((o), ghash_pytype)
 #define GHASH_H(o) (((ghash_pyobj *)(o))->h)
-#define GHASH_F(o) (((ghash_pyobj *)(o))->f)
-extern PyObject *ghash_pywrap(PyObject *, ghash *, unsigned);
+extern PyObject *ghash_pywrap(PyObject *, ghash *);
 extern int convghash(PyObject *, void *);
 extern int convgmhash(PyObject *, void *);
 
@@ -561,7 +555,6 @@ extern int convgcmac(PyObject *, void *);
 
 typedef struct gmac_pyobj {
   PyHeapTypeObject ty;
-  unsigned f;
   gmac *m;
 } gmac_pyobj;
 
@@ -569,7 +562,7 @@ extern PyTypeObject *gmac_pytype;
 #define GMAC_PYCHECK(o) PyObject_TypeCheck((o), gmac_pytype)
 #define GMAC_M(o) (((gmac_pyobj *)(o))->m)
 #define GMAC_F(o) (((gmac_pyobj *)(o))->f)
-extern PyObject *gmac_pywrap(PyObject *, gmac *, unsigned);
+extern PyObject *gmac_pywrap(PyObject *, gmac *);
 extern int convgmac(PyObject *, void *);
 
 /*----- Key generation ----------------------------------------------------*/
index 6cdfad93c6e48d46c7dca78e1c64eae9e11d8050..9c43ca723db0fd3e66bac162ec1c19822bbda098 100644 (file)
--- a/pubkey.c
+++ b/pubkey.c
@@ -112,7 +112,7 @@ end:
 static PyObject *dsameth_beginhash(PyObject *me, PyObject *arg)
 {
   if (!PyArg_ParseTuple(arg, ":beginhash")) return (0);
-  return (ghash_pywrap(DSA_HASH(me), gdsa_beginhash(DSA_D(me)), f_freeme));
+  return (ghash_pywrap(DSA_HASH(me), gdsa_beginhash(DSA_D(me))));
 }
 
 static PyObject *dsameth_endhash(PyObject *me, PyObject *arg)
@@ -366,7 +366,7 @@ end:
 static PyObject *kcdsameth_beginhash(PyObject *me, PyObject *arg)
 {
   if (!PyArg_ParseTuple(arg, ":beginhash")) return (0);
-  return (ghash_pywrap(DSA_HASH(me), gkcdsa_beginhash(DSA_D(me)), f_freeme));
+  return (ghash_pywrap(DSA_HASH(me), gkcdsa_beginhash(DSA_D(me))));
 }
 
 static PyObject *kcdsameth_endhash(PyObject *me, PyObject *arg)