Skip to content

Commit 4e20999

Browse files
committed
Revert "Modify mjPLUGIN_LIB_INIT to use C runtime initializer."
This reverts commit 50fe86a.
1 parent 50fe86a commit 4e20999

1 file changed

Lines changed: 32 additions & 10 deletions

File tree

include/mujoco/mjplugin.h

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,39 @@ struct mjSDF_ {
182182
};
183183
typedef struct mjSDF_ mjSDF;
184184

185-
#if defined(__has_attribute) && __has_attribute(constructor)
186-
#define mjPLUGIN_LIB_INIT \
187-
static void _mjplugin_init(void) __attribute__((constructor)); \
188-
static void _mjplugin_init(void)
185+
#if defined(__has_attribute)
186+
187+
#if __has_attribute(constructor)
188+
#define mjPLUGIN_LIB_INIT __attribute__((constructor)) static void _mjplugin_init(void)
189+
#endif // __has_attribute(constructor)
190+
189191
#elif defined(_MSC_VER)
190-
#pragma section(".CRT$XCU", read)
191-
#define mjPLUGIN_LIB_INIT \
192-
static void _mjplugin_init(void); \
193-
__pragma(warning(suppress: 4189)) __declspec(allocate(".CRT$XCU")) static void (*_mjplugin_init_ptr)(void) = _mjplugin_init; \
194-
static void _mjplugin_init(void)
195-
#endif
192+
193+
#ifndef mjDLLMAIN
194+
#define mjDLLMAIN DllMain
195+
#endif
196+
197+
#if !defined(mjEXTERNC)
198+
#if defined(__cplusplus)
199+
#define mjEXTERNC extern "C"
200+
#else
201+
#define mjEXTERNC
202+
#endif // defined(__cplusplus)
203+
#endif // !defined(mjEXTERNC)
204+
205+
// NOLINTBEGIN(runtime/int)
206+
#define mjPLUGIN_LIB_INIT \
207+
static void _mjplugin_dllmain(void); \
208+
mjEXTERNC int __stdcall mjDLLMAIN(void* hinst, unsigned long reason, void* reserved) { \
209+
if (reason == 1) { \
210+
_mjplugin_dllmain(); \
211+
} \
212+
return 1; \
213+
} \
214+
static void _mjplugin_dllmain(void)
215+
// NOLINTEND(runtime/int)
216+
217+
#endif // defined(_MSC_VER)
196218

197219
// function pointer type for mj_loadAllPluginLibraries callback
198220
typedef void (*mjfPluginLibraryLoadCallback)(const char* filename, int first, int count);

0 commit comments

Comments
 (0)