New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make static linking work in Windows #205
Conversation
What is the status of this PR? Did it change things on non-Windows platforms when AVS_STATIC_LIB is not defined? |
Oh hi printerf. I was waiting for qyot27 to give another round of review. I think he/she might be busy with some Haiku issues or forgot about it. As to your question about non-Windows platforms, since all my changes are related to |
A minimal skeleton demo would be welcome to demonstrate static linking. Not if I wouldn't do that but to spare time. Sorry, I had no time either to go any deeper into the subject and to check whether if it works O.K. for this specific needs but may cause surprises in another area. |
No, I've been slammed with other things I've had to take care of. The two things I was mostly concerned with was the fact it adds API entries (which should be done as part of a larger bump so we're not constantly incrementing things) and that some of the tests on Windows were resulting in unstable initialization in ffmpeg. |
Changed the code a bit so that it only adds API when
Anywhere I can check these myself?
I can make this for Windows later. As to test for stability on non-Windows platform, what needed to be done? I don't see any unit or integration test in repo, so if I make a Linux virtual machine, what are the steps you recommend to try? |
Was it with static linking avisynth to ffmpeg? |
This whole Thread Local Storage (TLS) allocation is guarded by a All this magic was needed because of XP support; XP had zero thread safety mechanism regarding __declspec(thread), which simply did not work for XP and crashed. I have already spent quite a few days on XP and thread init (that's why our XP builds should specify an additional /ZcThreadSafeInit- hack) I recommend not using #define XP_TLS for non-XP builds. Secondly TlsAlloc bounds to DLL_PROCESS_ATTACH which can occur only once, DLL loads are reference counted, DLL_PROCESS_ATTACH can occur only once. For DLL unload: reference counter is decremented and when reaches zero, DLL_PROCESS_DETACH is called which in turn is calling TlsFree when XP-style TLS is defined. It's not that easy, clearly I do not want to support XP in this regard (neither in other aspects :) ). No wonder that clang, boost and others have stopped xp support for ages. There is a possibility that it still does not work with an undefined XP_TLS, but at least we have to search problems in other areas. |
About XP stuff, I don't think I changed anything related to it, did I? Without |
On non-XP we don't need TlsAlloc, the language will do the needed stuff automatically by __declspec(thread) |
OK. I understand you now. Here is what I went through.
I'm testing on Windows 10. https://github.com/AviSynth/AviSynthPlus/blob/master/avs_core/core/main.cpp#L125 is always executed, which defines What am I missing? Is there some CMake magic that checks Windows version and overrides the definition of |
Well, at the moment simply uncomment define XP_TLS and build the whole avisynth without it. |
OK. Now the change is simpler. And here is the minimum demo that just creates environment and print version string. I tested on my Windows 10 environment (using some MSBuild trick to make sure the header and lib files are in path). Do you want me to test it on a Linux?
|
Thanks. I wonder how it behaves if you stress test it and do the core create/delete parallelly from N threads. |
These commits finally - if they work - will be put together into a single good one. For example this latter config.h commit disables the XP_TLS handling from Avisynth+ globally, which is an unwanted step at the moment, I intended to ask for doing it only in your test bench if it works or not. |
Oh, I know. Was just showing what I changed for the record. Will update before final.
Will do. |
Here's the parallel demo. Haven't noticed any failure.
|
Seems good. What does that syntax in 'main' line do? I mean that |
Trailing return style is actually C++11. Main take for me is the aligned function names. Imagine
instead of
in the header file. |
Since I had time to run some tests again, I discovered that the loadtime instability with FFmpeg was actually present in 3.7.0, and it was in one of the core filters (Invert) the test script was using. Further, issues with the 64-bit GCC build also existed with 3.7.0, so fixing that should be a separate issue from this anyway. Given that, I squashed the changes in this PR into a single commit and pushed it to master. |
To use the generated .lib file, I made the following changes to my own program:
#define AVS_STATIC_LIB
before#include <avisynth.h>
.AVS_linkage
stuff.LoadLibrary()
withAvsAllocTls()
.FreeLibrary()
withAvsFreeTls()
.I don't know what
CAVIFileSynth
is, and I don't use it, so I didn't change anything aboutDllGetClassObject
andDllCanUnloadNow
.