PyTypeObject *PyDec_Type;
PyTypeObject *PyDecSignalDict_Type;
PyTypeObject *DecimalTuple;
+
+ /* Top level Exception; inherits from ArithmeticError */
+ PyObject *DecimalException;
} decimal_state;
static decimal_state global_state;
PyObject *ex; /* corresponding exception */
} DecCondMap;
-/* Top level Exception; inherits from ArithmeticError */
-static PyObject *DecimalException = NULL;
-
/* Exceptions that correspond to IEEE signals */
#define SUBNORMAL 5
#define INEXACT 6
CHECK_INT(PyModule_AddType(m, state->DecimalTuple));
/* Create top level exception */
- ASSIGN_PTR(DecimalException, PyErr_NewException(
+ ASSIGN_PTR(state->DecimalException, PyErr_NewException(
"decimal.DecimalException",
PyExc_ArithmeticError, NULL));
- CHECK_INT(PyModule_AddObject(m, "DecimalException", Py_NewRef(DecimalException)));
+ CHECK_INT(PyModule_AddType(m, (PyTypeObject *)state->DecimalException));
/* Create signal tuple */
ASSIGN_PTR(SignalTuple, PyTuple_New(SIGNAL_MAP_LEN));
switch (cm->flag) {
case MPD_Float_operation:
- base = PyTuple_Pack(2, DecimalException, PyExc_TypeError);
+ base = PyTuple_Pack(2, state->DecimalException, PyExc_TypeError);
break;
case MPD_Division_by_zero:
- base = PyTuple_Pack(2, DecimalException, PyExc_ZeroDivisionError);
+ base = PyTuple_Pack(2, state->DecimalException,
+ PyExc_ZeroDivisionError);
break;
case MPD_Overflow:
base = PyTuple_Pack(2, signal_map[INEXACT].ex,
signal_map[SUBNORMAL].ex);
break;
default:
- base = PyTuple_Pack(1, DecimalException);
+ base = PyTuple_Pack(1, state->DecimalException);
break;
}