From 949b644bc7ecb800eb10cd7b047374a550bb1947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Fri, 20 Mar 2026 23:03:40 +0800 Subject: [PATCH] optimize(zecall): better calling experience --- internal/zecall/zecall_windows.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/zecall/zecall_windows.go b/internal/zecall/zecall_windows.go index 99d3cbe..9d3169e 100644 --- a/internal/zecall/zecall_windows.go +++ b/internal/zecall/zecall_windows.go @@ -21,18 +21,18 @@ var ( procMap = map[string]*syscall.Proc{} ) -// Init load lib using syscall. -func Init() error { +func init() { + if libZeLoader != nil { + return + } h, err := syscall.LoadLibrary(zeLibraryName) if err != nil { - return err + panic(err) } libZeLoader = &syscall.DLL{Handle: h, Name: zeLibraryName} - - return nil } -// Register a process for calling. +// Register a process for calling. For generated init only. Not thread-safe. func Register(name string) error { if libZeLoader == nil { return ErrZeCallNotInit @@ -45,7 +45,7 @@ func Register(name string) error { return nil } -// Call invokes a registered proc by name. +// Call invokes a registered proc by name. For generated call only. // The go:uintptrescapes directive tells the compiler that args may contain // pointers converted to uintptr, so the GC will keep them alive during the call. //