X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/ba8b854c88c822a8e0db25c33bc8625120889492..e95512be8777eb7038fa26bffa0709013dc08f19:/buffer.c?ds=sidebyside diff --git a/buffer.c b/buffer.c index 6569516..b88232b 100644 --- a/buffer.c +++ b/buffer.c @@ -53,11 +53,11 @@ 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 }; + static const char *const kwlist[] = { "data", 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", kwlist, &p, &n)) + if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", KWLIST, &p, &n)) goto end; q = xmalloc(n); memcpy(q, p, n); @@ -171,9 +171,9 @@ end: static PyObject *rbmeth_getecpt(PyObject *me, PyObject *arg, PyObject *kw) { PyObject *cobj = Py_None; - static char *kwlist[] = { "curve", 0 }; + static const char *const kwlist[] = { "curve", 0 }; ec pt = EC_INIT; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O:getecpt", kwlist, &cobj)) + if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O:getecpt", KWLIST, &cobj)) goto end; if (cobj == Py_None) cobj = (PyObject *)ecpt_pytype; if (!PyType_Check(cobj) || @@ -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@ */ @@ -354,9 +354,9 @@ static PyObject *wbuf_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) char *p; size_t n = 64; buf_pyobj *me = 0; - static char *kwlist[] = { "size", 0 }; + static const char *const kwlist[] = { "size", 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:new", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:new", KWLIST, convszt, &n)) goto end; me = (buf_pyobj *)ty->tp_alloc(ty, 0); @@ -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,9 +482,13 @@ 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 } }; @@ -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@ */