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

Commit 431d7f7

Browse files
committed
purify Demangle
1 parent ebd2f8c commit 431d7f7

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/core/demangle.d

+22-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private struct Demangle
4343
// allocation during the course of a parsing run, this is still
4444
// faster than assembling the result piecemeal.
4545

46-
46+
pure:
4747
enum AddType { no, yes }
4848

4949

@@ -506,10 +506,7 @@ private struct Demangle
506506

507507
tbuf[tlen] = 0;
508508
debug(info) printf( "got (%s)\n", tbuf.ptr );
509-
import core.stdc.stdlib : strtold;
510-
val = strtold( tbuf.ptr, null );
511-
import core.stdc.stdio : snprintf;
512-
tlen = snprintf( tbuf.ptr, tbuf.length, "%#Lg", val );
509+
pureReprintReal( tbuf.ptr, tbuf.length );
513510
debug(info) printf( "converted (%.*s)\n", cast(int) tlen, tbuf.ptr );
514511
put( tbuf[0 .. tlen] );
515512
}
@@ -2389,3 +2386,23 @@ string decodeDmdString( const(char)[] ln, ref size_t p )
23892386
}
23902387
return s;
23912388
}
2389+
2390+
// locally purified for internal use here only
2391+
extern (C) private
2392+
{
2393+
pure @trusted @nogc nothrow pragma(mangle, "fakePureReprintReal") real pureReprintReal(char* nptr, size_t len);
2394+
2395+
char* fakePureReprintReal(char* nptr, size_t len)
2396+
{
2397+
import core.stdc.stdlib : strtold;
2398+
import core.stdc.stdio : snprintf;
2399+
import core.stdc.errno : errno;
2400+
2401+
const err = errno;
2402+
real val = strtold(nptr, null);
2403+
len = snprintf(nptr, len, "%#Lg", val);
2404+
errno = err;
2405+
2406+
return nptr;
2407+
}
2408+
}

0 commit comments

Comments
 (0)