From fbca05a1f15343b6e3a3b31edb3983e473fd7608 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Tue, 7 Mar 2006 14:25:03 +0000 Subject: [PATCH] Remove the various `getuNN' functions and replace them with getulong(). Organization: Straylight/Edgeware From: Mark Wooding They weren't doing any real good anyway, and the implementation was randomly buggy. --- buffer.c | 2 +- catacomb-python.h | 3 +-- key.c | 6 +++--- rand.c | 4 ++-- util.c | 16 +++++++--------- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/buffer.c b/buffer.c index 7456a3d..7220d84 100644 --- a/buffer.c +++ b/buffer.c @@ -114,7 +114,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); \ } diff --git a/catacomb-python.h b/catacomb-python.h index fa99298..722d7ad 100644 --- a/catacomb-python.h +++ b/catacomb-python.h @@ -237,8 +237,7 @@ extern int convszt(PyObject *, void *); extern int convbool(PyObject *, void *); extern PyObject *abstract_pynew(PyTypeObject *, PyObject *, PyObject *); extern PyObject *getbool(int); -#define DECL_GETU_(n) extern PyObject *getu##n(uint##n); -DOUINTSZ(DECL_GETU_) +extern PyObject *getulong(unsigned long); extern void *newtype(PyTypeObject *, const PyTypeObject *, const char *); extern PyObject * mkexc(PyObject *, PyObject *, const char *, PyMethodDef *); diff --git a/key.c b/key.c index 3cd1f1e..c9accd3 100644 --- a/key.c +++ b/key.c @@ -287,7 +287,7 @@ static PyObject *meth__KeyData_readflags(PyObject *me, PyObject *arg) goto end; if ((err = key_readflags(p, &end, &f, &m)) != 0) KEYERR(err); - rc = Py_BuildValue("(NNs)", getu32(f), getu32(m), end); + rc = Py_BuildValue("(NNs)", getulong(f), getulong(m), end); end: return (rc); } @@ -446,7 +446,7 @@ end: } static PyObject *kdget_flags(PyObject *me, void *hunoz) - { return (getu32(KEYDATA_KD(me)->e)); } + { return (getulong(KEYDATA_KD(me)->e)); } static PyMethodDef keydata_pymethods[] = { #define METHNAME(func) kdmeth_##func @@ -1463,7 +1463,7 @@ static PyObject *kmeth_fingerprint(PyObject *me, } static PyObject *kget_id(PyObject *me, void *hunoz) - { return (getu32(KEY_K(me)->id)); } + { return (getulong(KEY_K(me)->id)); } static PyObject *kget_file(PyObject *me, void *hunoz) { RETURN_OBJ(KEY_KFOBJ(me)); } static PyObject *kget_type(PyObject *me, void *hunoz) diff --git a/rand.c b/rand.c index 4b40a75..7f33e13 100644 --- a/rand.c +++ b/rand.c @@ -80,7 +80,7 @@ static PyObject *grmeth_byte(PyObject *me, PyObject *arg) static PyObject *grmeth_word(PyObject *me, PyObject *arg) { if (!PyArg_ParseTuple(arg, ":word")) return (0); - return (getu32(grand_word(GRAND_R(me)))); + return (getulong(grand_word(GRAND_R(me)))); } static PyObject *grmeth_range(PyObject *me, PyObject *arg) @@ -1076,7 +1076,7 @@ static PyObject *bbsmeth_bits(PyObject *me, PyObject *arg) grand *r = GRAND_R(me); unsigned n; uint32 w; if (!PyArg_ParseTuple(arg, "O&:bits", convuint, &n)) goto end; if (n > 32) VALERR("can't get more than 32 bits"); - r->ops->misc(r, BBS_BITS, n, &w); return (getu32(w)); + r->ops->misc(r, BBS_BITS, n, &w); return (getulong(w)); end: return (0); } diff --git a/util.c b/util.c index 27af83a..166cdbb 100644 --- a/util.c +++ b/util.c @@ -32,15 +32,13 @@ /*----- Conversions -------------------------------------------------------*/ -#define GETU_(n) \ - PyObject *getu##n(uint##n w) \ - { \ - if (w <= MASK##n) \ - return (PyInt_FromLong(w)); \ - else \ - return (PyLong_FromUnsignedLong(w)); \ - } -DOUINTSZ(GETU_) +PyObject *getulong(unsigned long w) +{ + if (w <= MASK32) + return (PyInt_FromLong(w)); + else + return (PyLong_FromUnsignedLong(w)); +} PyObject *getbool(int b) { -- [mdw]