Skip to content

Commit bd4cdec

Browse files
committed
Reapply "Modify mjPLUGIN_LIB_INIT to use C runtime initializer."
This reverts commit 4e20999.
1 parent 4e20999 commit bd4cdec

File tree

1 file changed

+10
-32
lines changed

1 file changed

+10
-32
lines changed

include/mujoco/mjplugin.h

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

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-
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)
191189
#elif defined(_MSC_VER)
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)
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
218196

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

0 commit comments

Comments
 (0)