@@ -178,11 +178,15 @@ typedef struct {
178
178
mpd_uint_t data [_Py_DEC_MINALLOC ];
179
179
} PyDecObject ;
180
180
181
+ #define _PyDecObject_CAST (op ) ((PyDecObject *)(op))
182
+
181
183
typedef struct {
182
184
PyObject_HEAD
183
185
uint32_t * flags ;
184
186
} PyDecSignalDictObject ;
185
187
188
+ #define _PyDecSignalDictObject_CAST (op ) ((PyDecSignalDictObject *)(op))
189
+
186
190
typedef struct PyDecContextObject {
187
191
PyObject_HEAD
188
192
mpd_context_t ctx ;
@@ -193,23 +197,27 @@ typedef struct PyDecContextObject {
193
197
decimal_state * modstate ;
194
198
} PyDecContextObject ;
195
199
200
+ #define _PyDecContextObject_CAST (op ) ((PyDecContextObject *)(op))
201
+
196
202
typedef struct {
197
203
PyObject_HEAD
198
204
PyObject * local ;
199
205
PyObject * global ;
200
206
} PyDecContextManagerObject ;
201
207
208
+ #define _PyDecContextManagerObject_CAST (op ) ((PyDecContextManagerObject *)(op))
209
+
202
210
#undef MPD
203
211
#undef CTX
204
212
#define PyDec_CheckExact (st , v ) Py_IS_TYPE(v, (st)->PyDec_Type)
205
213
#define PyDec_Check (st , v ) PyObject_TypeCheck(v, (st)->PyDec_Type)
206
214
#define PyDecSignalDict_Check (st , v ) Py_IS_TYPE(v, (st)->PyDecSignalDict_Type)
207
215
#define PyDecContext_Check (st , v ) PyObject_TypeCheck(v, (st)->PyDecContext_Type)
208
- #define MPD (v ) (&((PyDecObject *) v)->dec)
209
- #define SdFlagAddr (v ) (((PyDecSignalDictObject *) v)->flags)
210
- #define SdFlags (v ) (*((PyDecSignalDictObject *) v)->flags)
211
- #define CTX (v ) (&((PyDecContextObject *) v)->ctx)
212
- #define CtxCaps (v ) (((PyDecContextObject *) v)->capitals)
216
+ #define MPD (v ) (&_PyDecObject_CAST( v)->dec)
217
+ #define SdFlagAddr (v ) (_PyDecSignalDictObject_CAST( v)->flags)
218
+ #define SdFlags (v ) (*_PyDecSignalDictObject_CAST( v)->flags)
219
+ #define CTX (v ) (&_PyDecContextObject_CAST( v)->ctx)
220
+ #define CtxCaps (v ) (_PyDecContextObject_CAST( v)->capitals)
213
221
214
222
static inline decimal_state *
215
223
get_module_state_from_ctx (PyObject * v )
@@ -1413,24 +1421,26 @@ context_new(PyTypeObject *type,
1413
1421
}
1414
1422
1415
1423
static int
1416
- context_traverse (PyDecContextObject * self , visitproc visit , void * arg )
1424
+ context_traverse (PyObject * op , visitproc visit , void * arg )
1417
1425
{
1426
+ PyDecContextObject * self = _PyDecContextObject_CAST (op );
1418
1427
Py_VISIT (Py_TYPE (self ));
1419
1428
Py_VISIT (self -> traps );
1420
1429
Py_VISIT (self -> flags );
1421
1430
return 0 ;
1422
1431
}
1423
1432
1424
1433
static int
1425
- context_clear (PyDecContextObject * self )
1434
+ context_clear (PyObject * op )
1426
1435
{
1436
+ PyDecContextObject * self = _PyDecContextObject_CAST (op );
1427
1437
Py_CLEAR (self -> traps );
1428
1438
Py_CLEAR (self -> flags );
1429
1439
return 0 ;
1430
1440
}
1431
1441
1432
1442
static void
1433
- context_dealloc (PyDecContextObject * self )
1443
+ context_dealloc (PyObject * self )
1434
1444
{
1435
1445
PyTypeObject * tp = Py_TYPE (self );
1436
1446
PyObject_GC_UnTrack (self );
@@ -1473,15 +1483,15 @@ context_init(PyObject *self, PyObject *args, PyObject *kwds)
1473
1483
}
1474
1484
1475
1485
static PyObject *
1476
- context_repr (PyDecContextObject * self )
1486
+ context_repr (PyObject * self )
1477
1487
{
1478
1488
mpd_context_t * ctx ;
1479
1489
char flags [MPD_MAX_SIGNAL_LIST ];
1480
1490
char traps [MPD_MAX_SIGNAL_LIST ];
1481
1491
int n , mem ;
1482
1492
1483
1493
#ifdef Py_DEBUG
1484
- decimal_state * state = get_module_state_from_ctx (( PyObject * ) self );
1494
+ decimal_state * state = get_module_state_from_ctx (self );
1485
1495
assert (PyDecContext_Check (state , self ));
1486
1496
#endif
1487
1497
ctx = CTX (self );
@@ -1501,7 +1511,7 @@ context_repr(PyDecContextObject *self)
1501
1511
"Context(prec=%zd, rounding=%s, Emin=%zd, Emax=%zd, "
1502
1512
"capitals=%d, clamp=%d, flags=%s, traps=%s)" ,
1503
1513
ctx -> prec , mpd_round_string [ctx -> round ], ctx -> emin , ctx -> emax ,
1504
- self -> capitals , ctx -> clamp , flags , traps );
1514
+ CtxCaps ( self ) , ctx -> clamp , flags , traps );
1505
1515
}
1506
1516
1507
1517
static void
@@ -1621,16 +1631,16 @@ context_reduce(PyObject *self, PyObject *Py_UNUSED(dummy))
1621
1631
1622
1632
static PyGetSetDef context_getsets [] =
1623
1633
{
1624
- { "prec" , ( getter ) context_getprec , ( setter ) context_setprec , NULL , NULL },
1625
- { "Emax" , ( getter ) context_getemax , ( setter ) context_setemax , NULL , NULL },
1626
- { "Emin" , ( getter ) context_getemin , ( setter ) context_setemin , NULL , NULL },
1627
- { "rounding" , ( getter ) context_getround , ( setter ) context_setround , NULL , NULL },
1628
- { "capitals" , ( getter ) context_getcapitals , ( setter ) context_setcapitals , NULL , NULL },
1629
- { "clamp" , ( getter ) context_getclamp , ( setter ) context_setclamp , NULL , NULL },
1634
+ { "prec" , context_getprec , context_setprec , NULL , NULL },
1635
+ { "Emax" , context_getemax , context_setemax , NULL , NULL },
1636
+ { "Emin" , context_getemin , context_setemin , NULL , NULL },
1637
+ { "rounding" , context_getround , context_setround , NULL , NULL },
1638
+ { "capitals" , context_getcapitals , context_setcapitals , NULL , NULL },
1639
+ { "clamp" , context_getclamp , context_setclamp , NULL , NULL },
1630
1640
#ifdef EXTRA_FUNCTIONALITY
1631
- { "_allcr" , ( getter ) context_getallcr , ( setter ) context_setallcr , NULL , NULL },
1632
- { "_traps" , ( getter ) context_gettraps , ( setter ) context_settraps , NULL , NULL },
1633
- { "_flags" , ( getter ) context_getstatus , ( setter ) context_setstatus , NULL , NULL },
1641
+ { "_allcr" , context_getallcr , context_setallcr , NULL , NULL },
1642
+ { "_traps" , context_gettraps , context_settraps , NULL , NULL },
1643
+ { "_flags" , context_getstatus , context_setstatus , NULL , NULL },
1634
1644
#endif
1635
1645
{NULL }
1636
1646
};
@@ -1946,39 +1956,39 @@ ctxmanager_new(PyObject *m, PyObject *args, PyObject *kwds)
1946
1956
}
1947
1957
1948
1958
static int
1949
- ctxmanager_traverse (PyDecContextManagerObject * self , visitproc visit ,
1950
- void * arg )
1959
+ ctxmanager_traverse (PyObject * op , visitproc visit , void * arg )
1951
1960
{
1961
+ PyDecContextManagerObject * self = _PyDecContextManagerObject_CAST (op );
1952
1962
Py_VISIT (Py_TYPE (self ));
1953
1963
Py_VISIT (self -> local );
1954
1964
Py_VISIT (self -> global );
1955
1965
return 0 ;
1956
1966
}
1957
1967
1958
1968
static int
1959
- ctxmanager_clear (PyDecContextManagerObject * self )
1969
+ ctxmanager_clear (PyObject * op )
1960
1970
{
1971
+ PyDecContextManagerObject * self = _PyDecContextManagerObject_CAST (op );
1961
1972
Py_CLEAR (self -> local );
1962
1973
Py_CLEAR (self -> global );
1963
1974
return 0 ;
1964
1975
}
1965
1976
1966
1977
static void
1967
- ctxmanager_dealloc (PyDecContextManagerObject * self )
1978
+ ctxmanager_dealloc (PyObject * self )
1968
1979
{
1969
1980
PyTypeObject * tp = Py_TYPE (self );
1970
1981
PyObject_GC_UnTrack (self );
1971
1982
(void )ctxmanager_clear (self );
1972
- tp -> tp_free (( PyObject * ) self );
1983
+ tp -> tp_free (self );
1973
1984
Py_DECREF (tp );
1974
1985
}
1975
1986
1976
1987
static PyObject *
1977
- ctxmanager_set_local (PyDecContextManagerObject * self ,
1978
- PyObject * Py_UNUSED (dummy ))
1988
+ ctxmanager_set_local (PyObject * op , PyObject * Py_UNUSED (dummy ))
1979
1989
{
1980
1990
PyObject * ret ;
1981
-
1991
+ PyDecContextManagerObject * self = _PyDecContextManagerObject_CAST ( op );
1982
1992
ret = PyDec_SetCurrentContext (PyType_GetModule (Py_TYPE (self )), self -> local );
1983
1993
if (ret == NULL ) {
1984
1994
return NULL ;
@@ -1989,11 +1999,10 @@ ctxmanager_set_local(PyDecContextManagerObject *self,
1989
1999
}
1990
2000
1991
2001
static PyObject *
1992
- ctxmanager_restore_global (PyDecContextManagerObject * self ,
1993
- PyObject * Py_UNUSED (args ))
2002
+ ctxmanager_restore_global (PyObject * op , PyObject * Py_UNUSED (args ))
1994
2003
{
1995
2004
PyObject * ret ;
1996
-
2005
+ PyDecContextManagerObject * self = _PyDecContextManagerObject_CAST ( op );
1997
2006
ret = PyDec_SetCurrentContext (PyType_GetModule (Py_TYPE (self )), self -> global );
1998
2007
if (ret == NULL ) {
1999
2008
return NULL ;
@@ -2005,8 +2014,8 @@ ctxmanager_restore_global(PyDecContextManagerObject *self,
2005
2014
2006
2015
2007
2016
static PyMethodDef ctxmanager_methods [] = {
2008
- {"__enter__" , ( PyCFunction ) ctxmanager_set_local , METH_NOARGS , NULL },
2009
- {"__exit__" , ( PyCFunction ) ctxmanager_restore_global , METH_VARARGS , NULL },
2017
+ {"__enter__" , ctxmanager_set_local , METH_NOARGS , NULL },
2018
+ {"__exit__" , ctxmanager_restore_global , METH_VARARGS , NULL },
2010
2019
{NULL , NULL }
2011
2020
};
2012
2021
@@ -5041,8 +5050,8 @@ dec_imag(PyObject *self, void *Py_UNUSED(closure))
5041
5050
5042
5051
static PyGetSetDef dec_getsets [] =
5043
5052
{
5044
- { "real" , ( getter ) dec_real , NULL , NULL , NULL },
5045
- { "imag" , ( getter ) dec_imag , NULL , NULL , NULL },
5053
+ { "real" , dec_real , NULL , NULL , NULL },
5054
+ { "imag" , dec_imag , NULL , NULL , NULL },
5046
5055
{NULL }
5047
5056
};
5048
5057
0 commit comments