@@ -80,9 +80,7 @@ typedef struct {
80
80
PyObject * traps ;
81
81
PyObject * flags ;
82
82
int capitals ;
83
- #ifndef WITHOUT_THREADS
84
83
PyThreadState * tstate ;
85
- #endif
86
84
} PyDecContextObject ;
87
85
88
86
typedef struct {
@@ -124,15 +122,10 @@ incr_false(void)
124
122
}
125
123
126
124
127
- #ifdef WITHOUT_THREADS
128
- /* Default module context */
129
- static PyObject * module_context = NULL ;
130
- #else
131
125
/* Key for thread state dictionary */
132
126
static PyObject * tls_context_key = NULL ;
133
127
/* Invariant: NULL or the most recently accessed thread local context */
134
128
static PyDecContextObject * cached_context = NULL ;
135
- #endif
136
129
137
130
/* Template for creating new thread contexts, calling Context() without
138
131
* arguments and initializing the module_context on first access. */
@@ -1219,21 +1212,18 @@ context_new(PyTypeObject *type, PyObject *args UNUSED, PyObject *kwds UNUSED)
1219
1212
SdFlagAddr (self -> flags ) = & ctx -> status ;
1220
1213
1221
1214
CtxCaps (self ) = 1 ;
1222
- #ifndef WITHOUT_THREADS
1223
1215
self -> tstate = NULL ;
1224
- #endif
1225
1216
1226
1217
return (PyObject * )self ;
1227
1218
}
1228
1219
1229
1220
static void
1230
1221
context_dealloc (PyDecContextObject * self )
1231
1222
{
1232
- #ifndef WITHOUT_THREADS
1233
1223
if (self == cached_context ) {
1234
1224
cached_context = NULL ;
1235
1225
}
1236
- #endif
1226
+
1237
1227
Py_XDECREF (self -> traps );
1238
1228
Py_XDECREF (self -> flags );
1239
1229
Py_TYPE (self )-> tp_free (self );
@@ -1501,76 +1491,6 @@ static PyGetSetDef context_getsets [] =
1501
1491
/* Global, thread local and temporary contexts */
1502
1492
/******************************************************************************/
1503
1493
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
1574
1494
/*
1575
1495
* Thread local storage currently has a speed penalty of about 4%.
1576
1496
* All functions that map Python's arithmetic operators to mpdecimal
@@ -1713,7 +1633,6 @@ PyDec_SetCurrentContext(PyObject *self UNUSED, PyObject *v)
1713
1633
Py_DECREF (v );
1714
1634
Py_RETURN_NONE ;
1715
1635
}
1716
- #endif
1717
1636
1718
1637
/* Context manager object for the 'with' statement. The manager
1719
1638
* owns one reference to the global (outer) context and one
@@ -5840,17 +5759,9 @@ PyInit__decimal(void)
5840
5759
CHECK_INT (PyModule_AddObject (m , "DefaultContext" ,
5841
5760
default_context_template ));
5842
5761
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
5850
5762
ASSIGN_PTR (tls_context_key , PyUnicode_FromString ("___DECIMAL_CTX__" ));
5851
5763
Py_INCREF (Py_True );
5852
5764
CHECK_INT (PyModule_AddObject (m , "HAVE_THREADS" , Py_True ));
5853
- #endif
5854
5765
5855
5766
/* Init basic context template */
5856
5767
ASSIGN_PTR (basic_context_template ,
@@ -5906,12 +5817,8 @@ PyInit__decimal(void)
5906
5817
Py_CLEAR (MutableMapping ); /* GCOV_NOT_REACHED */
5907
5818
Py_CLEAR (SignalTuple ); /* GCOV_NOT_REACHED */
5908
5819
Py_CLEAR (DecimalTuple ); /* GCOV_NOT_REACHED */
5909
- #ifdef WITHOUT_THREADS
5910
- Py_CLEAR (module_context ); /* GCOV_NOT_REACHED */
5911
- #else
5912
5820
Py_CLEAR (default_context_template ); /* GCOV_NOT_REACHED */
5913
5821
Py_CLEAR (tls_context_key ); /* GCOV_NOT_REACHED */
5914
- #endif
5915
5822
Py_CLEAR (basic_context_template ); /* GCOV_NOT_REACHED */
5916
5823
Py_CLEAR (extended_context_template ); /* GCOV_NOT_REACHED */
5917
5824
Py_CLEAR (m ); /* GCOV_NOT_REACHED */
0 commit comments