Skip to content

Commit aa29186

Browse files
committed
address review: revert macro changes
1 parent d944c4d commit aa29186

File tree

3 files changed

+118
-507
lines changed

3 files changed

+118
-507
lines changed

Modules/_decimal/_decimal.c

Lines changed: 31 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -4348,6 +4348,8 @@ nm_##MPDFUNC(PyObject *self, PyObject *other) \
43484348

43494349
/* Boolean function without a context arg. */
43504350
#define Dec_BoolFunc(MPDFUNC) \
4351+
static PyObject * \
4352+
dec_##MPDFUNC(PyObject *self, PyObject *Py_UNUSED(dummy)) \
43514353
{ \
43524354
return MPDFUNC(MPD(self)) ? incr_true() : incr_false(); \
43534355
}
@@ -4421,9 +4423,19 @@ nm_##MPDFUNC(PyObject *self, PyObject *other) \
44214423
NOT take a context. The context is used to record InvalidOperation
44224424
if the second operand cannot be converted exactly. */
44234425
#define Dec_BinaryFuncVA_NO_CTX(MPDFUNC) \
4426+
static PyObject * \
4427+
dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \
44244428
{ \
4429+
static char *kwlist[] = {"other", "context", NULL}; \
4430+
PyObject *context = Py_None; \
4431+
PyObject *other; \
44254432
PyObject *a, *b; \
44264433
PyObject *result; \
4434+
\
4435+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O", kwlist, \
4436+
&other, &context)) { \
4437+
return NULL; \
4438+
} \
44274439
decimal_state *state = \
44284440
get_module_state_by_def(Py_TYPE(self)); \
44294441
CONTEXT_CHECK_VA(state, context); \
@@ -4846,98 +4858,13 @@ _decimal_Decimal_fma_impl(PyObject *self, PyObject *other, PyObject *third,
48464858
Dec_TernaryFuncVA(mpd_qfma)
48474859

48484860
/* Boolean functions, no context arg */
4849-
4850-
/*[clinic input]
4851-
_decimal.Decimal.is_canonical
4852-
4853-
Return True if the argument is canonical and False otherwise.
4854-
4855-
Currently, a Decimal instance is always canonical, so this operation
4856-
always returns True.
4857-
[clinic start generated code]*/
4858-
4859-
static PyObject *
4860-
_decimal_Decimal_is_canonical_impl(PyObject *self)
4861-
/*[clinic end generated code: output=b29668684f45443e input=b3b3e6878ccf40b8]*/
48624861
Dec_BoolFunc(mpd_iscanonical)
4863-
4864-
/*[clinic input]
4865-
_decimal.Decimal.is_finite
4866-
4867-
Return True if the argument is a finite number, and False otherwise.
4868-
[clinic start generated code]*/
4869-
4870-
static PyObject *
4871-
_decimal_Decimal_is_finite_impl(PyObject *self)
4872-
/*[clinic end generated code: output=537306fbfc9131f8 input=e9b8b5866704bae6]*/
48734862
Dec_BoolFunc(mpd_isfinite)
4874-
4875-
/*[clinic input]
4876-
_decimal.Decimal.is_infinite
4877-
4878-
Return True if the argument is infinite, and False otherwise.
4879-
[clinic start generated code]*/
4880-
4881-
static PyObject *
4882-
_decimal_Decimal_is_infinite_impl(PyObject *self)
4883-
/*[clinic end generated code: output=31b775ff28f05ce2 input=8f3937a790ee4ec2]*/
48844863
Dec_BoolFunc(mpd_isinfinite)
4885-
4886-
/*[clinic input]
4887-
_decimal.Decimal.is_nan
4888-
4889-
Return True if the argument is a (quiet or signaling) NaN, else False.
4890-
[clinic start generated code]*/
4891-
4892-
static PyObject *
4893-
_decimal_Decimal_is_nan_impl(PyObject *self)
4894-
/*[clinic end generated code: output=b704e8b49a164388 input=795e5dac85976994]*/
48954864
Dec_BoolFunc(mpd_isnan)
4896-
4897-
/*[clinic input]
4898-
_decimal.Decimal.is_qnan
4899-
4900-
Return True if the argument is a quiet NaN, and False otherwise.
4901-
[clinic start generated code]*/
4902-
4903-
static PyObject *
4904-
_decimal_Decimal_is_qnan_impl(PyObject *self)
4905-
/*[clinic end generated code: output=85b5241f43798376 input=00485f3c3cfae0af]*/
49064865
Dec_BoolFunc(mpd_isqnan)
4907-
4908-
/*[clinic input]
4909-
_decimal.Decimal.is_snan
4910-
4911-
Return True if the argument is a signaling NaN and False otherwise.
4912-
[clinic start generated code]*/
4913-
4914-
static PyObject *
4915-
_decimal_Decimal_is_snan_impl(PyObject *self)
4916-
/*[clinic end generated code: output=50de9ec6507e4a4f input=f3b0f8592c921879]*/
49174866
Dec_BoolFunc(mpd_issnan)
4918-
4919-
/*[clinic input]
4920-
_decimal.Decimal.is_signed
4921-
4922-
Return True if the argument has a negative sign and False otherwise.
4923-
4924-
Note that both zeros and NaNs can carry signs.
4925-
[clinic start generated code]*/
4926-
4927-
static PyObject *
4928-
_decimal_Decimal_is_signed_impl(PyObject *self)
4929-
/*[clinic end generated code: output=8ec7bc85d8e755e4 input=97c3437ab5dffecc]*/
49304867
Dec_BoolFunc(mpd_issigned)
4931-
4932-
/*[clinic input]
4933-
_decimal.Decimal.is_zero
4934-
4935-
Return True if the argument is a zero and False otherwise.
4936-
[clinic start generated code]*/
4937-
4938-
static PyObject *
4939-
_decimal_Decimal_is_zero_impl(PyObject *self)
4940-
/*[clinic end generated code: output=2d87ea1b15879112 input=ae616674cd050a51]*/
49414868
Dec_BoolFunc(mpd_iszero)
49424869

49434870
/* Boolean functions, optional context arg */
@@ -5217,57 +5144,7 @@ _decimal_Decimal_to_eng_string_impl(PyObject *self, PyObject *context)
52175144
}
52185145

