dl: remove workaround; cgen: add DllMain()#23961
Conversation
|
Connected to Huly®: V_0.6-22356 |
|
I can't understand how this is supposed to work in practice? How is the DLL informed that it has been loaded? In other words, when can the internal initialization take place? |
|
From the Windows docs: For a DLL created by V, this function is always needed, so that Since this was not created by default in the past, people who ran into problems had to create their own DllMain() that called _vinit(), or use some sort of other hacky workaround. If there was a "standard" workaround, then I agree, it should've been marked deprecated. I don't recall there being such a standard, but I don't do much with Windows (except complain about it). |
|
I know that, but the thing is that this PR killed all dlls that need to do an internal initialization, because with this PR the "V-internal" DllMain is called and thus the author of a dll can no longer tell when this happens.
I would argue that the previous way was the standard workaround |
|
I think what should've been done was to make this auto DllMain() optional, only to be generated if there was no existing DllMain(). That way, if you wanted to do your own initialization, you would write your own DllMain(). This change is necessary if there is no DllMain() already, otherwise, DLLs created by V just silently don't work as expected. Of course, if you provide your own DllMain() and don't call _vinit(), you'll still get the same problem, but at least it could then be documented, and your own fault if you didn't read the docs. One could argue that doing initialization any other way than with a DllMain() goes against the Windows specs, so is definitely not standard. |
This would have been a possibility, yes.
I would not say that this change is necessary, but yes, a change is necessary.
I don't know what is being referred to here. To my comment that the previous way was the quasi-standard? If so, then you have overlooked the fact that the previous way ultimately did exactly the same thing as this PR. |
Fix issue #8313
When create
.dllunder windows, create a defaultDllMain()for it, which will call_vinit(0, (voidptr)0);and_vcleanup();.Then we can remove the workaround in
dl.open()anddl.close()This is helpful when try to create dll can be called by non-v APPs.