upgpkg: ufw 0.36.2-1
[ArchLinux/community.git] / kvirc / trunk / python3.patch
blobb3aa3ee1951be560981859a1ef544c761054d8ff
1 From dbe8ef6dad916124c3714abc469403ed9991261c Mon Sep 17 00:00:00 2001
2 From: wodim <neikokz@gmail.com>
3 Date: Sat, 26 Aug 2017 15:02:56 +0200
4 Subject: [PATCH 1/5] Add support for Python 3
6 ---
7 CMakeLists.txt | 7 ++----
8 src/modules/python/libkvipython.cpp | 26 ++++++++++++++++++++
9 src/modules/pythoncore/kvircmodule.cpp | 2 +-
10 src/modules/pythoncore/pythonheaderwrapper.h | 6 +++++
11 4 files changed, 35 insertions(+), 6 deletions(-)
13 diff --git a/CMakeLists.txt b/CMakeLists.txt
14 index 96659b5c3..c3d103726 100644
15 --- a/CMakeLists.txt
16 +++ b/CMakeLists.txt
17 @@ -69,9 +69,6 @@ set(CMAKE_KVIRC_BUILD_CPU ${CMAKE_SYSTEM_PROCESSOR})
18 set(CMAKE_KVIRC_BUILD_COMPILER ${CMAKE_CXX_COMPILER})
19 set(CMAKE_KVIRC_BUILD_COMPILER_FLAGS ${CMAKE_CXX_FLAGS})
21 -# Prefer Python 2.7 over 3.x (which is currently incompatible) - GitHub issue #2020
22 -set(Python_ADDITIONAL_VERSIONS "2.7")
24 # Suffix for GNU/Linux
25 set(LIB_SUFFIX
26 CACHE STRING "Define suffix of directory name (32/64)"
27 @@ -786,10 +783,10 @@ endif()
28 # Check for Python support
29 option(WANT_PYTHON "Compile Python support" ON)
30 if(WANT_PYTHON)
31 - find_package(PythonLibs 2.7)
32 + find_package(PythonLibs)
33 if(PYTHONLIBS_FOUND)
34 set(COMPILE_PYTHON_SUPPORT 1)
35 - set(CMAKE_STATUS_PYTHON_SUPPORT "Yes")
36 + set(CMAKE_STATUS_PYTHON_SUPPORT "Yes, Python ${PYTHONLIBS_VERSION_STRING}")
37 list(APPEND LIBS ${PYTHON_LIBRARIES})
38 include_directories(${PYTHON_INCLUDE_DIRS})
39 else()
40 diff --git a/src/modules/python/libkvipython.cpp b/src/modules/python/libkvipython.cpp
41 index 6bdd56a80..700e8939b 100644
42 --- a/src/modules/python/libkvipython.cpp
43 +++ b/src/modules/python/libkvipython.cpp
44 @@ -502,6 +502,31 @@ static bool python_kvs_fnc_isAvailable(KviKvsModuleFunctionCall * c)
45 return true;
48 +/*
49 + @doc: python.version
50 + @type:
51 + function
52 + @title:
53 + $python.version
54 + @short:
55 + Check which version of Python is supported in this build of KVIrc
56 + @syntax:
57 + $python.version
58 + @description:
59 + Returns which major version of Python is KVIrc linked to ([b]2[/b] or [b]3[/b])
60 + or [b]0[/b] if Python is not supported at all.
61 +*/
63 +static bool python_kvs_fnc_version(KviKvsModuleFunctionCall * c)
65 +#ifdef COMPILE_PYTHON_SUPPORT
66 + c->returnValue()->setInteger(PY_MAJOR_VERSION);
67 +#else
68 + c->returnValue()->setBoolean(false);
69 +#endif
70 + return true;
73 static bool python_module_init(KviModule * m)
75 // register the command anyway
76 @@ -509,6 +534,7 @@ static bool python_module_init(KviModule * m)
77 KVSM_REGISTER_SIMPLE_COMMAND(m, "destroy", python_kvs_cmd_destroy);
79 KVSM_REGISTER_FUNCTION(m, "isAvailable", python_kvs_fnc_isAvailable);
80 + KVSM_REGISTER_FUNCTION(m, "version", python_kvs_fnc_version);
81 #ifdef COMPILE_PYTHON_SUPPORT
82 g_pPythonCoreModule = g_pModuleManager->getModule("pythoncore");
83 #endif
84 diff --git a/src/modules/pythoncore/kvircmodule.cpp b/src/modules/pythoncore/kvircmodule.cpp
85 index 8937b6a63..659345d7e 100644
86 --- a/src/modules/pythoncore/kvircmodule.cpp
87 +++ b/src/modules/pythoncore/kvircmodule.cpp
88 @@ -423,7 +423,7 @@ PyMODINIT_FUNC python_init()
89 else
91 // Create a CObject containing the API pointer array's address
92 - PyObject * pC_API_Object = PyCObject_FromVoidPtr(PyKVIrc_API, nullptr);
93 + PyObject * pC_API_Object = PyCapsule_New((void *)PyKVIrc_API, "kvirc._C_API", nullptr);
94 if(pC_API_Object)
95 PyModule_AddObject(pModule, "_C_API", pC_API_Object);
97 diff --git a/src/modules/pythoncore/pythonheaderwrapper.h b/src/modules/pythoncore/pythonheaderwrapper.h
98 index 47f60d361..2b34066c3 100644
99 --- a/src/modules/pythoncore/pythonheaderwrapper.h
100 +++ b/src/modules/pythoncore/pythonheaderwrapper.h
101 @@ -1,6 +1,12 @@
102 #ifndef _PYTHONHEADERWRAPPER_H_
103 #define _PYTHONHEADERWRAPPER_H_
105 +// As of Python 3, something inside <Python.h> defines a struct with a member
106 +// called "slots" which conflicts with the builtin Qt keyword. But since we
107 +// include stuff from KVIrc itself back into the python module, we can't just
108 +// use QT_NO_KEYWORDS.
109 +#undef slots
111 // See http://stackoverflow.com/questions/16200997/why-doesnt-include-python-h-work and http://stackoverflow.com/questions/19716859/puzzling-dependency-of-boost-python-1-54-debug-build-to-python27-lib-on-window
113 #if defined(_DEBUG) && defined(_MSC_VER)
115 From 77983c1ac38efa87a3c644b3918dd1648040aee0 Mon Sep 17 00:00:00 2001
116 From: wodim <neikokz@gmail.com>
117 Date: Mon, 1 Apr 2019 15:02:39 +0200
118 Subject: [PATCH 2/5] This is not necessary anymore
121 src/modules/python/libkvipython.cpp | 26 --------------------------
122 1 file changed, 26 deletions(-)
124 diff --git a/src/modules/python/libkvipython.cpp b/src/modules/python/libkvipython.cpp
125 index 700e8939b..6bdd56a80 100644
126 --- a/src/modules/python/libkvipython.cpp
127 +++ b/src/modules/python/libkvipython.cpp
128 @@ -502,31 +502,6 @@ static bool python_kvs_fnc_isAvailable(KviKvsModuleFunctionCall * c)
129 return true;
133 - @doc: python.version
134 - @type:
135 - function
136 - @title:
137 - $python.version
138 - @short:
139 - Check which version of Python is supported in this build of KVIrc
140 - @syntax:
141 - $python.version
142 - @description:
143 - Returns which major version of Python is KVIrc linked to ([b]2[/b] or [b]3[/b])
144 - or [b]0[/b] if Python is not supported at all.
147 -static bool python_kvs_fnc_version(KviKvsModuleFunctionCall * c)
149 -#ifdef COMPILE_PYTHON_SUPPORT
150 - c->returnValue()->setInteger(PY_MAJOR_VERSION);
151 -#else
152 - c->returnValue()->setBoolean(false);
153 -#endif
154 - return true;
157 static bool python_module_init(KviModule * m)
159 // register the command anyway
160 @@ -534,7 +509,6 @@ static bool python_module_init(KviModule * m)
161 KVSM_REGISTER_SIMPLE_COMMAND(m, "destroy", python_kvs_cmd_destroy);
163 KVSM_REGISTER_FUNCTION(m, "isAvailable", python_kvs_fnc_isAvailable);
164 - KVSM_REGISTER_FUNCTION(m, "version", python_kvs_fnc_version);
165 #ifdef COMPILE_PYTHON_SUPPORT
166 g_pPythonCoreModule = g_pModuleManager->getModule("pythoncore");
167 #endif
169 From 2c881f711d518bbe4db95bf183ddc946c12f7751 Mon Sep 17 00:00:00 2001
170 From: Alexey Sokolov <sokolov@google.com>
171 Date: Sun, 29 Dec 2019 23:26:31 +0000
172 Subject: [PATCH 3/5] Replace FindPythonLibs with FindPython3 in CMake
175 CMakeLists.txt | 12 ++++++------
176 1 file changed, 6 insertions(+), 6 deletions(-)
178 diff --git a/CMakeLists.txt b/CMakeLists.txt
179 index 385bbbd4d..e7fee2820 100644
180 --- a/CMakeLists.txt
181 +++ b/CMakeLists.txt
182 @@ -34,7 +34,7 @@
183 ###############################################################################
185 # Minimum CMake version
186 -cmake_minimum_required(VERSION 3.1.0)
187 +cmake_minimum_required(VERSION 3.12)
189 # Name of the project
190 project(kvirc)
191 @@ -748,12 +748,12 @@ endif()
192 # Check for Python support
193 option(WANT_PYTHON "Compile Python support" ON)
194 if(WANT_PYTHON)
195 - find_package(PythonLibs)
196 - if(PYTHONLIBS_FOUND)
197 + find_package(Python3 COMPONENTS Development)
198 + if(Python3_FOUND)
199 set(COMPILE_PYTHON_SUPPORT 1)
200 - set(CMAKE_STATUS_PYTHON_SUPPORT "Yes, Python ${PYTHONLIBS_VERSION_STRING}")
201 - list(APPEND LIBS ${PYTHON_LIBRARIES})
202 - include_directories(${PYTHON_INCLUDE_DIRS})
203 + set(CMAKE_STATUS_PYTHON_SUPPORT "Yes, Python ${Python3_VERSION}")
204 + list(APPEND LIBS ${Python3_LIBRARIES})
205 + include_directories(${Python3_INCLUDE_DIRS})
206 else()
207 set(CMAKE_STATUS_PYTHON_SUPPORT "No, not found.")
208 endif()
210 From 79dbba4260113b453fcea155881ecb4c6f82963b Mon Sep 17 00:00:00 2001
211 From: Alexey Sokolov <sokolov@google.com>
212 Date: Mon, 30 Dec 2019 07:32:51 +0000
213 Subject: [PATCH 5/5] Stop unsetting _DEBUG when including Python.h
215 Because of https://stackoverflow.com/questions/59126760/building-a-python-c-extension-on-windows-with-a-debug-python-installation
217 src/modules/pythoncore/pythonheaderwrapper.h | 10 +---------
218 1 file changed, 1 insertion(+), 9 deletions(-)
220 diff --git a/src/modules/pythoncore/pythonheaderwrapper.h b/src/modules/pythoncore/pythonheaderwrapper.h
221 index 2b34066c3..173e3c289 100644
222 --- a/src/modules/pythoncore/pythonheaderwrapper.h
223 +++ b/src/modules/pythoncore/pythonheaderwrapper.h
224 @@ -7,14 +7,6 @@
225 // use QT_NO_KEYWORDS.
226 #undef slots
228 -// See http://stackoverflow.com/questions/16200997/why-doesnt-include-python-h-work and http://stackoverflow.com/questions/19716859/puzzling-dependency-of-boost-python-1-54-debug-build-to-python27-lib-on-window
230 -#if defined(_DEBUG) && defined(_MSC_VER)
231 -# undef _DEBUG
232 -# include <Python.h>
233 -# define _DEBUG 1
234 -#else
235 -# include <Python.h>
236 -#endif
237 +#include <Python.h>
239 #endif