Skip to content

Commit

Permalink
Merge the svn
Browse files Browse the repository at this point in the history
  • Loading branch information
SiegeLord committed Apr 8, 2012
2 parents 47b0d52 + 1afaf28 commit 6821850
Show file tree
Hide file tree
Showing 24 changed files with 2,280 additions and 193 deletions.
3 changes: 2 additions & 1 deletion tango/core/Array.d
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,7 @@ else
buf[p2] = t;
}

if( buf.length < 2 )
if( buf.length < 1 )
return 0;

size_t l = 0,
Expand Down Expand Up @@ -1955,6 +1955,7 @@ else
test( "abcdefg".dup, ( char c ) { return c < 'd'; }, 3 );
test( "gfedcba".dup, ( char c ) { return c < 'd'; }, 3 );
test( "bbdaabc".dup, ( char c ) { return c < 'c'; }, 5 );
test( "f".dup, ( char c ) { return c == 'f'; }, 1 );
}
}
}
Expand Down
58 changes: 57 additions & 1 deletion tango/core/BitManip.d
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ debug( UnitTest )
*/
uint bitswap( uint x )
{
version( D_InlineAsm_X86 )
{
asm
Expand Down Expand Up @@ -286,11 +285,68 @@ uint bitswap( uint x )
}
/**
* Reverses the order of bits in a 64-bit integer.
*/
ulong bitswap ( ulong x )
{
version( D_InlineAsm_X86_64 )
{
asm
{
// Author: Tiago Gasiba.
mov RAX, x;
mov RDX, RAX;
shr RAX, 1;
mov RCX, 0x5555_5555_5555_5555L;
and RDX, RCX;
and RAX, RCX;
shl RDX, 1;
or RAX, RDX;
mov RDX, RAX;
shr RAX, 2;
mov RCX, 0x3333_3333_3333_3333L;
and RDX, RCX;
and RAX, RCX;
shl RDX, 2;
or RAX, RDX;
mov RDX, RAX;
shr RAX, 4;
mov RCX, 0x0f0f_0f0f_0f0f_0f0fL;
and RDX, RCX;
and RAX, RCX;
shl RDX, 4;
or RAX, RDX;
bswap RAX;
}
}
else
{
// swap odd and even bits
x = ((x >> 1) & 0x5555_5555_5555_5555L) | ((x & 0x5555_5555_5555_5555L) << 1);
// swap consecutive pairs
x = ((x >> 2) & 0x3333_3333_3333_3333L) | ((x & 0x3333_3333_3333_3333L) << 2);
// swap nibbles
x = ((x >> 4) & 0x0f0f_0f0f_0f0f_0f0fL) | ((x & 0x0f0f_0f0f_0f0f_0f0fL) << 4);
// swap bytes
x = ((x >> 8) & 0x00FF_00FF_00FF_00FFL) | ((x & 0x00FF_00FF_00FF_00FFL) << 8);
// swap shorts
x = ((x >> 16) & 0x0000_FFFF_0000_FFFFL) | ((x & 0x0000_FFFF_0000_FFFFL) << 16);
// swap ints
x = ( x >> 32 ) | ( x << 32);
return x;
}
}
debug( UnitTest )
{
unittest
{
assert( bitswap( 0x8000_0100 ) == 0x0080_0001 );
assert( bitswap( 0x8000_0100_0080_0001 ) == 0x1000_0800_0010_0008 );
}
}
Expand Down
4 changes: 2 additions & 2 deletions tango/core/Thread.d
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ else version( Posix )
push R13 ;
push R14 ;
push R15 ;
push EAX ; // 16 byte align the stack
push RAX ; // 16 byte align the stack
}
}
else
Expand Down Expand Up @@ -443,7 +443,7 @@ else version( Posix )
asm
{
// Not sure what goes here, popad is invalid in 64 bit code
pop EAX ; // 16 byte align the stack
pop RAX ; // 16 byte align the stack
pop R15 ;
pop R14 ;
pop R13 ;
Expand Down
19 changes: 10 additions & 9 deletions tango/core/sync/Atomic.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* concurrent programming.
* The current design replaces the previous Atomic module by Sean and is inspired
* partly by the llvm atomic operations, and Sean's version
*
*
* If no atomic ops are available an (inefficent) fallback solution is provided
* For classes atomic access means atomic access to their *address* not their content
*
*
* If you want unique counters or flags to communicate in multithreading settings
* look at tango.core.sync.Counter that provides them in a better way and handles
* better the absence of atomic ops.
Expand Down Expand Up @@ -67,8 +67,8 @@ private {
is( T == ulong )/+||
is( T == ucent )+/;
}
/// substitutes classes with void*

/// substitutes classes with void*
template ClassPtr(T){
static if (is(T==class)){
alias void* ClassPtr;
Expand Down Expand Up @@ -106,7 +106,7 @@ template atomicValueIsProperlyAligned( T )
* if device is true als uncached and device memory is synchronized
*
* Barriers are typically paired
*
*
* For example if you want to ensure that all writes
* are done before setting a flags that communicates that an objects is initialized you would
* need memoryBarrier(false,false,false,true) before setting the flag.
Expand All @@ -117,7 +117,7 @@ template atomicValueIsProperlyAligned( T )
* incompatible definitions around (some obviously wrong), so some care migth be in order
* To be safer memoryBarrier(false,true,false,true) might be used for acquire, and
* memoryBarrier(true,false,true,false) for release which are slighlty stronger.
*
*
* These barriers are also called write barrier and read barrier respectively.
*
* A full memory fence is (true,true,true,true) and ensures that stores and loads before the
Expand All @@ -129,7 +129,8 @@ template atomicValueIsProperlyAligned( T )
version( LDC )
{
void memoryBarrier(bool ll, bool ls, bool sl,bool ss,bool device=false)(){
llvm_memory_barrier(ll,ls,sl,ss,device);
// XXX: this is overly conservative
llvm_memory_fence();
}
} else */version(D_InlineAsm_X86){
void memoryBarrier(bool ll, bool ls, bool sl,bool ss,bool device=false)(){
Expand Down Expand Up @@ -359,7 +360,7 @@ private T aCasT(T,V)(ref T val, T newval, T equalTo){
vAtt.v=atomicCAS(*valPtr.v,vNew.v,vOld.v);
return vAtt.t;
}
/// internal reduction
/// internal reduction
private T aCas(T)(ref T val, T newval, T equalTo){
static if (T.sizeof==1){
return aCasT!(T,ubyte)(val,newval,equalTo);
Expand All @@ -378,7 +379,7 @@ private T aCas(T)(ref T val, T newval, T equalTo){
* Atomic compare & exchange (can be used to implement everything else)
* stores newval into val if val==equalTo in one atomic operation.
* Barriers are not implied, just atomicity!
* Returns the value that is checked against equalTo (i.e. an exchange was performed
* Returns the value that is checked against equalTo (i.e. an exchange was performed
* if result==equalTo, otherwise one can use the result as the current value).
*/
version(LDC){
Expand Down
6 changes: 6 additions & 0 deletions tango/core/tools/Demangler.d
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ public class Demangler
/** Demangles the given string. */
public inout(char)[] demangle (inout(char)[] input)
{
// Special case for "_Dmain"
if (input == "_Dmain")
return "main";
char[4096] buf=void;
auto res=DemangleInstance(this,input,buf);
if (res.mangledName() && res.input.length==0){
Expand All @@ -262,6 +265,9 @@ public class Demangler
/** Demangles the given string using output to hold the result. */
public inout(char)[] demangle (inout(char)[] input, char[] output)
{
// Special case for "_Dmain"
if (input == "_Dmain")
return "main";
auto res=DemangleInstance(this,input,output);
if (res.mangledName () && res.input.length==0) {
return cast(inout(char)[])res.slice();
Expand Down
76 changes: 63 additions & 13 deletions tango/core/tools/StackTrace.d
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,48 @@ shared static this(){
internalFuncs["_D5tango4core10stacktrace10StackTrace14BasicTraceInfo5traceMFPS5tango4core10stacktrace10StackTrace12TraceContextiZv"]=1;
internalFuncs["_D5tango4core10stacktrace10StackTrace11basicTracerFPvZC9Exception9TraceInfo"]=1;
internalFuncs["_rt_createTraceContext"]=1;
internalFuncs["_D2rt6dmain24mainUiPPaZi7runMainMFZv"]=1;
internalFuncs["_D2rt6dmain24mainUiPPaZi6runAllMFZv"]=1;
internalFuncs["_D2rt6dmain24mainUiPPaZi7tryExecMFDFZvZv"]=1;
internalFuncs["_D2rt8compiler3dmd2rt6dmain24mainUiPPaZi7runMainMFZv"]=1;
internalFuncs["_D2rt8compiler3dmd2rt6dmain24mainUiPPaZi6runAllMFZv"]=1;
internalFuncs["_D2rt8compiler3dmd2rt6dmain24mainUiPPaZi7tryExecMFDFZvZv"]=1;
internalFuncs["main"]=1;
// glib specific
internalFuncs["__libc_start_main"]=1;
// backtrace() gets always the backtrace at the point it were called, so
// ignore things we don't really want to see
internalFuncs["_D5tango4core5tools10StackTrace20defaultAddrBacktraceFPS5tango4core5tools10StackTrace12TraceContextPS5tango4core5tools10StackTrace12TraceContextPkkPiZk"]=1;
internalFuncs["_D5tango4core5tools10StackTrace14BasicTraceInfo5traceMFPS5tango4core5tools10StackTrace12TraceContextiZv"]=1;
internalFuncs["_D5tango4core5tools10StackTrace11basicTracerFPvZC9Exception9TraceInfo"]=1;
// assertion internals should not be shown to users
internalFuncs["onAssertError"]=1;
internalFuncs["_d_assert"]=1;
internalFuncs["onAssertErrorMsg"]=1;
internalFuncs["_d_assert_msg"]=1;
// ignore calls when called for uncaught exceptions
internalFuncs["_d_throwc"]=1;
}

// function to determine if a name is an internal method
char[][] internalMethodEnders = [
"8__assertFiZv",
"9__requireMFZv"
];
bool isInternalMethod(char[] name)
{
static bool endsWith(char[] str, char[] what)
{
if (str.length < what.length)
return false;
return str[$-what.length .. $] == what;
}
if (name[0..2] != "_D"){
return false;
}
foreach (end; internalMethodEnders){
if (endsWith(name, end)){
return true;
}
}
return false;
}

/// returns the name of the function at the given adress (if possible)
Expand Down Expand Up @@ -209,22 +248,33 @@ class BasicTraceInfo: Throwable.TraceInfo{
fInfo.exactAddress=(addrPrecision & 2) || (iframe==0 && (addrPrecision & 1));
rt_symbolizeFrameInfo(fInfo,&context,buf);

auto r= fInfo.func in internalFuncs;
fInfo.internalFunction |= (r !is null);
if (!fInfo.internalFunction){
auto r= (fInfo.func in internalFuncs);
fInfo.internalFunction = (r !is null);
if (!fInfo.internalFunction){
fInfo.internalFunction = isInternalMethod(fInfo.func);
}
}
fInfo.func = demangler.demangle(fInfo.func,buf2);
int res=loopBody(fInfo);
if (res) return res;
}
return 0;
}
/// writes out the stacktrace
override string toString()
{
string buf;
foreach( i, line; this )
buf ~= i ? "\n" ~ line : line;
return buf;
}

/// Writes out the stacktrace.
void writeOut(scope void delegate(char[]) sink){
int ignored = 0;
foreach (ref fInfo; this){
if (!fInfo.internalFunction){
fInfo.iframe -= ignored;
fInfo.writeOut(sink);
fInfo.iframe += ignored;
sink("\n");
}
else ignored++;
}
}
}

version(linux){
Expand Down
50 changes: 10 additions & 40 deletions tango/io/vfs/ZipFolder.d
Original file line number Diff line number Diff line change
Expand Up @@ -455,45 +455,13 @@ else
return !archive.readonly;
}

// workaround for a bug in gdb. See ticket #190
version (GNU)
{
override VfsFolder close(bool commit = true)
in { assert( valid ); }
body
{
return closeImpl(commit);
}

override VfsFolder sync()
{
assert( valid );
return syncImpl();
}
}
else
{
override VfsFolder close(bool commit = true)
in { assert( valid ); }
body
{
return closeImpl(commit);
}


override VfsFolder sync()
in { assert( valid ); }
body
{
return syncImpl();
}
}

/**
* Closes this folder object. If commit is true, then the folder is
* sync'ed before being closed.
*/
protected VfsFolder closeImpl(bool commit = true)
VfsFolder close(bool commit = true)
in { assert( valid ); }
body
{
// MUTATE
if( commit ) sync();
Expand All @@ -508,10 +476,10 @@ else
* This will flush any changes to the archive to disk. Note that this
* applies to the entire archive, not just this folder and its contents.
*/
protected VfsFolder syncImpl()
in { assert( valid ); }
body
override VfsFolder sync()
{
assert( valid );

// MUTATE
archive.sync();
return this;
Expand Down Expand Up @@ -668,7 +636,8 @@ class ZipFolder : ZipSubFolder
*/
final override VfsFolder close(bool commit = true)
{
assert( valid );
assert (valid);

debug( ZipFolder )
Stderr.formatln("ZipFolder.close({})",commit);

Expand Down Expand Up @@ -703,7 +672,8 @@ class ZipFolder : ZipSubFolder
}
body
{
assert( valid );
assert( valid );

debug( ZipFolder )
Stderr("ZipFolder.sync()").newline;

Expand Down
8 changes: 1 addition & 7 deletions tango/net/Uri.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ private import tango.core.Exception;

private import Integer = tango.text.convert.Integer;

/*******************************************************************************
external links
*******************************************************************************/

extern(C) void* memchr(in void* s, int c, size_t n);
private import tango.stdc.string : memchr;

/*******************************************************************************
Expand Down
Loading

0 comments on commit 6821850

Please sign in to comment.