@@ -81,8 +81,11 @@ static PyObject*
81
81
test_config (PyObject * self , PyObject * Py_UNUSED (ignored ))
82
82
{
83
83
#define CHECK_SIZEOF (FATNAME , TYPE ) \
84
- if (FATNAME != sizeof(TYPE)) \
85
- return sizeof_error(self, #FATNAME, #TYPE, FATNAME, sizeof(TYPE))
84
+ do { \
85
+ if (FATNAME != sizeof(TYPE)) { \
86
+ return sizeof_error(self, #FATNAME, #TYPE, FATNAME, sizeof(TYPE)); \
87
+ } \
88
+ } while (0)
86
89
87
90
CHECK_SIZEOF (SIZEOF_SHORT , short );
88
91
CHECK_SIZEOF (SIZEOF_INT , int );
@@ -103,21 +106,25 @@ test_sizeof_c_types(PyObject *self, PyObject *Py_UNUSED(ignored))
103
106
#pragma GCC diagnostic push
104
107
#pragma GCC diagnostic ignored "-Wtype-limits"
105
108
#endif
106
- #define CHECK_SIZEOF (TYPE , EXPECTED ) \
107
- if (EXPECTED != sizeof(TYPE)) { \
108
- PyErr_Format(get_testerror(self), \
109
- "sizeof(%s) = %u instead of %u", \
110
- #TYPE, sizeof(TYPE), EXPECTED); \
111
- return (PyObject*)NULL; \
112
- }
109
+ #define CHECK_SIZEOF (TYPE , EXPECTED ) \
110
+ do { \
111
+ if (EXPECTED != sizeof(TYPE)) { \
112
+ PyErr_Format(get_testerror(self), \
113
+ "sizeof(%s) = %u instead of %u", \
114
+ #TYPE, sizeof(TYPE), EXPECTED); \
115
+ return (PyObject*)NULL; \
116
+ } \
117
+ } while (0)
113
118
#define IS_SIGNED (TYPE ) (((TYPE)-1) < (TYPE)0)
114
- #define CHECK_SIGNNESS (TYPE , SIGNED ) \
115
- if (IS_SIGNED(TYPE) != SIGNED) { \
116
- PyErr_Format(get_testerror(self), \
117
- "%s signness is %i, instead of %i", \
118
- #TYPE, IS_SIGNED(TYPE), SIGNED); \
119
- return (PyObject*)NULL; \
120
- }
119
+ #define CHECK_SIGNNESS (TYPE , SIGNED ) \
120
+ do { \
121
+ if (IS_SIGNED(TYPE) != SIGNED) { \
122
+ PyErr_Format(get_testerror(self), \
123
+ "%s signness is %i, instead of %i", \
124
+ #TYPE, IS_SIGNED(TYPE), SIGNED); \
125
+ return (PyObject*)NULL; \
126
+ } \
127
+ } while (0)
121
128
122
129
/* integer types */
123
130
CHECK_SIZEOF (Py_UCS1 , 1 );
@@ -884,27 +891,34 @@ test_string_to_double(PyObject *self, PyObject *Py_UNUSED(ignored)) {
884
891
double result ;
885
892
const char * msg ;
886
893
887
- #define CHECK_STRING (STR , expected ) \
888
- result = PyOS_string_to_double(STR, NULL, NULL); \
889
- if (result == -1.0 && PyErr_Occurred()) \
890
- return NULL; \
891
- if (result != (double)expected) { \
892
- msg = "conversion of " STR " to float failed"; \
893
- goto fail; \
894
- }
894
+ #define CHECK_STRING (STR , expected ) \
895
+ do { \
896
+ result = PyOS_string_to_double(STR, NULL, NULL); \
897
+ if (result == -1.0 && PyErr_Occurred()) { \
898
+ return NULL; \
899
+ } \
900
+ if (result != (double)expected) { \
901
+ msg = "conversion of " STR " to float failed"; \
902
+ goto fail; \
903
+ } \
904
+ } while (0)
895
905
896
- #define CHECK_INVALID (STR ) \
897
- result = PyOS_string_to_double(STR, NULL, NULL); \
898
- if (result == -1.0 && PyErr_Occurred()) { \
899
- if (PyErr_ExceptionMatches(PyExc_ValueError)) \
900
- PyErr_Clear(); \
901
- else \
902
- return NULL; \
903
- } \
904
- else { \
905
- msg = "conversion of " STR " didn't raise ValueError"; \
906
- goto fail; \
907
- }
906
+ #define CHECK_INVALID (STR ) \
907
+ do { \
908
+ result = PyOS_string_to_double(STR, NULL, NULL); \
909
+ if (result == -1.0 && PyErr_Occurred()) { \
910
+ if (PyErr_ExceptionMatches(PyExc_ValueError)) { \
911
+ PyErr_Clear(); \
912
+ } \
913
+ else { \
914
+ return NULL; \
915
+ } \
916
+ } \
917
+ else { \
918
+ msg = "conversion of " STR " didn't raise ValueError"; \
919
+ goto fail; \
920
+ } \
921
+ } while (0)
908
922
909
923
CHECK_STRING ("0.1" , 0.1 );
910
924
CHECK_STRING ("1.234" , 1.234 );
@@ -971,16 +985,22 @@ test_capsule(PyObject *self, PyObject *Py_UNUSED(ignored))
971
985
};
972
986
known_capsule * known = & known_capsules [0 ];
973
987
974
- #define FAIL (x ) { error = (x); goto exit; }
988
+ #define FAIL (x ) \
989
+ do { \
990
+ error = (x); \
991
+ goto exit; \
992
+ } while (0)
975
993
976
994
#define CHECK_DESTRUCTOR \
977
- if (capsule_error) { \
978
- FAIL(capsule_error); \
979
- } \
980
- else if (!capsule_destructor_call_count) { \
981
- FAIL("destructor not called!"); \
982
- } \
983
- capsule_destructor_call_count = 0; \
995
+ do { \
996
+ if (capsule_error) { \
997
+ FAIL(capsule_error); \
998
+ } \
999
+ else if (!capsule_destructor_call_count) { \
1000
+ FAIL("destructor not called!"); \
1001
+ } \
1002
+ capsule_destructor_call_count = 0; \
1003
+ } while (0)
984
1004
985
1005
object = PyCapsule_New (capsule_pointer , capsule_name , capsule_destructor );
986
1006
PyCapsule_SetContext (object , capsule_context );
@@ -1024,12 +1044,12 @@ test_capsule(PyObject *self, PyObject *Py_UNUSED(ignored))
1024
1044
static char buffer [256 ];
1025
1045
#undef FAIL
1026
1046
#define FAIL (x ) \
1027
- { \
1028
- sprintf(buffer, "%s module: \"%s\" attribute: \"%s\"", \
1029
- x, known->module, known->attribute); \
1030
- error = buffer; \
1031
- goto exit; \
1032
- } \
1047
+ do { \
1048
+ sprintf(buffer, "%s module: \"%s\" attribute: \"%s\"", \
1049
+ x, known->module, known->attribute); \
1050
+ error = buffer; \
1051
+ goto exit; \
1052
+ } while (0)
1033
1053
1034
1054
PyObject * module = PyImport_ImportModule (known -> module );
1035
1055
if (module ) {
@@ -1978,11 +1998,15 @@ test_pythread_tss_key_state(PyObject *self, PyObject *args)
1978
1998
"an already initialized key" );
1979
1999
}
1980
2000
#define CHECK_TSS_API (expr ) \
2001
+ do { \
1981
2002
(void)(expr); \
1982
2003
if (!PyThread_tss_is_created(&tss_key)) { \
1983
2004
return raiseTestError(self, "test_pythread_tss_key_state", \
1984
2005
"TSS key initialization state was not " \
1985
- "preserved after calling " #expr); }
2006
+ "preserved after calling " #expr); \
2007
+ } \
2008
+ } while (0)
2009
+
1986
2010
CHECK_TSS_API (PyThread_tss_set (& tss_key , NULL ));
1987
2011
CHECK_TSS_API (PyThread_tss_get (& tss_key ));
1988
2012
#undef CHECK_TSS_API
@@ -2304,7 +2328,7 @@ test_py_setref(PyObject *self, PyObject *Py_UNUSED(ignored))
2304
2328
\
2305
2329
Py_DECREF (obj ); \
2306
2330
Py_RETURN_NONE ; \
2307
- } while (0 ) \
2331
+ } while (0 )
2308
2332
2309
2333
2310
2334
// Test Py_NewRef() and Py_XNewRef() macros
0 commit comments