ImportC and nothrow/@nogc?
Manu
turkeyman at gmail.com
Sun Aug 25 10:28:57 UTC 2024
On Sun, 25 Aug 2024 at 19:26, Dom DiSc via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:
> On Saturday, 24 August 2024 at 17:10:39 UTC, Manu wrote:
> > We need to have:
> >
> > @trusted {
> > some_code;
> > }
>
> We have:
>
> () @trusted {
> some_code;
> }();
>
> Which works kind of the same, beside it's ugly as hell.
> Until we have real trusted blocks, I use this (heavily).
..."kind of the same"
int normal_scope(int x, int y)
{
int t;
// normal scope
{
t = x + y;
}
return t;
}
assume CS:.text._D7example12normal_scopeFiiZi
push RBP
mov RBP,RSP
sub RSP,020h
mov -010h[RBP],EDI
mov -8[RBP],ESI
mov dword ptr -018h[RBP],0
mov EAX,-8[RBP]
add EAX,-010h[RBP]
mov -018h[RBP],EAX
leave
ret
int stupid_hack(int x, int y)
{
int t;
// stupid hack
() @trusted {
t = x + y;
}();
return t;
}
assume CS:.text._D7example11stupid_hackFiiZi
push RBP
mov RBP,RSP
sub RSP,020h
mov -010h[RBP],EDI
mov -8[RBP],ESI
mov dword ptr -018h[RBP],0
mov RDI,RBP
call qword ptr pure nothrow @nogc @trusted void
example.stupid_hack(int, int).__lambda4()@GOTPCREL[RIP]
mov EAX,-018h[RBP]
leave
ret
assume CS:.text.pure nothrow @nogc @trusted void
example.stupid_hack(int, int).__lambda4()
pure nothrow @nogc @trusted void example.stupid_hack(int, int).__lambda4():
push RBP
mov RBP,RSP
sub RSP,010h
mov -8[RBP],RDI
mov RAX,-8[RBP]
mov ECX,-8[RAX]
add ECX,-010h[RAX]
mov -018h[RAX],ECX
leave
ret
add [RAX],AL
I hope we can agree that this is definitely not 'kind of the same'...
And that's to say nothing about the damage it causes to the debug info, and
the ability to breakpoint and step through the code in a sane way.
Completely unacceptable hack. I won't give this pattern the dignity of my
fingertips approval under any circumstances. It should not be legitimised.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20240825/bcb4514f/attachment-0001.htm>
More information about the Digitalmars-d
mailing list