Lines Matching defs:context

134 /* Invariant: NULL or the most recently accessed thread local context */
143 /* Basic and extended context templates */
483 dec_addstatus(PyObject *context, uint32_t status)
485 mpd_context_t *ctx = CTX(context);
539 mpd_context_t flags, which reside in the context object. When a
540 new context is created, context.traps and context.flags are
542 a context, it cannot be deleted. */
1143 "context attributes cannot be deleted");
1396 PyObject *context;
1411 context = PyObject_CallObject((PyObject *)&PyDecContext_Type, NULL);
1412 if (context == NULL) {
1415 *CTX(context) = ctx;
1417 return context;
1498 "argument must be a context"); \
1508 "optional argument must be a context"); \
1520 * functions have to look up the current context for each and every
1525 /* Get the context from the thread state dictionary. */
1544 /* We already have a thread local context. */
1552 /* Set up a new thread local context. */
1566 /* Cache the context of the current thread, assuming that it
1575 /* Return borrowed reference to thread local context. */
1587 /* ctxobj := borrowed reference to the current context */
1594 /* Return a new reference to the current context */
1598 PyObject *context;
1600 context = current_context();
1601 if (context == NULL) {
1605 Py_INCREF(context);
1606 return context;
1609 /* Set the thread local context to a new context, decrement old reference */
1624 /* If the new context is one of the templates, make a copy.
1683 /* ctxobj := borrowed reference to the current context */
1691 /* Return a new reference to the current context */
1698 /* Set the thread local context to a new context, decrement old reference */
1704 /* If the new context is one of the templates, make a copy.
1731 * owns one reference to the global (outer) context and one
1732 * to the local (inner) context. */
1765 "optional argument must be a context");
1994 /* Return a new PyDecObject or a subtype from a C string. Use the context
1998 PyObject *context)
2008 mpd_qset_string(MPD(dec), s, CTX(context), &status);
2009 if (dec_addstatus(context, status)) {
2021 PyObject *context)
2040 if (dec_addstatus(context, status)) {
2051 PyObject *context)
2061 dec = PyDecType_FromCString(type, s, context);
2071 PyObject *context)
2081 dec = PyDecType_FromCStringExact(type, s, context);
2109 PyDecType_FromSsize(PyTypeObject *type, mpd_ssize_t v, PyObject *context)
2119 mpd_qset_ssize(MPD(dec), v, CTX(context), &status);
2120 if (dec_addstatus(context, status)) {
2129 PyDecType_FromSsizeExact(PyTypeObject *type, mpd_ssize_t v, PyObject *context)
2143 if (dec_addstatus(context, status)) {
2150 /* Convert from a PyLongObject. The context is not modified; flags set
2201 /* Return a new PyDecObject from a PyLongObject. Use the context for
2204 PyDecType_FromLong(PyTypeObject *type, const PyObject *v, PyObject *context)
2214 dec = dec_from_long(type, v, CTX(context), &status);
2219 if (dec_addstatus(context, status)) {
2227 /* Return a new PyDecObject from a PyLongObject. Use a maximum context
2231 PyObject *context)
2253 if (dec_addstatus(context, status)) {
2273 PyObject *context)
2288 return PyDecType_FromLongExact(type, v, context);
2346 dec = PyDecType_FromLongExact(type, n, context);
2370 if (dec_addstatus(context, status)) {
2381 if (dec_addstatus(context, status)) {
2394 PyObject *context)
2399 dec = PyDecType_FromFloatExact(type, v, context);
2404 mpd_qfinalize(MPD(dec), CTX(context), &status);
2405 if (dec_addstatus(context, status)) {
2415 PyDecType_FromDecimalExact(PyTypeObject *type, PyObject *v, PyObject *context)
2431 if (dec_addstatus(context, status)) {
2606 PyObject *context)
2624 dec = PyDecType_FromCString(type, s, context);
2633 PyObject *context)
2651 dec = PyDecType_FromCStringExact(type, s, context);
2657 #define PyDec_FromCString(str, context) \
2658 PyDecType_FromCString(&PyDec_Type, str, context)
2659 #define PyDec_FromCStringExact(str, context) \
2660 PyDecType_FromCStringExact(&PyDec_Type, str, context)
2662 #define PyDec_FromUnicode(unicode, context) \
2663 PyDecType_FromUnicode(&PyDec_Type, unicode, context)
2664 #define PyDec_FromUnicodeExact(unicode, context) \
2665 PyDecType_FromUnicodeExact(&PyDec_Type, unicode, context)
2666 #define PyDec_FromUnicodeExactWS(unicode, context) \
2667 PyDecType_FromUnicodeExactWS(&PyDec_Type, unicode, context)
2669 #define PyDec_FromSsize(v, context) \
2670 PyDecType_FromSsize(&PyDec_Type, v, context)
2671 #define PyDec_FromSsizeExact(v, context) \
2672 PyDecType_FromSsizeExact(&PyDec_Type, v, context)
2674 #define PyDec_FromLong(pylong, context) \
2675 PyDecType_FromLong(&PyDec_Type, pylong, context)
2676 #define PyDec_FromLongExact(pylong, context) \
2677 PyDecType_FromLongExact(&PyDec_Type, pylong, context)
2679 #define PyDec_FromFloat(pyfloat, context) \
2680 PyDecType_FromFloat(&PyDec_Type, pyfloat, context)
2681 #define PyDec_FromFloatExact(pyfloat, context) \
2682 PyDecType_FromFloatExact(&PyDec_Type, pyfloat, context)
2684 #define PyDec_FromSequence(sequence, context) \
2685 PyDecType_FromSequence(&PyDec_Type, sequence, context)
2686 #define PyDec_FromSequenceExact(sequence, context) \
2687 PyDecType_FromSequenceExact(&PyDec_Type, sequence, context)
2693 PyObject *context;
2696 CURRENT_CONTEXT(context);
2697 result = PyDecType_FromFloatExact(&PyDec_Type, pyfloat, context);
2707 ctx_from_float(PyObject *context, PyObject *v)
2709 return PyDec_FromFloat(v, context);
2712 /* Apply the context to the input operand. Return a new PyDecObject. */
2714 dec_apply(PyObject *v, PyObject *context)
2725 if (dec_addstatus(context, status)) {
2730 mpd_qfinalize(MPD(result), CTX(context), &status);
2731 if (dec_addstatus(context, status)) {
2743 PyDecType_FromObjectExact(PyTypeObject *type, PyObject *v, PyObject *context)
2746 return PyDecType_FromSsizeExact(type, 0, context);
2749 return PyDecType_FromDecimalExact(type, v, context);
2752 return PyDecType_FromUnicodeExactWS(type, v, context);
2755 return PyDecType_FromLongExact(type, v, context);
2758 return PyDecType_FromSequenceExact(type, v, context);
2761 if (dec_addstatus(context, MPD_Float_operation)) {
2764 return PyDecType_FromFloatExact(type, v, context);
2774 /* The context is used during conversion. This function is the
2775 equivalent of context.create_decimal(). */
2777 PyDec_FromObject(PyObject *v, PyObject *context)
2780 return PyDec_FromSsize(0, context);
2783 mpd_context_t *ctx = CTX(context);
2788 if (dec_addstatus(context, MPD_Conversion_syntax)) {
2798 return dec_apply(v, context);
2801 return PyDec_FromUnicode(v, context);
2804 return PyDec_FromLong(v, context);
2807 return PyDec_FromSequence(v, context);
2810 if (dec_addstatus(context, MPD_Float_operation)) {
2813 return PyDec_FromFloat(v, context);
2826 static char *kwlist[] = {"value", "context", NULL};
2828 PyObject *context = Py_None;
2831 &v, &context)) {
2834 CONTEXT_CHECK_VA(context);
2836 return PyDecType_FromObjectExact(type, v, context);
2840 ctx_create_decimal(PyObject *context, PyObject *args)
2848 return PyDec_FromObject(v, context);
2862 convert_op(int type_err, PyObject **conv, PyObject *v, PyObject *context)
2871 *conv = PyDec_FromLongExact(v, context);
2891 #define CONVERT_OP(a, v, context) \
2892 if (!convert_op(NOT_IMPL, a, v, context)) { \
2896 #define CONVERT_BINOP(a, b, v, w, context) \
2897 if (!convert_op(NOT_IMPL, a, v, context)) { \
2900 if (!convert_op(NOT_IMPL, b, w, context)) { \
2905 #define CONVERT_TERNOP(a, b, c, v, w, x, context) \
2906 if (!convert_op(NOT_IMPL, a, v, context)) { \
2909 if (!convert_op(NOT_IMPL, b, w, context)) { \
2913 if (!convert_op(NOT_IMPL, c, x, context)) { \
2920 #define CONVERT_OP_RAISE(a, v, context) \
2921 if (!convert_op(TYPE_ERR, a, v, context)) { \
2925 #define CONVERT_BINOP_RAISE(a, b, v, w, context) \
2926 if (!convert_op(TYPE_ERR, a, v, context)) { \
2929 if (!convert_op(TYPE_ERR, b, w, context)) { \
2934 #define CONVERT_TERNOP_RAISE(a, b, c, v, w, x, context) \
2935 if (!convert_op(TYPE_ERR, a, v, context)) { \
2938 if (!convert_op(TYPE_ERR, b, w, context)) { \
2942 if (!convert_op(TYPE_ERR, c, x, context)) { \
2956 multiply_by_denominator(PyObject *v, PyObject *r, PyObject *context)
2971 denom = PyDec_FromLongExact(tmp, context);
3016 numerator_as_decimal(PyObject *r, PyObject *context)
3025 num = PyDec_FromLongExact(tmp, context);
3037 int op, PyObject *context)
3039 mpd_context_t *ctx = CTX(context);
3048 *wcmp = PyDec_FromLongExact(w, context);
3052 dec_addstatus(context, MPD_Float_operation)) {
3057 *wcmp = PyDec_FromFloatExact(w, context);
3072 *wcmp = PyDec_FromFloatExact(tmp, context);
3087 *wcmp = numerator_as_decimal(w, context);
3089 *vcmp = multiply_by_denominator(v, w, context);
3134 /* PyDecObject as a string. The default module context is only used for
3139 PyObject *res, *context;
3143 CURRENT_CONTEXT(context);
3144 size = mpd_to_sci_size(&cp, MPD(dec), CtxCaps(context));
3159 PyObject *res, *context;
3162 CURRENT_CONTEXT(context);
3163 cp = mpd_to_sci(MPD(dec), CtxCaps(context));
3309 PyObject *context;
3323 CURRENT_CONTEXT(context);
3370 if (!mpd_parse_fmt_str(&spec, fmt, CtxCaps(context))) {
3436 mpd_qrescale(&tmp, &tmp, -spec.prec, CTX(context), &status);
3440 mpd_qrescale(&tmp, &tmp, -spec.prec, CTX(context), &status);
3445 _mpd_round(&tmp, &tmp, prec, CTX(context), &status);
3450 _mpd_round(&tmp, &tmp, spec.prec+1, CTX(context), &status);
3465 decstring = mpd_qformat_spec(mpd, &spec, CTX(context), &status);
3494 * mode. The context precision is not observed. */
3496 dec_as_long(PyObject *dec, PyObject *context, int round)
3523 workctx = *CTX(context);
3526 if (dec_addstatus(context, status)) {
3589 PyObject *context;
3604 CURRENT_CONTEXT(context);
3620 /* context and rounding are unused here: the conversion is exact */
3621 numerator = dec_as_long(tmp, context, MPD_ROUND_FLOOR);
3681 static char *kwlist[] = {"rounding", "context", NULL};
3684 PyObject *context = Py_None;
3689 &rounding, &context)) {
3692 CONTEXT_CHECK_VA(context);
3694 workctx = *CTX(context);
3711 if (dec_addstatus(context, status)) {
3722 static char *kwlist[] = {"rounding", "context", NULL};
3725 PyObject *context = Py_None;
3730 &rounding, &context)) {
3733 CONTEXT_CHECK_VA(context);
3735 workctx = *CTX(context);
3752 if (dec_addstatus(context, status)) {
3798 PyObject *context;
3801 CURRENT_CONTEXT(context);
3827 mpd_qquantize(MPD(result), MPD(dec), &q, CTX(context), &status);
3828 if (dec_addstatus(context, status)) {
3836 return dec_as_long(dec, context, MPD_ROUND_HALF_EVEN);
3940 /* Unary number method that uses the default module context. */
3946 PyObject *context; \
3949 CURRENT_CONTEXT(context); \
3954 MPDFUNC(MPD(result), MPD(self), CTX(context), &status); \
3955 if (dec_addstatus(context, status)) { \
3963 /* Binary number method that uses default module context. */
3970 PyObject *context; \
3973 CURRENT_CONTEXT(context) ; \
3974 CONVERT_BINOP(&a, &b, self, other, context); \
3982 MPDFUNC(MPD(result), MPD(a), MPD(b), CTX(context), &status); \
3985 if (dec_addstatus(context, status)) { \
3993 /* Boolean function without a context arg. */
4001 /* Boolean function with an optional context arg. */
4006 static char *kwlist[] = {"context", NULL}; \
4007 PyObject *context = Py_None; \
4010 &context)) { \
4013 CONTEXT_CHECK_VA(context); \
4015 return MPDFUNC(MPD(self), CTX(context)) ? incr_true() : incr_false(); \
4018 /* Unary function with an optional context arg. */
4023 static char *kwlist[] = {"context", NULL}; \
4025 PyObject *context = Py_None; \
4029 &context)) { \
4032 CONTEXT_CHECK_VA(context); \
4038 MPDFUNC(MPD(result), MPD(self), CTX(context), &status); \
4039 if (dec_addstatus(context, status)) { \
4047 /* Binary function with an optional context arg. */
4052 static char *kwlist[] = {"other", "context", NULL}; \
4056 PyObject *context = Py_None; \
4060 &other, &context)) { \
4063 CONTEXT_CHECK_VA(context); \
4064 CONVERT_BINOP_RAISE(&a, &b, self, other, context); \
4072 MPDFUNC(MPD(result), MPD(a), MPD(b), CTX(context), &status); \
4075 if (dec_addstatus(context, status)) { \
4083 /* Binary function with an optional context arg. Actual MPDFUNC does
4084 NOT take a context. The context is used to record InvalidOperation
4090 static char *kwlist[] = {"other", "context", NULL}; \
4091 PyObject *context = Py_None; \
4097 &other, &context)) { \
4100 CONTEXT_CHECK_VA(context); \
4101 CONVERT_BINOP_RAISE(&a, &b, self, other, context); \
4116 /* Ternary function with an optional context arg. */
4121 static char *kwlist[] = {"other", "third", "context", NULL}; \
4125 PyObject *context = Py_None; \
4129 &other, &third, &context)) { \
4132 CONTEXT_CHECK_VA(context); \
4133 CONVERT_TERNOP_RAISE(&a, &b, &c, self, other, third, context); \
4142 MPDFUNC(MPD(result), MPD(a), MPD(b), MPD(c), CTX(context), &status); \
4146 if (dec_addstatus(context, status)) { \
4173 PyObject *context;
4175 CURRENT_CONTEXT(context);
4176 return dec_as_long(dec, context, MPD_ROUND_DOWN);
4190 PyObject *context;
4194 CURRENT_CONTEXT(context);
4195 CONVERT_BINOP(&a, &b, v, w, context);
4211 mpd_qdivmod(MPD(q), MPD(r), MPD(a), MPD(b), CTX(context), &status);
4214 if (dec_addstatus(context, status)) {
4231 PyObject *context;
4234 CURRENT_CONTEXT(context);
4235 CONVERT_BINOP(&a, &b, base, exp, context);
4238 if (!convert_op(NOT_IMPL, &c, mod, context)) {
4255 CTX(context), &status);
4259 CTX(context), &status);
4264 if (dec_addstatus(context, status)) {
4277 /* Unary arithmetic functions, optional context arg */
4286 /* Binary arithmetic functions, optional context arg */
4296 /* Ternary arithmetic functions, optional context arg */
4299 /* Boolean functions, no context arg */
4309 /* Boolean functions, optional context arg */
4313 /* Unary functions, no context arg */
4397 /* Unary functions, optional context arg */
4404 static char *kwlist[] = {"context", NULL};
4405 PyObject *context = Py_None;
4409 &context)) {
4412 CONTEXT_CHECK_VA(context);
4414 cp = mpd_class(MPD(self), CTX(context));
4421 static char *kwlist[] = {"context", NULL};
4423 PyObject *context = Py_None;
4428 &context)) {
4431 CONTEXT_CHECK_VA(context);
4433 size = mpd_to_eng_size(&s, MPD(self), CtxCaps(context));
4445 /* Binary functions, optional context arg for conversion errors */
4452 static char *kwlist[] = {"other", "context", NULL};
4456 PyObject *context = Py_None;
4460 &other, &context)) {
4463 CONTEXT_CHECK_VA(context);
4464 CONVERT_BINOP_RAISE(&a, &b, self, other, context);
4476 if (dec_addstatus(context, status)) {
4487 static char *kwlist[] = {"other", "context", NULL};
4491 PyObject *context = Py_None;
4494 &other, &context)) {
4497 CONTEXT_CHECK_VA(context);
4498 CONVERT_BINOP_RAISE(&a, &b, self, other, context);
4507 /* Binary functions, optional context arg */
4519 static char *kwlist[] = {"exp", "rounding", "context", NULL};
4521 PyObject *context = Py_None;
4528 &w, &rounding, &context)) {
4531 CONTEXT_CHECK_VA(context);
4533 workctx = *CTX(context);
4544 CONVERT_BINOP_RAISE(&a, &b, v, w, context);
4556 if (dec_addstatus(context, status)) {
4570 PyObject *context;
4577 CURRENT_CONTEXT(context);
4578 CONVERT_BINOP_CMP(&a, &b, v, w, op, context);
4589 if (dec_addstatus(context, status)) {
4626 PyObject *context;
4628 CURRENT_CONTEXT(context);
4629 return dec_as_long(self, context, MPD_ROUND_CEILING);
4665 PyObject *context;
4667 CURRENT_CONTEXT(context);
4668 return dec_as_long(self, context, MPD_ROUND_FLOOR);
4671 /* Always uses the module context */
4831 PyObject *context;
4833 CURRENT_CONTEXT(context);
4834 return dec_as_long(self, context, MPD_ROUND_DOWN);
4906 /* Unary arithmetic functions, optional context arg */
4918 /* Binary arithmetic functions, optional context arg */
4929 /* Ternary arithmetic functions, optional context arg */
4932 /* Boolean functions, no context arg */
4942 /* Boolean functions, optional context arg */
4946 /* Unary functions, no context arg */
4952 /* Unary functions, optional context arg for conversion errors */
4956 /* Unary functions, optional context arg */
4962 /* Binary functions, optional context arg for conversion errors */
4968 /* Binary functions, optional context arg */
5050 /* Boolean context method. */
5053 ctx_##MPDFUNC(PyObject *context, PyObject *v) \
5058 CONVERT_OP_RAISE(&a, v, context); \
5060 ret = MPDFUNC(MPD(a), CTX(context)) ? incr_true() : incr_false(); \
5065 /* Boolean context method. MPDFUNC does NOT use a context. */
5068 ctx_##MPDFUNC(PyObject *context, PyObject *v) \
5073 CONVERT_OP_RAISE(&a, v, context); \
5080 /* Unary context method. */
5083 ctx_##MPDFUNC(PyObject *context, PyObject *v) \
5088 CONVERT_OP_RAISE(&a, v, context); \
5095 MPDFUNC(MPD(result), MPD(a), CTX(context), &status); \
5097 if (dec_addstatus(context, status)) { \
5105 /* Binary context method. */
5108 ctx_##MPDFUNC(PyObject *context, PyObject *args) \
5119 CONVERT_BINOP_RAISE(&a, &b, v, w, context); \
5127 MPDFUNC(MPD(result), MPD(a), MPD(b), CTX(context), &status); \
5130 if (dec_addstatus(context, status)) { \
5139 * Binary context method. The context is only used for conversion.
5140 * The actual MPDFUNC does NOT take a context arg.
5144 ctx_##MPDFUNC(PyObject *context, PyObject *args) \
5154 CONVERT_BINOP_RAISE(&a, &b, v, w, context); \
5169 /* Ternary context method. */
5172 ctx_##MPDFUNC(PyObject *context, PyObject *args) \
5183 CONVERT_TERNOP_RAISE(&a, &b, &c, v, w, x, context); \
5192 MPDFUNC(MPD(result), MPD(a), MPD(b), MPD(c), CTX(context), &status); \
5196 if (dec_addstatus(context, status)) { \
5237 ctx_mpd_qdivmod(PyObject *context, PyObject *args)
5249 CONVERT_BINOP_RAISE(&a, &b, v, w, context);
5265 mpd_qdivmod(MPD(q), MPD(r), MPD(a), MPD(b), CTX(context), &status);
5268 if (dec_addstatus(context, status)) {
5282 ctx_mpd_qpow(PyObject *context, PyObject *args, PyObject *kwds)
5295 CONVERT_BINOP_RAISE(&a, &b, base, exp, context);
5298 if (!convert_op(TYPE_ERR, &c, mod, context)) {
5315 CTX(context), &status);
5319 CTX(context), &status);
5324 if (dec_addstatus(context, status)) {
5337 ctx_mpd_radix(PyObject *context, PyObject *dummy)
5339 return dec_mpd_radix(context, dummy);
5354 ctx_iscanonical(PyObject *context UNUSED, PyObject *v)
5367 PyDecContext_Apply(PyObject *context, PyObject *v)
5371 CONVERT_OP_RAISE(&a, v, context);
5373 result = dec_apply(a, context);
5379 ctx_canonical(PyObject *context UNUSED, PyObject *v)
5392 ctx_mpd_qcopy_abs(PyObject *context, PyObject *v)
5397 CONVERT_OP_RAISE(&a, v, context);
5407 if (dec_addstatus(context, status)) {
5416 ctx_copy_decimal(PyObject *context, PyObject *v)
5420 CONVERT_OP_RAISE(&result, v, context);
5425 ctx_mpd_qcopy_negate(PyObject *context, PyObject *v)
5430 CONVERT_OP_RAISE(&a, v, context);
5440 if (dec_addstatus(context, status)) {
5452 ctx_mpd_class(PyObject *context, PyObject *v)
5457 CONVERT_OP_RAISE(&a, v, context);
5459 cp = mpd_class(MPD(a), CTX(context));
5466 ctx_mpd_to_sci(PyObject *context, PyObject *v)
5473 CONVERT_OP_RAISE(&a, v, context);
5475 size = mpd_to_sci_size(&s, MPD(a), CtxCaps(context));
5489 ctx_mpd_to_eng(PyObject *context, PyObject *v)
5496 CONVERT_OP_RAISE(&a, v, context);
5498 size = mpd_to_eng_size(&s, MPD(a), CtxCaps(context));
5516 ctx_mpd_qcopy_sign(PyObject *context, PyObject *args)
5527 CONVERT_BINOP_RAISE(&a, &b, v, w, context);
5539 if (dec_addstatus(context, status)) {
5556 ctx_mpd_same_quantum(PyObject *context, PyObject *args)
5566 CONVERT_BINOP_RAISE(&a, &b, v, w, context);
5661 /* Set context values */
6011 /* Init default context template first */
6030 /* Init basic context template */
6038 /* Init extended context template */