chiark / gitweb /
catacomb/__init__.py: Settle on SHAKE256 for X448 box-key generation.
[catacomb-python] / buffer.c
index 8e4ece55ffda821835914e8d071e59cd74b18d45..43bf02de7647989b3d91b5fd48d47dc2d3b8ab5a 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -1,13 +1,11 @@
 /* -*-c-*-
- *
- * $Id$
  *
  * Reading and writing buffers of stuff
  *
  * (c) 2005 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of the Python interface to Catacomb.
  *
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * Catacomb/Python is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with Catacomb/Python; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -55,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 };
 
@@ -79,11 +77,11 @@ 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)
-  { assert(seg == 0); *q = BBASE(BUF_B(me)); return (BSZ(BUF_B(me))); }
+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)
 {
@@ -114,7 +112,7 @@ end:
     uint##n x;                                                         \
     if (!PyArg_ParseTuple(arg, ":getu" #w)) goto end;                  \
     if (buf_getu##w(BUF_B(me), &x)) BUFERR();                          \
-    return (getu32(x));                                                        \
+    return (getulong(x));                                              \
   end:                                                                 \
     return (0);                                                                \
   }
@@ -186,7 +184,7 @@ static PyObject *rbmeth_getecpt(PyObject *me, PyObject *arg, PyObject *kw)
 end:
   return (0);
 }
-    
+
 static PyObject *rbmeth_getecptraw(PyObject *me, PyObject *arg)
 {
   PyTypeObject *cobj = ecpt_pytype;
@@ -236,6 +234,7 @@ static PyObject *rbget_offset(PyObject *me, void *hunoz)
 static int rbset_offset(PyObject *me, PyObject *x, void *hunoz)
 {
   size_t n;
+  if (!x) NIERR("__del__");
   if (!convszt(x, &n)) goto end;
   if (n > BSZ(BUF_B(me))) VALERR("out of range");
   BCUR(BUF_B(me)) = BBASE(BUF_B(me)) + n;
@@ -286,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@ */
 
@@ -341,7 +340,7 @@ static void ensure(PyObject *me, size_t n)
   if (BLEFT(b) < n) {
     size_t nn = BSZ(b);
     octet *p;
-    size_t want = BLEFT(b) + n;
+    size_t want = BLEN(b) + n;
     while (nn < want) nn <<= 1;
     p = xrealloc(BBASE(b), nn, BSZ(b));
     BCUR(b) = p + BLEN(b);
@@ -368,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)
@@ -388,7 +387,7 @@ 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)));
@@ -411,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)));           \
@@ -492,7 +491,7 @@ static PyGetSetDef wbuf_pygetset[] = {
 
 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)")
@@ -519,7 +518,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@ */