Skip to content

Commit 6a7acb8

Browse files
committed
address review: revert macro
1 parent 3584f8a commit 6a7acb8

File tree

7 files changed

+102
-828
lines changed

7 files changed

+102
-828
lines changed

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,6 @@ struct _Py_global_strings {
787787
STRUCT_FOR_ID(template)
788788
STRUCT_FOR_ID(term)
789789
STRUCT_FOR_ID(text)
790-
STRUCT_FOR_ID(third)
791790
STRUCT_FOR_ID(threading)
792791
STRUCT_FOR_ID(throw)
793792
STRUCT_FOR_ID(time)

Include/internal/pycore_runtime_init_generated.h

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_decimal/_decimal.c

Lines changed: 29 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -4358,9 +4358,18 @@ dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \
43584358

43594359
/* Unary function with an optional context arg. */
43604360
#define Dec_UnaryFuncVA(MPDFUNC) \
4361+
static PyObject * \
4362+
dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \
43614363
{ \
4364+
static char *kwlist[] = {"context", NULL}; \
43624365
PyObject *result; \
4366+
PyObject *context = Py_None; \
43634367
uint32_t status = 0; \
4368+
\
4369+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, \
4370+
&context)) { \
4371+
return NULL; \
4372+
} \
43644373
decimal_state *state = \
43654374
get_module_state_by_def(Py_TYPE(self)); \
43664375
CONTEXT_CHECK_VA(state, context); \
@@ -4453,10 +4462,20 @@ dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \
44534462

44544463
/* Ternary function with an optional context arg. */
44554464
#define Dec_TernaryFuncVA(MPDFUNC) \
4465+
static PyObject * \
4466+
dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \
44564467
{ \
4468+
static char *kwlist[] = {"other", "third", "context", NULL}; \
4469+
PyObject *other, *third; \
44574470
PyObject *a, *b, *c; \
44584471
PyObject *result; \
4472+
PyObject *context = Py_None; \
44594473
uint32_t status = 0; \
4474+
\
4475+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O", kwlist, \
4476+
&other, &third, &context)) { \
4477+
return NULL; \
4478+
} \
44604479
decimal_state *state = get_module_state_by_def(Py_TYPE(self)); \
44614480
CONTEXT_CHECK_VA(state, context); \
44624481
CONVERT_TERNOP_RAISE(&a, &b, &c, self, other, third, context); \
@@ -4606,112 +4625,12 @@ nm_mpd_qpow(PyObject *base, PyObject *exp, PyObject *mod)
46064625
/******************************************************************************/
46074626