52195146
/* Binary functions, optional context arg for conversion errors */
5220-
5221-
/*[clinic input]
5222-
_decimal.Decimal.compare_total = _decimal.Decimal.compare
5223-
5224-
Compare two operands using their abstract representation.
5225-
5226-
Similar to the compare() method, but the result
5227-
gives a total ordering on Decimal instances. Two Decimal instances with
5228-
the same numeric value but different representations compare unequal
5229-
in this ordering:
5230-
5231-
>>> Decimal('12.0').compare_total(Decimal('12'))
5232-
Decimal('-1')
5233-
5234-
Quiet and signaling NaNs are also included in the total ordering. The
5235-
result of this function is Decimal('0') if both operands have the same
5236-
representation, Decimal('-1') if the first operand is lower in the
5237-
total order than the second, and Decimal('1') if the first operand is
5238-
higher in the total order than the second operand. See the
5239-
specification for details of the total order.
5240-
5241-
This operation is unaffected by context and is quiet: no flags are
5242-
changed and no rounding is performed. As an exception, the C version
5243-
may raise InvalidOperation if the second operand cannot be converted
5244-
exactly.
5245-
[clinic start generated code]*/
5246-
5247-
static PyObject *
5248-
_decimal_Decimal_compare_total_impl(PyObject *self, PyObject *other,
5249-
PyObject *context)
5250-
/*[clinic end generated code: output=dca119b5e881a83e input=6f3111ec5fdbf3c1]*/
52515147
Dec_BinaryFuncVA_NO_CTX(mpd_compare_total)
5252-
5253-
/*[clinic input]
5254-
_decimal.Decimal.compare_total_mag = _decimal.Decimal.compare
5255-
5256-
As compare_total(), but ignores the sign of each operand.
5257-
5258-
x.compare_total_mag(y) is equivalent to
5259-
x.copy_abs().compare_total(y.copy_abs()).
5260-
5261-
This operation is unaffected by context and is quiet: no flags are
5262-
changed and no rounding is performed. As an exception, the C version
5263-
may raise InvalidOperation if the second operand cannot be converted
5264-
exactly.
5265-
[clinic start generated code]*/
5266-
5267-
static PyObject *
5268-
_decimal_Decimal_compare_total_mag_impl(PyObject *self, PyObject *other,
5269-
PyObject *context)
5270-
/*[clinic end generated code: output=6bf1b3419112d0dd input=eba17c4c24eb2833]*/
52715148
Dec_BinaryFuncVA_NO_CTX(mpd_compare_total_mag)
52725149

