#ifdef _WIN32
# define NODE_MODULE_EXPORT __declspec(dllexport)
#else
- # define NODE_MODULE_EXPORT /* empty */
+ # define NODE_MODULE_EXPORT __attribute__((visibility("default")))
#endif
-#define NODE_MODULE(modname, regfunc) \
+#if defined(_MSC_VER)
+#pragma section(".CRT$XCU", read)
+#define NODE_C_CTOR(fn) \
+ static void __cdecl fn(void); \
+ __declspec(dllexport, allocate(".CRT$XCU")) \
+ void (__cdecl*fn ## _)(void) = fn; \
+ static void __cdecl fn(void)
+#else
+#define NODE_C_CTOR(fn) \
+ static void fn(void) __attribute__((constructor)); \
+ static void fn(void)
+#endif
+
+#define NODE_MODULE_X(modname, regfunc, priv, flags) \
extern "C" { \
- NODE_MODULE_EXPORT node::node_module_struct modname ## _module = \
+ static node::node_module _module = \
{ \
- NODE_STANDARD_MODULE_STUFF, \
- (node::addon_register_func)regfunc, \
- NODE_STRINGIFY(modname) \
+ NODE_MODULE_VERSION, \
+ flags, \
+ NULL, \
+ __FILE__, \
+ (node::addon_register_func) (regfunc), \
+ NULL, \
+ NODE_STRINGIFY(modname), \
+ priv, \
+ NULL \
}; \
+ NODE_C_CTOR(_register_ ## modname) { \
+ node_module_register(&_module); \
+ } \
}
-#define NODE_MODULE_DECL(modname) \
- extern "C" node::node_module_struct modname ## _module;
+#define NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, priv, flags) \
+ extern "C" { \
+ static node::node_module _module = \
+ { \
+ NODE_MODULE_VERSION, \
+ flags, \
+ NULL, \
+ __FILE__, \
+ NULL, \
+ (node::addon_context_register_func) (regfunc), \
+ NODE_STRINGIFY(modname), \
+ priv, \
+ NULL \
+ }; \
+ NODE_C_CTOR(_register_ ## modname) { \
+ node_module_register(&_module); \
+ } \
+ }
-/* Called after the event loop exits but before the VM is disposed.
- * Callbacks are run in reverse order of registration, i.e. newest first.
- */
-NODE_EXTERN void AtExit(void (*cb)(void* arg), void* arg = 0);
+#define NODE_MODULE(modname, regfunc) \
+ NODE_MODULE_X(modname, regfunc, NULL, 0)
+
+#define NODE_MODULE_CONTEXT_AWARE(modname, regfunc) \
+ NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, 0)
+
+#define NODE_MODULE_CONTEXT_AWARE_BUILTIN(modname, regfunc) \
+ NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, NM_F_BUILTIN) \
/*
- * MakeCallback doesn't have a HandleScope. That means the callers scope
- * will retain ownership of created handles from MakeCallback and related.
- * There is by default a wrapping HandleScope before uv_run, if the caller
- * doesn't have a HandleScope on the stack the global will take ownership
- * which won't be reaped until the uv loop exits.
- *
- * If a uv callback is fired, and there is no enclosing HandleScope in the
- * cb, you will appear to leak 4-bytes for every invocation. Take heed.
+ * For backward compatibility in add-on modules.
*/
+#define NODE_MODULE_DECL /* nothing */
-NODE_EXTERN void SetErrno(uv_err_t err);
-NODE_EXTERN v8::Handle<v8::Value>
-MakeCallback(const v8::Handle<v8::Object> object,
- const char* method,
- int argc,
- v8::Handle<v8::Value> argv[]);
-
-NODE_EXTERN v8::Handle<v8::Value>
-MakeCallback(const v8::Handle<v8::Object> object,
- const v8::Handle<v8::String> symbol,
- int argc,
- v8::Handle<v8::Value> argv[]);
-
-NODE_EXTERN v8::Handle<v8::Value>
-MakeCallback(const v8::Handle<v8::Object> object,
- const v8::Handle<v8::Function> callback,
- int argc,
- v8::Handle<v8::Value> argv[]);
+/* Called after the event loop exits but before the VM is disposed.
+ * Callbacks are run in reverse order of registration, i.e. newest first.
+ */
+NODE_EXTERN void AtExit(void (*cb)(void* arg), void* arg = 0);
} // namespace node