X-Git-Url: https://git.distorted.org.uk/~mdw/pyke/blobdiff_plain/0a3ee1bdfd6ebd5c4bb71e2f117880243f0731f4..2ec562f15a095c23bc7c16199ea7428007b7b8ec:/util.c diff --git a/util.c b/util.c index d613a7a..9332c8b 100644 --- a/util.c +++ b/util.c @@ -280,14 +280,14 @@ PyTypeObject *inittype(PyTypeObject *tyskel, PyTypeObject *meta) void setconstants(PyObject *mod, const struct nameval *c) { PyObject *x; + unsigned long u; while (c->name) { - if (c->value > LONG_MAX) - x = PyLong_FromUnsignedLong(c->value); - else - x = PyInt_FromLong(c->value); - PyModule_AddObject(mod, (/*unconst*/ char *)c->name, x); - c++; + u = c->value; + if (u <= LONG_MAX) x = PyInt_FromLong(u); + else if (c->f&CF_SIGNED) x = PyInt_FromLong(-1 - (long)(ULONG_MAX - u)); + else x = PyLong_FromUnsignedLong(u); + PyModule_AddObject(mod, (/*unconst*/ char *)c->name, x); c++; } }