Skip to content

Commit 021169f

Browse files
Fix compiler warning for misleading guarding in the tkinter (GH-26244) (GH-26252)
The newest gcc emmits this warning: ``` /Modules/_tkinter.c:272:9: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation] 272 | if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate; } | ^~ /Modules/_tkinter.c:2869:5: note: in expansion of macro ‘LEAVE_PYTHON’ 2869 | LEAVE_PYTHON | ^~~~~~~~~~~~ /Modules/_tkinter.c:243:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’ 243 | (*(PyThreadState**)Tcl_GetThreadData(&state_key, sizeof(PyThreadState*))) | ^ /Modules/_tkinter.c:272:57: note: in expansion of macro ‘tcl_tstate’ 272 | if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate; } | ^~~~~~~~~~ /Modules/_tkinter.c:2869:5: note: in expansion of macro ‘LEAVE_PYTHON’ 2869 | LEAVE_PYTHON ``` that's because the macro packs together two statements at the same level as the "if". The warning is misleading but is very noisy so it makes sense to fix it. (cherry picked from commit 95d0471) Co-authored-by: Pablo Galindo <[email protected]> Co-authored-by: Pablo Galindo <[email protected]>
1 parent d4a9264 commit 021169f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Modules/_tkinter.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,15 @@ static PyThreadState *tcl_tstate = NULL;
246246
#endif
247247

248248
#define ENTER_TCL \
249-
{ PyThreadState *tstate = PyThreadState_Get(); Py_BEGIN_ALLOW_THREADS \
250-
if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate;
249+
{ PyThreadState *tstate = PyThreadState_Get(); \
250+
Py_BEGIN_ALLOW_THREADS \
251+
if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); \
252+
tcl_tstate = tstate;
251253

252254
#define LEAVE_TCL \
253255
tcl_tstate = NULL; \
254-
if(tcl_lock)PyThread_release_lock(tcl_lock); Py_END_ALLOW_THREADS}
256+
if(tcl_lock)PyThread_release_lock(tcl_lock); \
257+
Py_END_ALLOW_THREADS}
255258

256259
#define ENTER_OVERLAP \
257260
Py_END_ALLOW_THREADS
@@ -261,12 +264,14 @@ static PyThreadState *tcl_tstate = NULL;
261264

262265
#define ENTER_PYTHON \
263266
{ PyThreadState *tstate = tcl_tstate; tcl_tstate = NULL; \
264-
if(tcl_lock) \
265-
PyThread_release_lock(tcl_lock); PyEval_RestoreThread((tstate)); }
267+
if(tcl_lock) \
268+
PyThread_release_lock(tcl_lock); \
269+
PyEval_RestoreThread((tstate)); }
266270

267271
#define LEAVE_PYTHON \
268272
{ PyThreadState *tstate = PyEval_SaveThread(); \
269-
if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate; }
273+
if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); \
274+
tcl_tstate = tstate; }
270275

271276
#define CHECK_TCL_APPARTMENT \
272277
if (((TkappObject *)self)->threaded && \

0 commit comments

Comments
 (0)