| Thread overview | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 22, 2013 When to call setAssertHandler? | ||||
|---|---|---|---|---|
| ||||
So I want to install my own assertHandler. The problem is, that even if I call "setAssetHandler" in a shared module constructor, and that module does not import any other modules, it is still not initialized first. Is there a way to set the assert before any module constructors run without hacking druntime? Kind Regards Benjamin Thaut | ||||
March 25, 2013 Re: When to call setAssertHandler? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Benjamin Thaut | On Mar 22, 2013, at 2:58 AM, Benjamin Thaut <code@benjamin-thaut.de> wrote:
> So I want to install my own assertHandler. The problem is, that even if I call "setAssetHandler" in a shared module constructor, and that module does not import any other modules, it is still not initialized first. Is there a way to set the assert before any module constructors run without hacking druntime?
I'm afraid not. I suppose this is a case I should have handled, but it didn't occur to me at the time.
| |||
March 26, 2013 Re: When to call setAssertHandler? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Benjamin Thaut | On 2013-03-22 10:58, Benjamin Thaut wrote: > So I want to install my own assertHandler. The problem is, that even if > I call "setAssetHandler" in a shared module constructor, and that module > does not import any other modules, it is still not initialized first. Is > there a way to set the assert before any module constructors run without > hacking druntime? As a workaround you could try overriding "onAssertError" and/or "onAssertErrorMsg". https://github.com/D-Programming-Language/druntime/blob/master/src/core/exception.d#L393 -- /Jacob Carlborg | |||
March 26, 2013 Re: When to call setAssertHandler? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | Am 26.03.2013 10:09, schrieb Jacob Carlborg:
> On 2013-03-22 10:58, Benjamin Thaut wrote:
>> So I want to install my own assertHandler. The problem is, that even if
>> I call "setAssetHandler" in a shared module constructor, and that module
>> does not import any other modules, it is still not initialized first. Is
>> there a way to set the assert before any module constructors run without
>> hacking druntime?
>
> As a workaround you could try overriding "onAssertError" and/or
> "onAssertErrorMsg".
>
> https://github.com/D-Programming-Language/druntime/blob/master/src/core/exception.d#L393
>
>
Yes, but this workaround does not work for windows 64 bit as the microsoft linker complains about duplicate symbols. Also I think it will only work with dmd because all other compiles (I tested with gdc) also complain about duplicate symbols.
Kind Regards
Benjamin Thaut
| |||
March 26, 2013 Re: When to call setAssertHandler? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | Am 25.03.2013 23:49, schrieb Sean Kelly:
> On Mar 22, 2013, at 2:58 AM, Benjamin Thaut <code@benjamin-thaut.de> wrote:
>
>> So I want to install my own assertHandler. The problem is, that even if I call "setAssetHandler" in a shared module constructor, and that module does not import any other modules, it is still not initialized first. Is there a way to set the assert before any module constructors run without hacking druntime?
>
> I'm afraid not. I suppose this is a case I should have handled, but it didn't occur to me at the time.
>
Do you have some idea how to solve this in a generic way? Is this even possible without adding another feature to the language?
Kind Regards
Benjamin Thaut
| |||
March 26, 2013 Re: When to call setAssertHandler? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Benjamin Thaut | On 2013-03-26 19:35, Benjamin Thaut wrote: > Yes, but this workaround does not work for windows 64 bit as the > microsoft linker complains about duplicate symbols. Also I think it will > only work with dmd because all other compiles (I tested with gdc) also > complain about duplicate symbols. I suspected that. -- /Jacob Carlborg | |||
March 27, 2013 Re: When to call setAssertHandler? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Benjamin Thaut | On Mar 26, 2013, at 11:37 AM, Benjamin Thaut <code@benjamin-thaut.de> wrote:
> Am 25.03.2013 23:49, schrieb Sean Kelly:
>> On Mar 22, 2013, at 2:58 AM, Benjamin Thaut <code@benjamin-thaut.de> wrote:
>>
>>> So I want to install my own assertHandler. The problem is, that even if I call "setAssetHandler" in a shared module constructor, and that module does not import any other modules, it is still not initialized first. Is there a way to set the assert before any module constructors run without hacking druntime?
>>
>> I'm afraid not. I suppose this is a case I should have handled, but it didn't occur to me at the time.
>
> Do you have some idea how to solve this in a generic way? Is this even possible without adding another feature to the language?
I'd have to give it some thought. My first idea for solving the problem (looking for a specific named function using dlsym) should work but it seems like a hack. The easiest fix without any library changes would be to have all the modules in your app that you want to run after the hook is set import the module that initializes the hook.
| |||
March 28, 2013 Re: When to call setAssertHandler? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Benjamin Thaut | On 2013-03-22 10:58, Benjamin Thaut wrote: > So I want to install my own assertHandler. The problem is, that even if > I call "setAssetHandler" in a shared module constructor, and that module > does not import any other modules, it is still not initialized first. Is > there a way to set the assert before any module constructors run without > hacking druntime? What is your use case? Do you want to use assert in a module constructor? Or is it when running unit tests. I mean, why can't use set it in "main". If it's for unit testing, could you setup your own unit test runner that calls "setAssetHandler" before running the tests? -- /Jacob Carlborg | |||
March 28, 2013 Re: When to call setAssertHandler? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | Am 28.03.2013 08:15, schrieb Jacob Carlborg: > On 2013-03-22 10:58, Benjamin Thaut wrote: >> So I want to install my own assertHandler. The problem is, that even if >> I call "setAssetHandler" in a shared module constructor, and that module >> does not import any other modules, it is still not initialized first. Is >> there a way to set the assert before any module constructors run without >> hacking druntime? > > What is your use case? Do you want to use assert in a module > constructor? Or is it when running unit tests. I mean, why can't use set > it in "main". If it's for unit testing, could you setup your own unit > test runner that calls "setAssetHandler" before running the tests? > It's because I'm want to use assert in a module constructor. (Well not directly, but functions I call in a module constructor use assert). On Windows x64 I want to use the CrtDebugReport to display any failing assert and I want this to happen for all asserts and not only for asserts that happen after main started. -- Kind Regards Benjamin Thaut | |||
March 28, 2013 Re: When to call setAssertHandler? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | Am 27.03.2013 20:04, schrieb Sean Kelly: > On Mar 26, 2013, at 11:37 AM, Benjamin Thaut <code@benjamin-thaut.de> wrote: > >> Am 25.03.2013 23:49, schrieb Sean Kelly: >>> On Mar 22, 2013, at 2:58 AM, Benjamin Thaut <code@benjamin-thaut.de> wrote: >>> >>>> So I want to install my own assertHandler. The problem is, that even if I call "setAssetHandler" in a shared module constructor, and that module does not import any other modules, it is still not initialized first. Is there a way to set the assert before any module constructors run without hacking druntime? >>> >>> I'm afraid not. I suppose this is a case I should have handled, but it didn't occur to me at the time. >> >> Do you have some idea how to solve this in a generic way? Is this even possible without adding another feature to the language? > > I'd have to give it some thought. My first idea for solving the problem (looking for a specific named function using dlsym) should work but it seems like a hack. The easiest fix without any library changes would be to have all the modules in your app that you want to run after the hook is set import the module that initializes the hook. > Well I'm not afraid of library changes, I already have a heavily modified version of druntime and phobos. But whenever I find a problem within D I strive to find a solution which works for everyone ;-) -- Kind Regards Benjamin Thaut | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply