windows: address review feedback on DLL CRT init PR

Use b.allocator instead of b.graph.arena for SDK detection and
path formatting -- b.allocator is the public API, b.graph.arena
is an internal field.

Move test_dll_init.c from windows/Ghostty.Tests/ to test/windows/
with a README. Test infrastructure belongs under test/, not the
Windows app directory.
This commit is contained in:
Alessandro De Blasis
2026-03-27 04:18:16 +01:00
committed by Mitchell Hashimoto
parent 656700d803
commit 5d92222621
3 changed files with 30 additions and 2 deletions

28
test/windows/README.md Normal file
View File

@@ -0,0 +1,28 @@
# Windows Tests
Manual test programs for Windows-specific functionality.
## test_dll_init.c
Regression test for the DLL CRT initialization fix. Loads ghostty.dll
at runtime and calls ghostty_info + ghostty_init to verify the MSVC C
runtime is properly initialized.
### Build
```
zig cc test_dll_init.c -o test_dll_init.exe -target native-native-msvc
```
### Run
```
copy ..\..\zig-out\lib\ghostty.dll . && test_dll_init.exe
```
Expected output (after the CRT fix):
```
ghostty_info: <version string>
ghostty_init: 0
```

View File

@@ -0,0 +1,54 @@
/*
* Minimal reproducer for the libghostty DLL CRT initialization issue.
*
* Before the fix (DllMain calling __vcrt_initialize / __acrt_initialize),
* ghostty_init crashed with "access violation writing 0x0000000000000024"
* because Zig's _DllMainCRTStartup does not initialize the MSVC C runtime
* for DLL targets.
*
* Build: zig cc test_dll_init.c -o test_dll_init.exe -target native-native-msvc
* Run: copy ..\..\zig-out\lib\ghostty.dll . && test_dll_init.exe
*
* Expected output (after fix):
* ghostty_info: <version string>
* ghostty_init: 0
*/
#include <stdio.h>
#include <windows.h>
typedef struct {
int build_mode;
const char *version;
size_t version_len;
} ghostty_info_s;
typedef ghostty_info_s (*ghostty_info_fn)(void);
typedef int (*ghostty_init_fn)(size_t, char **);
int main(void) {
HMODULE dll = LoadLibraryA("ghostty.dll");
if (!dll) {
fprintf(stderr, "LoadLibrary failed: %lu\n", GetLastError());
return 1;
}
ghostty_info_fn info_fn = (ghostty_info_fn)GetProcAddress(dll, "ghostty_info");
if (info_fn) {
ghostty_info_s info = info_fn();
fprintf(stderr, "ghostty_info: %.*s\n", (int)info.version_len, info.version);
}
ghostty_init_fn init_fn = (ghostty_init_fn)GetProcAddress(dll, "ghostty_init");
if (init_fn) {
char *argv[] = {"ghostty"};
int result = init_fn(1, argv);
fprintf(stderr, "ghostty_init: %d\n", result);
if (result != 0) return 1;
}
/* Skip FreeLibrary -- ghostty's global state cleanup and CRT
* teardown ordering is not yet handled. The OS reclaims everything
* on process exit. */
return 0;
}