@@ -80,9 +80,7 @@ typedef struct {
8080 PyObject * traps ;
8181 PyObject * flags ;
8282 int capitals ;
83- #ifndef WITHOUT_THREADS
8483 PyThreadState * tstate ;
85- #endif
8684} PyDecContextObject ;
8785
8886typedef struct {
@@ -124,15 +122,10 @@ incr_false(void)
124122}
125123
126124
127- #ifdef WITHOUT_THREADS
128- /* Default module context */
129- static PyObject * module_context = NULL ;
130- #else
131125/* Key for thread state dictionary */
132126static PyObject * tls_context_key = NULL ;
133127/* Invariant: NULL or the most recently accessed thread local context */
134128static PyDecContextObject * cached_context = NULL ;
135- #endif
136129
137130/* Template for creating new thread contexts, calling Context() without
138131 * arguments and initializing the module_context on first access. */
@@ -1219,21 +1212,18 @@ context_new(PyTypeObject *type, PyObject *args UNUSED, PyObject *kwds UNUSED)
12191212 SdFlagAddr (self -> flags ) = & ctx -> status ;
12201213
12211214 CtxCaps (self ) = 1 ;
1222- #ifndef WITHOUT_THREADS
12231215 self -> tstate = NULL ;
1224- #endif
12251216
12261217 return (PyObject * )self ;
12271218}
12281219
12291220static void
12301221context_dealloc (PyDecContextObject * self )
12311222{
1232- #ifndef WITHOUT_THREADS
12331223 if (self == cached_context ) {
12341224 cached_context = NULL ;
12351225 }
1236- #endif
1226+
12371227 Py_XDECREF (self -> traps );
12381228 Py_XDECREF (self -> flags );
12391229 Py_TYPE (self )-> tp_free (self );
@@ -1501,76 +1491,6 @@ static PyGetSetDef context_getsets [] =
15011491/* Global, thread local and temporary contexts */
15021492/******************************************************************************/
15031493
1504- #ifdef WITHOUT_THREADS
1505- /* Return borrowed reference to the current context. When compiled
1506- * without threads, this is always the module context. */
1507- static int module_context_set = 0 ;
1508- static PyObject *
1509- current_context (void )
1510- {
1511- /* In decimal.py, the module context is automatically initialized
1512- * from the DefaultContext when it is first accessed. This
1513- * complicates the code and has a speed penalty of 1-2%. */
1514- if (module_context_set ) {
1515- return module_context ;
1516- }
1517-
1518- * CTX (module_context ) = * CTX (default_context_template );
1519- CTX (module_context )-> status = 0 ;
1520- CTX (module_context )-> newtrap = 0 ;
1521- CtxCaps (module_context ) = CtxCaps (default_context_template );
1522-
1523- module_context_set = 1 ;
1524- return module_context ;
1525- }
1526-
1527- /* ctxobj := borrowed reference to the current context */
1528- #define CURRENT_CONTEXT (ctxobj ) \
1529- ctxobj = current_context()
1530-
1531- /* ctx := pointer to the mpd_context_t struct of the current context */
1532- #define CURRENT_CONTEXT_ADDR (ctx ) \
1533- ctx = CTX(current_context())
1534-
1535- /* Return a new reference to the current context */
1536- static PyObject *
1537- PyDec_GetCurrentContext (PyObject * self UNUSED , PyObject * args UNUSED )
1538- {
1539- PyObject * context ;
1540-
1541- CURRENT_CONTEXT (context );
1542-
1543- Py_INCREF (context );
1544- return context ;
1545- }
1546-
1547- /* Set the module context to a new context, decrement old reference */
1548- static PyObject *
1549- PyDec_SetCurrentContext (PyObject * self UNUSED , PyObject * v )
1550- {
1551- CONTEXT_CHECK (v );
1552-
1553- /* If the new context is one of the templates, make a copy.
1554- * This is the current behavior of decimal.py. */
1555- if (v == default_context_template ||
1556- v == basic_context_template ||
1557- v == extended_context_template ) {
1558- v = context_copy (v , NULL );
1559- if (v == NULL ) {
1560- return NULL ;
1561- }
1562- CTX (v )-> status = 0 ;
1563- }
1564- else {
1565- Py_INCREF (v );
1566- }
1567-
1568- Py_XDECREF (module_context );
1569- module_context = v ;
1570- module_context_set = 1 ;
1571- Py_RETURN_NONE ;
1572- }
1573- #else
15741494/*
15751495 * Thread local storage currently has a speed penalty of about 4%.
15761496 * All functions that map Python's arithmetic operators to mpdecimal
@@ -1713,7 +1633,6 @@ PyDec_SetCurrentContext(PyObject *self UNUSED, PyObject *v)
17131633 Py_DECREF (v );
17141634 Py_RETURN_NONE ;
17151635}
1716- #endif
17171636
17181637/* Context manager object for the 'with' statement. The manager
17191638 * owns one reference to the global (outer) context and one
@@ -5840,17 +5759,9 @@ PyInit__decimal(void)
58405759 CHECK_INT (PyModule_AddObject (m , "DefaultContext" ,
58415760 default_context_template ));
58425761
5843- #ifdef WITHOUT_THREADS
5844- /* Init module context */
5845- ASSIGN_PTR (module_context ,
5846- PyObject_CallObject ((PyObject * )& PyDecContext_Type , NULL ));
5847- Py_INCREF (Py_False );
5848- CHECK_INT (PyModule_AddObject (m , "HAVE_THREADS" , Py_False ));
5849- #else
58505762 ASSIGN_PTR (tls_context_key , PyUnicode_FromString ("___DECIMAL_CTX__" ));
58515763 Py_INCREF (Py_True );
58525764 CHECK_INT (PyModule_AddObject (m , "HAVE_THREADS" , Py_True ));
5853- #endif
58545765
58555766 /* Init basic context template */
58565767 ASSIGN_PTR (basic_context_template ,
@@ -5906,12 +5817,8 @@ PyInit__decimal(void)
59065817 Py_CLEAR (MutableMapping ); /* GCOV_NOT_REACHED */
59075818 Py_CLEAR (SignalTuple ); /* GCOV_NOT_REACHED */
59085819 Py_CLEAR (DecimalTuple ); /* GCOV_NOT_REACHED */
5909- #ifdef WITHOUT_THREADS
5910- Py_CLEAR (module_context ); /* GCOV_NOT_REACHED */
5911- #else
59125820 Py_CLEAR (default_context_template ); /* GCOV_NOT_REACHED */
59135821 Py_CLEAR (tls_context_key ); /* GCOV_NOT_REACHED */
5914- #endif
59155822 Py_CLEAR (basic_context_template ); /* GCOV_NOT_REACHED */
59165823 Py_CLEAR (extended_context_template ); /* GCOV_NOT_REACHED */
59175824 Py_CLEAR (m ); /* GCOV_NOT_REACHED */
0 commit comments