Skip to content

Commit

Permalink
Treat warnings as errors on MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Oct 15, 2024
1 parent 6d8c17a commit 43be1c2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 30 deletions.
4 changes: 2 additions & 2 deletions pythoncapi_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,7 @@ static inline int PyUnicode_Equal(PyObject *str1, PyObject *str2)
}

#if PY_VERSION_HEX >= 0x030d0000 && !defined(PYPY_VERSION)
PyAPI_FUNC(int) _PyUnicode_Equal(PyObject *str1, PyObject *str2);
extern int _PyUnicode_Equal(PyObject *str1, PyObject *str2);

return _PyUnicode_Equal(str1, str2);
#elif PY_VERSION_HEX >= 0x03060000 && !defined(PYPY_VERSION)
Expand All @@ -1564,7 +1564,7 @@ static inline PyObject* PyBytes_Join(PyObject *sep, PyObject *iterable)
static inline Py_hash_t Py_HashBuffer(const void *ptr, Py_ssize_t len)
{
#if PY_VERSION_HEX >= 0x03000000 && !defined(PYPY_VERSION)
PyAPI_FUNC(Py_hash_t) _Py_HashBytes(const void *src, Py_ssize_t len);
extern Py_hash_t _Py_HashBytes(const void *src, Py_ssize_t len);

return _Py_HashBytes(ptr, len);
#else
Expand Down
67 changes: 39 additions & 28 deletions tests/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,43 @@
# Windows uses MSVC compiler
MSVC = (os.name == "nt")

# C compiler flags for GCC and clang
COMMON_FLAGS = [
# Treat warnings as error
'-Werror',
# Enable all warnings
'-Wall', '-Wextra',
# Extra warnings
'-Wconversion',
# /usr/lib64/pypy3.7/include/pyport.h:68:20: error: redefinition of typedef
# 'Py_hash_t' is a C11 feature
"-Wno-typedef-redefinition",
]
CFLAGS = COMMON_FLAGS + [
# Use C99 for pythoncapi_compat.c which initializes PyModuleDef with a
# mixture of designated and non-designated initializers
'-std=c99',
]
CPPFLAGS = list(COMMON_FLAGS)
# FIXME: _Py_CAST() emits C++ compilers on Python 3.12.
# See: https://github.com/python/cpython/issues/94731
if 0:
CPPFLAGS.extend((
'-Wold-style-cast',
'-Wzero-as-null-pointer-constant',
))
if not MSVC:
# C compiler flags for GCC and clang
COMMON_FLAGS = [
# Treat warnings as error
'-Werror',
# Enable all warnings
'-Wall', '-Wextra',
# Extra warnings
'-Wconversion',
# /usr/lib64/pypy3.7/include/pyport.h:68:20: error: redefinition of typedef
# 'Py_hash_t' is a C11 feature
"-Wno-typedef-redefinition",
]
CFLAGS = COMMON_FLAGS + [
# Use C99 for pythoncapi_compat.c which initializes PyModuleDef with a
# mixture of designated and non-designated initializers
'-std=c99',
]
CXXFLAGS = list(COMMON_FLAGS)
# FIXME: _Py_CAST() emits C++ compilers on Python 3.12.
# See: https://github.com/python/cpython/issues/94731
if 0:
CXXFLAGS.extend((
'-Wold-style-cast',
'-Wzero-as-null-pointer-constant',
))
else:
COMMON_FLAGS = [
# Display warnings level 1 to 4
'/W4',
# Treat all compiler warnings as compiler errors
'/WX',
]
CFLAGS = COMMON_FLAGS + [
'/std:c99'
]
CXXFLAGS = list(COMMON_FLAGS)


def main():
Expand All @@ -68,9 +80,8 @@ def main():

cflags = ['-I' + SRC_DIR]
cppflags = list(cflags)
if not MSVC:
cflags.extend(CFLAGS)
cppflags.extend(CPPFLAGS)
cflags.extend(CFLAGS)
cppflags.extend(CXXFLAGS)

# C extension
c_ext = Extension(
Expand Down

0 comments on commit 43be1c2

Please sign in to comment.