chiark / gitweb /
debian/: Use `dh_python2' for packaging.
[catacomb-python] / buffer.c
index 9b6e0ff73006f22b0d807df7825dfa2eebe8b638..bf1cadc554a5cc00d8e070b810a9868d2eb8c4c0 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -53,7 +53,7 @@ static PyObject *buferr;
 static PyObject *rbuf_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
 {
   char *p, *q;
-  int n;
+  Py_ssize_t n;
   buf_pyobj *me = 0;
   static char *kwlist[] = { "data", 0 };
 
@@ -77,10 +77,10 @@ static void buf_pydealloc(PyObject *me)
   FREEOBJ(me);
 }
 
-static int rbuf_pysegcount(PyObject *me, int *nn)
+static Py_ssize_t rbuf_pysegcount(PyObject *me, Py_ssize_t *nn)
   { if (nn) *nn = BSZ(BUF_B(me)); return (1); }
 
-static int rbuf_pyreadbuf(PyObject *me, int seg, void **q)
+static Py_ssize_t rbuf_pyreadbuf(PyObject *me, Py_ssize_t seg, void **q)
   { assert(seg == 0); *q = BCUR(BUF_B(me)); return (BLEFT(BUF_B(me))); }
 
 static PyObject *rbmeth_skip(PyObject *me, PyObject *arg)
@@ -285,7 +285,7 @@ static PyBufferProcs rbuf_pybuffer = {
 
 static PyTypeObject rbuf_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "catacomb.ReadBuffer",               /* @tp_name@ */
+  "ReadBuffer",                                /* @tp_name@ */
   sizeof(buf_pyobj),                   /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
@@ -308,7 +308,7 @@ static PyTypeObject rbuf_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-  "A read buffer.",
+"ReadBuffer(STR): a read buffer.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -367,10 +367,10 @@ end:
   return ((PyObject *)me);
 }
 
-static int wbuf_pysegcount(PyObject *me, int *nn)
+static Py_ssize_t wbuf_pysegcount(PyObject *me, Py_ssize_t *nn)
   { if (nn) *nn = BLEN(BUF_B(me)); return (1); }
 
-static int wbuf_pyreadbuf(PyObject *me, int seg, void **q)
+static Py_ssize_t wbuf_pyreadbuf(PyObject *me, Py_ssize_t seg, void **q)
   { assert(seg == 0); *q = BBASE(BUF_B(me)); return (BLEN(BUF_B(me))); }
 
 static PyObject *wbmeth_zero(PyObject *me, PyObject *arg)
@@ -387,10 +387,10 @@ static PyObject *wbmeth_zero(PyObject *me, PyObject *arg)
 static PyObject *wbmeth_put(PyObject *me, PyObject *arg)
 {
   void *p;
-  int n;
+  Py_ssize_t n;
   if (!PyArg_ParseTuple(arg, "s#:put", &p, &n)) return (0);
   ensure(me, n);
-  buf_put(BUF_B(me), p, n); assert(BOK(BUF_B(m)));
+  buf_put(BUF_B(me), p, n); assert(BOK(BUF_B(me)));
   RETURN_ME;
 }
 
@@ -410,7 +410,7 @@ DOUINTCONV(WBMETH_PUTU_)
   static PyObject *wbmeth_putblk##w(PyObject *me, PyObject *arg)       \
   {                                                                    \
     char *p;                                                           \
-    int sz;                                                            \
+    Py_ssize_t sz;                                                     \
     if (!PyArg_ParseTuple(arg, "s#:putblk" #w, &p, &sz)) return (0);   \
     ensure(me, sz + SZ_##n);                                           \
     buf_putmem##w(BUF_B(me), p, sz); assert(BOK(BUF_B(me)));           \
@@ -482,16 +482,20 @@ static PyObject *wbmeth_putgeraw(PyObject *me, PyObject *arg)
 static PyObject *wbget_size(PyObject *me, void *hunoz)
   { return (PyInt_FromLong(BLEN(BUF_B(me)))); }
 
+static PyObject *wbget_contents(PyObject *me, void *hunoz)
+  { return (bytestring_pywrap(BBASE(BUF_B(me)), BLEN(BUF_B(me)))); }
+
 static PyGetSetDef wbuf_pygetset[] = {
 #define GETSETNAME(op, name) wb##op##_##name
   GET  (size,                  "WBUF.size -> SIZE")
+  GET  (contents,              "WBUF.contents -> STR")
 #undef GETSETNAME
   { 0 }
 };
 
 static PyMethodDef wbuf_pymethods[] = {
 #define METHNAME(func) wbmeth_##func
-  METH (zero,                  "WBUF.skip(N)")
+  METH (zero,                  "WBUF.zero(N)")
   METH (put,                   "WBUF.put(BYTES)")
 #define WBMETH_DECL_PUTU_(n, W, w)                                     \
     METH(putu##w, "WBUF.putu" #w "(INT)")
@@ -518,7 +522,7 @@ static PyBufferProcs wbuf_pybuffer = {
 
 static PyTypeObject wbuf_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
-  "catacomb.WriteBuffer",              /* @tp_name@ */
+  "WriteBuffer",                       /* @tp_name@ */
   sizeof(buf_pyobj),                   /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
 
@@ -541,7 +545,7 @@ static PyTypeObject wbuf_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-  "A write buffer.",
+"WriteBuffer([size = ?]): a write buffer.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */