Skip to content

Commit 0768eed

Browse files
aiskeendebakpt
andauthored
gh-81057: Inline single-use error messages in _decimal and make the rest const (#156809)
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
1 parent ce5c012 commit 0768eed

2 files changed

Lines changed: 20 additions & 31 deletions

File tree

‎Modules/_decimal/_decimal.c‎

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -348,30 +348,6 @@ static const char *dec_signal_string[MPD_NUM_FLAGS] = {
348348
"Underflow",
349349
};
350350

351-
static const char *invalid_rounding_err =
352-
"valid values for rounding are:\n\
353-
[ROUND_CEILING, ROUND_FLOOR, ROUND_UP, ROUND_DOWN,\n\
354-
ROUND_HALF_UP, ROUND_HALF_DOWN, ROUND_HALF_EVEN,\n\
355-
ROUND_05UP]";
356-
357-
static const char *invalid_signals_err =
358-
"valid values for signals are:\n\
359-
[InvalidOperation, FloatOperation, DivisionByZero,\n\
360-
Overflow, Underflow, Subnormal, Inexact, Rounded,\n\
361-
Clamped]";
362-
363-
#ifdef EXTRA_FUNCTIONALITY
364-
static const char *invalid_flags_err =
365-
"valid values for _flags or _traps are:\n\
366-
signals:\n\
367-
[DecIEEEInvalidOperation, DecFloatOperation, DecDivisionByZero,\n\
368-
DecOverflow, DecUnderflow, DecSubnormal, DecInexact, DecRounded,\n\
369-
DecClamped]\n\
370-
conditions which trigger DecIEEEInvalidOperation:\n\
371-
[DecInvalidOperation, DecConversionSyntax, DecDivisionImpossible,\n\
372-
DecDivisionUndefined, DecFpuError, DecInvalidContext, DecMallocError]";
373-
#endif
374-
375351
static int
376352
value_error_int(const char *mesg)
377353
{
@@ -442,7 +418,11 @@ exception_as_flag(decimal_state *state, PyObject *ex)
442418
}
443419
}
444420

445-
PyErr_SetString(PyExc_KeyError, invalid_signals_err);
421+
PyErr_SetString(PyExc_KeyError,
422+
"valid values for signals are:\n"
423+
" [InvalidOperation, FloatOperation, DivisionByZero,\n"
424+
" Overflow, Underflow, Subnormal, Inexact, Rounded,\n"
425+
" Clamped]");
446426
return DEC_INVALID_SIGNALS;
447427
}
448428

@@ -601,7 +581,15 @@ long_as_flags(PyObject *v)
601581
return DEC_ERR_OCCURRED;
602582
}
603583
if (x < 0 || x > (long)MPD_Max_status) {
604-
PyErr_SetString(PyExc_TypeError, invalid_flags_err);
584+
PyErr_SetString(PyExc_TypeError,
585+
"valid values for _flags or _traps are:\n"
586+
" signals:\n"
587+
" [DecIEEEInvalidOperation, DecFloatOperation, DecDivisionByZero,\n"
588+
" DecOverflow, DecUnderflow, DecSubnormal, DecInexact, DecRounded,\n"
589+
" DecClamped]\n"
590+
" conditions which trigger DecIEEEInvalidOperation:\n"
591+
" [DecInvalidOperation, DecConversionSyntax, DecDivisionImpossible,\n"
592+
" DecDivisionUndefined, DecFpuError, DecInvalidContext, DecMallocError]");
605593
return DEC_INVALID_SIGNALS;
606594
}
607595

@@ -657,7 +645,11 @@ getround(decimal_state *state, PyObject *v)
657645
}
658646
}
659647

660-
return type_error_int(invalid_rounding_err);
648+
return type_error_int(
649+
"valid values for rounding are:\n"
650+
" [ROUND_CEILING, ROUND_FLOOR, ROUND_UP, ROUND_DOWN,\n"
651+
" ROUND_HALF_UP, ROUND_HALF_DOWN, ROUND_HALF_EVEN,\n"
652+
" ROUND_05UP]");
661653
}
662654

663655

@@ -671,7 +663,7 @@ getround(decimal_state *state, PyObject *v)
671663
initialized to new SignalDicts. Once a SignalDict is tied to
672664
a context, it cannot be deleted. */
673665

674-
static const char *INVALID_SIGNALDICT_ERROR_MSG = "invalid signal dict";
666+
static const char *const INVALID_SIGNALDICT_ERROR_MSG = "invalid signal dict";
675667

676668
static int
677669
signaldict_init(PyObject *self,

‎Tools/c-analyzer/cpython/ignored.tsv‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,8 @@ Modules/_decimal/_decimal.c - cond_map_template -
240240
Modules/_decimal/_decimal.c - dec_signal_string -
241241
Modules/_decimal/_decimal.c - dflt_ctx -
242242
Modules/_decimal/_decimal.c - int_constants -
243-
Modules/_decimal/_decimal.c - invalid_rounding_err -
244-
Modules/_decimal/_decimal.c - invalid_signals_err -
245243
Modules/_decimal/_decimal.c - signal_map_template -
246244
Modules/_decimal/_decimal.c - ssize_constants -
247-
Modules/_decimal/_decimal.c - INVALID_SIGNALDICT_ERROR_MSG -
248245
Modules/_elementtree.c - ExpatMemoryHandler -
249246
Modules/_hashopenssl.c - py_hashes -
250247
Modules/_hacl/Hacl_Hash_SHA1.c - _h0 -

0 commit comments

Comments
 (0)