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 246bb24ca45c6175e2f672e58cdd455d484e2d05..38b8446f4b0ba86411b7a13706f904c7a6eb7629 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 aa5e69201e4e01126353874828f0c76db6d6b8bb..b9f910fd1ab3fb09547f6b05f46de8f9a0b1e0b5 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 a1199c6619b5769f47f2a5797e5a733a3d2ffc93..37e02936b4df0269ae8a429516d42c334eea7182 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 5584df280d8530ee003efae5e7562d6965360052..c1f3b82869fdfcf75ddc6f38fd3cea770907aeb2 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 174f6cf5c5a1fa9310471328fc668fb9988fa463..bfb4dcc52827fff16ce855a513a1694d607c3918 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 68e05680a48913b73cacbf85c2171abac156e362..bb28188ae162231ea5d7adab0feee4cc5e3621f7 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 38b72152bc11d9b7f769255e6cf351dc98fc6703..85ea681314e569fa8713ca9ccd8da8f4ab35b673 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 67b248fd76af439848e26e141a799ef143a6e3f5..2544aaaf554d7183d539c4510d9d51f7df6caa28 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 ed08fcd779eeae78954868e234819f4e43f2a4e9..7e3de7ea63279edb992ee7e2b3764e5a7dfed06e 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 9e97b7bcf382ae8f3d92ef250cb925aef69cf9f6..48ba3f05a1b24d4d91a2d8b2c574b759d4519d3c 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 74217e83a8416189797c1c2d4ce887c719349e89..de6f3d45a7c1600760d5edd88f005373d359640e 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)