digitalmars.D.learn - When to call setAssertHandler?
- Benjamin Thaut (7/7) Mar 22 2013 So I want to install my own assertHandler. The problem is, that even if
- Sean Kelly (8/9) Mar 25 2013 if I call "setAssetHandler" in a shared module constructor, and that =
- Benjamin Thaut (5/8) Mar 26 2013 Do you have some idea how to solve this in a generic way? Is this even
- Sean Kelly (14/22) Mar 27 2013 wrote:
- Benjamin Thaut (7/17) Mar 28 2013 Well I'm not afraid of library changes, I already have a heavily
- Jacob Carlborg (6/11) Mar 26 2013 As a workaround you could try overriding "onAssertError" and/or
- Benjamin Thaut (7/16) Mar 26 2013 Yes, but this workaround does not work for windows 64 bit as the
- Jacob Carlborg (4/8) Mar 26 2013 I suspected that.
- Jacob Carlborg (7/12) Mar 28 2013 What is your use case? Do you want to use assert in a module
- Benjamin Thaut (9/19) Mar 28 2013 It's because I'm want to use assert in a module constructor. (Well not
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
Mar 22 2013
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.=
Mar 25 2013
Am 25.03.2013 23:49, schrieb Sean Kelly:On Mar 22, 2013, at 2:58 AM, Benjamin Thaut <code benjamin-thaut.de> wrote: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 ThautSo 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.
Mar 26 2013
On Mar 26, 2013, at 11:37 AM, Benjamin Thaut <code benjamin-thaut.de> = wrote:Am 25.03.2013 23:49, schrieb Sean Kelly:wrote:On Mar 22, 2013, at 2:58 AM, Benjamin Thaut <code benjamin-thaut.de> =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?=20So I want to install my own assertHandler. The problem is, that even =it didn't occur to me at the time.=20 I'm afraid not. I suppose this is a case I should have handled, but ==20 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.=
Mar 27 2013
Am 27.03.2013 20:04, schrieb Sean Kelly:On Mar 26, 2013, at 11:37 AM, Benjamin Thaut <code benjamin-thaut.de> wrote: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 ThautAm 25.03.2013 23:49, schrieb Sean Kelly: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.On Mar 22, 2013, at 2:58 AM, Benjamin Thaut <code benjamin-thaut.de> wrote:Do you have some idea how to solve this in a generic way? Is this even possible without adding another feature to the language?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.
Mar 28 2013
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
Mar 26 2013
Am 26.03.2013 10:09, schrieb Jacob Carlborg:On 2013-03-22 10:58, 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. Kind Regards Benjamin ThautSo 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
Mar 26 2013
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
Mar 26 2013
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
Mar 28 2013
Am 28.03.2013 08:15, schrieb Jacob Carlborg:On 2013-03-22 10:58, Benjamin Thaut wrote: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 ThautSo 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?
Mar 28 2013