digitalmars.D - BetterC and Windows API calls
- pineapple (13/13) Jun 02 2023 I've been experimenting a bit with betterC recently, and I've
- bauss (5/18) Jun 02 2023 If it works without -betterC and crashes when toggled on, then
- Steven Schveighoffer (7/24) Jun 02 2023 That error code is 0xC0000005, which is an access violation (segfault).
- pineapple (6/12) Jun 03 2023 Ahh, I had not even got around to considering that accessing the
- Dave P. (3/19) Jun 03 2023 Still file an issue though, TLS should either work or fail to
- IGotD- (4/6) Jun 03 2023 No, it should still be possible to compile TLS into the binary
- Richard (Rikki) Andrew Cattermole (4/6) Jun 03 2023 Its a known issue, ryuuckk has ran into it.
- ryuukk_ (4/10) Jun 04 2023 Yes it is fixed with 2.104
I've been experimenting a bit with betterC recently, and I've found that a trivial use of `QueryPerformanceFrequency` (the extern declaration imported from `core.sys.windows.winbase`) immediately crashes my program with status code 3221225477. https://github.com/pineapplemachine/scamp.d/blob/master/src/scamp/time/monotonic.d#L76 What's going on here? The same code works as expected, without crashing, if I compile without -betterC. Before this, I found that trying to use the `core.sys.windows.winbase` module's convenience overrides that accept a long pointer instead of a LARGE_INTEGER struct pointer would result in a linker error when compiling with -betterC. Is there something I need to be doing differently to make Windows API calls, or is this a bug with betterC?
Jun 02 2023
On Friday, 2 June 2023 at 19:19:57 UTC, pineapple wrote:I've been experimenting a bit with betterC recently, and I've found that a trivial use of `QueryPerformanceFrequency` (the extern declaration imported from `core.sys.windows.winbase`) immediately crashes my program with status code 3221225477. https://github.com/pineapplemachine/scamp.d/blob/master/src/scamp/time/monotonic.d#L76 What's going on here? The same code works as expected, without crashing, if I compile without -betterC. Before this, I found that trying to use the `core.sys.windows.winbase` module's convenience overrides that accept a long pointer instead of a LARGE_INTEGER struct pointer would result in a linker error when compiling with -betterC. Is there something I need to be doing differently to make Windows API calls, or is this a bug with betterC?If it works without -betterC and crashes when toggled on, then I'm going to assume it's either a bug or memory was corrupted before said call to QueryPerformanceFrequency. Try to isolate the call and see if it crashes with nothing else.
Jun 02 2023
On 6/2/23 3:19 PM, pineapple wrote:I've been experimenting a bit with betterC recently, and I've found that a trivial use of `QueryPerformanceFrequency` (the extern declaration imported from `core.sys.windows.winbase`) immediately crashes my program with status code 3221225477. https://github.com/pineapplemachine/scamp.d/blob/master/src/scamp/time/monotonic.d#L76 What's going on here? The same code works as expected, without crashing, if I compile without -betterC. Before this, I found that trying to use the `core.sys.windows.winbase` module's convenience overrides that accept a long pointer instead of a LARGE_INTEGER struct pointer would result in a linker error when compiling with -betterC. Is there something I need to be doing differently to make Windows API calls, or is this a bug with betterC?That error code is 0xC0000005, which is an access violation (segfault). Basically, a memory read/write error. Using static in D means TLS. I'm not sure what the rules are for TLS and betterC, but perhaps it's not properly set up? Maybe try __gshared instead of static? Not sure. -Steve
Jun 02 2023
On Friday, 2 June 2023 at 21:23:46 UTC, Steven Schveighoffer wrote:That error code is 0xC0000005, which is an access violation (segfault). Basically, a memory read/write error. Using static in D means TLS. I'm not sure what the rules are for TLS and betterC, but perhaps it's not properly set up? Maybe try __gshared instead of static? Not sure. -SteveAhh, I had not even got around to considering that accessing the `static` declaration could be the problem. That seems like a bug? Anyway, declaring it as either `static shared` or `static __gshared` fixes the crash - thanks for pointing me to that!
Jun 03 2023
On Saturday, 3 June 2023 at 08:13:30 UTC, pineapple wrote:On Friday, 2 June 2023 at 21:23:46 UTC, Steven Schveighoffer wrote:Still file an issue though, TLS should either work or fail to compile, not crash at runtime.That error code is 0xC0000005, which is an access violation (segfault). Basically, a memory read/write error. Using static in D means TLS. I'm not sure what the rules are for TLS and betterC, but perhaps it's not properly set up? Maybe try __gshared instead of static? Not sure. -SteveAhh, I had not even got around to considering that accessing the `static` declaration could be the problem. That seems like a bug? Anyway, declaring it as either `static shared` or `static __gshared` fixes the crash - thanks for pointing me to that!
Jun 03 2023
On Saturday, 3 June 2023 at 16:39:54 UTC, Dave P. wrote:Still file an issue though, TLS should either work or fail to compile, not crash at runtime.No, it should still be possible to compile TLS into the binary because someone might have done a bespoke TLS implementation. We cannot block that possibility.
Jun 03 2023
On 04/06/2023 4:39 AM, Dave P. wrote:Still file an issue though, TLS should either work or fail to compile, not crash at runtime.Its a known issue, ryuuckk has ran into it. It might be fixed as of 2.104, nobody has checked I think. https://issues.dlang.org/show_bug.cgi?id=20737
Jun 03 2023
On Saturday, 3 June 2023 at 17:27:48 UTC, Richard (Rikki) Andrew Cattermole wrote:On 04/06/2023 4:39 AM, Dave P. wrote:Yes it is fixed with 2.104 https://dlang.org/changelog/2.104.0.htmlStill file an issue though, TLS should either work or fail to compile, not crash at runtime.Its a known issue, ryuuckk has ran into it. It might be fixed as of 2.104, nobody has checked I think. https://issues.dlang.org/show_bug.cgi?id=20737
Jun 04 2023