chiark / gitweb /
Further fixing to use `Py_ssize_t' in place of int.
[catacomb-python] / group.c
diff --git a/group.c b/group.c
index 1f733a092d87f49f3f2d7fb483d3d9ed85e3acdc..5cc40e54a364cecb0028ca35329e9afc5fb0c792 100644 (file)
--- a/group.c
+++ b/group.c
@@ -264,7 +264,7 @@ static PyObject *meth__parse(PyObject *me, PyObject *arg, PyTypeObject *ty,
   if (!PyArg_ParseTuple(arg, "Os:parse", &me, &p)) goto end;
   qd.p = p;
   qd.e = 0;
-  if (parse(&qd, &gp)) SYNERR(qd.e);
+  if (parse(&qd, &gp)) VALERR(qd.e);
   rc = fginfo_pywrap(&gp, ty);
 end:
   return (rc);
@@ -302,7 +302,7 @@ static PyGetSetDef bindhinfo_pygetset[] = {
 
 static PyTypeObject fginfo_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "catacomb.FGInfo",                   /* @tp_name@ */
+  "FGInfo",                            /* @tp_name@ */
   sizeof(fginfo_pyobj),                        /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
@@ -350,7 +350,7 @@ static PyTypeObject fginfo_pytype_skel = {
 
 static PyTypeObject dhinfo_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "catacomb.DHInfo",                   /* @tp_name@ */
+  "DHInfo",                            /* @tp_name@ */
   sizeof(fginfo_pyobj),                        /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
@@ -398,7 +398,7 @@ static PyTypeObject dhinfo_pytype_skel = {
 
 static PyTypeObject bindhinfo_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "catacomb.BinDHInfo",                        /* @tp_name@ */
+  "BinDHInfo",                         /* @tp_name@ */
   sizeof(fginfo_pyobj),                        /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
@@ -517,7 +517,7 @@ static PyObject *ge_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
     sc.buf = PyString_AS_STRING(x);
     sc.lim = sc.buf + PyString_GET_SIZE(x);
     if (G_READ(g, xx, &mptext_stringops, &sc) || sc.buf < sc.lim)
-      SYNERR("malformed group element string");
+      VALERR("malformed group element string");
   } else
     TYERR("can't convert to group element");
   return (ge_pywrap((PyObject *)ty, xx));
@@ -542,7 +542,7 @@ static PyObject *group_dopywrap(PyTypeObject *ty, group *g)
   gobj->ty.ht_type.tp_alloc = PyType_GenericAlloc;
   gobj->ty.ht_type.tp_free = 0;
   gobj->ty.ht_type.tp_new = ge_pynew;
-  PyType_Ready(&gobj->ty.ht_type);
+  typeready(&gobj->ty.ht_type);
   return ((PyObject *)gobj);
 }
 
@@ -868,7 +868,7 @@ static PyObject *meth__GE_fromstring(PyObject *me, PyObject *arg)
   g = GROUP_G(me);
   x = G_CREATE(g);
   if (G_READ(g, x, &mptext_stringops, &sc))
-    SYNERR("bad group element string");
+    VALERR("bad group element string");
   return (Py_BuildValue("(Ns#)", ge_pywrap(me, x),
                        sc.buf, (int)(sc.lim - sc.buf)));
 end:
@@ -887,7 +887,7 @@ static PyObject *meth__Group_parse(PyObject *me, PyObject *arg)
   qd.p = p;
   qd.e = 0;
   if ((g = group_parse(&qd)) == 0)
-    SYNERR(qd.e);
+    VALERR(qd.e);
   return (group_pywrap(g));
 end:
   return (0);
@@ -914,6 +914,20 @@ static PyObject *gget_g(PyObject *me, void *hunoz)
   G_COPY(g, x, g->g); return (ge_pywrap(me, x));
 }
 
+static long ge_pyhash(PyObject *me)
+{
+  buf b;
+  size_t sz = GE_G(me)->noctets + 4;
+  uint32 h = 0xf672c776 + GE_G(me)->ops->ty;
+  octet *p = xmalloc(sz);
+  buf_init(&b, p, sz);
+  G_TOBUF(GE_G(me), &b, GE_X(me));
+  assert(BOK(&b));
+  h = unihash_hash(&unihash_global, h, BBASE(&b), BLEN(&b));
+  xfree(p);
+  return (h % LONG_MAX);
+}
+
 static PyObject *gget_r(PyObject *me, void *hunoz)
   { return (mp_pywrap(MP_COPY(GROUP_G(me)->r))); }
 
@@ -986,7 +1000,7 @@ static PyNumberMethods ge_pynumber = {
 
 static PyTypeObject ge_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "catacomb.GE",                       /* @tp_name@ */
+  "GE",                                        /* @tp_name@ */
   sizeof(ge_pyobj),                    /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
@@ -999,7 +1013,7 @@ static PyTypeObject ge_pytype_skel = {
   &ge_pynumber,                                /* @tp_as_number@ */
   0,                                   /* @tp_as_sequence@ */
   0,                                   /* @tp_as_mapping@ */
-  0,                                   /* @tp_hash@ */
+  ge_pyhash,                           /* @tp_hash@ */
   0,                                   /* @tp_call@ */
   ge_pystr,                            /* @tp_str@ */
   0,                                   /* @tp_getattro@ */
@@ -1056,7 +1070,7 @@ G.mexp([(X0, N0), (X1, N1), ...]) -> X0^N0 X1^N1 ...")
 
 static PyTypeObject group_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "catacomb.Group",                    /* @tp_name@ */
+  "Group",                             /* @tp_name@ */
   sizeof(group_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
@@ -1133,7 +1147,7 @@ static PyObject *primegroup_pynew(PyTypeObject *ty,
 
 static PyTypeObject primegroup_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "catacomb.PrimeGroup",               /* @tp_name@ */
+  "PrimeGroup",                                /* @tp_name@ */
   sizeof(group_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
@@ -1210,7 +1224,7 @@ static PyObject *bingroup_pynew(PyTypeObject *ty,
 
 static PyTypeObject bingroup_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "catacomb.BinGroup",                 /* @tp_name@ */
+  "BinGroup",                          /* @tp_name@ */
   sizeof(group_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
@@ -1288,7 +1302,7 @@ static PyObject *ecgroup_pynew(PyTypeObject *ty,
 
 static PyTypeObject ecgroup_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "catacomb.ECGroup",                  /* @tp_name@ */
+  "ECGroup",                           /* @tp_name@ */
   sizeof(group_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */