chiark / gitweb /
*.pyx, defs.pxi, grim.h: Add awful casts to `PyObject_AsReadBuffer'.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 27 Jul 2017 09:46:14 +0000 (10:46 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 16 Aug 2017 03:31:32 +0000 (04:31 +0100)
Muffles compiler warnings.  The second argument is meant to be `const
void **' which is hard to manufacture with Pyrex.  Smuggle a `const
void *' into Pyrex's brain from `grim.h' and cast the arguments.

assoc.pyx
codec.pyx
codec.pyx.in
crc32.pyx
defs.pxi
fdutils.pyx
grim.h
pkbuf.pyx
selpk.pyx
sym.pyx
unihash.pyx

index 246bb24..38b8446 100644 (file)
--- a/assoc.pyx
+++ b/assoc.pyx
@@ -38,7 +38,7 @@ cdef class AssocTable (Mapping):
     cdef _assoc_entry *e
     cdef atom *a
     a = ATOM_A(atom_pyintern(key))
-    PyObject_AsReadBuffer(key, &p, &n)
+    PyObject_AsReadBuffer(key, <cvp *>&p, &n)
     if f:
       f[0] = 0
       e = <_assoc_entry *>assoc_find(&me._t, a, PSIZEOF(e), f)
index aa5e692..b9f910f 100644 (file)
--- a/codec.pyx
+++ b/codec.pyx
@@ -115,7 +115,7 @@ cdef class _BaseCodec:
       raise ValueError, 'Encoding finished'
     DCREATE(&d)
     try:
-      PyObject_AsReadBuffer(text, &p, &len)
+      PyObject_AsReadBuffer(text, <cvp *>&p, &len)
       code(me.c, p, len, &d)
       if finishp:
         code(me.c, NULL, 0, &d)
index a1199c6..37e0293 100644 (file)
@@ -64,7 +64,7 @@ cdef class %CLASS%Encode:
     cdef dstr d
     DCREATE(&d)
     try:
-      PyObject_AsReadBuffer(text, &p, &len)
+      PyObject_AsReadBuffer(text, <cvp *>&p, &len)
       _%PREFIX%_encode(&me.ctx, p, len, &d)
       rc = PyString_FromStringAndSize(d.buf, d.len)
     finally:
@@ -95,7 +95,7 @@ cdef class %CLASS%Decode:
     cdef dstr d
     DCREATE(&d)
     try:
-      PyObject_AsReadBuffer(text, &p, &len)
+      PyObject_AsReadBuffer(text, <cvp *>&p, &len)
       _%PREFIX%_decode(&me.ctx, p, len, &d)
       rc = PyString_FromStringAndSize(d.buf, d.len)
     finally:
index 5584df2..c1f3b82 100644 (file)
--- a/crc32.pyx
+++ b/crc32.pyx
@@ -32,7 +32,7 @@ cdef class CRC32:
   def chunk(me, data):
     cdef void *p
     cdef Py_ssize_t n
-    PyObject_AsReadBuffer(data, &p, &n)
+    PyObject_AsReadBuffer(data, <cvp *>&p, &n)
     me._a = c_crc32(me._a, p, n)
     return me
   def done(me):
@@ -42,7 +42,7 @@ def crc32(data):
   cdef void *p
   cdef Py_ssize_t n
   cdef uint32 c
-  PyObject_AsReadBuffer(data, &p, &n)
+  PyObject_AsReadBuffer(data, <cvp *>&p, &n)
   c = c_crc32(0, p, n)
   return _u32(c)
 
index 174f6cf..bfb4dcc 100644 (file)
--- a/defs.pxi
+++ b/defs.pxi
@@ -439,5 +439,6 @@ cdef extern from 'mLib/daemonize.h':
 
 cdef extern from 'grim.h':
   int PSIZEOF(void *x)
+  ctypedef void *cvp
 
 ###----- That's all, folks --------------------------------------------------
index 68e0568..bb28188 100644 (file)
@@ -36,7 +36,7 @@ def fdsend(sock, file, buffer):
   cdef void *p
   cdef Py_ssize_t len
   cdef int rc
-  PyObject_AsReadBuffer(buffer, &p, &len)
+  PyObject_AsReadBuffer(buffer, <cvp *>&p, &len)
   rc = fdpass_send(_getfd(sock), _getfd(file), p, len)
   if rc < 0:
     _oserror()
diff --git a/grim.h b/grim.h
index 38b7215..85ea681 100644 (file)
--- a/grim.h
+++ b/grim.h
@@ -38,6 +38,7 @@
 /*----- Utilities ---------------------------------------------------------*/
 
 #define PSIZEOF(x) sizeof(*x)
+typedef const void *cvp;
 
 #define RETURN_OBJ(obj) do { Py_INCREF(obj); return (obj); } while (0)
 #define RETURN_ME RETURN_OBJ(me)
index 67b248f..2544aaa 100644 (file)
--- a/pkbuf.pyx
+++ b/pkbuf.pyx
@@ -83,7 +83,7 @@ cdef class PacketBuffer:
     cdef unsigned char *p
     cdef unsigned char *q
     cdef size_t n
-    PyObject_AsReadBuffer(str, <void **>&p, &len)
+    PyObject_AsReadBuffer(str, <cvp *>&p, &len)
     while len > 0:
       n = pkbuf_free(&me.pk, &q)
       if n > len:
@@ -115,7 +115,7 @@ cdef void _pkfunc(unsigned char *p, size_t n, pkbuf *pk,
   else:
     r = pb.packet(PyString_FromStringAndSize(<char *>p, n))
     if r is not None:
-      PyObject_AsReadBuffer(r, &rp, &rn)
+      PyObject_AsReadBuffer(r, <cvp *>&rp, &rn)
       if rn > n:
         raise ValueError, 'remaining buffer too large'
       if rn:
index ed08fcd..7e3de7e 100644 (file)
--- a/selpk.pyx
+++ b/selpk.pyx
@@ -93,7 +93,7 @@ cdef void _selpkfunc(unsigned char *p, size_t n, pkbuf *pk,
   else:
     r = pb.packet(PyString_FromStringAndSize(<char *>p, n))
     if r is not None:
-      PyObject_AsReadBuffer(r, &rp, &rn)
+      PyObject_AsReadBuffer(r, <cvp *>&rp, &rn)
       if rn > n:
         raise ValueError, 'remaining buffer too large'
       if rn:
diff --git a/sym.pyx b/sym.pyx
index 9e97b7b..48ba3f0 100644 (file)
--- a/sym.pyx
+++ b/sym.pyx
@@ -36,7 +36,7 @@ cdef class SymTable (Mapping):
     cdef void *p
     cdef Py_ssize_t n
     cdef _sym_entry *e
-    PyObject_AsReadBuffer(key, &p, &n)
+    PyObject_AsReadBuffer(key, <cvp *>&p, &n)
     if f:
       f[0] = 0
       e = <_sym_entry *>sym_find(&me._t, <char *>p, n, PSIZEOF(e), f)
index 74217e8..de6f3d4 100644 (file)
@@ -52,7 +52,7 @@ cdef class Unihash:
   def chunk(me, data):
     cdef void *p
     cdef Py_ssize_t n
-    PyObject_AsReadBuffer(data, &p, &n)
+    PyObject_AsReadBuffer(data, <cvp *>&p, &n)
     me._a = unihash_hash(me._i, me._a, p, n)
   def done(me):
     return _u32(me._a)