Repository navigation
Load optional Windows DLLs at runtime and drop delay loading - #146
Conversation
Signed-off-by: Quin Gillespie <[email protected]>
|
Can you provide a reproduction of this particular bug? I am hesitant to switch to run-time library loading just because it means we must manually maintain structures for each backend but scattered all over the codebase. For what it's worth, a consuming application shouldn't require /delayload regardless of it's link mode; that would defeat the point of /delayload. If this is indeed a problem then I think it may be easier to figure out why that is instead of completely replacing a substantial portion of the library. |
|
@ethindp thanks! You're right that nothing linking I built master with #include <prism.h>
#include <stdio.h>
int main(void) {
PrismConfig cfg = prism_config_init();
PrismContext* ctx = prism_init(&cfg);
PrismBackend* backend = prism_registry_create_best(ctx);
printf("started, best backend: %s\n", backend ? prism_backend_name(backend) : "none");
prism_shutdown(ctx);
return 0;
}
Linking the same object again with On the maintenance side, it is your project so it is of course your choice, but I'd argue it's less than before. |
|
@trypsynth So, I agree with you (even if I'm not super happy switching away from delay loading, but the alternatives, from what my research shows, are even worse). Some comments since they're systematic across the entire diff:
|
|
@ethindp thanks, I'll address all four points in an upcoming commit. I'd push back slightly on point 3, though. Each API is actually cached in a function-local static, so the library only loads once, but I do agree it reads badly. I'll have each backend hold a pointer to its API, set once when it initializes, and call through that. I'll also fix point 4, but make the |
- Drop the `::` from the `decltype` pointers, which compile fine without it. - Use `TCHAR`, `_T` and the unsuffixed Win32 functions instead of wide strings and the `W` versions. - Have the Orca, Speech Dispatcher and Spiel backends hold a pointer to their bridge, set once in `initialize`, like the other backends already do, instead of calling the loader every time. Signed-off-by: Quin Gillespie <[email protected]>
|
@trypsynth The PCTalker functions are an exception since I had to manually reconstruct the header from the DLLs. I don't have any kind of SDK so had to do a bunch of work to try to figure out exactly how the DLL worked, so I've always treated that as an exception to the normal rule of avoiding suffixed functions. That rule (which should probably be in the contributing guidelines) primarily applies to win32 APIs, not to external ones. |
|
@trypsynth Please review CI/CD; this has failing checks. |
GCC 15 rejects a member declared as decltype(&name) name; with -Wchanges-meaning, since the member's name changes what the earlier unqualified lookup found. Looking the function up as ::name avoids the rule, which applies only to unqualified names.
Currently when calling static Prism from Rust,
/DELAYLOADonly works on the final link, and Cargo never passes a dependency's link args to the binary, so unless your app remembers a build script for it, the screen reader DLLs and the Wine bridges become hard imports. In Fedra, for example, without putting a 15-line or so function in my build.rs, it dies on launch asking forbyctrl-x64.dll,ZDSRAPI_x64.dll, andPCTKUSR.dllusing prismer and prism-sys, hence this PR.In other words, this does on Windows what #136 did on Linux.
SharedLibrarygets a Windows side, and ZDSR, BoyPCReader, PC-Talker, Orca, and the Wine sides of Speech Dispatcher and Spiel each bind the functions they actually call into adecltypetable. If the DLL or a function is missing, the backend just reports itself unavailable.open_optional_librarykeeps the old search order: the DLL search path, then prism's own folder, then the ZDSR or BoyPC install folder from the registry. With nothing delay-loaded anymore,delayimp.cpp,defs/, the generated import libraries, the/DELAYflags, andprism-static-windows.txtall go, and CONTRIBUTING now describes the new way.I tested x64 static, x64 shared, and Win32 with MSVC, and they all build clean. A static test program initializes every backend: NVDA, OneCore, and SAPI succeed, and the six converted ones all return
BackendNotAvailableinstead of crashing. Also, neitherprism.dllnor Fedra imports any of the six DLLs anymore.With MinGW (WinLibs GCC 16), everything this touches compiles, but prism still doesn't build there overall because of ATL and C++/WinRT. Decided just to not touch that, now or probably ever.
Sidenote: Once this lands, I'll update prism-sys to stop reading
prism-static-windows.txt.Cheers, and sorry for the huge diff!