From 4da5d1989eecf7739f172b8fb8041ce899ee49f9 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Wed, 1 Jul 2020 15:37:21 +0200 Subject: [PATCH] ddemangle, use FPC compat string too --- dexed-d/src/common.d | 4 ++-- dexed-d/src/ddemangle.d | 8 +++++--- src/u_ddemangle.pas | 4 ++-- src/u_dexed_d.pas | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/dexed-d/src/common.d b/dexed-d/src/common.d index 970ec5ba..1facd161 100644 --- a/dexed-d/src/common.d +++ b/dexed-d/src/common.d @@ -464,12 +464,12 @@ public: alias RT = FpcArray!T; enum isChar = is(Unqual!T == char); size_t len = size_t.sizeof * 2 + T.sizeof * array.length + ubyte(isChar); - void* mem = getMem(len); + auto mem = cast(Unqual!T*) getMem(len); // init refcount to -1 and length to izArray length *cast(size_t*) (mem + 0 ) = -1; *cast(size_t*) (mem + size_t.sizeof) = array.length; // copy izArray data - mem[size_t.sizeof * 2 .. len - ubyte(isChar)] = array.ptr[0.. array.length * T.sizeof]; + mem[size_t.sizeof * 2 .. len - ubyte(isChar)] = (cast(T*) array.ptr)[0.. array.length * T.sizeof]; // FreePascal specifies that strings are guaranteed to be zero terminated. static if (isChar) *cast(char*) (mem + len - 1) = '\0'; diff --git a/dexed-d/src/ddemangle.d b/dexed-d/src/ddemangle.d index 2609bc94..a235e448 100644 --- a/dexed-d/src/ddemangle.d +++ b/dexed-d/src/ddemangle.d @@ -3,11 +3,11 @@ module ddemangle; import core.demangle : demangle; import std.regex : replaceAll, Captures, regex, Regex; import core.stdc.string : strlen; -import std.string : toStringz; +import common : FpcArray; extern(C): -export const(char)* ddemangle(const(char)* line) +export FpcArray!(const(char))* ddemangle(const(char)* line) { __gshared Regex!char reDemangle; __gshared bool reInit; @@ -16,7 +16,9 @@ export const(char)* ddemangle(const(char)* line) reInit = true; reDemangle = regex(r"\b_?_D[0-9a-zA-Z_]+\b"); } - return replaceAll!(demangleMatch)(line[0 .. line.strlen], reDemangle).toStringz; + return FpcArray!(const(char)).fromArray( + replaceAll!(demangleMatch)(line[0 .. line.strlen], reDemangle) + ); } extern(D): private: diff --git a/src/u_ddemangle.pas b/src/u_ddemangle.pas index 1191c426..3f90a80b 100644 --- a/src/u_ddemangle.pas +++ b/src/u_ddemangle.pas @@ -24,7 +24,7 @@ begin s := pchar(value); // note, assign to result has for effect to alloc a FPC string // (by implicit convertion) so the D memory is not used. - result := ddemangle(s); + result := string(ddemangle(s)); minimizeGcHeap(); end else @@ -40,7 +40,7 @@ begin begin value := values[i]; if pos('_D', value) > 0 then - value := demangle(PChar(value)); + value := demangle(PChar(value)); output.AddStrings(value); end; end; diff --git a/src/u_dexed_d.pas b/src/u_dexed_d.pas index 2a762adf..d5568ddf 100644 --- a/src/u_dexed_d.pas +++ b/src/u_dexed_d.pas @@ -62,7 +62,7 @@ procedure minimizeGcHeap(const now: boolean = false); cdecl; external libdexedd_ // noop procedure setRtOptions(); cdecl; external libdexedd_name; // Demangle a line possibly containing a D mangled name. -function ddemangle(const text: PChar): PChar; cdecl; external libdexedd_name; +function ddemangle(const text: PChar): pointer; cdecl; external libdexedd_name; // Detects wether the source code for the module `src` contains the main() function. function hasMainFun(const src: PChar): Boolean; cdecl; external libdexedd_name; // Returns the DDOC template for the declaration location at `caretLine` in the source code `src`.