Modify mj_PLUGIN_LIB_INIT to support multiple plugins in the same compilation unit.
Previously on MSVC we used DllMain to register plugins, you cannot have multiple definitions of DllMain in a single unit so you would get errors if you tried to register two plugins. This modifies the implementation to insert a function pointer into the C runtime initialization instead. PiperOrigin-RevId: 896612678 Change-Id: I07732147b955d741c836acff6da986db0e9b9eff
This commit is contained in:
committed by
Copybara-Service
parent
33fd2fe40e
commit
f2461f9ce6
@@ -691,17 +691,13 @@ mjPLUGIN_LIB_INIT
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
#define mjPLUGIN_LIB_INIT \
|
||||
static void _mjplugin_dllmain(void); \
|
||||
mjEXTERNC int __stdcall mjDLLMAIN(void* hinst, unsigned long reason, void* reserved) { \
|
||||
if (reason == 1) { \
|
||||
_mjplugin_dllmain(); \
|
||||
} \
|
||||
return 1; \
|
||||
} \
|
||||
static void _mjplugin_dllmain(void)
|
||||
#define mjPLUGIN_LIB_INIT(n) \
|
||||
static void _mj_init_##n(void) __attribute__((constructor)); \
|
||||
static void _mj_init_##n(void)
|
||||
|
||||
Register a plugin as a dynamic library. See :ref:`plugin registration<exRegistration>` for more details.
|
||||
Register a plugin before `main()` is called. This macro takes a unique identifier `n` as an argument that is used to avoid
|
||||
name collisions between different plugin initialization functions. See :ref:`plugin registration<exRegistration>` for
|
||||
more details.
|
||||
|
||||
|
||||
.. _tyXMacro:
|
||||
|
||||
Reference in New Issue
Block a user