From 3503fa80c02e19a718245f92eba31f6b0a5cf45c Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Thu, 26 Sep 2024 21:02:12 +0100 Subject: Enable rebuilding the plugin while it is loaded --- compile | 3 ++- compile.bat | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/compile b/compile index 9045f53..31e4b8f 100755 --- a/compile +++ b/compile @@ -46,7 +46,8 @@ cc() { ld() { $CC -shared -flto -fpic -fuse-ld=lld $ldflags -L.build -ldl \ - -ltier0 -lvstdlib -o sst.so$objs + -ltier0 -lvstdlib -o .build/sst.so$objs + mv .build/sst.so sst.so } src="\ diff --git a/compile.bat b/compile.bat index 11d0aac..1eebb59 100644 --- a/compile.bat +++ b/compile.bat @@ -137,10 +137,27 @@ if "%dbg%"=="1" ( ) %CC% -fuse-ld=lld -shared -flto %ldflags% -Wl,/IMPLIB:.build/sst.lib,/Brepro,/nodefaultlib ^ -L.build %clibs% -lkernel32 -luser32 -lbcryptprimitives -lshlwapi -ld3d9 -ldsound ^ --ltier0 -lvstdlib -lntdll -o sst.dll%objs% .build/dll.res || goto :end +-ltier0 -lvstdlib -lntdll -o .build/sst.dll%objs% .build/dll.res || goto :end :: get rid of another useless file (can we just not create this???) del .build\sst.lib +:: awkward logic to replace sst.dll while it's potentially loaded, because +:: windows likes to lock things and/or doesn't have atomic rename. +:: very TOCTOU-ish code, not good at all, but sometimes bad is good enough +move /y .build\sst.dll sst.dll >nul 2>nul || ( + move /y sst.dll .build\sst.old.dll >nul 2>nul || ( + echo:ERROR: couldn't remove sst.dll OR .build/sst.old.dll - are both loaded?>&2 + goto :end + ) + move .build\sst.dll sst.dll >nul 2>nul || ( + echo:ERROR: couldn't replace sst.dll - did something just try to load it?>&2 + goto :end + ) +) +:: try to cleanup the .old again - it'll fail if we just moved it but may work +:: in some eventual future invocation +if exist .build\sst.old.dll del .build\sst.old.dll >nul 2>nul + %HOSTCC% -fuse-ld=lld -O2 -g -include test/test.h -o .build/bitbuf.test.exe test/bitbuf.test.c || goto :end .build\bitbuf.test.exe || goto :end :: special case: test must be 32-bit -- cgit v1.2.3-54-g00ecf