diff options
| author | Eli Zaretskii | 2015-11-18 22:09:08 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2015-11-18 22:09:08 +0200 |
| commit | 520dc85f313e2a30759fd73206c30bff27062785 (patch) | |
| tree | d59145d63be40c3d706547d538df408b7c59ba77 /src | |
| parent | 9328e3d0ea374ab2d99a311cbf6f9db75cf718bf (diff) | |
| download | emacs-520dc85f313e2a30759fd73206c30bff27062785.tar.gz emacs-520dc85f313e2a30759fd73206c30bff27062785.zip | |
Fix MS-Windows build --with-modules
* src/module.c: Reformat copyright commentary.
(module_vec_get): Use explicit cast to size_t to avoid compiler
warning in 32-bit builds.
(check_main_thread) [WINDOWSNT]: Fix letter-case in Windows APIs.
Compare thread IDs directly, as GetThreadId is not available
before Windows Vista.
(check_main_thread) [WINDOWSNT]: Duplicate the thread handle
without using APIs and constants not available on XP and older
systems. Obtain and store the thread ID as well.
Diffstat (limited to 'src')
| -rw-r--r-- | src/module.c | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/src/module.c b/src/module.c index 125fd7fed26..9360744c4ec 100644 --- a/src/module.c +++ b/src/module.c | |||
| @@ -1,22 +1,21 @@ | |||
| 1 | /* | 1 | /* module.c - Module loading and runtime implementation |
| 2 | module.c - Module loading and runtime implementation | 2 | |
| 3 | Copyright (C) 2015 Free Software Foundation, Inc. | 3 | Copyright (C) 2015 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This file is part of GNU Emacs. | 5 | This file is part of GNU Emacs. |
| 6 | 6 | ||
| 7 | GNU Emacs is free software: you can redistribute it and/or modify | 7 | GNU Emacs is free software: you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by | 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation, either version 3 of the License, or | 9 | the Free Software Foundation, either version 3 of the License, or |
| 10 | (at your option) any later version. | 10 | (at your option) any later version. |
| 11 | 11 | ||
| 12 | GNU Emacs is distributed in the hope that it will be useful, | 12 | GNU Emacs is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. | 15 | GNU General Public License for more details. |
| 16 | 16 | ||
| 17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License |
| 18 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | 18 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
| 19 | */ | ||
| 20 | 19 | ||
| 21 | #include <stdbool.h> | 20 | #include <stdbool.h> |
| 22 | #include <stddef.h> | 21 | #include <stddef.h> |
| @@ -53,9 +52,11 @@ static thrd_t main_thread; | |||
| 53 | static pthread_t main_thread; | 52 | static pthread_t main_thread; |
| 54 | #elif defined(WINDOWSNT) | 53 | #elif defined(WINDOWSNT) |
| 55 | #include <windows.h> | 54 | #include <windows.h> |
| 56 | /* On Windows, we store a handle to the main thread instead of the | 55 | /* On Windows, we store both a handle to the main thread and the |
| 57 | thread ID because the latter can be reused when a thread terminates. */ | 56 | thread ID because the latter can be reused when a thread |
| 57 | terminates. */ | ||
| 58 | static HANDLE main_thread; | 58 | static HANDLE main_thread; |
| 59 | static DWORD main_thread_id; | ||
| 59 | #endif | 60 | #endif |
| 60 | 61 | ||
| 61 | 62 | ||
| @@ -757,7 +758,8 @@ static emacs_value module_vec_get (emacs_env *env, | |||
| 757 | eassert (size >= 0); | 758 | eassert (size >= 0); |
| 758 | if (i >= size) | 759 | if (i >= size) |
| 759 | { | 760 | { |
| 760 | if (i > MOST_POSITIVE_FIXNUM) i = MOST_POSITIVE_FIXNUM; | 761 | if (i > MOST_POSITIVE_FIXNUM) |
| 762 | i = (size_t) MOST_POSITIVE_FIXNUM; | ||
| 761 | module_args_out_of_range (env, lvec, make_number (i)); | 763 | module_args_out_of_range (env, lvec, make_number (i)); |
| 762 | return NULL; | 764 | return NULL; |
| 763 | } | 765 | } |
| @@ -899,8 +901,8 @@ static void check_main_thread (void) | |||
| 899 | /* CompareObjectHandles would be perfect, but is only available in | 901 | /* CompareObjectHandles would be perfect, but is only available in |
| 900 | Windows 10. Also check whether the thread is still running to | 902 | Windows 10. Also check whether the thread is still running to |
| 901 | protect against thread identifier reuse. */ | 903 | protect against thread identifier reuse. */ |
| 902 | eassert (GetCurrentThreadID () == GetThreadID (main_thread) && | 904 | eassert (GetCurrentThreadId () == main_thread_id |
| 903 | WaitForSingleObject (main_thread, 0) == WAIT_TIMEOUT); | 905 | && WaitForSingleObject (main_thread, 0) == WAIT_TIMEOUT); |
| 904 | #endif | 906 | #endif |
| 905 | } | 907 | } |
| 906 | 908 | ||
| @@ -1175,11 +1177,22 @@ void module_init (void) | |||
| 1175 | #elif defined(HAVE_PTHREAD) | 1177 | #elif defined(HAVE_PTHREAD) |
| 1176 | main_thread = pthread_self (); | 1178 | main_thread = pthread_self (); |
| 1177 | #elif defined(WINDOWSNT) | 1179 | #elif defined(WINDOWSNT) |
| 1180 | /* This calls APIs that are only available on Vista and later. */ | ||
| 1181 | #if 0 | ||
| 1178 | /* GetCurrentProcess returns a pseudohandle, which we have to duplicate. */ | 1182 | /* GetCurrentProcess returns a pseudohandle, which we have to duplicate. */ |
| 1179 | if (! DuplicateHandle (GetCurrentProcess(), GetCurrentThread(), | 1183 | if (! DuplicateHandle (GetCurrentProcess(), GetCurrentThread(), |
| 1180 | GetCurrentProcess(), &main_thread, | 1184 | GetCurrentProcess(), &main_thread, |
| 1181 | SYNCHRONIZE | THREAD_QUERY_LIMITED_INFORMATION, | 1185 | SYNCHRONIZE | THREAD_QUERY_INFORMATION, |
| 1182 | FALSE, 0)) | 1186 | FALSE, 0)) |
| 1183 | emacs_abort (); | 1187 | emacs_abort (); |
| 1188 | #else | ||
| 1189 | /* GetCurrentThread returns a pseudohandle, which we have to duplicate. */ | ||
| 1190 | HANDLE th = GetCurrentThread (); | ||
| 1191 | if (!DuplicateHandle (GetCurrentProcess (), th, | ||
| 1192 | GetCurrentProcess (), &main_thread, 0, FALSE, | ||
| 1193 | DUPLICATE_SAME_ACCESS)) | ||
| 1194 | emacs_abort (); | ||
| 1195 | main_thread_id = GetCurrentThreadId (); | ||
| 1196 | #endif | ||
| 1184 | #endif | 1197 | #endif |
| 1185 | } | 1198 | } |