chiark / gitweb /
Buffer sharing and subbuffers.
[catacomb-python] / algorithms.c
index 2113cc5a171ccd3e5fcbd435980474232332cc5e..bd094fdc80f625f98fd92edef31df91c421a54fe 100644 (file)
@@ -777,9 +777,48 @@ static PyGetSetDef gchash_pygetset[] = {
   { 0 }
 };
 
   { 0 }
 };
 
+#define GHMETH_HASHU_(n, W, w)                                         \
+  static PyObject *ghmeth_hashu##w(PyObject *me, PyObject *arg)                \
+  {                                                                    \
+    uint##n x;                                                         \
+    if (!PyArg_ParseTuple(arg, "O&:hashu" #w, convu##n, &x)) goto end; \
+    GH_HASHU##W(GHASH_H(me), x);                                       \
+    RETURN_ME;                                                         \
+  end:                                                                 \
+    return (0);                                                                \
+  }
+DOUINTCONV(GHMETH_HASHU_)
+
+#define GHMETH_HASHBUF_(n, W, w)                                       \
+  static PyObject *ghmeth_hashbuf##w(PyObject *me, PyObject *arg)      \
+  {                                                                    \
+    char *p;                                                           \
+    int sz;                                                            \
+    if (!PyArg_ParseTuple(arg, "s#:hashbuf" #w, &p, &sz)) goto end;    \
+    if (sz > MASK##n) TYERR("string too long");                                \
+    GH_HASHBUF##W(GHASH_H(me), p, sz);                                 \
+    RETURN_ME;                                                         \
+  end:                                                                 \
+    return (0);                                                                \
+  }
+DOUINTCONV(GHMETH_HASHBUF_)
+
+static PyObject *ghmeth_hashstrz(PyObject *me, PyObject *arg)
+{
+  char *p;
+  if (!PyArg_ParseTuple(arg, "s:hashstrz", &p)) return (0);
+  GH_HASHSTRZ(GHASH_H(me), p);
+  RETURN_ME;
+}
+
 static PyMethodDef ghash_pymethods[] = {
 #define METHNAME(name) ghmeth_##name
   METH (hash,                  "H.hash(M)")
 static PyMethodDef ghash_pymethods[] = {
 #define METHNAME(name) ghmeth_##name
   METH (hash,                  "H.hash(M)")
+#define METHU_(n, W, w) METH(hashu##w, "H.hashu" #w "(WORD)")
+  DOUINTCONV(METHU_)
+#define METHBUF_(n, W, w) METH(hashbuf##w, "H.hashbuf" #w "(BYTES)")
+  DOUINTCONV(METHBUF_)
+  METH (hashstrz,              "H.hashstrz(STRING)")
   METH (done,                  "H.done() -> HASH")
 #undef METHNAME
   { 0 }
   METH (done,                  "H.done() -> HASH")
 #undef METHNAME
   { 0 }