X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/994b671e8ee14c5690c179bb19d3f1cfc4286186..e9007aacc11beec8ee9521ff960c58f56b035ebc:/key.c diff --git a/key.c b/key.c index 504206d..d91651a 100644 --- a/key.c +++ b/key.c @@ -36,25 +36,32 @@ static PyObject *keyfilebrokenexc; static PyObject *kxmeth___init__(PyObject *me, PyObject *arg) { - int err; + long err; PyObject *x = 0; + Py_ssize_t n; + + n = PyTuple_GET_SIZE(arg); + if (n < 2) TYERR("__init__() takes at least two arguments"); + me = PyTuple_GET_ITEM(arg, 0); + err = PyInt_AsLong(PyTuple_GET_ITEM(arg, 1)); + if (err == -1 && PyErr_Occurred()) goto end; + if (INT_MIN > err || err > INT_MAX) OVFERR("error code out of range"); - if (!PyArg_ParseTuple(arg, "Oi:__init__", &me, &err) || - (x = PyInt_FromLong(err)) == 0 || - PyObject_SetAttrString(me, "err", x)) - goto fail; + x = PyInt_FromLong(err); if (!x) goto end; + if (PyObject_SetAttrString(me, "err", x)) goto end; Py_DECREF(x); x = 0; + if ((x = PyString_FromString(key_strerror(err))) == 0 || PyObject_SetAttrString(me, "errstring", x)) - goto fail; + goto end; Py_DECREF(x); x = 0; - if ((x = PySequence_GetSlice(arg, 1, PySequence_Size(arg))) == 0 || + if ((x = PyTuple_GetSlice(arg, 1, n)) == 0 || PyObject_SetAttrString(me, "args", x)) - goto fail; + goto end; Py_DECREF(x); x = 0; RETURN_NONE; -fail: +end: Py_XDECREF(x); return (0); }