Skip to content

Commit f6121eb

Browse files
authored
Build C and C++ extensions with /W4 on Windows (#168)
Build C and C++ extensions with /W4 on Windows on Python 3.12 and newer. Move PyAPI_FUNC() definitions to the file level. Remove also -Wno-typedef-redefinition flag.
1 parent 6290c7b commit f6121eb

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

pythoncapi_compat.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,11 @@ static inline int PyLong_IsZero(PyObject *obj)
15691569

15701570
// gh-124502 added PyUnicode_Equal() to Python 3.14.0a0
15711571
#if PY_VERSION_HEX < 0x030E00A0
1572+
1573+
#if PY_VERSION_HEX >= 0x030d0000 && !defined(PYPY_VERSION)
1574+
PyAPI_FUNC(int) _PyUnicode_Equal(PyObject *str1, PyObject *str2);
1575+
#endif
1576+
15721577
static inline int PyUnicode_Equal(PyObject *str1, PyObject *str2)
15731578
{
15741579
if (!PyUnicode_Check(str1)) {
@@ -1583,8 +1588,6 @@ static inline int PyUnicode_Equal(PyObject *str1, PyObject *str2)
15831588
}
15841589

15851590
#if PY_VERSION_HEX >= 0x030d0000 && !defined(PYPY_VERSION)
1586-
PyAPI_FUNC(int) _PyUnicode_Equal(PyObject *str1, PyObject *str2);
1587-
15881591
return _PyUnicode_Equal(str1, str2);
15891592
#elif PY_VERSION_HEX >= 0x03060000 && !defined(PYPY_VERSION)
15901593
return _PyUnicode_EQ(str1, str2);
@@ -1607,11 +1610,14 @@ static inline PyObject* PyBytes_Join(PyObject *sep, PyObject *iterable)
16071610

16081611

16091612
#if PY_VERSION_HEX < 0x030E00A0
1613+
1614+
#if PY_VERSION_HEX >= 0x03000000 && !defined(PYPY_VERSION)
1615+
PyAPI_FUNC(Py_hash_t) _Py_HashBytes(const void *src, Py_ssize_t len);
1616+
#endif
1617+
16101618
static inline Py_hash_t Py_HashBuffer(const void *ptr, Py_ssize_t len)
16111619
{
16121620
#if PY_VERSION_HEX >= 0x03000000 && !defined(PYPY_VERSION)
1613-
PyAPI_FUNC(Py_hash_t) _Py_HashBytes(const void *src, Py_ssize_t len);
1614-
16151621
return _Py_HashBytes(ptr, len);
16161622
#else
16171623
Py_hash_t hash;
@@ -1948,11 +1954,14 @@ PyLongWriter_Finish(PyLongWriter *writer)
19481954

19491955
// gh-127350 added Py_fopen() and Py_fclose() to Python 3.14a4
19501956
#if PY_VERSION_HEX < 0x030E00A4
1957+
1958+
#if 0x030400A2 <= PY_VERSION_HEX && !defined(PYPY_VERSION)
1959+
PyAPI_FUNC(FILE*) _Py_fopen_obj(PyObject *path, const char *mode);
1960+
#endif
1961+
19511962
static inline FILE* Py_fopen(PyObject *path, const char *mode)
19521963
{
19531964
#if 0x030400A2 <= PY_VERSION_HEX && !defined(PYPY_VERSION)
1954-
PyAPI_FUNC(FILE*) _Py_fopen_obj(PyObject *path, const char *mode);
1955-
19561965
return _Py_fopen_obj(path, mode);
19571966
#else
19581967
FILE *f;
@@ -2664,6 +2673,10 @@ PyUnstable_Unicode_GET_CACHED_HASH(PyObject *op)
26642673
// to make objects immortal until 3.14 which has _Py_SetImmortal(). Since
26652674
// immortal objects are primarily needed for free-threading, this API is implemented
26662675
// for 3.14 using _Py_SetImmortal() and uses private macros on 3.13.
2676+
#if 0x030E0000 <= PY_VERSION_HEX
2677+
PyAPI_FUNC(void) _Py_SetImmortal(PyObject *op);
2678+
#endif
2679+
26672680
static inline int
26682681
PyUnstable_SetImmortal(PyObject *op)
26692682
{
@@ -2672,7 +2685,6 @@ PyUnstable_SetImmortal(PyObject *op)
26722685
return 0;
26732686
}
26742687
#if 0x030E0000 <= PY_VERSION_HEX
2675-
PyAPI_FUNC(void) _Py_SetImmortal(PyObject *op);
26762688
_Py_SetImmortal(op);
26772689
#else
26782690
// Python 3.13 doesn't export _Py_SetImmortal() function

tests/setup.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
'-Wall', '-Wextra',
3333
# Extra warnings
3434
'-Wconversion',
35-
# /usr/lib64/pypy3.7/include/pyport.h:68:20: error: redefinition of typedef
36-
# 'Py_hash_t' is a C11 feature
37-
'-Wno-typedef-redefinition',
3835
# Formatting checks
3936
'-Wformat',
4037
'-Wformat-nonliteral',
@@ -47,6 +44,14 @@
4744
# Treat all compiler warnings as compiler errors
4845
'/WX',
4946
))
47+
# Python 3.11 and older emits C4100 "unreferenced parameter" warnings
48+
# on Py_UNUSED() parameters. Py_UNUSED() was modified in Python 3.12
49+
# to support MSVC.
50+
if sys.version_info >= (3, 12):
51+
COMMON_FLAGS.extend((
52+
# Display warnings level 1 to 4
53+
'/W4',
54+
))
5055
CFLAGS = list(COMMON_FLAGS)
5156
CXXFLAGS = list(COMMON_FLAGS)
5257

0 commit comments

Comments
 (0)