K.Takata's patch queue for Vim
Revision | fa9e27de856fd4e659fa3b28f1724197450273b4 (tree) |
---|---|
Zeit | 2022-02-07 23:46:17 |
Autor | K.Takata <kentkt@csc....> |
Commiter | K.Takata |
Update for 8.2.4317
Remove a merged patch.
@@ -30,5 +30,4 @@ | ||
30 | 30 | wip-win32-vimdir-encoding.patch #+wip |
31 | 31 | win32-directwrite-ambiwidth-auto.patch |
32 | 32 | suppress-warnings.patch |
33 | -win32-hook-python-exit.patch | |
34 | 33 | fix-config_cache-removal.patch #+rejected |
@@ -1,242 +0,0 @@ | ||
1 | -# HG changeset patch | |
2 | -# Parent 4663988fb4ea1471b21985a8e37ebc6f7a6ef96d | |
3 | - | |
4 | -diff --git a/runtime/doc/if_pyth.txt b/runtime/doc/if_pyth.txt | |
5 | ---- a/runtime/doc/if_pyth.txt | |
6 | -+++ b/runtime/doc/if_pyth.txt | |
7 | -@@ -834,6 +834,19 @@ 3. You undefine PY_NO_RTLD_GLOBAL in aut | |
8 | - Raising SystemExit exception in python isn't endorsed way to quit vim, use: > | |
9 | - :py vim.command("qall!") | |
10 | - < | |
11 | -+ *Exxxx* | |
12 | -+This error can occur when python 3 cannot load the required modules. This | |
13 | -+means that your python 3 is not correctly installed or there are some mistakes | |
14 | -+in your settings. Please check the following items: | |
15 | -+1. Make sure that python 3 is correctly installed. Also check the version of | |
16 | -+ python. | |
17 | -+2. Check the 'pythonthreedll' option. | |
18 | -+3. Check the 'pythonthreehome' option. | |
19 | -+4. Check the PATH environment variable if you don't set 'pythonthreedll'. | |
20 | -+ On MS-Windows, you can use where.exe to check which dll will be loaded. | |
21 | -+ E.g. > | |
22 | -+ where.exe python310.dll | |
23 | -+5. Check the PYTHONPATH and PYTHONHOME environment variables. | |
24 | - | |
25 | - *has-python* | |
26 | - You can test what Python version is available with: > | |
27 | -diff --git a/src/if_python3.c b/src/if_python3.c | |
28 | ---- a/src/if_python3.c | |
29 | -+++ b/src/if_python3.c | |
30 | -@@ -112,12 +112,18 @@ typedef PyObject PySliceObject_T; | |
31 | - typedef PySliceObject PySliceObject_T; | |
32 | - #endif | |
33 | - | |
34 | -+#ifndef MSWIN | |
35 | -+# define HINSTANCE void* | |
36 | -+#endif | |
37 | -+#if defined(DYNAMIC_PYTHON3) || defined(MSWIN) | |
38 | -+static HINSTANCE hinstPy3 = 0; // Instance of python.dll | |
39 | -+#endif | |
40 | -+ | |
41 | - #if defined(DYNAMIC_PYTHON3) || defined(PROTO) | |
42 | - | |
43 | - # ifndef MSWIN | |
44 | - # include <dlfcn.h> | |
45 | - # define FARPROC void* | |
46 | --# define HINSTANCE void* | |
47 | - # if defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL) | |
48 | - # define load_dll(n) dlopen((n), RTLD_LAZY) | |
49 | - # else | |
50 | -@@ -459,8 +465,6 @@ static void(*py3_PyObject_GC_Del)(void * | |
51 | - static void(*py3_PyObject_GC_UnTrack)(void *); | |
52 | - static int (*py3_PyType_IsSubtype)(PyTypeObject *, PyTypeObject *); | |
53 | - | |
54 | --static HINSTANCE hinstPy3 = 0; // Instance of python.dll | |
55 | -- | |
56 | - // Imported exception objects | |
57 | - static PyObject *p3imp_PyExc_AttributeError; | |
58 | - static PyObject *p3imp_PyExc_IndexError; | |
59 | -@@ -1032,13 +1036,8 @@ reset_stdin(void) | |
60 | - { | |
61 | - FILE *(*py__acrt_iob_func)(unsigned) = NULL; | |
62 | - FILE *(*pyfreopen)(const char *, const char *, FILE *) = NULL; | |
63 | -- HINSTANCE hinst; | |
64 | -+ HINSTANCE hinst = hinstPy3; | |
65 | - | |
66 | --# ifdef DYNAMIC_PYTHON3 | |
67 | -- hinst = hinstPy3; | |
68 | --# else | |
69 | -- hinst = GetModuleHandle(PYTHON3_DLL); | |
70 | --# endif | |
71 | - if (hinst == NULL || is_stdin_readable()) | |
72 | - return; | |
73 | - | |
74 | -@@ -1063,6 +1062,52 @@ reset_stdin(void) | |
75 | - # define reset_stdin() | |
76 | - #endif | |
77 | - | |
78 | -+// Python 3.2 or later will abort inside Py_Initialize() when mandatory | |
79 | -+// modules cannot be load. (e.g. 'pythonthreehome' is wrongly set.) | |
80 | -+// Install a hook to python dll's exit() and recover from it. | |
81 | -+#if defined(MSWIN) && (PY_VERSION_HEX >= 0x030200f0) | |
82 | -+# define HOOK_EXIT | |
83 | -+# include <setjmp.h> | |
84 | -+ | |
85 | -+static jmp_buf jb; | |
86 | -+static void *orig_exit = NULL; | |
87 | -+ | |
88 | -+ static void | |
89 | -+hooked_exit(int ret) | |
90 | -+{ | |
91 | -+ // Recover from exit. | |
92 | -+ longjmp(jb, 1); | |
93 | -+} | |
94 | -+ | |
95 | -+// Install a hook to python dll's exit(). | |
96 | -+ static void | |
97 | -+hook_py_exit(void) | |
98 | -+{ | |
99 | -+ HINSTANCE hinst = hinstPy3; | |
100 | -+ | |
101 | -+ if (hinst == NULL || orig_exit != NULL) | |
102 | -+ return; | |
103 | -+ | |
104 | -+ orig_exit = hook_dll_import_func(hinst, "exit", (void*)hooked_exit); | |
105 | -+} | |
106 | -+ | |
107 | -+// Remove the hook. | |
108 | -+ static void | |
109 | -+restore_py_exit(void) | |
110 | -+{ | |
111 | -+ HINSTANCE hinst = hinstPy3; | |
112 | -+ | |
113 | -+ if (hinst == NULL) | |
114 | -+ return; | |
115 | -+ | |
116 | -+ if (orig_exit != NULL) | |
117 | -+ hook_dll_import_func(hinst, "exit", orig_exit); | |
118 | -+ orig_exit = NULL; | |
119 | -+} | |
120 | -+#else | |
121 | -+# define restore_py_exit() | |
122 | -+#endif | |
123 | -+ | |
124 | - static int | |
125 | - Python3_Init(void) | |
126 | - { | |
127 | -@@ -1095,8 +1140,27 @@ Python3_Init(void) | |
128 | - | |
129 | - PyImport_AppendInittab("vim", Py3Init_vim); | |
130 | - | |
131 | -+#if !defined(DYNAMIC_PYTHON3) && defined(MSWIN) | |
132 | -+ hinstPy3 = GetModuleHandle(PYTHON3_DLL); | |
133 | -+#endif | |
134 | - reset_stdin(); | |
135 | -- Py_Initialize(); | |
136 | -+ | |
137 | -+#ifdef HOOK_EXIT | |
138 | -+ hook_py_exit(); | |
139 | -+ if (setjmp(jb) == 0) | |
140 | -+#endif | |
141 | -+ { | |
142 | -+ Py_Initialize(); | |
143 | -+ restore_py_exit(); | |
144 | -+ } | |
145 | -+#ifdef HOOK_EXIT | |
146 | -+ else | |
147 | -+ { | |
148 | -+ restore_py_exit(); | |
149 | -+ emsg(_("Exxxx: Critical error in python3 initialization. Check your python3 installation.")); | |
150 | -+ goto fail; | |
151 | -+ } | |
152 | -+#endif | |
153 | - | |
154 | - #if PY_VERSION_HEX < 0x03090000 | |
155 | - // Initialise threads. This is deprecated since Python 3.9. | |
156 | -diff --git a/src/os_win32.c b/src/os_win32.c | |
157 | ---- a/src/os_win32.c | |
158 | -+++ b/src/os_win32.c | |
159 | -@@ -573,14 +573,18 @@ mch_is_gui_executable(void) | |
160 | - } | |
161 | - #endif | |
162 | - | |
163 | --#if defined(DYNAMIC_ICONV) || defined(DYNAMIC_GETTEXT) || defined(PROTO) | |
164 | -+#if defined(DYNAMIC_ICONV) || defined(DYNAMIC_GETTEXT) \ | |
165 | -+ || defined(FEAT_PYTHON3) || defined(PROTO) | |
166 | - /* | |
167 | - * Get related information about 'funcname' which is imported by 'hInst'. | |
168 | - * If 'info' is 0, return the function address. | |
169 | - * If 'info' is 1, return the module name which the function is imported from. | |
170 | -+ * If 'info' is 2, hook the function with 'ptr', and return the original | |
171 | -+ * function address. | |
172 | - */ | |
173 | - static void * | |
174 | --get_imported_func_info(HINSTANCE hInst, const char *funcname, int info) | |
175 | -+get_imported_func_info(HINSTANCE hInst, const char *funcname, int info, | |
176 | -+ const void *ptr) | |
177 | - { | |
178 | - PBYTE pImage = (PBYTE)hInst; | |
179 | - PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)hInst; | |
180 | -@@ -612,12 +616,23 @@ get_imported_func_info(HINSTANCE hInst, | |
181 | - + (UINT_PTR)(pINT->u1.AddressOfData)); | |
182 | - if (strcmp((char *)pImpName->Name, funcname) == 0) | |
183 | - { | |
184 | -+ void *original; | |
185 | -+ DWORD old, new = PAGE_READWRITE; | |
186 | -+ | |
187 | - switch (info) | |
188 | - { | |
189 | - case 0: | |
190 | - return (void *)pIAT->u1.Function; | |
191 | - case 1: | |
192 | - return (void *)(pImage + pImpDesc->Name); | |
193 | -+ case 2: | |
194 | -+ original = (void *)pIAT->u1.Function; | |
195 | -+ VirtualProtect(&pIAT->u1.Function, sizeof(void *), | |
196 | -+ new, &old); | |
197 | -+ pIAT->u1.Function = (UINT_PTR)ptr; | |
198 | -+ VirtualProtect(&pIAT->u1.Function, sizeof(void *), | |
199 | -+ old, &new); | |
200 | -+ return original; | |
201 | - default: | |
202 | - return NULL; | |
203 | - } | |
204 | -@@ -635,7 +650,7 @@ find_imported_module_by_funcname(HINSTAN | |
205 | - { | |
206 | - char *modulename; | |
207 | - | |
208 | -- modulename = (char *)get_imported_func_info(hInst, funcname, 1); | |
209 | -+ modulename = (char *)get_imported_func_info(hInst, funcname, 1, NULL); | |
210 | - if (modulename != NULL) | |
211 | - return GetModuleHandleA(modulename); | |
212 | - return NULL; | |
213 | -@@ -647,7 +662,17 @@ find_imported_module_by_funcname(HINSTAN | |
214 | - void * | |
215 | - get_dll_import_func(HINSTANCE hInst, const char *funcname) | |
216 | - { | |
217 | -- return get_imported_func_info(hInst, funcname, 0); | |
218 | -+ return get_imported_func_info(hInst, funcname, 0, NULL); | |
219 | -+} | |
220 | -+ | |
221 | -+/* | |
222 | -+ * Hook the function named 'funcname' which is imported by 'hInst' DLL, | |
223 | -+ * and return the original function address. | |
224 | -+ */ | |
225 | -+ void * | |
226 | -+hook_dll_import_func(HINSTANCE hInst, const char *funcname, const void *hook) | |
227 | -+{ | |
228 | -+ return get_imported_func_info(hInst, funcname, 2, hook); | |
229 | - } | |
230 | - #endif | |
231 | - | |
232 | -diff --git a/src/proto/os_win32.pro b/src/proto/os_win32.pro | |
233 | ---- a/src/proto/os_win32.pro | |
234 | -+++ b/src/proto/os_win32.pro | |
235 | -@@ -4,6 +4,7 @@ HINSTANCE vimLoadLib(char *name); | |
236 | - int mch_is_gui_executable(void); | |
237 | - HINSTANCE find_imported_module_by_funcname(HINSTANCE hInst, const char *funcname); | |
238 | - void *get_dll_import_func(HINSTANCE hInst, const char *funcname); | |
239 | -+void *hook_dll_import_func(HINSTANCE hInst, const char *funcname, const void *hook); | |
240 | - int dyn_libintl_init(void); | |
241 | - void dyn_libintl_end(void); | |
242 | - void PlatformId(void); |