46084627
/* Unary arithmetic functions, optional context arg */
4609-
4610-
/*[clinic input]
4611-
_decimal.Decimal.exp
4612-
4613-
context: object = None
4614-
4615-
Return the value of the (natural) exponential function e**x.
4616-
4617-
The function always uses the ROUND_HALF_EVEN mode and the result is
4618-
correctly rounded.
4619-
[clinic start generated code]*/
4620-
4621-
static PyObject *
4622-
_decimal_Decimal_exp_impl(PyObject *self, PyObject *context)
4623-
/*[clinic end generated code: output=c0833b6e9b8c836f input=274784af925e60c9]*/
46244628
Dec_UnaryFuncVA(mpd_qexp)
4625-
4626-
/*[clinic input]
4627-
_decimal.Decimal.ln
4628-
4629-
context: object = None
4630-
4631-
Return the natural (base e) logarithm of the operand.
4632-
4633-
The function always uses the ROUND_HALF_EVEN mode and the result is
4634-
correctly rounded.
4635-
[clinic start generated code]*/
4636-
4637-
static PyObject *
4638-
_decimal_Decimal_ln_impl(PyObject *self, PyObject *context)
4639-
/*[clinic end generated code: output=5191f4ef739b04b0 input=f267b224238c56e2]*/
46404629
Dec_UnaryFuncVA(mpd_qln)
4641-
4642-
/*[clinic input]
4643-
_decimal.Decimal.log10
4644-
4645-
context: object = None
4646-
4647-
Return the base ten logarithm of the operand.
4648-
4649-
The function always uses the ROUND_HALF_EVEN mode and the result is
4650-
correctly rounded.
4651-
[clinic start generated code]*/
4652-
4653-
static PyObject *
4654-
_decimal_Decimal_log10_impl(PyObject *self, PyObject *context)
4655-
/*[clinic end generated code: output=d5da63df75900275 input=d941f9335dc693cb]*/
46564630
Dec_UnaryFuncVA(mpd_qlog10)
4657-
4658-
/*[clinic input]
4659-
_decimal.Decimal.next_minus
4660-
4661-
context: object = None
4662-
4663-
Returns the largest representable number smaller than itself.
4664-
[clinic start generated code]*/
4665-
4666-
static PyObject *
4667-
_decimal_Decimal_next_minus_impl(PyObject *self, PyObject *context)
4668-
/*[clinic end generated code: output=aacbd758399f883f input=75666c6dc3cc8da9]*/
46694631
Dec_UnaryFuncVA(mpd_qnext_minus)
4670-
4671-
/*[clinic input]
4672-
_decimal.Decimal.next_plus
4673-
4674-
context: object = None
4675-
4676-
Returns the smallest representable number larger than itself.
4677-
[clinic start generated code]*/
4678-
4679-
static PyObject *
4680-
_decimal_Decimal_next_plus_impl(PyObject *self, PyObject *context)
4681-
/*[clinic end generated code: output=f3a7029a213c553c input=adcccf3f94e8da3f]*/
46824632
Dec_UnaryFuncVA(mpd_qnext_plus)
4683-
4684-
/*[clinic input]
4685-
_decimal.Decimal.normalize
4686-
4687-
context: object = None
4688-
4689-
Normalize the number by stripping trailing 0s
4690-
4691-
This also change anything equal to 0 to 0e0. Used for producing
4692-
canonical values for members of an equivalence class. For example,
4693-
Decimal('32.100') and Decimal('0.321000e+2') both normalize to
4694-
the equivalent value Decimal('32.1').
4695-
[clinic start generated code]*/
4696-
4697-
static PyObject *
4698-
_decimal_Decimal_normalize_impl(PyObject *self, PyObject *context)
4699-
/*[clinic end generated code: output=db2c8b3c8eccff36 input=8f0504baa4e8c7de]*/
47004633
Dec_UnaryFuncVA(mpd_qreduce)
4701-
4702-
/*[clinic input]
4703-
_decimal.Decimal.sqrt
4704-
4705-
context: object = None
4706-
4707-
Return the square root of the argument to full precision.
4708-
4709-
The result is correctly rounded using the ROUND_HALF_EVEN rounding mode.
4710-
[clinic start generated code]*/
4711-
4712-
static PyObject *
4713-
_decimal_Decimal_sqrt_impl(PyObject *self, PyObject *context)
4714-
/*[clinic end generated code: output=420722a199dd9c2b input=16df570867daf0d6]*/
47154634
Dec_UnaryFuncVA(mpd_qsqrt)
47164635

47174636
/* Binary arithmetic functions, optional context arg */
@@ -4725,27 +4644,6 @@ Dec_BinaryFuncVA(mpd_qnext_toward)
47254644
Dec_BinaryFuncVA(mpd_qrem_near)
47264645

47274646
/* Ternary arithmetic functions, optional context arg */
4728-
4729-
/*[clinic input]
4730-
_decimal.Decimal.fma
4731-
4732-
other: object
4733-
third: object
4734-
context: object = None
4735-
4736-
Fused multiply-add.
4737-
4738-
Return self*other+third with no rounding of the intermediate product
4739-
self*other.
4740-
4741-
>>> Decimal(2).fma(3, 5)
4742-
Decimal('11')
4743-
[clinic start generated code]*/
4744-
4745-
static PyObject *
4746-
_decimal_Decimal_fma_impl(PyObject *self, PyObject *other, PyObject *third,
4747-
PyObject *context)
4748-
/*[clinic end generated code: output=74a82b984e227b69 input=48f9aec6f389227a]*/
47494647
Dec_TernaryFuncVA(mpd_qfma)
47504648

47514649
/* Boolean functions, no context arg */
@@ -4909,35 +4807,7 @@ _decimal_Decimal_copy_negate_impl(PyObject *self)
49094807
}
49104808

49114809
/* Unary functions, optional context arg */
4912-
4913-
/*[clinic input]
4914-
_decimal.Decimal.logical_invert
4915-
4916-
context: object = None
4917-
4918-
Return the digit-wise inversion of the (logical) operand.
4919-
[clinic start generated code]*/
4920-
4921-
static PyObject *
4922-
_decimal_Decimal_logical_invert_impl(PyObject *self, PyObject *context)
4923-
/*[clinic end generated code: output=59beb9b1b51b9f34 input=063cc759635d249b]*/
49244810
Dec_UnaryFuncVA(mpd_qinvert)
4925-
4926-
/*[clinic input]
4927-
_decimal.Decimal.logb
4928-
4929-
context: object = None
4930-
4931-
Return the adjusted exponent of the operand as a Decimal instance.
4932-
4933-
If the operand is a zero, then Decimal('-Infinity') is returned and the
4934-
DivisionByZero condition is raised. If the operand is an infinity then
4935-
Decimal('Infinity') is returned.
4936-
[clinic start generated code]*/
4937-
4938-
static PyObject *
4939-
_decimal_Decimal_logb_impl(PyObject *self, PyObject *context)
4940-
/*[clinic end generated code: output=f278db20b47f301c input=1a0de8e49b101734]*/
49414811
Dec_UnaryFuncVA(mpd_qlogb)
49424812