52735150
/*[clinic input]
@@ -5906,14 +5783,14 @@ static PyMethodDef dec_methods [] =
59065783
_DECIMAL_DECIMAL_FMA_METHODDEF
59075784

59085785
/* Boolean functions, no context arg */
5909-
_DECIMAL_DECIMAL_IS_CANONICAL_METHODDEF
5910-
_DECIMAL_DECIMAL_IS_FINITE_METHODDEF
5911-
_DECIMAL_DECIMAL_IS_INFINITE_METHODDEF
5912-
_DECIMAL_DECIMAL_IS_NAN_METHODDEF
5913-
_DECIMAL_DECIMAL_IS_QNAN_METHODDEF
5914-
_DECIMAL_DECIMAL_IS_SNAN_METHODDEF
5915-
_DECIMAL_DECIMAL_IS_SIGNED_METHODDEF
5916-
_DECIMAL_DECIMAL_IS_ZERO_METHODDEF
5786+
{ "is_canonical", dec_mpd_iscanonical, METH_NOARGS, doc_is_canonical },
5787+
{ "is_finite", dec_mpd_isfinite, METH_NOARGS, doc_is_finite },
5788+
{ "is_infinite", dec_mpd_isinfinite, METH_NOARGS, doc_is_infinite },
5789+
{ "is_nan", dec_mpd_isnan, METH_NOARGS, doc_is_nan },
5790+
{ "is_qnan", dec_mpd_isqnan, METH_NOARGS, doc_is_qnan },
5791+
{ "is_snan", dec_mpd_issnan, METH_NOARGS, doc_is_snan },
5792+
{ "is_signed", dec_mpd_issigned, METH_NOARGS, doc_is_signed },
5793+
{ "is_zero", dec_mpd_iszero, METH_NOARGS, doc_is_zero },
59175794

59185795
/* Boolean functions, optional context arg */
59195796
_DECIMAL_DECIMAL_IS_NORMAL_METHODDEF
@@ -5936,8 +5813,8 @@ static PyMethodDef dec_methods [] =
59365813
_DECIMAL_DECIMAL_TO_ENG_STRING_METHODDEF
59375814

59385815
/* Binary functions, optional context arg for conversion errors */
5939-
_DECIMAL_DECIMAL_COMPARE_TOTAL_METHODDEF
5940-
_DECIMAL_DECIMAL_COMPARE_TOTAL_MAG_METHODDEF
5816+
{ "compare_total", _PyCFunction_CAST(dec_mpd_compare_total), METH_VARARGS|METH_KEYWORDS, doc_compare_total },
5817+
{ "compare_total_mag", _PyCFunction_CAST(dec_mpd_compare_total_mag), METH_VARARGS|METH_KEYWORDS, doc_compare_total_mag },
59415818
_DECIMAL_DECIMAL_COPY_SIGN_METHODDEF
59425819
_DECIMAL_DECIMAL_SAME_QUANTUM_METHODDEF
59435820

@@ -6145,12 +6022,19 @@ ctx_##MPDFUNC(PyObject *context, PyObject *args) \
61456022

61466023
/* Ternary context method. */
61476024
#define DecCtx_TernaryFunc(MPDFUNC) \
6025+
static PyObject * \
6026+
ctx_##MPDFUNC(PyObject *context, PyObject *args) \
61486027
{ \
6028+
PyObject *v, *w, *x; \
61496029
PyObject *a, *b, *c; \
61506030
PyObject *result; \
61516031
uint32_t status = 0; \
61526032
\
6153-
CONVERT_TERNOP_RAISE(&a, &b, &c, x, y, z, context); \
6033+
if (!PyArg_ParseTuple(args, "OOO", &v, &w, &x)) { \
6034+
return NULL; \
6035+
} \
6036+
\
6037+
CONVERT_TERNOP_RAISE(&a, &b, &c, v, w, x, context); \
61546038
decimal_state *state = get_module_state_from_ctx(context); \
61556039
if ((result = dec_alloc(state)) == NULL) { \
61566040
Py_DECREF(a); \
@@ -6322,23 +6206,6 @@ _decimal_Context_power_impl(PyObject *context, PyObject *base, PyObject *exp,
63226206
}
63236207

63246208
/* Ternary arithmetic functions */
6325-
6326-
/*[clinic input]
6327-
_decimal.Context.fma
6328-
6329-
self as context: self
6330-
x: object
6331-
y: object
6332-
z: object
6333-
/
6334-
6335-
Return x multiplied by y, plus z.
6336-
[clinic start generated code]*/
6337-
6338-
static PyObject *
6339-
_decimal_Context_fma_impl(PyObject *context, PyObject *x, PyObject *y,
6340-
PyObject *z)
6341-
/*[clinic end generated code: output=2d6174716faaf4e1 input=80479612da3333d1]*/
63426209
DecCtx_TernaryFunc(mpd_qfma)
63436210

63446211
/* No argument */
@@ -6633,7 +6500,7 @@ static PyMethodDef context_methods [] =
66336500
_DECIMAL_CONTEXT_POWER_METHODDEF
66346501

66356502
/* Ternary arithmetic functions */
6636-
_DECIMAL_CONTEXT_FMA_METHODDEF
6503+
{ "fma", ctx_mpd_qfma, METH_VARARGS, doc_ctx_fma },
66376504

66386505
/* No argument */
66396506
_DECIMAL_CONTEXT_ETINY_METHODDEF

0 commit comments

Comments
 (0)