chiark / gitweb /
Merge remote-tracking branch 'origin/HEAD'
[catacomb-python] / bytestring.c
index 4abb260cabd6e72196d63be90b500ba50884af40..2b74648d91d9ca2793f206ba4091e941123465f1 100644 (file)
@@ -61,11 +61,11 @@ static PyObject *bytestring_pynew(PyTypeObject *ty,
   return (dowrap(ty, p, n));
 }
 
-static PyObject *meth_ctstreq(PyObject *me, PyObject *args)
+static PyObject *meth_ctstreq(PyObject *me, PyObject *arg)
 {
   char *p, *q;
   Py_ssize_t psz, qsz;
-  if (!PyArg_ParseTuple(args, "s#s#:ctstreq", &p, &psz, &q, &qsz))
+  if (!PyArg_ParseTuple(arg, "s#s#:ctstreq", &p, &psz, &q, &qsz))
     goto end;
   if (psz == qsz && ct_memeq(p, q, psz)) RETURN_TRUE;
   else RETURN_FALSE;
@@ -73,6 +73,17 @@ end:
   return (0);
 }
 
+static PyObject *meth__ByteString_zero(PyObject *me, PyObject *arg)
+{
+  size_t sz;
+  PyObject *rc = 0;
+  if (!PyArg_ParseTuple(arg, "OO&:zero", &me, convszt, &sz)) goto end;
+  rc = bytestring_pywrap(0, sz);
+  memset(PyString_AS_STRING(rc), 0, sz);
+end:
+  return (rc);
+}
+
 static PyObject *bytestring_pyrichcompare(PyObject *me,
                                          PyObject *you, int op)
 {
@@ -228,6 +239,7 @@ static PyTypeObject bytestring_pytype_skel = {
 static PyMethodDef methods[] = {
 #define METHNAME(func) meth_##func
   METH  (ctstreq,              "ctstreq(S, T) -> BOOL")
+  METH (_ByteString_zero,      "zero(N) -> 0000...00")
 #undef METHNAME
   { 0 }
 };