July 22, 2021

On Tuesday, 13 July 2021 at 17:49:54 UTC, Adam D Ruppe wrote:

>

On Tuesday, 13 July 2021 at 16:52:43 UTC, seany wrote:

>

What will it return to me?

true if it succeeded.

>

I want to catch the segfault and a segfault has occured, I want run a different code at that point.

You mean transparently rerun some code? That's better done with the lowlevel sigaction handler.

But if you just want to standard try/catch then do something in the catch block, this is fine.

import etc.linux.memoryerror;

void main() {
registerMemoryErrorHandler();
int* a;
try {
*a = 4;
} catch(Throwable e) {
import std.stdio;
writeln("Caught");
}
}

It can be used on ldc2 too but it isn't as reliable since ldc considers null access to be undefined behavior anyway and thus may optimize out your catch....

You also need to compile in the module with ldc so build it like

$ ldc2 seg.d ~/d/ldc/import/etc/linux/memoryerror.d

just including the memoryerror file o the command line lets it link.

how can I specify this with dub ?

If i do dub build -b release --compiler=ldc2 /usr/include/dmd/druntime/import/etc/linux/memoryerror.d ; I get : Package '/usr/include/dmd/druntime/import/etc/linux/memoryerror.d' was neither found locally nor online.

July 22, 2021

On Thursday, 22 July 2021 at 14:19:37 UTC, seany wrote:

>

On Tuesday, 13 July 2021 at 17:49:54 UTC, Adam D Ruppe wrote:

>

On Tuesday, 13 July 2021 at 16:52:43 UTC, seany wrote:

>

What will it return to me?

true if it succeeded.

>

I want to catch the segfault and a segfault has occured, I want run a different code at that point.

You mean transparently rerun some code? That's better done with the lowlevel sigaction handler.

But if you just want to standard try/catch then do something in the catch block, this is fine.

import etc.linux.memoryerror;

void main() {
registerMemoryErrorHandler();
int* a;
try {
*a = 4;
} catch(Throwable e) {
import std.stdio;
writeln("Caught");
}
}

It can be used on ldc2 too but it isn't as reliable since ldc considers null access to be undefined behavior anyway and thus may optimize out your catch....

You also need to compile in the module with ldc so build it like

$ ldc2 seg.d ~/d/ldc/import/etc/linux/memoryerror.d

just including the memoryerror file o the command line lets it link.

how can I specify this with dub ?

If i do dub build -b release --compiler=ldc2 /usr/include/dmd/druntime/import/etc/linux/memoryerror.d ; I get : Package '/usr/include/dmd/druntime/import/etc/linux/memoryerror.d' was neither found locally nor online.

I have added this to my dub.json :

"mylib":{
                    "versions": "~master",
                    "path": "/usr/include/dmd/druntime/import/"
            },

Result : .dub/build/application-release-linux.posix-x86_64-ldc_v1.24.0-5496805BDFFAF7D74739CE42F7A6E3B0/tracker_ai.o:traits.d:function _D14analysisEngine9geoEngine15analyze_tillageMFZv: error: undefined reference to '_D3etc5linux11memoryerror26registerMemoryErrorHandlerFZb'

July 22, 2021

On Thursday, 22 July 2021 at 14:19:37 UTC, seany wrote:

>

how can I specify this with dub ?

Probably easiest to just copy the memoryerror.d file from druntime into your dub source dir.

July 22, 2021
On Thursday, 22 July 2021 at 15:12:37 UTC, Adam D Ruppe wrote:
> On Thursday, 22 July 2021 at 14:19:37 UTC, seany wrote:
>> how can I specify this with dub ?
>
> Probably easiest to just copy the memoryerror.d file from druntime into your dub source dir.

I did copy in subfolder /etc/linux. same as this :

`.dub/build/application-release-linux.posix-x86_64-ldc_v1.24.0-5496805BDFFAF7D74739CE42F7A6E3B0/tracker_ai.o:traits.d:function _D14analysisEngine9geoEngine15analyze_tillageMFZv: error: undefined reference to '_D3etc5linux11memoryerror26registerMemoryErrorHandlerFZb`
1 2
Next ›   Last »