X-Git-Url: https://git.distorted.org.uk/~mdw/pyke/blobdiff_plain/61355eafd47fdabf8a4d80985dc6a06f22bdcb35..598327e56b4c57b391881c30f52f068e611552ba:/catacomb.c diff --git a/catacomb.c b/catacomb.c index 572f80f..b54227f 100644 --- a/catacomb.c +++ b/catacomb.c @@ -31,14 +31,16 @@ /*----- Main code ---------------------------------------------------------*/ static const struct nameval consts[] = { -#define C(x) { #x, x } +#define CF(f, x) { #x, f, x } +#define C(x) { #x, (x) >= 0 ? 0 : CF_SIGNED, x } C(FTY_PRIME), C(FTY_BINARY), C(PGEN_PASS), C(PGEN_FAIL), C(PGEN_BEGIN), C(PGEN_TRY), C(PGEN_DONE), C(PGEN_ABORT), C(MPW_MAX), + C(RAND_IBITS), C(PMODE_READ), C(PMODE_VERIFY), C(KOPEN_READ), C(KOPEN_WRITE), C(KOPEN_NOFILE), - C(KEXP_FOREVER), C(KEXP_EXPIRE), + CF(0, KEXP_FOREVER), CF(0, KEXP_EXPIRE), C(KF_ENCMASK), C(KENC_BINARY), C(KENC_MP), C(KENC_STRUCT), C(KENC_ENCRYPT), C(KENC_STRING), C(KENC_EC), C(KF_CATMASK), C(KCAT_SYMM), C(KCAT_PRIV), C(KCAT_PUB), C(KCAT_SHARE), @@ -56,6 +58,7 @@ static const struct nameval consts[] = { KEY_ERRORS(ENTRY) #undef ENTRY #undef C +#undef CF { 0 } }; @@ -71,11 +74,12 @@ PyObject *mexp_common(PyObject *me, PyObject *arg, PyObject *qq, *x, *y, *z = 0; char *v = 0, *vv; - if (PyTuple_Size(arg) == 1) - arg = PyTuple_GetItem(arg, 0); + if (PyTuple_GET_SIZE(arg) == 1) + arg = PyTuple_GET_ITEM(arg, 0); Py_INCREF(arg); if (!PySequence_Check(arg)) TYERR("not a sequence"); - n = PySequence_Size(arg); if (!n) { z = id(me); goto end; } + n = PySequence_Size(arg); if (n < 0) goto end; + if (!n) { z = id(me); goto end; } x = PySequence_GetItem(arg, 0); if (PySequence_Check(x)) flat = 0; @@ -131,7 +135,7 @@ static PyObject *smallprimes(void) int i; for (i = 0; i < NPRIME; i++) - PyList_SetItem(v, i, PyInt_FromLong(primetab[i])); + PyList_SET_ITEM(v, i, PyInt_FromLong(primetab[i])); return (v); } @@ -147,14 +151,14 @@ static PyObject *meth__ego(PyObject *me, PyObject *arg) static PyMethodDef methods[] = { #define METHNAME(func) meth_##func - METH (_ego, "_ego(ARGV0)") + METH (_ego, "_ego(ARGV0)") #undef METHNAME { 0 } }; static void init_random(void) { -#if PY_MAJOR_VERSION >= 3 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 6) +#if PY_VERSION_HEX >= 0x02060000 char *seed; uint32 r; @@ -170,6 +174,8 @@ static void init_random(void) EXPORT void init_base(void) { PyObject *mod; + + modname = PyString_FromString("catacomb"); addmethods(methods); INIT_MODULES; init_random();