From a00f74a6b52f32f868a5ed96307d218cb81abf90 Mon Sep 17 00:00:00 2001 From: ivmai Date: Thu, 24 Sep 2009 07:31:03 +0000 Subject: [PATCH] 2009-09-24 Ivan Maidanski (ivmai145.diff) * Makefile.direct (GC_WINMAIN_REDIRECT): Add the comment for. * Makefile.direct (NO_GETENV): Update the comment. * include/gc.h (GC_WINMAIN_WINCE_LPTSTR): Remove macro. * include/gc.h (GC_WinMain): Remove declaration. * include/gc.h (WinMain): Define (as GC_WinMain) if and only if GC_WINMAIN_REDIRECT. * tests/test.c (GC_COND_INIT): Define as GC_INIT() also in case of WinCE target unless GC_WINMAIN_REDIRECT is defined. * tests/test.c (WINMAIN_LPTSTR): New macro. * tests/test.c (WinMain): Use WINMAIN_LPTSTR instead of LP[W]STR and GC_WINMAIN_WINCE_LPTSTR. * win32_threads.c (start_mark_threads): Add the comment for MARK_THREAD_STACK_SIZE. * win32_threads.c: Recognize new GC_WINMAIN_REDIRECT macro. * win32_threads.c (WINMAIN_LPTSTR, WINMAIN_THREAD_STACK_SIZE): New macro (only if GC_WINMAIN_REDIRECT). * win32_threads.c: Undefine WinMain macro if GC_WINMAIN_REDIRECT. * win32_threads.c (GC_WinMain): Add prototype (only if GC_WINMAIN_REDIRECT). * win32_threads.c (main_thread_args, WinMain): Rename GC_WINMAIN_WINCE_LPTSTR to WINMAIN_LPTSTR. * win32_threads.c (WinMain): Call GC_INIT() instead of GC_init(); use WINMAIN_THREAD_STACK_SIZE. * win32_threads.c (WinMain): Call GC_deinit() and DeleteCriticalSection() only if WinCE; add FIXME. --- ChangeLog | 29 +++++++++++++++++++++++++++++ Makefile.direct | 7 ++++++- include/gc.h | 26 +++++++++----------------- tests/test.c | 23 ++++++++++++----------- win32_threads.c | 41 +++++++++++++++++++++++++++++++---------- 5 files changed, 87 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index 74f3929f..421ae875 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2009-09-24 Ivan Maidanski + (ivmai145.diff) + + * Makefile.direct (GC_WINMAIN_REDIRECT): Add the comment for. + * Makefile.direct (NO_GETENV): Update the comment. + * include/gc.h (GC_WINMAIN_WINCE_LPTSTR): Remove macro. + * include/gc.h (GC_WinMain): Remove declaration. + * include/gc.h (WinMain): Define (as GC_WinMain) if and only if + GC_WINMAIN_REDIRECT. + * tests/test.c (GC_COND_INIT): Define as GC_INIT() also in case of + WinCE target unless GC_WINMAIN_REDIRECT is defined. + * tests/test.c (WINMAIN_LPTSTR): New macro. + * tests/test.c (WinMain): Use WINMAIN_LPTSTR instead of LP[W]STR + and GC_WINMAIN_WINCE_LPTSTR. + * win32_threads.c (start_mark_threads): Add the comment for + MARK_THREAD_STACK_SIZE. + * win32_threads.c: Recognize new GC_WINMAIN_REDIRECT macro. + * win32_threads.c (WINMAIN_LPTSTR, WINMAIN_THREAD_STACK_SIZE): New + macro (only if GC_WINMAIN_REDIRECT). + * win32_threads.c: Undefine WinMain macro if GC_WINMAIN_REDIRECT. + * win32_threads.c (GC_WinMain): Add prototype (only if + GC_WINMAIN_REDIRECT). + * win32_threads.c (main_thread_args, WinMain): Rename + GC_WINMAIN_WINCE_LPTSTR to WINMAIN_LPTSTR. + * win32_threads.c (WinMain): Call GC_INIT() instead of GC_init(); + use WINMAIN_THREAD_STACK_SIZE. + * win32_threads.c (WinMain): Call GC_deinit() and + DeleteCriticalSection() only if WinCE; add FIXME. + 2009-09-24 Ivan Maidanski * os_dep.c (GC_get_main_stack_base): add assertion for mem_base diff --git a/Makefile.direct b/Makefile.direct index f15d2657..ba1ca66f 100644 --- a/Makefile.direct +++ b/Makefile.direct @@ -281,10 +281,15 @@ HOSTCFLAGS=$(CFLAGS) # event objects (one per each marker instead of that based on Win32 # SignalObjectAndWait() using a single event object). This is the default # for WinCE. +# -DGC_WINMAIN_REDIRECT (Win32 only) Redirect (rename) an application WinMain +# to GC_WinMain; implement the "real" WinMain which starts a new thread to +# call GC_WinMain after initializing the GC. Useful for WinCE. +# Incompatible with GC_DLL. # -DNO_GETENV prevents the collector from looking at environment variables. # These may otherwise alter its configuration, or turn off GC altogether. # I don't know of a reason to disable this, except possibly if the -# resulting process runs as a privileged user? +# resulting process runs as a privileged user. (This is on by default for +# WinCE.) # -DUSE_GLOBAL_ALLOC. Win32 only. Use GlobalAlloc instead of # VirtualAlloc to allocate the heap. May be needed to work around # a Windows NT/2000 issue. Incompatible with USE_MUNMAP. diff --git a/include/gc.h b/include/gc.h index 549b9d83..4079132f 100644 --- a/include/gc.h +++ b/include/gc.h @@ -1267,25 +1267,17 @@ GC_API void GC_CALL GC_register_has_static_roots_callback( GC_API void GC_CALL GC_endthreadex(unsigned /* retval */); -# else - /* win32_threads.c implements the real WinMain, which will start */ - /* a new thread to call GC_WinMain after initializing the garbage */ - /* collector. */ -# ifdef UNDER_CE -# define GC_WINMAIN_WINCE_LPTSTR LPWSTR -# else -# define GC_WINMAIN_WINCE_LPTSTR LPSTR -# endif - /* not exported (since defined outside GC by an application) */ - int WINAPI GC_WinMain( - HINSTANCE /* hInstance */, HINSTANCE /* hPrevInstance */, - GC_WINMAIN_WINCE_LPTSTR /* lpCmdLine */, int /* nCmdShow */); -# ifndef GC_BUILD -# define WinMain GC_WinMain -# endif -# endif /* defined(_WIN32_WCE) */ +# endif /* !_WIN32_WCE */ + #endif /* !GC_NO_THREAD_DECLS */ +#ifdef GC_WINMAIN_REDIRECT + /* win32_threads.c implements the real WinMain(), which will start */ + /* a new thread to call GC_WinMain() after initializing the garbage */ + /* collector. */ +# define WinMain GC_WinMain +#endif + /* * Use implicit thread registration via DllMain. * Must be called before GC_INIT and other GC routines. diff --git a/tests/test.c b/tests/test.c index 4f59d322..5621db8f 100644 --- a/tests/test.c +++ b/tests/test.c @@ -82,7 +82,8 @@ /* Call GC_INIT only on platforms on which we think we really need it, */ /* so that we can test automatic initialization on the rest. */ #if defined(CYGWIN32) || defined (AIX) || defined(DARWIN) \ - || defined(THREAD_LOCAL_ALLOC) + || defined(THREAD_LOCAL_ALLOC) \ + || (defined(MSWINCE) && !defined(GC_WINMAIN_REDIRECT)) # define GC_COND_INIT() GC_INIT() #else # define GC_COND_INIT() @@ -1352,14 +1353,18 @@ void GC_CALLBACK warn_proc(char *msg, GC_word p) /*FAIL;*/ } +#if defined(MSWINCE) && defined(UNDER_CE) +# define WINMAIN_LPTSTR LPWSTR +#else +# define WINMAIN_LPTSTR LPSTR +#endif #if !defined(PCR) \ && !defined(GC_WIN32_THREADS) && !defined(GC_PTHREADS) \ || defined(LINT) -#if defined(MSWINCE) && defined(UNDER_CE) - int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prev, LPWSTR cmd, int n) -#elif defined(MSWIN32) && !defined(__MINGW32__) || defined(MSWINCE) - int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prev, LPSTR cmd, int n) +#if defined(MSWIN32) && !defined(__MINGW32__) || defined(MSWINCE) + int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prev, + WINMAIN_LPTSTR cmd, int n) #else int main(void) #endif @@ -1502,12 +1507,8 @@ DWORD __stdcall thr_window(void *arg) } #endif -#ifdef MSWINCE - int APIENTRY GC_WinMain(HINSTANCE instance, HINSTANCE prev, - GC_WINMAIN_WINCE_LPTSTR cmd, int n) -#else - int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prev, LPSTR cmd, int n) -#endif +int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prev, + WINMAIN_LPTSTR cmd, int n) { # if NTHREADS > 0 HANDLE h[NTHREADS]; diff --git a/win32_threads.c b/win32_threads.c index a115609f..e5f2e0c5 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -1644,7 +1644,8 @@ static void start_mark_threads(void) marker_last_stack_min[i] = ADDR_LIMIT; # ifdef MSWINCE /* There is no _beginthreadex() in WinCE. */ - handle = CreateThread(NULL /* lpsa */, MARK_THREAD_STACK_SIZE, + handle = CreateThread(NULL /* lpsa */, + MARK_THREAD_STACK_SIZE /* ignored */, GC_mark_thread, (LPVOID)(word)i, 0 /* fdwCreate */, &thread_id); if (handle == NULL) { @@ -2058,12 +2059,25 @@ GC_API void GC_CALL GC_endthreadex(unsigned retval) #endif /* !GC_PTHREADS */ -#if defined(MSWINCE) && !defined(GC_DLL) +#ifdef GC_WINMAIN_REDIRECT +/* This might be useful on WinCE. Shouldn't be used with GC_DLL. */ + +# if defined(MSWINCE) && defined(UNDER_CE) +# define WINMAIN_LPTSTR LPWSTR +# else +# define WINMAIN_LPTSTR LPSTR +# endif + +/* This is defined in gc.h. */ +# undef WinMain + +/* Defined outside GC by an application. */ +int WINAPI GC_WinMain(HINSTANCE, HINSTANCE, WINMAIN_LPTSTR, int); typedef struct { HINSTANCE hInstance; HINSTANCE hPrevInstance; - GC_WINMAIN_WINCE_LPTSTR lpCmdLine; + WINMAIN_LPTSTR lpCmdLine; int nShowCmd; } main_thread_args; @@ -2074,8 +2088,12 @@ static DWORD WINAPI main_thread_start(LPVOID arg) args->lpCmdLine, args->nShowCmd); } +# ifndef WINMAIN_THREAD_STACK_SIZE +# define WINMAIN_THREAD_STACK_SIZE 0 /* default value */ +# endif + int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - GC_WINMAIN_WINCE_LPTSTR lpCmdLine, int nShowCmd) + WINMAIN_LPTSTR lpCmdLine, int nShowCmd) { DWORD exit_code = 1; @@ -2086,10 +2104,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, DWORD thread_id; /* initialize everything */ - GC_init(); + GC_INIT(); /* start the main thread */ - thread_h = GC_CreateThread(NULL /* lpsa */, 0 /* dwStackSize (ignored) */, + thread_h = GC_CreateThread(NULL /* lpsa */, + WINMAIN_THREAD_STACK_SIZE /* ignored on WinCE */, main_thread_start, &args, 0 /* fdwCreate */, &thread_id); @@ -2103,13 +2122,15 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, ABORT("GC_CreateThread(main_thread) failed"); } - GC_deinit(); - DeleteCriticalSection(&GC_allocate_ml); - +# ifdef MSWINCE + /* FIXME: Is this really obligatory on WinCE? */ + GC_deinit(); + DeleteCriticalSection(&GC_allocate_ml); +# endif return (int) exit_code; } -#endif /* MSWINCE */ +#endif /* GC_WINMAIN_REDIRECT */ /* Called by GC_init() - we hold the allocation lock. */ void GC_thr_init(void) { -- 2.40.0