From 704500e11c6a7e240acc047607d34bc6db520f15 Mon Sep 17 00:00:00 2001 Message-Id: <704500e11c6a7e240acc047607d34bc6db520f15.1714441755.git.mdw@distorted.org.uk> From: Mark Wooding Date: Thu, 27 Jul 2017 10:46:14 +0100 Subject: [PATCH] *.pyx, defs.pxi, grim.h: Add awful casts to `PyObject_AsReadBuffer'. Organization: Straylight/Edgeware From: Mark Wooding 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 | 2 +- codec.pyx | 2 +- codec.pyx.in | 4 ++-- crc32.pyx | 4 ++-- defs.pxi | 1 + fdutils.pyx | 2 +- grim.h | 1 + pkbuf.pyx | 4 ++-- selpk.pyx | 2 +- sym.pyx | 2 +- unihash.pyx | 2 +- 11 files changed, 14 insertions(+), 12 deletions(-) diff --git a/assoc.pyx b/assoc.pyx index 246bb24..38b8446 100644 --- 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, &p, &n) if f: f[0] = 0 e = <_assoc_entry *>assoc_find(&me._t, a, PSIZEOF(e), f) diff --git a/codec.pyx b/codec.pyx index aa5e692..b9f910f 100644 --- 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, &p, &len) code(me.c, p, len, &d) if finishp: code(me.c, NULL, 0, &d) diff --git a/codec.pyx.in b/codec.pyx.in index a1199c6..37e0293 100644 --- a/codec.pyx.in +++ b/codec.pyx.in @@ -64,7 +64,7 @@ cdef class %CLASS%Encode: cdef dstr d DCREATE(&d) try: - PyObject_AsReadBuffer(text, &p, &len) + PyObject_AsReadBuffer(text, &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, &p, &len) _%PREFIX%_decode(&me.ctx, p, len, &d) rc = PyString_FromStringAndSize(d.buf, d.len) finally: diff --git a/crc32.pyx b/crc32.pyx index 5584df2..c1f3b82 100644 --- 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, &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, &p, &n) c = c_crc32(0, p, n) return _u32(c) diff --git a/defs.pxi b/defs.pxi index 174f6cf..bfb4dcc 100644 --- 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 -------------------------------------------------- diff --git a/fdutils.pyx b/fdutils.pyx index 68e0568..bb28188 100644 --- a/fdutils.pyx +++ b/fdutils.pyx @@ -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, &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 --- 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) diff --git a/pkbuf.pyx b/pkbuf.pyx index 67b248f..2544aaa 100644 --- 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, &p, &len) + PyObject_AsReadBuffer(str, &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(p, n)) if r is not None: - PyObject_AsReadBuffer(r, &rp, &rn) + PyObject_AsReadBuffer(r, &rp, &rn) if rn > n: raise ValueError, 'remaining buffer too large' if rn: diff --git a/selpk.pyx b/selpk.pyx index ed08fcd..7e3de7e 100644 --- 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(p, n)) if r is not None: - PyObject_AsReadBuffer(r, &rp, &rn) + PyObject_AsReadBuffer(r, &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 --- 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, &p, &n) if f: f[0] = 0 e = <_sym_entry *>sym_find(&me._t, p, n, PSIZEOF(e), f) diff --git a/unihash.pyx b/unihash.pyx index 74217e8..de6f3d4 100644 --- a/unihash.pyx +++ b/unihash.pyx @@ -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, &p, &n) me._a = unihash_hash(me._i, me._a, p, n) def done(me): return _u32(me._a) -- [mdw]