From 096125d963400951e0f160ced86416ef8c9c98b0 Mon Sep 17 00:00:00 2001 From: grischka Date: Sat, 18 Feb 2017 09:51:23 +0100 Subject: win32: adjust new unicode support - lib/Makefile: add (win)crt1_w.o - crt1.c/_runtmain: return to tcc & only use for UNICODE (because it might be not 100% reliable with for example wildcards (tcc *.c -run ...) - tccrun.c/tccpe.c: load -run startup_code only if called from tcc_run(). Otherwise main may not be defined. See libtcc_test.c - tests2/Makefile: pass extra options in FLAGS to allow overriding TCC Also: - tccpe.c: support weak attribute. (I first tried to solve the problem above by using it but then didn't) --- win32/build-tcc.bat | 10 +++++----- win32/lib/crt1.c | 25 ++++++++++++------------- win32/lib/crt1w.c | 3 +++ win32/lib/wincrt1.c | 21 ++++++++++++--------- win32/lib/wincrt1w.c | 3 +++ 5 files changed, 35 insertions(+), 27 deletions(-) create mode 100644 win32/lib/crt1w.c create mode 100644 win32/lib/wincrt1w.c (limited to 'win32') diff --git a/win32/build-tcc.bat b/win32/build-tcc.bat index 8da1404..daf5a12 100644 --- a/win32/build-tcc.bat +++ b/win32/build-tcc.bat @@ -137,12 +137,12 @@ copy>nul tiny_libmaker.exe tiny_libmaker-m%T%.exe %CC% -o tiny_libmaker-m%TX%.exe tools\tiny_libmaker.c %DX% :libtcc1.a -@set O1=libtcc1.o crt1.o wincrt1.o crt1_w.o wincrt1_w.o dllcrt1.o dllmain.o chkstk.o bcheck.o +@set O1=libtcc1.o crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o bcheck.o .\tcc -m32 %D32% -c ../lib/libtcc1.c .\tcc -m32 %D32% -c lib/crt1.c -.\tcc -m32 %D32% -c lib/crt1.c -D_UNICODE -DUNICODE -o crt1_w.o +.\tcc -m32 %D32% -c lib/crt1w.c .\tcc -m32 %D32% -c lib/wincrt1.c -.\tcc -m32 %D32% -c lib/wincrt1.c -D_UNICODE -DUNICODE -o wincrt1_w.o +.\tcc -m32 %D32% -c lib/wincrt1w.c .\tcc -m32 %D32% -c lib/dllcrt1.c .\tcc -m32 %D32% -c lib/dllmain.c .\tcc -m32 %D32% -c lib/chkstk.S @@ -153,9 +153,9 @@ tiny_libmaker-m32 lib/32/libtcc1.a %O1% alloca86.o alloca86-bt.o @if errorlevel 1 goto :the_end .\tcc -m64 %D64% -c ../lib/libtcc1.c .\tcc -m64 %D64% -c lib/crt1.c -.\tcc -m64 %D64% -c lib/crt1.c -D_UNICODE -DUNICODE -o crt1_w.o +.\tcc -m64 %D64% -c lib/crt1w.c .\tcc -m64 %D64% -c lib/wincrt1.c -.\tcc -m64 %D64% -c lib/wincrt1.c -D_UNICODE -DUNICODE -o wincrt1_w.o +.\tcc -m64 %D64% -c lib/wincrt1w.c .\tcc -m64 %D64% -c lib/dllcrt1.c .\tcc -m64 %D64% -c lib/dllmain.c .\tcc -m64 %D64% -c lib/chkstk.S diff --git a/win32/lib/crt1.c b/win32/lib/crt1.c index 1e2bd17..a9b1a30 100644 --- a/win32/lib/crt1.c +++ b/win32/lib/crt1.c @@ -65,24 +65,23 @@ void _tstart(void) exit(ret); } -void _runtmain(int argc0, /* as tcc passed in */ char **argv0) +int _runtmain(int argc, /* as tcc passed in */ char **argv) { - __TRY__ - int argc, ret; - _TCHAR **argv; - _TCHAR **env; - _startupinfo start_info; - - __set_app_type(_CONSOLE_APP); +#ifdef UNICODE + int wargc; + _TCHAR **wargv, **wenv; + _startupinfo start_info = {0}; + + __tgetmainargs(&wargc, &wargv, &wenv, _dowildcard, &start_info); + if (argc < wargc) + wargv += wargc - argc; +#define argv wargv +#endif #ifdef __i386 _controlfp(_PC_53, _MCW_PC); #endif - - start_info.newmode = 0; - __tgetmainargs( &argc, &argv, &env, _dowildcard, &start_info); - ret = _tmain(argc0, argv + argc - argc0, env); - exit(ret); + return _tmain(argc, argv, NULL); } // ============================================= diff --git a/win32/lib/crt1w.c b/win32/lib/crt1w.c new file mode 100644 index 0000000..2b8bbc8 --- /dev/null +++ b/win32/lib/crt1w.c @@ -0,0 +1,3 @@ +#define _UNICODE 1 +#define UNICODE 1 +#include "crt1.c" diff --git a/win32/lib/wincrt1.c b/win32/lib/wincrt1.c index 06f42f0..a4197bb 100644 --- a/win32/lib/wincrt1.c +++ b/win32/lib/wincrt1.c @@ -68,22 +68,25 @@ int _twinstart(void) exit(ret); } -int _runtwinmain(int argc0, /* as tcc passed in */ char **argv0) +int _runtwinmain(int argc, /* as tcc passed in */ char **argv) { _TCHAR *szCmd, *p; - int argc; - _TCHAR **argv; - _TCHAR **env; - _startupinfo start_info; +#ifdef UNICODE + int wargc; + _TCHAR **wargv, **wenv; + _startupinfo start_info = {0}; - start_info.newmode = 0; - __tgetmainargs(&argc, &argv, &env, 0, &start_info); + __tgetmainargs(&wargc, &wargv, &wenv, 0, &start_info); + if (argc < wargc) + wargv += wargc - argc; +#define argv wargv +#endif p = GetCommandLine(); szCmd = NULL; - if (argc0 > 1) - szCmd = _tcsstr(p, argv[argc - argc0 + 1]); + if (argc > 1) + szCmd = _tcsstr(p, argv[1]); if (NULL == szCmd) szCmd = __T(""); else if (szCmd > p && szCmd[-1] == __T('\"')) diff --git a/win32/lib/wincrt1w.c b/win32/lib/wincrt1w.c new file mode 100644 index 0000000..a7d349e --- /dev/null +++ b/win32/lib/wincrt1w.c @@ -0,0 +1,3 @@ +#define _UNICODE 1 +#define UNICODE 1 +#include "wincrt1.c" -- cgit v1.3.1