private
{
+ import memory;
import util.console;
- import stdc.stddef;
- import stdc.stdlib;
- import stdc.string;
+ import core.stdc.stddef;
+ import core.stdc.stdlib;
+ import core.stdc.string;
}
-version( Windows )
+version (Windows)
{
+ extern (Windows) alias int function() FARPROC;
+ extern (Windows) FARPROC GetProcAddress(void*, in char*);
+ extern (Windows) void* LoadLibraryA(in char*);
+ extern (Windows) int FreeLibrary(void*);
extern (Windows) void* LocalFree(void*);
extern (Windows) wchar_t* GetCommandLineW();
extern (Windows) wchar_t** CommandLineToArgvW(wchar_t*, int*);
extern (Windows) export int WideCharToMultiByte(uint, uint, wchar_t*, int, char*, int, char*, int);
- pragma(lib, "shell32.lib"); // needed for CommandLineToArgvW
+ pragma(lib, "shell32.lib"); // needed for CommandLineToArgvW
}
extern (C) void _STI_monitor_staticctor();
extern (C) void _moduleDtor();
extern (C) void thread_joinAll();
+/***********************************
+ * These are a temporary means of providing a GC hook for DLL use. They may be
+ * replaced with some other similar functionality later.
+ */
+extern (C)
+{
+ void* gc_getProxy();
+ void gc_setProxy(void* p);
+ void gc_clrProxy();
+
+ alias void* function() gcGetFn;
+ alias void function(void*) gcSetFn;
+ alias void function() gcClrFn;
+}
+
+extern (C) void* rt_loadLibrary(in char[] name)
+{
+ version (Windows)
+ {
+ char[260] temp = void;
+ temp[0 .. name.length] = name[];
+ temp[name.length] = cast(char) 0;
+ void* ptr = LoadLibraryA(temp.ptr);
+ if (ptr is null)
+ return ptr;
+ gcSetFn gcSet = cast(gcSetFn) GetProcAddress(ptr, "gc_setProxy");
+ if (gcSet !is null)
+ gcSet(gc_getProxy());
+ return ptr;
+
+ }
+ else version (linux)
+ {
+ throw new Exception("rt_loadLibrary not yet implemented on linux.");
+ }
+}
+
+extern (C) bool rt_unloadLibrary(void* ptr)
+{
+ version (Windows)
+ {
+ gcClrFn gcClr = cast(gcClrFn) GetProcAddress(ptr, "gc_clrProxy");
+ if (gcClr !is null)
+ gcClr();
+ return FreeLibrary(ptr) != 0;
+ }
+ else version (linux)
+ {
+ throw new Exception("rt_unloadLibrary not yet implemented on linux.");
+ }
+}
+
/***********************************
* These functions must be defined for any D program linked
* against this library.
*/
-extern (C) void onAssertError( char[] file, size_t line );
-extern (C) void onAssertErrorMsg( char[] file, size_t line, char[] msg );
-extern (C) void onArrayBoundsError( char[] file, size_t line );
-extern (C) void onSwitchError( char[] file, size_t line );
+extern (C) void onAssertError(string file, size_t line);
+extern (C) void onAssertErrorMsg(string file, size_t line, string msg);
+extern (C) void onRangeError(string file, size_t line);
+extern (C) void onHiddenFuncError(Object o);
+extern (C) void onSwitchError(string file, size_t line);
extern (C) bool runModuleUnitTests();
// this function is called from the utf module
-//extern (C) void onUnicodeError( char[] msg, size_t idx );
+//extern (C) void onUnicodeError(string msg, size_t idx);
/***********************************
* These are internal callbacks for various language errors.
*/
-extern (C) void _d_assert( char[] file, uint line )
+extern (C) void _d_assert(string file, uint line)
{
- onAssertError( file, line );
+ onAssertError(file, line);
}
-extern (C) static void _d_assert_msg( char[] msg, char[] file, uint line )
+extern (C) static void _d_assert_msg(string msg, string file, uint line)
{
- onAssertErrorMsg( file, line, msg );
+ onAssertErrorMsg(file, line, msg);
}
-extern (C) void _d_array_bounds( char[] file, uint line )
+extern (C) void _d_array_bounds(string file, uint line)
{
- onArrayBoundsError( file, line );
+ onRangeError(file, line);
}
-extern (C) void _d_switch_error( char[] file, uint line )
+extern (C) void _d_switch_error(string file, uint line)
{
- onSwitchError( file, line );
+ onSwitchError(file, line);
+}
+
+extern (C) void _d_hidden_func()
+{
+ Object o;
+ asm
+ {
+ mov o, EAX;
+ }
+ onHiddenFuncError(o);
}
bool _d_isHalting = false;
}
}
-alias void delegate( Exception ) ExceptionHandler;
+alias void delegate(Throwable) ExceptionHandler;
-extern (C) bool rt_init( ExceptionHandler dg = null )
+extern (C) bool rt_init(ExceptionHandler dg = null)
{
_d_criticalInit();
try
{
gc_init();
+ initStaticDataGC();
version (Windows)
_minit();
_moduleCtor();
return true;
}
- catch( Exception e )
+ catch (Throwable e)
{
- if( dg )
- dg( e );
+ if (dg)
+ dg(e);
}
catch
{
}
}
-extern (C) bool rt_term( ExceptionHandler dg = null )
+extern (C) bool rt_term(ExceptionHandler dg = null)
{
try
{
gc_term();
return true;
}
- catch( Exception e )
+ catch (Throwable e)
{
- if( dg )
- dg( e );
+ if (dg)
+ dg(e);
}
catch
{
for (size_t i = 0, p = 0; i < wargc; i++)
{
- int wlen = wcslen( wargs[i] );
+ int wlen = wcslen(wargs[i]);
int clen = WideCharToMultiByte(65001, 0, &wargs[i][0], wlen, null, 0, null, 0);
args[i] = cargp[p .. p+clen];
p += clen; assert(p <= cargl);
bool trapExceptions = rt_trapExceptions;
- void tryExec(void delegate() dg)
+ void tryExec(scope void delegate() dg)
{
if (trapExceptions)
{
dg();
}
- catch (Exception e)
+ catch (Throwable e)
{
while (e)
{
if (e.file)
{
- // fprintf(stderr, "%.*s(%u): %.*s\n", e.file, e.line, e.msg);
- console (e.classinfo.name)("@")(e.file)("(")(e.line)("): ")(e.toString)("\n");
+ // fprintf(stderr, "%.*s(%u): %.*s\n", e.file, e.line, e.msg);
+ console (e.classinfo.name)("@")(e.file)("(")(e.line)("): ")(e.msg)("\n");
}
else
{
- // fprintf(stderr, "%.*s\n", e.toString());
- console (e.classinfo.name)(": ")(e.toString)("\n");
+ // fprintf(stderr, "%.*s\n", e.toString());
+ console (e.toString)("\n");
}
if (e.info)
{
void runAll()
{
gc_init();
+ initStaticDataGC();
version (Windows)
_minit();
_moduleCtor();