]> granicus.if.org Git - gc/commitdiff
Enable gc.h inclusion by client without implicit include windows.h (Win32)
authorIvan Maidanski <ivmai@mail.ru>
Fri, 8 May 2015 06:26:36 +0000 (09:26 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 11 May 2015 15:59:49 +0000 (18:59 +0300)
* doc/README.macros (GC_DONT_INCLUDE_WINDOWS_H): Document.
* include/gc.h: Include windows.h unless GC_DONT_INCLUDE_WINDOWS_H
(only for Win32).
* include/gc.h (DECLSPEC_NORETURN): Define to __declspec(noreturn) by
default if windows.h not included (instead of empty).
* include/gc.h (GC_WIN32_SIZE_T): Define to DWORD (or unsigned long)
unless _WIN64 (instead of GC_uintptr_t which is unsigned int for
32-bit target).
* include/gc.h (GC_DllMain, GC_CreateThread, GC_ExitThread): If WINAPI
undefined (i.e., if windows.h not included by or prior to gc.h) then
declare the prototype using built-in C types instead of Windows types.

doc/README.macros
include/gc.h

index feb419dca2fadcd9188f977ec7fdb3f01498faeb..63a96f8051cd6ea304889053543e3f8d4fe0dfa0 100644 (file)
@@ -43,6 +43,10 @@ GC_NO_THREAD_REDIRECTS  Tested by gc.h.  Prevents redirection of thread
 GC_NO_THREAD_DECLS      Tested by gc.h.  MS Windows only.  Do not declare
                 Windows thread creation routines and do not include windows.h.
 
+GC_DONT_INCLUDE_WINDOWS_H   Tested by gc.h.  MS Windows only.  Do not include
+                windows.h from gc.h (but Windows-specific thread creation
+                routines are declared).
+
 GC_UNDERSCORE_STDCALL   Tested by gc.h.  Explicitly prefix exported/imported
                 WINAPI (__stdcall) symbols with '_' (underscore).  Could be
                 used with MinGW (for x86) compiler (in conjunction with
index abb097f07922ff2dee06e68771db01a68bf33f87..7c410434f45497b0685f68be6fa8a6b06bd7d992 100644 (file)
@@ -1498,7 +1498,9 @@ GC_API void GC_CALL GC_register_has_static_roots_callback(
 #     include <process.h> /* For _beginthreadex, _endthreadex */
 #   endif
 
-#   include <windows.h>
+#   if defined(GC_BUILD) || !defined(GC_DONT_INCLUDE_WINDOWS_H)
+#     include <windows.h>
+#   endif
 
 #   ifdef __cplusplus
       extern "C" {
@@ -1511,14 +1513,14 @@ GC_API void GC_CALL GC_register_has_static_roots_callback(
 #     define GC_ExitThread _GC_ExitThread
 #   endif
 
-#   ifdef GC_INSIDE_DLL
-      /* Export GC DllMain to be invoked from client DllMain.   */
-#     ifdef GC_UNDERSCORE_STDCALL
-#       define GC_DllMain _GC_DllMain
+#   ifndef DECLSPEC_NORETURN
+      /* Typically defined in winnt.h. */
+#     if defined(WINAPI)
+#       define DECLSPEC_NORETURN /* empty */
+#     else
+#       define DECLSPEC_NORETURN __declspec(noreturn)
 #     endif
-      GC_API BOOL WINAPI GC_DllMain(HINSTANCE /* inst */, ULONG /* reason */,
-                                    LPVOID /* reserved */);
-#   endif /* GC_INSIDE_DLL */
+#   endif
 
 #   if !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED) \
        && !defined(UINTPTR_MAX)
@@ -1526,7 +1528,28 @@ GC_API void GC_CALL GC_register_has_static_roots_callback(
 #   else
       typedef uintptr_t GC_uintptr_t;
 #   endif
-#   define GC_WIN32_SIZE_T GC_uintptr_t
+
+#   ifdef _WIN64
+#     define GC_WIN32_SIZE_T GC_uintptr_t
+#   elif defined(WINAPI) /* windows.h included */
+#     define GC_WIN32_SIZE_T DWORD
+#   else
+#     define GC_WIN32_SIZE_T unsigned long
+#   endif
+
+#   ifdef GC_INSIDE_DLL
+      /* Export GC DllMain to be invoked from client DllMain.   */
+#     ifdef GC_UNDERSCORE_STDCALL
+#       define GC_DllMain _GC_DllMain
+#     endif
+#     if defined(WINAPI) /* windows.h included */
+        GC_API BOOL WINAPI GC_DllMain(HINSTANCE /* inst */,
+                                      ULONG /* reason */,
+                                      LPVOID /* reserved */);
+#     else
+        GC_API int __stdcall GC_DllMain(void *, unsigned long, void *);
+#     endif
+#   endif /* GC_INSIDE_DLL */
 
     /* All threads must be created using GC_CreateThread or             */
     /* GC_beginthreadex, or must explicitly call GC_register_my_thread  */
@@ -1538,20 +1561,24 @@ GC_API void GC_CALL GC_register_has_static_roots_callback(
     /* Currently the collector expects all threads to fall through and  */
     /* terminate normally, or call GC_endthreadex() or GC_ExitThread,   */
     /* so that the thread is properly unregistered.                     */
-    GC_API HANDLE WINAPI GC_CreateThread(
+#   if defined(WINAPI) /* windows.h included */
+      GC_API HANDLE WINAPI GC_CreateThread(
                 LPSECURITY_ATTRIBUTES /* lpThreadAttributes */,
                 GC_WIN32_SIZE_T /* dwStackSize */,
                 LPTHREAD_START_ROUTINE /* lpStartAddress */,
                 LPVOID /* lpParameter */, DWORD /* dwCreationFlags */,
                 LPDWORD /* lpThreadId */);
 
-#   ifndef DECLSPEC_NORETURN
-      /* Typically defined in winnt.h. */
-#     define DECLSPEC_NORETURN /* empty */
-#   endif
-
-    GC_API DECLSPEC_NORETURN void WINAPI GC_ExitThread(
+      GC_API DECLSPEC_NORETURN void WINAPI GC_ExitThread(
                                                 DWORD /* dwExitCode */);
+#   else
+      struct _SECURITY_ATTRIBUTES;
+      GC_API void *__stdcall GC_CreateThread(struct _SECURITY_ATTRIBUTES *,
+                                GC_WIN32_SIZE_T,
+                                unsigned long (__stdcall *)(void *),
+                                void *, unsigned long, unsigned long *);
+      GC_API DECLSPEC_NORETURN void __stdcall GC_ExitThread(unsigned long);
+#   endif
 
 #   if !defined(_WIN32_WCE) && !defined(__CEGCC__)
       GC_API GC_uintptr_t GC_CALL GC_beginthreadex(