@@ -46,6 +46,9 @@ typedef struct {
46
46
PyTypeObject * PyDec_Type ;
47
47
PyTypeObject * PyDecSignalDict_Type ;
48
48
PyTypeObject * DecimalTuple ;
49
+
50
+ /* Top level Exception; inherits from ArithmeticError */
51
+ PyObject * DecimalException ;
49
52
} decimal_state ;
50
53
51
54
static decimal_state global_state ;
@@ -164,9 +167,6 @@ typedef struct {
164
167
PyObject * ex ; /* corresponding exception */
165
168
} DecCondMap ;
166
169
167
- /* Top level Exception; inherits from ArithmeticError */
168
- static PyObject * DecimalException = NULL ;
169
-
170
170
/* Exceptions that correspond to IEEE signals */
171
171
#define SUBNORMAL 5
172
172
#define INEXACT 6
@@ -5902,10 +5902,10 @@ PyInit__decimal(void)
5902
5902
CHECK_INT (PyModule_AddType (m , state -> DecimalTuple ));
5903
5903
5904
5904
/* Create top level exception */
5905
- ASSIGN_PTR (DecimalException , PyErr_NewException (
5905
+ ASSIGN_PTR (state -> DecimalException , PyErr_NewException (
5906
5906
"decimal.DecimalException" ,
5907
5907
PyExc_ArithmeticError , NULL ));
5908
- CHECK_INT (PyModule_AddObject (m , "DecimalException" , Py_NewRef ( DecimalException ) ));
5908
+ CHECK_INT (PyModule_AddType (m , ( PyTypeObject * ) state -> DecimalException ));
5909
5909
5910
5910
/* Create signal tuple */
5911
5911
ASSIGN_PTR (SignalTuple , PyTuple_New (SIGNAL_MAP_LEN ));
@@ -5918,10 +5918,11 @@ PyInit__decimal(void)
5918
5918
5919
5919
switch (cm -> flag ) {
5920
5920
case MPD_Float_operation :
5921
- base = PyTuple_Pack (2 , DecimalException , PyExc_TypeError );
5921
+ base = PyTuple_Pack (2 , state -> DecimalException , PyExc_TypeError );
5922
5922
break ;
5923
5923
case MPD_Division_by_zero :
5924
- base = PyTuple_Pack (2 , DecimalException , PyExc_ZeroDivisionError );
5924
+ base = PyTuple_Pack (2 , state -> DecimalException ,
5925
+ PyExc_ZeroDivisionError );
5925
5926
break ;
5926
5927
case MPD_Overflow :
5927
5928
base = PyTuple_Pack (2 , signal_map [INEXACT ].ex ,
@@ -5933,7 +5934,7 @@ PyInit__decimal(void)
5933
5934
signal_map [SUBNORMAL ].ex );
5934
5935
break ;
5935
5936
default :
5936
- base = PyTuple_Pack (1 , DecimalException );
5937
+ base = PyTuple_Pack (1 , state -> DecimalException );
5937
5938
break ;
5938
5939
}
5939
5940
0 commit comments