Skip to content

Commit 646b528

Browse files
committed
Issue #22463: Backport compiler warning fixes and workarounds
* Set but unused variable in Parser/pgen.c in non-debug builds. Patch by Christian Heimes. * Unused static function in Modules/readline.c. Patch by Georg Brandl. * main_window unused in Modules/tkappinit.c. Patch by Gregory P. Smith. * Dead assignment in Modules/_ctypes/cfield.c. Extracted from patch by Brett Cannon. * Expression result unused in PyObject_INIT macro expansions. Based on patches by Christian Heimes. * Load expat_config.h and therefore pyconfig.h before C stdlib headers are loaded. This silences pre-processor warnings including '_POSIX_C_SOURCE redefined'. Extracted from patch by Christian Heimes.
1 parent 4e6e565 commit 646b528

14 files changed

Lines changed: 32 additions & 23 deletions

File tree

Modules/_ctypes/cfield.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index,
4848
{
4949
CFieldObject *self;
5050
PyObject *proto;
51-
Py_ssize_t size, align, length;
51+
Py_ssize_t size, align;
5252
SETFUNC setfunc = NULL;
5353
GETFUNC getfunc = NULL;
5454
StgDictObject *dict;
@@ -102,7 +102,6 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index,
102102
}
103103

104104
size = dict->size;
105-
length = dict->length;
106105
proto = desc;
107106

108107
/* Field descriptors for 'c_char * n' are be scpecial cased to

Modules/datetimemodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ time_alloc(PyTypeObject *type, Py_ssize_t aware)
613613
sizeof(_PyDateTime_BaseTime));
614614
if (self == NULL)
615615
return (PyObject *)PyErr_NoMemory();
616-
PyObject_INIT(self, type);
616+
(void)PyObject_INIT(self, type);
617617
return self;
618618
}
619619

@@ -628,7 +628,7 @@ datetime_alloc(PyTypeObject *type, Py_ssize_t aware)
628628
sizeof(_PyDateTime_BaseDateTime));
629629
if (self == NULL)
630630
return (PyObject *)PyErr_NoMemory();
631-
PyObject_INIT(self, type);
631+
(void)PyObject_INIT(self, type);
632632
return self;
633633
}
634634

Modules/expat/xmlparse.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
See the file COPYING for copying permission.
33
*/
44

5-
#include <stddef.h>
6-
#include <string.h> /* memset(), memcpy() */
7-
#include <assert.h>
8-
#include <limits.h> /* UINT_MAX */
9-
#include <time.h> /* time() */
10-
115
#define XML_BUILDING_EXPAT 1
126

137
#ifdef COMPILED_FROM_DSP
@@ -22,6 +16,12 @@
2216
#include <expat_config.h>
2317
#endif /* ndef COMPILED_FROM_DSP */
2418

19+
#include <stddef.h>
20+
#include <string.h> /* memset(), memcpy() */
21+
#include <assert.h>
22+
#include <limits.h> /* UINT_MAX */
23+
#include <time.h> /* time() */
24+
2525
#include "ascii.h"
2626
#include "expat.h"
2727

Modules/readline.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ static const char libedit_version_tag[] = "EditLine wrapper";
6666
static int libedit_history_start = 0;
6767
#endif /* __APPLE__ */
6868

69+
#ifdef HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK
6970
static void
7071
on_completion_display_matches_hook(char **matches,
7172
int num_matches, int max_length);
72-
73+
#endif
7374

7475
/* Memory allocated for rl_completer_word_break_characters
7576
(see issue #17289 for the motivation). */
@@ -774,6 +775,7 @@ on_pre_input_hook()
774775

775776
/* C function to call the Python completion_display_matches */
776777

778+
#ifdef HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK
777779
static void
778780
on_completion_display_matches_hook(char **matches,
779781
int num_matches, int max_length)
@@ -874,6 +876,7 @@ on_completion(const char *text, int state)
874876
}
875877
return result;
876878
}
879+
#endif
877880

878881

879882
/* A more flexible constructor that saves the "begidx" and "endidx"

Modules/tkappinit.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ static int tk_load_failed;
2626
int
2727
Tcl_AppInit(Tcl_Interp *interp)
2828
{
29+
#ifdef WITH_MOREBUTTONS
2930
Tk_Window main_window;
31+
#endif
3032
const char *_tkinter_skip_tk_init;
3133
#ifdef TKINTER_PROTECT_LOADTK
3234
const char *_tkinter_tk_failed;
@@ -111,7 +113,11 @@ Tcl_AppInit(Tcl_Interp *interp)
111113
return TCL_ERROR;
112114
}
113115

116+
#ifdef WITH_MOREBUTTONS
114117
main_window = Tk_MainWindow(interp);
118+
#else
119+
Tk_MainWindow(interp);
120+
#endif
115121

116122
#ifdef TK_AQUA
117123
TkMacOSXInitAppleEvents(interp);

Objects/classobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,7 @@ PyMethod_New(PyObject *func, PyObject *self, PyObject *klass)
22562256
im = free_list;
22572257
if (im != NULL) {
22582258
free_list = (PyMethodObject *)(im->im_self);
2259-
PyObject_INIT(im, &PyMethod_Type);
2259+
(void)PyObject_INIT(im, &PyMethod_Type);
22602260
numfree--;
22612261
}
22622262
else {

Objects/complexobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ PyComplex_FromCComplex(Py_complex cval)
239239
op = (PyComplexObject *) PyObject_MALLOC(sizeof(PyComplexObject));
240240
if (op == NULL)
241241
return PyErr_NoMemory();
242-
PyObject_INIT(op, &PyComplex_Type);
242+
(void)PyObject_INIT(op, &PyComplex_Type);
243243
op->cval = cval;
244244
return (PyObject *) op;
245245
}

Objects/floatobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ PyFloat_FromDouble(double fval)
149149
/* Inline PyObject_New */
150150
op = free_list;
151151
free_list = (PyFloatObject *)Py_TYPE(op);
152-
PyObject_INIT(op, &PyFloat_Type);
152+
(void)PyObject_INIT(op, &PyFloat_Type);
153153
op->ob_fval = fval;
154154
return (PyObject *) op;
155155
}

Objects/intobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ PyInt_FromLong(long ival)
107107
/* Inline PyObject_New */
108108
v = free_list;
109109
free_list = (PyIntObject *)Py_TYPE(v);
110-
PyObject_INIT(v, &PyInt_Type);
110+
(void)PyObject_INIT(v, &PyInt_Type);
111111
v->ob_ival = ival;
112112
return (PyObject *) v;
113113
}
@@ -1466,7 +1466,7 @@ _PyInt_Init(void)
14661466
/* PyObject_New is inlined */
14671467
v = free_list;
14681468
free_list = (PyIntObject *)Py_TYPE(v);
1469-
PyObject_INIT(v, &PyInt_Type);
1469+
(void)PyObject_INIT(v, &PyInt_Type);
14701470
v->ob_ival = ival;
14711471
small_ints[ival + NSMALLNEGINTS] = v;
14721472
}

Objects/methodobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)
2020
op = free_list;
2121
if (op != NULL) {
2222
free_list = (PyCFunctionObject *)(op->m_self);
23-
PyObject_INIT(op, &PyCFunction_Type);
23+
(void)PyObject_INIT(op, &PyCFunction_Type);
2424
numfree--;
2525
}
2626
else {

0 commit comments

Comments
 (0)