Skip to content

Adding patches to fix build error in Windows + Python 3.9 (fixes #155) #319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions cmake/ConfigureChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2768,16 +2768,17 @@ endif()
##########################################################

if(ZLIB_LIBRARIES)
cmake_push_check_state()
set(CFG_HEADERS_SAVE ${CFG_HEADERS})
#cmake_push_check_state()
#set(CFG_HEADERS_SAVE ${CFG_HEADERS})

set(CFG_HEADERS ${CFG_HEADERS} zlib.h)
add_cond(CMAKE_REQUIRED_INCLUDES ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS})
add_cond(CMAKE_REQUIRED_LIBRARIES ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
check_symbol_exists(inflateCopy "${CFG_HEADERS}" HAVE_ZLIB_COPY)
#set(CFG_HEADERS ${CFG_HEADERS} zlib.h)
#add_cond(CMAKE_REQUIRED_INCLUDES ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS})
#add_cond(CMAKE_REQUIRED_LIBRARIES ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
#check_symbol_exists(inflateCopy "${CFG_HEADERS}" HAVE_ZLIB_COPY)
set(HAVE_ZLIB_COPY ON CACHE BOOL "Assume Zlib have inflateCopy since checking inflateCopy would result in error during CMake configure" FORCE)

set(CFG_HEADERS ${CFG_HEADERS_SAVE})
cmake_pop_check_state()
#set(CFG_HEADERS ${CFG_HEADERS_SAVE})
#cmake_pop_check_state()
endif()

# Check if tirpc static library and its dependencies can be linked statically
Expand Down
2 changes: 2 additions & 0 deletions cmake/Extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ function(add_python_extension name)
# libraries that we might want to link against (eg. readline)
set(target_name extension_${pretty_name})

set_property(GLOBAL APPEND PROPERTY FUCKING_PYTHON_EXTENSION_TARGETS ${target_name})

set(enable_default ON)
if(ADD_PYTHON_EXTENSION_NEVER_BUILTIN AND WITH_STATIC_DEPENDENCIES)
set(enable_default OFF)
Expand Down
16 changes: 7 additions & 9 deletions cmake/libpython/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,6 @@ if(UNIX)
list(APPEND PYTHON_COMMON_SOURCES
${SRC_DIR}/Python/frozenmain.c
)
else()
list(APPEND PYTHON_COMMON_SOURCES
${SRC_DIR}/Python/frozen.c
)
endif()

if(UNIX OR MINGW)
Expand Down Expand Up @@ -457,10 +453,16 @@ endif()
set(LIBPYTHON_FROZEN_SOURCES )
if(IS_PY3)

# Windows needs PyImport_FrozenModules declared...
if(WIN32)
set(FROZENMODULES_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/frozenmodules.c)
endif()

# Build _freeze_importlib executable
add_executable(_freeze_importlib
${SRC_DIR}/Programs/_freeze_importlib.c
${LIBPYTHON_OMIT_FROZEN_SOURCES}
${FROZENMODULES_SOURCE}
)
target_link_libraries(_freeze_importlib ${LIBPYTHON_TARGET_LIBRARIES})
if(builtin_compile_definitions_without_py_limited_api)
Expand Down Expand Up @@ -542,12 +544,8 @@ endif()
set(LIBPYTHON_SOURCES
${LIBPYTHON_OMIT_FROZEN_SOURCES}
${LIBPYTHON_FROZEN_SOURCES}
${SRC_DIR}/Python/frozen.c
)
if(UNIX)
list(APPEND LIBPYTHON_SOURCES
${SRC_DIR}/Python/frozen.c
)
endif()

# Build python libraries
function(add_libpython name type install component)
Expand Down
8 changes: 8 additions & 0 deletions cmake/libpython/frozenmodules.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* Dummy frozen modules initializer for building _freeze_importlib
under MS Windows, as using the frozen.c from the Python
distribution results in a circular include of importlib.h
*/
#include <Python.h>
#include <marshal.h>

const struct _frozen *PyImport_FrozenModules;
3 changes: 3 additions & 0 deletions cmake/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ if(UNIX AND PY_VERSION VERSION_GREATER "2.7.4")
)
install(FILES ${EXTENSION_BUILD_DIR}/${_sysconfigdata_py}
DESTINATION ${PYTHONHOME}/)
set_property(GLOBAL PROPERTY FUCK_PYTHON_SYSCONFIG_NIMABI ${EXTENSION_BUILD_DIR}/${_sysconfigdata_py})
set_property(GLOBAL PROPERTY FUCK_PYTHON_SYSCONFIG_NIMABI2 ${PYTHONHOME}/${_sysconfigdata_py})
set_property(GLOBAL PROPERTY FUCK_PYTHON_SYSCONFIG_NIMABI3 ${PROJECT_BINARY_DIR})
endif()

