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

Commit

Permalink
add C mangling depending on toolchain (needed for OSX)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainers committed Nov 20, 2014
1 parent 29e4fdd commit f7d5f30
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
30 changes: 30 additions & 0 deletions src/core/demangle.d
Expand Up @@ -1824,6 +1824,35 @@ unittest
static assert(!__traits(compiles, mangleFunc!(typeof(&fooCPP))("")));
}

/**
* Mangles a C function or variable.
*
* Params:
* dst = An optional destination buffer.
*
* Returns:
* The mangled name for a C function or variable, i.e.
* an underscore is prepended or not, depending on the
* compiler/linker tool chain
*/
char[] mangleC(const(char)[] sym, char[] dst = null)
{
version(Win32)
enum string prefix = "_";
else version(OSX)
enum string prefix = "_";
else
enum string prefix = "";

auto len = sym.length + prefix.length;
if( dst.length < len )
dst.length = len;

dst[0 .. prefix.length] = prefix[];
dst[prefix.length .. len] = sym[];
return dst[0 .. len];
}


version(unittest)
{
Expand Down Expand Up @@ -1953,3 +1982,4 @@ string decodeDmdString( const(char)[] ln, ref size_t p )
}
return s;
}

9 changes: 5 additions & 4 deletions src/rt/config.d
Expand Up @@ -36,19 +36,20 @@ module rt.config;
// line arguments, i.e. if command line arguments are not disabled, they can override
// options specified through the environment or embedded in the executable.

import core.demangle : mangleC;

// put each variable in its own COMDAT by making them template instances
template rt_envvars_enabled()
{
pragma(mangle,"rt_envvars_enabled") __gshared bool rt_envvars_enabled = false;
pragma(mangle,mangleC("rt_envvars_enabled")) __gshared bool rt_envvars_enabled = false;
}
template rt_cmdline_enabled()
{
pragma(mangle,"rt_cmdline_enabled") __gshared bool rt_cmdline_enabled = true;
pragma(mangle,mangleC("rt_cmdline_enabled")) __gshared bool rt_cmdline_enabled = true;
}
template rt_options()
{
pragma(mangle,"rt_options") __gshared string[] rt_options = [];
pragma(mangle,mangleC("rt_options")) __gshared string[] rt_options = [];
}

import core.stdc.ctype : toupper;
Expand All @@ -64,7 +65,7 @@ extern extern(C) string[] rt_args() @nogc nothrow;
* returns the options' value if
* - set on the command line as "--DRT-<opt>=value" (rt_cmdline_enabled enabled)
* - the environment variable "DRT_<OPT>" is set (rt_envvars_enabled enabled)
* - drt_args[] contains an entry "<opt>=value"
* - rt_options[] contains an entry "<opt>=value"
* - null otherwise
*/
string rt_configOption(string opt) @nogc nothrow
Expand Down

0 comments on commit f7d5f30

Please sign in to comment.