49434813
/*[clinic input]
@@ -5497,16 +5367,16 @@ static PyGetSetDef dec_getsets [] =
54975367
static PyMethodDef dec_methods [] =
54985368
{
54995369
/* Unary arithmetic functions, optional context arg */
5500-
_DECIMAL_DECIMAL_EXP_METHODDEF
5501-
_DECIMAL_DECIMAL_LN_METHODDEF
5502-
_DECIMAL_DECIMAL_LOG10_METHODDEF
5503-
_DECIMAL_DECIMAL_NEXT_MINUS_METHODDEF
5504-
_DECIMAL_DECIMAL_NEXT_PLUS_METHODDEF
5505-
_DECIMAL_DECIMAL_NORMALIZE_METHODDEF
5370+
{ "exp", _PyCFunction_CAST(dec_mpd_qexp), METH_VARARGS|METH_KEYWORDS, doc_exp },
5371+
{ "ln", _PyCFunction_CAST(dec_mpd_qln), METH_VARARGS|METH_KEYWORDS, doc_ln },
5372+
{ "log10", _PyCFunction_CAST(dec_mpd_qlog10), METH_VARARGS|METH_KEYWORDS, doc_log10 },
5373+
{ "next_minus", _PyCFunction_CAST(dec_mpd_qnext_minus), METH_VARARGS|METH_KEYWORDS, doc_next_minus },
5374+
{ "next_plus", _PyCFunction_CAST(dec_mpd_qnext_plus), METH_VARARGS|METH_KEYWORDS, doc_next_plus },
5375+
{ "normalize", _PyCFunction_CAST(dec_mpd_qreduce), METH_VARARGS|METH_KEYWORDS, doc_normalize },
55065376
_DECIMAL_DECIMAL_TO_INTEGRAL_METHODDEF
55075377
_DECIMAL_DECIMAL_TO_INTEGRAL_EXACT_METHODDEF
55085378
_DECIMAL_DECIMAL_TO_INTEGRAL_VALUE_METHODDEF
5509-
_DECIMAL_DECIMAL_SQRT_METHODDEF
5379+
{ "sqrt", _PyCFunction_CAST(dec_mpd_qsqrt), METH_VARARGS|METH_KEYWORDS, doc_sqrt },
55105380

55115381
/* Binary arithmetic functions, optional context arg */
55125382
{ "compare", _PyCFunction_CAST(dec_mpd_qcompare), METH_VARARGS|METH_KEYWORDS, doc_compare },
@@ -5520,7 +5390,7 @@ static PyMethodDef dec_methods [] =
55205390
{ "remainder_near", _PyCFunction_CAST(dec_mpd_qrem_near), METH_VARARGS|METH_KEYWORDS, doc_remainder_near },
55215391

55225392
/* Ternary arithmetic functions, optional context arg */
5523-
_DECIMAL_DECIMAL_FMA_METHODDEF
5393+
{ "fma", _PyCFunction_CAST(dec_mpd_qfma), METH_VARARGS|METH_KEYWORDS, doc_fma },
55245394

55255395
/* Boolean functions, no context arg */
55265396
{ "is_canonical", dec_mpd_iscanonical, METH_NOARGS, doc_is_canonical },
@@ -5547,8 +5417,8 @@ static PyMethodDef dec_methods [] =
55475417
_DECIMAL_DECIMAL_COPY_NEGATE_METHODDEF
55485418

55495419
/* Unary functions, optional context arg */
5550-
_DECIMAL_DECIMAL_LOGB_METHODDEF
5551-
_DECIMAL_DECIMAL_LOGICAL_INVERT_METHODDEF
5420+
{ "logb", _PyCFunction_CAST(dec_mpd_qlogb), METH_VARARGS|METH_KEYWORDS, doc_logb },
5421+
{ "logical_invert", _PyCFunction_CAST(dec_mpd_qinvert), METH_VARARGS|METH_KEYWORDS, doc_logical_invert },
55525422
_DECIMAL_DECIMAL_NUMBER_CLASS_METHODDEF
55535423
_DECIMAL_DECIMAL_TO_ENG_STRING_METHODDEF
55545424

0 commit comments

Comments
 (0)