if(UNIX AND NOT CMAKE_CROSSCOMPILING)
Expand Down
105 changes: 105 additions & 0 deletions patches/3.9/0001-Prevent-missing-include-of-io.h-found-in-msi-.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
--- a/PC/_msi.c 2022-09-08 15:57:12.205510328 +0800
+++ b/PC/_msi.c 2022-09-08 15:57:42.597842635 +0800
@@ -174,8 +174,7 @@
FileTimeToLocalFileTime(&bhfi.ftLastWriteTime, &filetime);
FileTimeToDosDateTime(&filetime, pdate, ptime);

- *pattribs = (int)(bhfi.dwFileAttributes &
- (_A_RDONLY | _A_SYSTEM | _A_HIDDEN | _A_ARCH));
+ *pattribs = (int)(bhfi.dwFileAttributes & 39); /* _A_RDONLY | _A_SYSTEM | _A_HIDDEN | _A_ARCH = 39 */

CloseHandle(handle);

--- a/Modules/posixmodule.c 2022-09-08 15:56:51.851881539 +0800
+++ b/Modules/posixmodule.c 2022-09-08 15:57:05.029367072 +0800
@@ -308,8 +308,8 @@
# define HAVE_PIPE 1
# define HAVE_SYSTEM 1
# define HAVE_CWAIT 1
-# define HAVE_FSYNC 1
-# define fsync _commit
+/*# define HAVE_FSYNC 1*/
+/*# define fsync _commit*/
# else
/* Unix functions that the configure script doesn't check for */
# ifndef __VXWORKS__
--- a/Modules/_winapi.c 2022-09-08 15:54:25.084773865 +0800
+++ b/Modules/_winapi.c 2022-09-08 15:54:50.474541290 +0800
@@ -145,7 +145,7 @@

/*[clinic input]
module _winapi
-class _winapi.Overlapped "OverlappedObject *" "&OverlappedType"
+class _winapi.Overlapped "OverlappedObject *" "&WinApiOverlappedType"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=c13d3f5fd1dabb84]*/

@@ -304,7 +304,7 @@
{NULL}
};

-PyTypeObject OverlappedType = {
+PyTypeObject WinApiOverlappedType = {
PyVarObject_HEAD_INIT(NULL, 0)
/* tp_name */ "_winapi.Overlapped",
/* tp_basicsize */ sizeof(OverlappedObject),
@@ -350,7 +350,7 @@
{
OverlappedObject *self;

- self = PyObject_New(OverlappedObject, &OverlappedType);
+ self = PyObject_New(OverlappedObject, &WinApiOverlappedType);
if (!self)
return NULL;
self->handle = handle;
@@ -1941,7 +1941,7 @@
PyObject *d;
PyObject *m;

- if (PyType_Ready(&OverlappedType) < 0)
+ if (PyType_Ready(&WinApiOverlappedType) < 0)
return NULL;

m = PyModule_Create(&winapi_module);
@@ -1949,7 +1949,7 @@
return NULL;
d = PyModule_GetDict(m);

- PyDict_SetItemString(d, "Overlapped", (PyObject *) &OverlappedType);
+ PyDict_SetItemString(d, "Overlapped", (PyObject *) &WinApiOverlappedType);

/* constants */
WINAPI_CONSTANT(F_DWORD, CREATE_NEW_CONSOLE);
--- a/Modules/_decimal/libmpdec/mpdecimal.c 2022-09-08 15:59:03.704908109 +0800
+++ b/Modules/_decimal/libmpdec/mpdecimal.c 2022-09-08 15:59:15.807383050 +0800
@@ -63,7 +63,7 @@


#if defined(_MSC_VER)
- #define ALWAYS_INLINE __forceinline
+ #define ALWAYS_INLINE extern __forceinline
#elif defined(__IBMC__) || defined(LEGACY_COMPILER)
#define ALWAYS_INLINE
#undef inline
@@ -517,7 +517,7 @@
}

/* Same as mpd_qresize, but do not set the result no NaN on failure. */
-static ALWAYS_INLINE int
+ALWAYS_INLINE int
mpd_qresize_cxx(mpd_t *result, mpd_ssize_t nwords)
{
assert(!mpd_isconst_data(result)); /* illegal operation for a const */
--- a/Modules/_decimal/libmpdec/mpdecimal.h 2022-09-09 15:51:38.202653415 +0800
+++ b/Modules/_decimal/libmpdec/mpdecimal.h 2022-09-09 15:52:07.611967326 +0800
@@ -105,6 +105,10 @@
/* Configuration */
/******************************************************************************/

+#if !defined(CONFIG_64) && !defined(CONFIG_32) && !defined(UNIVERSAL)
+#define CONFIG_64 1
+#endif
+
#if defined(UNIVERSAL)
#if defined(CONFIG_64) || defined(CONFIG_32)
#error "cannot use CONFIG_64 or CONFIG_32 with UNIVERSAL."