Message 156952 - Python tracker (original) (raw)

I have a couple of questions about the proposed capsule C API. In order to be useful, it should be possible to set temporary contexts and pass them to functions. For example, PyDec_Add could look like:

PyDec_Add(PyObject *a, PyObject *b, PyObject *context);

To stay sane, either access macros or access functions to the context would need to be provided:

CTX(workcontext)->prec = 100; PyDec_SetPrec(workcontext, 100); PyDecContext_SetPrec(workcontext, 100);

Probably flags would need to be checked at some point:

if (CTX(workcontext)->status & MPD_Underflow) if (PyDec_GetStatus(workcontext) & MPD_Underflow) if (PyDecContext_GetStatus(workcontext) & MPD_Underflow)

I wonder if users would not be better off if libmpdec functions and access macros were exposed instead. The big advantage is that errors (even malloc errors) propagate in the form of NaNs, so it is not necessary to do repeated error checking.

Also, I find things like (status & MPD_Underflow) more readable than the alternatives above.

I've attached a short (fake) example to demonstrate what I mean.