8000 gh-106078: Move DecimalException to _decimal state (#106301) · python/cpython@dbefa88 · GitHub
[go: up one dir, main page]

Skip to content

Commit dbefa88

Browse files
gh-106078: Move DecimalException to _decimal state (#106301)
1 parent bc7eb17 commit dbefa88

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

Modules/_decimal/_decimal.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ typedef struct {
4646
PyTypeObject *PyDec_Type;
4747
PyTypeObject *PyDecSignalDict_Type;
4848
PyTypeObject *DecimalTuple;
49+
50+
/* Top level Exception; inherits from ArithmeticError */
51+
PyObject *DecimalException;
4952
} decimal_state;
5053

5154
static decimal_state global_state;
@@ -164,9 +167,6 @@ typedef struct {
164167
PyObject *ex; /* corresponding exception */
165168
} DecCondMap;
166169

167-
/* Top level Exception; inherits from ArithmeticError */
168-
static PyObject *DecimalException = NULL;
169-
170170
/* Exceptions that correspond to IEEE signals */
171171
#define SUBNORMAL 5
172172
#define INEXACT 6
@@ -5902,10 +5902,10 @@ PyInit__decimal(void)
59025902
CHECK_INT(PyModule_AddType(m, state->DecimalTuple));
59035903

59045904
/* Create top level exception */
5905-
ASSIGN_PTR(DecimalException, PyErr_NewException(
5905+
ASSIGN_PTR(state->DecimalException, PyErr_NewException(
59065906
"decimal.DecimalException",
59075907
PyExc_ArithmeticError, NULL));
5908-
CHECK_INT(PyModule_AddObject(m, "DecimalException", Py_NewRef(DecimalException)));
5908+
CHECK_INT(PyModule_AddType(m, (PyTypeObject *)state->DecimalException));
59095909

59105910
/* Create signal tuple */
59115911
ASSIGN_PTR(SignalTuple, PyTuple_New(SIGNAL_MAP_LEN));
@@ -5918,10 +5918,11 @@ PyInit__decimal(void)
59185918

59195919
switch (cm->flag) {
59205920
case MPD_Float_operation:
5921-
base = PyTuple_Pack(2, DecimalException, PyExc_TypeError);
5921+
base = PyTuple_Pack(2, state->DecimalException, PyExc_TypeError);
59225922
break;
59235923
case MPD_Division_by_zero:
5924-
base = PyTuple_Pack(2, DecimalException, PyExc_ZeroDivisionError);
5924+
base = PyTuple_Pack(2, state->DecimalException,
5925+
PyExc_ZeroDivisionError);
59255926
break;
59265927
case MPD_Overflow:
59275928
base = PyTuple_Pack(2, signal_map[INEXACT].ex,
@@ -5933,7 +5934,7 @@ PyInit__decimal(void)
59335934
signal_map[SUBNORMAL].ex);
59345935
break;
59355936
default:
5936-
base = PyTuple_Pack(1, DecimalException);
5937+
base = PyTuple_Pack(1, state->DecimalException);
59375938
break;
59385939
}
59395940

Tools/c-analyzer/cpython/globals-to-fix.tsv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ Modules/xxlimited_35.c - Xxo_Type -
393393
## exception types
394394
Modules/_ctypes/_ctypes.c - PyExc_ArgError -
395395
Modules/_cursesmodule.c - PyCursesError -
396-
Modules/_decimal/_decimal.c - DecimalException -
397396
Modules/_tkinter.c - Tkinter_TclError -
398397
Modules/xxlimited_35.c - ErrorObject -
399398
Modules/xxmodule.c - ErrorObject -

0 commit comments

Comments
 (0)
0