Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba7469b

Browse files
committed
Build the C extension with -Wall -Wextra -Werror
1 parent 8ae53ae commit ba7469b

2 files changed

Lines changed: 30 additions & 18 deletions

File tree

tests/setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#!/usr/bin/env python3
22

3+
CFLAGS = ['-Wall', '-Wextra', '-Werror']
4+
35
def main():
46
from distutils.core import setup, Extension
57

68
ext = Extension('test_pythoncapi_compat_cext',
7-
sources=['test_pythoncapi_compat_cext.c'])
9+
sources=['test_pythoncapi_compat_cext.c'],
10+
extra_compile_args=CFLAGS)
811

912
setup(name="test_pythoncapi_compat", ext_modules=[ext])
1013

tests/test_pythoncapi_compat_cext.c

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
# define PYTHON3 1
88
#endif
99

10+
#ifndef Py_UNUSED
11+
// Backport the macro for Python 3.5 and older
12+
# if defined(__GNUC__) || defined(__clang__)
13+
# define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
14+
# else
15+
# define Py_UNUSED(name) _unused_ ## name
16+
# endif
17+
#endif
18+
1019
static PyObject*
1120
ASSERT_FAILED(const char *err_msg)
1221
{
@@ -15,7 +24,7 @@ ASSERT_FAILED(const char *err_msg)
1524
}
1625

1726
static PyObject *
18-
test_object(PyObject *self, PyObject *ignored)
27+
test_object(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
1928
{
2029
PyObject *obj = PyList_New(0);
2130
if (obj == NULL) {
@@ -54,7 +63,7 @@ test_object(PyObject *self, PyObject *ignored)
5463

5564

5665
static PyObject *
57-
test_steal_ref(PyObject *self, PyObject *ignored)
66+
test_steal_ref(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
5867
{
5968
PyObject *obj = PyList_New(0);
6069
if (obj == NULL) {
@@ -83,7 +92,7 @@ test_steal_ref(PyObject *self, PyObject *ignored)
8392

8493

8594
static PyObject *
86-
test_frame(PyObject *self, PyObject *ignored)
95+
test_frame(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
8796
{
8897
PyThreadState *tstate = PyThreadState_Get();
8998

@@ -136,7 +145,7 @@ test_frame(PyObject *self, PyObject *ignored)
136145

137146

138147
static PyObject *
139-
test_thread_state(PyObject *self, PyObject *ignored)
148+
test_thread_state(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
140149
{
141150
PyThreadState *tstate = PyThreadState_Get();
142151

@@ -161,7 +170,7 @@ test_thread_state(PyObject *self, PyObject *ignored)
161170

162171

163172
static PyObject *
164-
test_interpreter(PyObject *self, PyObject *ignored)
173+
test_interpreter(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
165174
{
166175
// test PyInterpreterState_Get()
167176
PyInterpreterState *interp = PyInterpreterState_Get();
@@ -175,7 +184,7 @@ test_interpreter(PyObject *self, PyObject *ignored)
175184

176185

177186
static PyObject *
178-
test_calls(PyObject *self, PyObject *ignored)
187+
test_calls(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
179188
{
180189
PyObject *func = (PyObject *)&PyUnicode_Type;
181190

@@ -205,7 +214,7 @@ test_calls(PyObject *self, PyObject *ignored)
205214

206215

207216
static PyObject *
208-
test_gc(PyObject *self, PyObject *ignored)
217+
test_gc(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
209218
{
210219
PyObject *tuple = PyTuple_New(1);
211220
Py_INCREF(Py_None);
@@ -287,7 +296,7 @@ test_module_addobjectref(PyObject *module)
287296

288297

289298
static PyObject *
290-
test_module(PyObject *self, PyObject *ignored)
299+
test_module(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
291300
{
292301
PyObject *module = PyImport_ImportModule("sys");
293302
if (module == NULL) {
@@ -313,15 +322,15 @@ test_module(PyObject *self, PyObject *ignored)
313322

314323

315324
static struct PyMethodDef methods[] = {
316-
{"test_object", test_object, METH_NOARGS},
317-
{"test_steal_ref", test_steal_ref, METH_NOARGS},
318-
{"test_frame", test_frame, METH_NOARGS},
319-
{"test_thread_state", test_thread_state, METH_NOARGS},
320-
{"test_interpreter", test_interpreter, METH_NOARGS},
321-
{"test_calls", test_calls, METH_NOARGS},
322-
{"test_gc", test_gc, METH_NOARGS},
323-
{"test_module", test_module, METH_NOARGS},
324-
{NULL, NULL}
325+
{"test_object", test_object, METH_NOARGS, NULL},
326+
{"test_steal_ref", test_steal_ref, METH_NOARGS, NULL},
327+
{"test_frame", test_frame, METH_NOARGS, NULL},
328+
{"test_thread_state", test_thread_state, METH_NOARGS, NULL},
329+
{"test_interpreter", test_interpreter, METH_NOARGS, NULL},
330+
{"test_calls", test_calls, METH_NOARGS, NULL},
331+
{"test_gc", test_gc, METH_NOARGS, NULL},
332+
{"test_module", test_module, METH_NOARGS, NULL},
333+
{NULL, NULL, 0, NULL}
325334
};
326335

327336

0 commit comments

Comments
 (0)