mirror of
https://github.com/bellard/quickjs.git
synced 2024-11-25 15:18:12 +08:00
win32 dll fix
This commit is contained in:
parent
6a89d7c270
commit
855fef2606
@ -466,8 +466,50 @@ typedef JSModuleDef *(JSInitModuleFunc)(JSContext *ctx,
|
|||||||
static JSModuleDef *js_module_loader_so(JSContext *ctx,
|
static JSModuleDef *js_module_loader_so(JSContext *ctx,
|
||||||
const char *module_name)
|
const char *module_name)
|
||||||
{
|
{
|
||||||
JS_ThrowReferenceError(ctx, "shared library modules are not supported yet");
|
JSModuleDef *m;
|
||||||
|
HANDLE hd;
|
||||||
|
JSInitModuleFunc *init;
|
||||||
|
char *filename;
|
||||||
|
|
||||||
|
if (!strchr(module_name, '/')) {
|
||||||
|
/* must add a '/' so that the DLL is not searched in the
|
||||||
|
system library paths */
|
||||||
|
filename = js_malloc(ctx, strlen(module_name) + 2 + 1);
|
||||||
|
if (!filename)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
strcpy(filename, "./");
|
||||||
|
strcpy(filename + 2, module_name);
|
||||||
|
} else {
|
||||||
|
filename = (char *)module_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* C module */
|
||||||
|
hd = LoadLibrary(filename);
|
||||||
|
if (filename != module_name)
|
||||||
|
js_free(ctx, filename);
|
||||||
|
if (!hd) {
|
||||||
|
JS_ThrowReferenceError(ctx, "could not load module filename '%s'('%s') as shared library",
|
||||||
|
module_name,filename);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
init = (JSInitModuleFunc*)GetProcAddress(hd,"js_init_module");
|
||||||
|
if (!init) {
|
||||||
|
JS_ThrowReferenceError(ctx, "could not load module filename '%s': js_init_module not found",
|
||||||
|
module_name);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
m = init(ctx, module_name);
|
||||||
|
if (!m) {
|
||||||
|
JS_ThrowReferenceError(ctx, "could not load module filename '%s': initialization error",
|
||||||
|
module_name);
|
||||||
|
fail:
|
||||||
|
if (hd)
|
||||||
|
FreeLibrary(hd);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static JSModuleDef *js_module_loader_so(JSContext *ctx,
|
static JSModuleDef *js_module_loader_so(JSContext *ctx,
|
||||||
@ -495,15 +537,13 @@ static JSModuleDef *js_module_loader_so(JSContext *ctx,
|
|||||||
if (filename != module_name)
|
if (filename != module_name)
|
||||||
js_free(ctx, filename);
|
js_free(ctx, filename);
|
||||||
if (!hd) {
|
if (!hd) {
|
||||||
JS_ThrowReferenceError(ctx, "could not load module filename '%s' as shared library",
|
goto dlerror;
|
||||||
module_name);
|
|
||||||
goto fail;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init = dlsym(hd, "js_init_module");
|
init = dlsym(hd, "js_init_module");
|
||||||
if (!init) {
|
if (!init) {
|
||||||
JS_ThrowReferenceError(ctx, "could not load module filename '%s': js_init_module not found",
|
dlerror:
|
||||||
module_name);
|
JS_ThrowReferenceError(ctx, "could not load module filename '%s': %s", module_name, dlerror());
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -578,7 +618,13 @@ JSModuleDef *js_module_loader(JSContext *ctx,
|
|||||||
{
|
{
|
||||||
JSModuleDef *m;
|
JSModuleDef *m;
|
||||||
|
|
||||||
if (has_suffix(module_name, ".so")) {
|
if (
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
has_suffix(module_name, ".so")
|
||||||
|
#else
|
||||||
|
has_suffix(module_name, ".dll")
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
m = js_module_loader_so(ctx, module_name);
|
m = js_module_loader_so(ctx, module_name);
|
||||||
} else {
|
} else {
|
||||||
size_t buf_len;
|
size_t buf_len;
|
||||||
|
Loading…
Reference in New Issue
Block a user