From c44f1e3cc4328563952749af6b061914b39257d3 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 11 Jun 2025 11:56:07 -0400 Subject: [PATCH] fix: Define PY3_DLLNAME as wide string to fix C4133 warnings Fixes warnings when passing narrow string literals to Windows APIs expecting wide strings: ``` C:\path\to\Python-3.12.10\Python\dynload_win.c(191,27): warning C4133: 'function': incompatible types - from 'char [8] ' to 'const wchar_t *' [C:\path\to\pycbs-3.12-build\CMakeBuild\libpython\libpython-shared.vcxproj] ``` Ensures PY3_DLLNAME is consistently defined with the wide string modifier (`L`) across relevant CMake sections. --- cmake/extensions/CMakeLists.txt | 3 ++- cmake/libpython/CMakeLists.txt | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cmake/extensions/CMakeLists.txt b/cmake/extensions/CMakeLists.txt index 24a293c4..0aa7b726 100644 --- a/cmake/extensions/CMakeLists.txt +++ b/cmake/extensions/CMakeLists.txt @@ -374,13 +374,14 @@ add_python_extension(_xxtestfuzz ) # Python 3.8 +set(_wide_char_modifier "L") add_python_extension(_testinternalcapi REQUIRES IS_PY3_8_OR_GREATER SOURCES _testinternalcapi.c DEFINITIONS - "PY3_DLLNAME=\"python3$<$:_d>\"" + "PY3_DLLNAME=${_wide_char_modifier}\"python3$<$:_d>\"" ) # Python 3.9 diff --git a/cmake/libpython/CMakeLists.txt b/cmake/libpython/CMakeLists.txt index 97a73b6c..c344b674 100644 --- a/cmake/libpython/CMakeLists.txt +++ b/cmake/libpython/CMakeLists.txt @@ -66,15 +66,14 @@ if(WIN32 AND PY_VERSION VERSION_LESS "3.11") set(PYTHONPATH "${PYTHONPATH}${PATHSEP}.\\\\${PYTHONHOME_ESCAPED}\\\\lib-tk") endif() - set(_wide_char_modifier) - set(_wide_char_modifier "L") + set(_wide_char_modifier "L") set_property( SOURCE ${SRC_DIR}/PC/getpathp.c PROPERTY COMPILE_DEFINITIONS "LANDMARK=${_wide_char_modifier}\"${PYTHONHOME_ESCAPED}\\\\os.py\"" "PYTHONPATH=${_wide_char_modifier}\"${PYTHONPATH}\"" - "PY3_DLLNAME=\"python3$<$:_d>\"" + "PY3_DLLNAME=${_wide_char_modifier}\"python3$<$:_d>\"" ) endif() @@ -217,10 +216,11 @@ elseif(WIN32) Py_ENABLE_SHARED MS_DLL_ID="${ms_dll_id}" ) + set(_wide_char_modifier "L") set_property( SOURCE ${SRC_DIR}/Python/dynload_win.c PROPERTY COMPILE_DEFINITIONS - "PY3_DLLNAME=\"python3$<$:_d>\"" # Python 3.11 + "PY3_DLLNAME=${_wide_char_modifier}\"python3$<$:_d>\"" # Python 3.11 ) endif() @@ -341,10 +341,11 @@ endif() # Introduced in Python 3.10 and removed in Python 3.11 if(WIN32 AND "${PY_VERSION_MAJOR}.${PY_VERSION_MINOR}" VERSION_EQUAL "3.10") + set(_wide_char_modifier "L") set_property( SOURCE ${SRC_DIR}/Python/pathconfig.c PROPERTY COMPILE_DEFINITIONS - "PY3_DLLNAME=\"python3$<$:_d>\"" + "PY3_DLLNAME=${_wide_char_modifier}\"python3$<$:_d>\"" ) endif()