Skip to content

Instantly share code, notes, and snippets.

@gabrielschulhof
Last active October 12, 2016 10:12
Show Gist options
  • Save gabrielschulhof/e4d2bed23cf035548718fe4b6abbd032 to your computer and use it in GitHub Desktop.
Save gabrielschulhof/e4d2bed23cf035548718fe4b6abbd032 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <uv.h>
void Init() {
printf("Init\n");
}
struct old_module {
int version;
void *aPointer;
const char *filename;
void (*entry_point)(void);
const char *module_name;
};
struct new_module {
int version;
int something;
void *aPointer;
const char *filename;
void (*entry_point)(void);
void *anotherPointer;
const char *module_name;
void *yetAnotherPointer;
void *andAnotherPointer;
};
// 0.10
extern "C" {
__attribute__((visibility("default")))
struct old_module hello_module = {
.version = 11,
.aPointer = __null,
.filename = "../hello.cc",
.entry_point = Init,
.module_name = "hello"
};
}
// 0.12
extern "C" {
static struct new_module _module = {
.version = 14 /* 46 for 4.0.0 */,
.something = 0,
.aPointer = __null,
.filename = "../hello.cc",
.entry_point = Init,
.anotherPointer = __null,
.module_name = "hello",
.yetAnotherPointer = __null,
.andAnotherPointer = __null
};
void node_module_register(void *module) __attribute__((weak));
static void _register_hello(void) __attribute__((constructor));
static void _register_hello(void) {
if (node_module_register) {
// Key off the libuv version to decide whether it's a version 4
// module or one below that
if (uv_version() >= 0x10703) {
_module.version = 46;
}
node_module_register(&_module);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment