From: Ivan Maidanski Date: Fri, 8 May 2015 06:26:36 +0000 (+0300) Subject: Enable gc.h inclusion by client without implicit include windows.h (Win32) X-Git-Tag: gc7_6_0~199^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=90dd15959a370cc0a6499731d5216b1cc9b4ac44;p=gc Enable gc.h inclusion by client without implicit include windows.h (Win32) * 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. --- diff --git a/doc/README.macros b/doc/README.macros index feb419dc..63a96f80 100644 --- a/doc/README.macros +++ b/doc/README.macros @@ -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 diff --git a/include/gc.h b/include/gc.h index abb097f0..7c410434 100644 --- a/include/gc.h +++ b/include/gc.h @@ -1498,7 +1498,9 @@ GC_API void GC_CALL GC_register_has_static_roots_callback( # include /* For _beginthreadex, _endthreadex */ # endif -# include +# if defined(GC_BUILD) || !defined(GC_DONT_INCLUDE_WINDOWS_H) +# include +# 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(