From: Mark Wooding Date: Thu, 27 Jul 2017 09:41:22 +0000 (+0100) Subject: *.pyx, defs.pxi, *.c: Fixes for 64-bit builds. X-Git-Tag: 1.1.0~12 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib-python/commitdiff_plain/78911cdb6782ddccef6de3cc913b714e10d2fc14 *.pyx, defs.pxi, *.c: Fixes for 64-bit builds. Pyrex (at least nowadays) declares `PY_SSIZE_T_CLEAN', so make this be likely to work. Also, use `socklen_t' as necessary. --- diff --git a/array.c b/array.c index 724f16b..d83f64e 100644 --- a/array.c +++ b/array.c @@ -26,6 +26,8 @@ /*----- Header files ------------------------------------------------------*/ +#define PY_SSIZE_T_CLEAN + #include #include @@ -257,7 +259,7 @@ static void da_pydealloc(PyObject *me) DA_DESTROY(DA_V(me)); } -static int da_pylength(PyObject *me) +static Py_ssize_t da_pylength(PyObject *me) { return (DA_LEN(DA_V(me))); } static int da_pytraverse(PyObject *me, visitproc proc, void *arg) @@ -295,12 +297,12 @@ static PyObject *da_pyconcat(PyObject *me, PyObject *other) return (x); } -static PyObject *da_pyrepeat(PyObject *me, int times) +static PyObject *da_pyrepeat(PyObject *me, Py_ssize_t times) { PyObject *x = da_new(&da_pytype); PyObject **items = DA(DA_V(me)), **dest; size_t n = DA_LEN(DA_V(me)); - int i; + Py_ssize_t i; DA_ENSURE(DA_V(x), n * times); DA_UNSAFE_EXTEND(DA_V(x), n * times); @@ -310,7 +312,7 @@ static PyObject *da_pyrepeat(PyObject *me, int times) return (x); } -static PyObject *da_pygetitem(PyObject *me, int i) +static PyObject *da_pygetitem(PyObject *me, Py_ssize_t i) { PyObject *o; @@ -323,7 +325,7 @@ static PyObject *da_pygetitem(PyObject *me, int i) return (o); } -static PyObject *da_pygetslice(PyObject *me, int i, int j) +static PyObject *da_pygetslice(PyObject *me, Py_ssize_t i, Py_ssize_t j) { PyObject *x; @@ -336,7 +338,7 @@ static PyObject *da_pygetslice(PyObject *me, int i, int j) return (x); } -static int da_pyputitem(PyObject *me, int i, PyObject *x) +static int da_pyputitem(PyObject *me, Py_ssize_t i, PyObject *x) { PyObject **p; @@ -351,7 +353,8 @@ static int da_pyputitem(PyObject *me, int i, PyObject *x) return (0); } -static int da_pyputslice(PyObject *me, int i, int j, PyObject *x) +static int da_pyputslice(PyObject *me, Py_ssize_t i, Py_ssize_t j, + PyObject *x) { return (da_insert(me, x, i, j)); } static int da_pycontainsp(PyObject *me, PyObject *x) @@ -375,7 +378,7 @@ static PyObject *da_pyrepr(PyObject *me) dstr d = DSTR_INIT; PyObject *s, *rc = 0; char *p; - int n; + Py_ssize_t n; size_t i; dstr_puts(&d, "Array(["); @@ -403,11 +406,11 @@ static PyObject *da_pyappend(PyObject *me, PyObject *seq) RETURN_ME; } -static PyObject *da_pyiprepeat(PyObject *me, int times) +static PyObject *da_pyiprepeat(PyObject *me, Py_ssize_t times) { PyObject **items, **dest; size_t n = DA_LEN(DA_V(me)); - int i; + Py_ssize_t i; if (times < 0) { PyErr_SetString(PyExc_ValueError, "multiplier must be nonnegative"); @@ -432,7 +435,7 @@ static PyObject *da_pyiprepeat(PyObject *me, int times) static PyObject *da_pyget(PyObject *me, PyObject *index) { if (PySlice_Check(index)) { - int start, stop, step, len; + Py_ssize_t start, stop, step, len; PyObject *v; PyObject **ww; PyObject **vv; @@ -463,7 +466,7 @@ static PyObject *da_pyget(PyObject *me, PyObject *index) static int da_pyput(PyObject *me, PyObject *index, PyObject *x) { if (PySlice_Check(index)) { - int start, stop, step, len; + Py_ssize_t start, stop, step, len; size_t n; PyObject **ww; PyObject **vv; diff --git a/assoc.pyx b/assoc.pyx index 2a6e6e5..246bb24 100644 --- a/assoc.pyx +++ b/assoc.pyx @@ -34,7 +34,7 @@ cdef class AssocTable (Mapping): return 0 cdef void *_find(me, object key, unsigned *f) except NULL: cdef void *p - cdef int n + cdef Py_ssize_t n cdef _assoc_entry *e cdef atom *a a = ATOM_A(atom_pyintern(key)) diff --git a/atom-base.c b/atom-base.c index 68ab64b..f57eaee 100644 --- a/atom-base.c +++ b/atom-base.c @@ -66,7 +66,7 @@ PyObject *atom_pyintern(PyObject *x) { atom *a; const void *p; - int n; + Py_ssize_t n; if (ATOM_PYCHECK(x)) RETURN_OBJ(x); @@ -131,7 +131,7 @@ static PyObject *atom_pyrepr(PyObject *me) PyObject *s, *sr = 0; PyObject *rc = 0; char *p; - int n; + Py_ssize_t n; dstr d = DSTR_INIT; if ((s = aget_name(me, 0)) == 0 || diff --git a/codec.pyx b/codec.pyx index 1b395af..aa5e692 100644 --- a/codec.pyx +++ b/codec.pyx @@ -108,7 +108,7 @@ cdef class _BaseCodec: me.c.ops.destroy(me.c) cdef code(me, text, int finishp): cdef void *p - cdef int len + cdef Py_ssize_t len cdef dstr d cdef int err if me.c is NULL: diff --git a/codec.pyx.in b/codec.pyx.in index 98fc8dd..a1199c6 100644 --- a/codec.pyx.in +++ b/codec.pyx.in @@ -60,7 +60,7 @@ cdef class %CLASS%Encode: me.ctx.maxline = maxline def encode(me, text): cdef void *p - cdef int len + cdef Py_ssize_t len cdef dstr d DCREATE(&d) try: @@ -91,7 +91,7 @@ cdef class %CLASS%Decode: me.ctx.indent = NULL def decode(me, text): cdef void *p - cdef int len + cdef Py_ssize_t len cdef dstr d DCREATE(&d) try: diff --git a/crc32.pyx b/crc32.pyx index 5790d24..5584df2 100644 --- a/crc32.pyx +++ b/crc32.pyx @@ -31,7 +31,7 @@ cdef class CRC32: pass def chunk(me, data): cdef void *p - cdef int n + cdef Py_ssize_t n PyObject_AsReadBuffer(data, &p, &n) me._a = c_crc32(me._a, p, n) return me @@ -40,7 +40,7 @@ cdef class CRC32: def crc32(data): cdef void *p - cdef int n + cdef Py_ssize_t n cdef uint32 c PyObject_AsReadBuffer(data, &p, &n) c = c_crc32(0, p, n) diff --git a/defs.pxi b/defs.pxi index e7086b7..174f6cf 100644 --- a/defs.pxi +++ b/defs.pxi @@ -54,6 +54,7 @@ cdef extern from 'sys/time.h': int tv_usec cdef extern from 'sys/socket.h': + ctypedef int socklen_t struct sockaddr: int sa_family enum: @@ -94,9 +95,9 @@ cdef extern from 'Python.h': ctypedef struct PyTypeObject: pass - object PyString_FromStringAndSize(char *p, int len) - int PyString_AsStringAndSize(obj, char **p, int *len) except -1 - int PyObject_AsReadBuffer(obj, void **buf, int *len) except -1 + object PyString_FromStringAndSize(char *p, Py_ssize_t len) + int PyString_AsStringAndSize(obj, char **p, Py_ssize_t *len) except -1 + int PyObject_AsReadBuffer(obj, void **buf, Py_ssize_t *len) except -1 int PyObject_TypeCheck(obj, ty) object PyInt_FromLong(long i) object PyLong_FromUnsignedLong(unsigned long i) diff --git a/fdutils.pyx b/fdutils.pyx index 8e5d94a..68e0568 100644 --- a/fdutils.pyx +++ b/fdutils.pyx @@ -34,7 +34,7 @@ def fdflags(file, def fdsend(sock, file, buffer): cdef void *p - cdef int len + cdef Py_ssize_t len cdef int rc PyObject_AsReadBuffer(buffer, &p, &len) rc = fdpass_send(_getfd(sock), _getfd(file), p, len) @@ -45,7 +45,7 @@ def fdsend(sock, file, buffer): def fdrecv(sock, unsigned size): cdef void *p cdef buf - cdef int len + cdef Py_ssize_t len cdef PyObject *obj cdef int fd buf = PyString_FromStringAndSize(NULL, size) diff --git a/ident.pyx b/ident.pyx index 1cc9e9e..90d8f0f 100644 --- a/ident.pyx +++ b/ident.pyx @@ -55,7 +55,7 @@ cdef class SelIdentify: badproc = None, errorproc = None, failedproc = None, *hunoz, **hukairz): cdef sockaddr_in s_in, s_out - cdef size_t sz_in, sz_out + cdef socklen_t sz_in, sz_out cdef int fd if PyObject_TypeCheck(sk, socket.SocketType): fd = sk.fileno() diff --git a/lbuf.pyx b/lbuf.pyx index b80b5cc..2793e47 100644 --- a/lbuf.pyx +++ b/lbuf.pyx @@ -93,7 +93,7 @@ cdef class LineBuffer: cdef char *p return lbuf_free(&me.b, &p) def flush(me, str): - cdef int len + cdef Py_ssize_t len cdef char *p cdef char *q cdef size_t n diff --git a/pkbuf.pyx b/pkbuf.pyx index 963625e..67b248f 100644 --- a/pkbuf.pyx +++ b/pkbuf.pyx @@ -79,7 +79,7 @@ cdef class PacketBuffer: cdef unsigned char *p return pkbuf_free(&me.pk, &p) def flush(me, str): - cdef int len + cdef Py_ssize_t len cdef unsigned char *p cdef unsigned char *q cdef size_t n @@ -108,7 +108,7 @@ cdef void _pkfunc(unsigned char *p, size_t n, pkbuf *pk, size_t *keep, void *arg): cdef PacketBuffer pb cdef void *rp - cdef int rn + cdef Py_ssize_t rn pb = arg if p is NULL: pb.eof() diff --git a/selpk.pyx b/selpk.pyx index 42d15dd..ed08fcd 100644 --- a/selpk.pyx +++ b/selpk.pyx @@ -86,7 +86,7 @@ cdef void _selpkfunc(unsigned char *p, size_t n, pkbuf *pk, size_t *keep, void *arg): cdef SelPacketBuffer pb cdef void *rp - cdef int rn + cdef Py_ssize_t rn pb = arg if p is NULL: pb.eof() diff --git a/sym.pyx b/sym.pyx index e8842e6..9e97b7b 100644 --- a/sym.pyx +++ b/sym.pyx @@ -34,7 +34,7 @@ cdef class SymTable (Mapping): return 0 cdef void *_find(me, object key, unsigned *f) except NULL: cdef void *p - cdef int n + cdef Py_ssize_t n cdef _sym_entry *e PyObject_AsReadBuffer(key, &p, &n) if f: diff --git a/unihash.pyx b/unihash.pyx index 5b58d78..74217e8 100644 --- a/unihash.pyx +++ b/unihash.pyx @@ -51,7 +51,7 @@ cdef class Unihash: me._a = UNIHASH_INIT(me._i) def chunk(me, data): cdef void *p - cdef int n + cdef Py_ssize_t n PyObject_AsReadBuffer(data, &p, &n) me._a = unihash_hash(me._i, me._a, p, n) def done(me):