cgen,dl: remove workaround in dl, generate a DllMain() in cgen instead for -shared on windows (#23961)

This commit is contained in:
kbkpbot 2025-03-17 23:04:10 +08:00 committed by GitHub
parent ebfa7d86cf
commit bd2ec679f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 34 additions and 36 deletions

View file

@ -20,25 +20,11 @@ type FN_vcleanup_caller = fn ()
// open loads a given module into the address space of the calling process.
pub fn open(filename string, flags int) voidptr {
res := C.LoadLibrary(filename.to_wide())
// Because LoadLibrary has no constructor, this is a workaround
if !isnil(res) {
vinit_caller := FN_vinit_caller(sym(res, '_vinit_caller'))
if !isnil(vinit_caller) {
vinit_caller()
}
}
return res
}
// close frees the loaded a given module.
pub fn close(handle voidptr) bool {
// Because FreeLibrary has no destructor, this is a workaround
if !isnil(handle) {
vcleanup_caller := FN_vcleanup_caller(sym(handle, '_vcleanup_caller'))
if !isnil(vcleanup_caller) {
vcleanup_caller()
}
}
return C.FreeLibrary(handle)
}