diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b749c60..bdd3672 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,7 +53,7 @@ jobs: - os: windows-latest python: 3.6 - os: windows-latest - python: 3.12 + python: 3.13 # macOS: test only new Python - os: macos-latest diff --git a/pythoncapi_compat.h b/pythoncapi_compat.h index acaadf3..34a84c9 100644 --- a/pythoncapi_compat.h +++ b/pythoncapi_compat.h @@ -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) @@ -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 diff --git a/tests/setup.py b/tests/setup.py index 2e10c15..98f7798 100755 --- a/tests/setup.py +++ b/tests/setup.py @@ -13,38 +13,53 @@ # C++ is only supported on Python 3.6 and newer -TEST_CPP = (sys.version_info >= (3, 6)) +TEST_CXX = (sys.version_info >= (3, 6)) SRC_DIR = os.path.normpath(os.path.join(os.path.dirname(__file__), '..')) # 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 = [ + # Treat all compiler warnings as compiler errors + '/WX', + ] + if sys.version_info >= (3, 13): + COMMON_FLAGS.append( + # Display warnings level 1 to 4 + '/W4' + ) + CFLAGS = COMMON_FLAGS + [ + '/std:c99' + ] + CXXFLAGS = list(COMMON_FLAGS) def main(): @@ -68,9 +83,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( @@ -79,7 +93,7 @@ def main(): extra_compile_args=cflags) extensions = [c_ext] - if TEST_CPP: + if TEST_CXX: # C++ extension # MSVC has /std flag but doesn't support /std:c++11 @@ -89,7 +103,10 @@ def main(): ('test_pythoncapi_compat_cpp11ext', '-std=c++11'), ] else: - versions = [('test_pythoncapi_compat_cppext', None)] + versions = [ + ('test_pythoncapi_compat_cpp03ext', '/std:c++03'), + ('test_pythoncapi_compat_cpp11ext', '/std:c++11'), + ] for name, flag in versions: flags = list(cppflags) if flag is not None: