Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #564 from WalterBright/move-to-exception
Browse files Browse the repository at this point in the history
move exception functions to exception.d
  • Loading branch information
andralex committed Aug 11, 2013
2 parents 9b0b6e3 + 454b004 commit 975254c
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 100 deletions.
104 changes: 96 additions & 8 deletions src/core/exception.d
Expand Up @@ -2,17 +2,13 @@
* The exception module defines all system-level exceptions and provides a
* mechanism to alter system-level error handling.
*
* Copyright: Copyright Sean Kelly 2005 - 2011.
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Copyright: Copyright Sean Kelly 2005 - 2013.
* License: Distributed under the
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
* (See accompanying file LICENSE)
* Authors: Sean Kelly and Jonathan M Davis
* Source: $(DRUNTIMESRC core/_exception.d)
*/

/* Copyright Sean Kelly 2005 - 2011.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
module core.exception;

import core.stdc.stdio;
Expand Down Expand Up @@ -564,3 +560,95 @@ extern (C) void onUnicodeError( string msg, size_t idx, string file = __FILE__,
{
throw new UnicodeException( msg, idx, file, line );
}

/***********************************
* These functions must be defined for any D program linked
* against this library.
*/
/+
extern (C) void onAssertError(string file, size_t line);
extern (C) void onAssertErrorMsg(string file, size_t line, string msg);
extern (C) void onUnittestErrorMsg(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);
+/

/***********************************
* Function calls to these are generated by the compiler and inserted into
* the object code.
*/

extern (C)
{
// Use ModuleInfo to get file name for "m" versions

/* One of these three is called upon an assert() fail.
*/
void _d_assertm(ModuleInfo* m, uint line)
{
onAssertError(m.name, line);
}

void _d_assert_msg(string msg, string file, uint line)
{
onAssertErrorMsg(file, line, msg);
}

void _d_assert(string file, uint line)
{
onAssertError(file, line);
}

/* One of these three is called upon an assert() fail inside of a unittest block
*/
void _d_unittestm(ModuleInfo* m, uint line)
{
_d_unittest(m.name, line);
}

void _d_unittest_msg(string msg, string file, uint line)
{
onUnittestErrorMsg(file, line, msg);
}

void _d_unittest(string file, uint line)
{
_d_unittest_msg("unittest failure", file, line);
}

/* Called when an array index is out of bounds
*/
void _d_array_bounds(ModuleInfo* m, uint line)
{
onRangeError(m.name, line);
}

/* Called when a switch statement has no DefaultStatement, yet none of the cases match
*/
void _d_switch_error(ModuleInfo* m, uint line)
{
onSwitchError(m.name, line);
}

void _d_hidden_func()
{
Object o;
version(D_InlineAsm_X86)
asm
{
mov o, EAX;
}
else version(D_InlineAsm_X86_64)
asm
{
mov o, RDI;
}
else
static assert(0, "unknown os");

onHiddenFuncError(o);
}
}


93 changes: 1 addition & 92 deletions src/rt/dmain2.d
Expand Up @@ -60,6 +60,7 @@ extern (C) void rt_moduleTlsCtor();
extern (C) void rt_moduleDtor();
extern (C) void rt_moduleTlsDtor();
extern (C) void thread_joinAll();
extern (C) bool runModuleUnitTests();

version (OSX)
{
Expand Down Expand Up @@ -155,98 +156,6 @@ extern (C) bool rt_unloadLibrary(void* ptr)
}
}

/***********************************
* These functions must be defined for any D program linked
* against this library.
*/
extern (C) void onAssertError(string file, size_t line);
extern (C) void onAssertErrorMsg(string file, size_t line, string msg);
extern (C) void onUnittestErrorMsg(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(string msg, size_t idx);

/***********************************
* Function calls to these are generated by the compiler and inserted into
* the object code.
*/

extern (C)
{
// Use ModuleInfo to get file name for "m" versions

/* One of these three is called upon an assert() fail.
*/
void _d_assertm(ModuleInfo* m, uint line)
{
onAssertError(m.name, line);
}

void _d_assert_msg(string msg, string file, uint line)
{
onAssertErrorMsg(file, line, msg);
}

void _d_assert(string file, uint line)
{
onAssertError(file, line);
}

/* One of these three is called upon an assert() fail inside of a unittest block
*/
void _d_unittestm(ModuleInfo* m, uint line)
{
_d_unittest(m.name, line);
}

void _d_unittest_msg(string msg, string file, uint line)
{
onUnittestErrorMsg(file, line, msg);
}

void _d_unittest(string file, uint line)
{
_d_unittest_msg("unittest failure", file, line);
}

/* Called when an array index is out of bounds
*/
void _d_array_bounds(ModuleInfo* m, uint line)
{
onRangeError(m.name, line);
}

/* Called when a switch statement has no DefaultStatement, yet none of the cases match
*/
void _d_switch_error(ModuleInfo* m, uint line)
{
onSwitchError(m.name, line);
}

void _d_hidden_func()
{
Object o;
version(D_InlineAsm_X86)
asm
{
mov o, EAX;
}
else version(D_InlineAsm_X86_64)
asm
{
mov o, RDI;
}
else
static assert(0, "unknown os");

onHiddenFuncError(o);
}
}

/* To get out-of-band access to the args[] passed to main().
*/

Expand Down

0 comments on commit 975254c

Please sign in to comment.