HashMapper needing .dup for stack allocation workaround #164

Closed
opened 2024-02-27 20:25:35 +00:00 by deavmi · 7 comments
Owner

HashMapper

For some reason the value returned is some stack allocation and hence we need to dup it to get a heap-allocated copy we can actually return. Else we end up returning a stack pointer which then gets overwritten before usage.

Code below:

version(unittest) { writeln(format("hashMapper, prior to hashing the symbol name is: '%s'", path)); }

// FIXME: Needs dup, somewhere this is allocating KAK!
// Some bizarre stack-allocation (maybe) and then returning that in [len, stackPtr]?
string mappedSymbol = toHexString!(LetterCase.lower)(md5Of(path)).dup;

version(unittest) { writeln(format("hashMapper, AFTER hashing symbol name is: '%s'", mappedSymbol)); }
## HashMapper For some reason the value returned is some stack allocation and hence we need to `dup` it to get a heap-allocated copy we can actually return. Else we end up returning a stack pointer which then gets overwritten before usage. Code below: ```d version(unittest) { writeln(format("hashMapper, prior to hashing the symbol name is: '%s'", path)); } // FIXME: Needs dup, somewhere this is allocating KAK! // Some bizarre stack-allocation (maybe) and then returning that in [len, stackPtr]? string mappedSymbol = toHexString!(LetterCase.lower)(md5Of(path)).dup; version(unittest) { writeln(format("hashMapper, AFTER hashing symbol name is: '%s'", mappedSymbol)); } ```
deavmi added this to the Clean ups milestone 2024-02-27 20:25:35 +00:00
deavmi added the
qol
label 2024-02-27 20:25:35 +00:00
deavmi self-assigned this 2024-02-27 20:25:35 +00:00
deavmi added this to the Code emit project 2024-02-27 20:25:35 +00:00
deavmi added spent time 2024-02-27 20:57:02 +00:00
20 minutes
deavmi added the
hashmapper
label 2024-02-27 20:58:44 +00:00
deavmi added the due date 2024-04-27 2024-02-27 20:59:05 +00:00
deavmi changed title from Not so lekker things to HahsMapper needing .dup for stack allocation workaround 2024-02-27 20:59:28 +00:00
Author
Owner

I added the .dup but I don't like that solution.

I added the `.dup` but I don't like that solution.
deavmi changed title from HahsMapper needing .dup for stack allocation workaround to HashMapper needing .dup for stack allocation workaround 2024-02-27 20:59:48 +00:00
deavmi removed the due date 2024-04-27 2024-04-01 21:26:35 +01:00
deavmi added the due date 2024-04-05 2024-04-01 21:26:43 +01:00
Author
Owner

I should probably look at this again/

I should probably look at this again/
Author
Owner

// We do .dup because the hex string is allocated on the stack and
// returning that wll only be valid still the stack grows into the
// space it uccopies again later, so copy it to the heap rather
// and return that

// We do `.dup` because the hex string is allocated on the stack and // returning that wll only be valid still the stack grows into the // space it uccopies again later, so copy it to the heap rather // and return that
Author
Owner

// We do .dup because the hex string is allocated on the stack and
// returning that wll only be valid still the stack grows into the
// space it uccopies again later, so copy it to the heap rather
// and return that

Removed the .dup because when we use the format string a new one is allocated so it is no lonmger needed:

string mappedSymbol = format("t_%s", toHexString!(LetterCase.lower)(md5Of(path)));
> // We do `.dup` because the hex string is allocated on the stack and > // returning that wll only be valid still the stack grows into the > // space it uccopies again later, so copy it to the heap rather > // and return that Removed the `.dup` because when we use the format string a new one is allocated so it is no lonmger needed: ```d string mappedSymbol = format("t_%s", toHexString!(LetterCase.lower)(md5Of(path))); ```
deavmi added spent time 2024-04-07 12:33:19 +01:00
10 minutes
deavmi started working 2024-04-07 12:33:22 +01:00
Author
Owner

Waiting on semantic tests to run...

Waiting on semantic tests to run...
Author
Owner

All tests pass

All tests pass ✅
Author
Owner

I am now satisfied with this

I am now satisfied with this
deavmi stopped working 2024-04-07 12:39:40 +01:00
6 minutes 18 seconds
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Total Time Spent: 36 minutes 18 seconds
deavmi
36 minutes 18 seconds
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

2024-04-05

Dependencies

No dependencies set.

Reference: tlang/tlang#164
No description provided.