annotate tango/lib/compiler/llvmdc/dmain2.d @ 409:8d62834490d8

Fixed (I hope) problem with monitor/synchronized stuff not being properly initialized on Windows.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sun, 27 Jul 2008 15:03:04 +0200
parents 56a1c1c52142
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
1 /*
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
2 * Placed into the Public Domain.
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
3 * written by Walter Bright
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
4 * www.digitalmars.com
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
5 */
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
6
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
7 /*
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
8 * Modified by Sean Kelly <sean@f4.ca> for use with Tango.
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
9 */
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
10
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
11 private
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
12 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
13 import util.console;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
14
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
15 import tango.stdc.stddef;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
16 import tango.stdc.stdlib;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
17 import tango.stdc.string;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
18 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
19
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
20 version( Win32 )
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
21 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
22 extern (Windows) void* LocalFree(void*);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
23 extern (Windows) wchar_t* GetCommandLineW();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
24 extern (Windows) wchar_t** CommandLineToArgvW(wchar_t*, int*);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
25 extern (Windows) export int WideCharToMultiByte(uint, uint, wchar_t*, int, char*, int, char*, int);
402
56a1c1c52142 Removed unneeded references to _minit on Windows which breaks linking. _minit is an artifact of DMD on Win32.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 133
diff changeset
26 //pragma(lib, "shell32.lib"); // needed for CommandLineToArgvW
56a1c1c52142 Removed unneeded references to _minit on Windows which breaks linking. _minit is an artifact of DMD on Win32.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 133
diff changeset
27 //pragma(lib, "tango-win32-dmd.lib"); // links Tango's Win32 library to reduce EXE size
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
28 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
29
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
30 extern (C) void _STI_monitor_staticctor();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
31 extern (C) void _STD_monitor_staticdtor();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
32 extern (C) void _STI_critical_init();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
33 extern (C) void _STD_critical_term();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
34 extern (C) void gc_init();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
35 extern (C) void gc_term();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
36 extern (C) void _moduleCtor();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
37 extern (C) void _moduleDtor();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
38 extern (C) void thread_joinAll();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
39
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
40 //debug=PRINTF;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
41 debug(PRINTF) extern (C) int printf(char*, ...);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
42
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
43 /***********************************
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
44 * These functions must be defined for any D program linked
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
45 * against this library.
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
46 */
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
47 extern (C) void onAssertError( char[] file, size_t line );
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
48 extern (C) void onAssertErrorMsg( char[] file, size_t line, char[] msg );
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
49 extern (C) void onArrayBoundsError( char[] file, size_t line );
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
50 extern (C) void onSwitchError( char[] file, size_t line );
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
51 extern (C) bool runModuleUnitTests();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
52
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
53 // this function is called from the utf module
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
54 //extern (C) void onUnicodeError( char[] msg, size_t idx );
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
55
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
56 /***********************************
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
57 * These are internal callbacks for various language errors.
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
58 */
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
59 extern (C) void _d_assert( char[] file, uint line )
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
60 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
61 onAssertError( file, line );
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
62 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
63
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
64 extern (C) void _d_assert_msg( char[] msg, char[] file, uint line )
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
65 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
66 onAssertErrorMsg( file, line, msg );
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
67 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
68
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
69 extern (C) void _d_array_bounds( char[] file, uint line )
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
70 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
71 onArrayBoundsError( file, line );
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
72 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
73
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
74 extern (C) void _d_switch_error( char[] file, uint line )
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
75 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
76 onSwitchError( file, line );
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
77 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
78
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
79 bool _d_isHalting = false;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
80
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
81 extern (C) bool rt_isHalting()
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
82 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
83 return _d_isHalting;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
84 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
85
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
86 extern (C) bool rt_trapExceptions = true;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
87
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
88 void _d_criticalInit()
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
89 {
409
8d62834490d8 Fixed (I hope) problem with monitor/synchronized stuff not being properly initialized on Windows.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 402
diff changeset
90 _STI_monitor_staticctor();
8d62834490d8 Fixed (I hope) problem with monitor/synchronized stuff not being properly initialized on Windows.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 402
diff changeset
91 _STI_critical_init();
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
92 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
93
409
8d62834490d8 Fixed (I hope) problem with monitor/synchronized stuff not being properly initialized on Windows.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 402
diff changeset
94 // this is here so users can manually initialize the runtime
8d62834490d8 Fixed (I hope) problem with monitor/synchronized stuff not being properly initialized on Windows.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 402
diff changeset
95 // for example, when there is no main function etc.
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
96 extern (C) bool rt_init( void delegate( Exception ) dg = null )
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
97 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
98 _d_criticalInit();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
99
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
100 try
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
101 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
102 gc_init();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
103 _moduleCtor();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
104 return true;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
105 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
106 catch( Exception e )
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
107 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
108 if( dg )
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
109 dg( e );
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
110 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
111 catch
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
112 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
113
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
114 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
115 _d_criticalTerm();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
116 return false;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
117 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
118
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
119 void _d_criticalTerm()
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
120 {
409
8d62834490d8 Fixed (I hope) problem with monitor/synchronized stuff not being properly initialized on Windows.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 402
diff changeset
121 _STD_critical_term();
8d62834490d8 Fixed (I hope) problem with monitor/synchronized stuff not being properly initialized on Windows.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 402
diff changeset
122 _STD_monitor_staticdtor();
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
123 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
124
409
8d62834490d8 Fixed (I hope) problem with monitor/synchronized stuff not being properly initialized on Windows.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 402
diff changeset
125 // this is here so users can manually terminate the runtime
8d62834490d8 Fixed (I hope) problem with monitor/synchronized stuff not being properly initialized on Windows.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 402
diff changeset
126 // for example, when there is no main function etc.
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
127 extern (C) bool rt_term( void delegate( Exception ) dg = null )
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
128 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
129 try
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
130 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
131 thread_joinAll();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
132 _d_isHalting = true;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
133 _moduleDtor();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
134 gc_term();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
135 return true;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
136 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
137 catch( Exception e )
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
138 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
139 if( dg )
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
140 dg( e );
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
141 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
142 catch
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
143 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
144
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
145 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
146 finally
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
147 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
148 _d_criticalTerm();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
149 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
150 return false;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
151 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
152
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
153 /***********************************
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
154 * The D main() function supplied by the user's program
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
155 */
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
156 int main(char[][] args);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
157
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
158 /***********************************
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
159 * Substitutes for the C main() function.
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
160 * It's purpose is to wrap the call to the D main()
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
161 * function and catch any unhandled exceptions.
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
162 */
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
163
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
164 extern (C) int main(int argc, char **argv, char** env)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
165 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
166 char[][] args;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
167 int result;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
168
409
8d62834490d8 Fixed (I hope) problem with monitor/synchronized stuff not being properly initialized on Windows.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 402
diff changeset
169 debug(PRINTF) printf("main ctors\n");
8d62834490d8 Fixed (I hope) problem with monitor/synchronized stuff not being properly initialized on Windows.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 402
diff changeset
170 _STI_monitor_staticctor();
8d62834490d8 Fixed (I hope) problem with monitor/synchronized stuff not being properly initialized on Windows.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 402
diff changeset
171 _STI_critical_init();
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
172
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
173 debug(PRINTF) printf("main args\n");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
174 version (Win32)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
175 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
176 wchar_t* wcbuf = GetCommandLineW();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
177 size_t wclen = wcslen(wcbuf);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
178 int wargc = 0;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
179 wchar_t** wargs = CommandLineToArgvW(wcbuf, &wargc);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
180 assert(wargc == argc);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
181
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
182 char* cargp = null;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
183 size_t cargl = WideCharToMultiByte(65001, 0, wcbuf, wclen, null, 0, null, 0);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
184
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
185 cargp = cast(char*) alloca(cargl);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
186 args = ((cast(char[]*) alloca(wargc * (char[]).sizeof)))[0 .. wargc];
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
187
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
188 for (size_t i = 0, p = 0; i < wargc; i++)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
189 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
190 int wlen = wcslen( wargs[i] );
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
191 int clen = WideCharToMultiByte(65001, 0, &wargs[i][0], wlen, null, 0, null, 0);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
192 args[i] = cargp[p .. p+clen];
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
193 p += clen; assert(p <= cargl);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
194 WideCharToMultiByte(65001, 0, &wargs[i][0], wlen, &args[i][0], clen, null, 0);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
195 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
196 LocalFree(wargs);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
197 wargs = null;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
198 wargc = 0;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
199 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
200 else version (linux)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
201 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
202 char[]* am = cast(char[]*) malloc(argc * (char[]).sizeof);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
203 scope(exit) free(am);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
204
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
205 for (size_t i = 0; i < argc; i++)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
206 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
207 auto len = strlen(argv[i]);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
208 am[i] = argv[i][0 .. len];
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
209 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
210 args = am[0 .. argc];
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
211 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
212
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
213 debug(PRINTF) printf("main trap exceptions\n");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
214 bool trapExceptions = rt_trapExceptions;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
215
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
216 void tryExec(void delegate() dg)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
217 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
218 debug(PRINTF) printf("main try exec\n");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
219 if (trapExceptions)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
220 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
221 try
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
222 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
223 dg();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
224 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
225 catch (Exception e)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
226 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
227 while (e)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
228 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
229 if (e.file)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
230 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
231 debug(PRINTF) printf("%.*s(%u): %.*s\n", e.file.length, e.file.ptr, e.line, e.msg.length, e.msg.ptr);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
232 console (e.classinfo.name)("@")(e.file)("(")(e.line)("): ")(e.msg)("\n");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
233 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
234 else
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
235 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
236 // debug(PRINTF) printf("%.*s\n", e.toString());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
237 console (e.classinfo.name)(": ")(e.toString)("\n");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
238 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
239 e = e.next;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
240 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
241 result = EXIT_FAILURE;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
242 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
243 catch (Object o)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
244 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
245 // fprintf(stderr, "%.*s\n", o.toString());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
246 console (o.toString)("\n");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
247 result = EXIT_FAILURE;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
248 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
249 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
250 else
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
251 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
252 dg();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
253 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
254 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
255
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
256 // NOTE: The lifetime of a process is much like the lifetime of an object:
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
257 // it is initialized, then used, then destroyed. If initialization
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
258 // fails, the successive two steps are never reached. However, if
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
259 // initialization succeeds, then cleanup will occur even if the use
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
260 // step fails in some way. Here, the use phase consists of running
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
261 // the user's main function. If main terminates with an exception,
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
262 // the exception is handled and then cleanup begins. An exception
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
263 // thrown during cleanup, however, will abort the cleanup process.
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
264
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
265 void runMain()
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
266 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
267 debug(PRINTF) printf("main runMain\n");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
268 result = main(args);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
269 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
270
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
271 void runAll()
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
272 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
273 debug(PRINTF) printf("main runAll\n");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
274 gc_init();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
275 _moduleCtor();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
276 if (runModuleUnitTests())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
277 tryExec(&runMain);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
278 thread_joinAll();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
279 _d_isHalting = true;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
280 _moduleDtor();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
281 gc_term();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
282 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
283
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
284 tryExec(&runAll);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
285
409
8d62834490d8 Fixed (I hope) problem with monitor/synchronized stuff not being properly initialized on Windows.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 402
diff changeset
286 debug(PRINTF) printf("main dtor\n");
8d62834490d8 Fixed (I hope) problem with monitor/synchronized stuff not being properly initialized on Windows.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 402
diff changeset
287 _STD_critical_term();
8d62834490d8 Fixed (I hope) problem with monitor/synchronized stuff not being properly initialized on Windows.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 402
diff changeset
288 _STD_monitor_staticdtor();
8d62834490d8 Fixed (I hope) problem with monitor/synchronized stuff not being properly initialized on Windows.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 402
diff changeset
289
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
290 return result;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
diff changeset
291 }