mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 08:09:08 -05:00
fix(ext/ffi): don't panic in dlopen (#12344)
This commit is contained in:
parent
822047b845
commit
ab2e0a465e
3 changed files with 15 additions and 2 deletions
|
@ -1,6 +1,5 @@
|
||||||
// Copyright 2021 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2021 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use deno_core::error::anyhow;
|
|
||||||
use deno_core::error::bad_resource_id;
|
use deno_core::error::bad_resource_id;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::include_js_files;
|
use deno_core::include_js_files;
|
||||||
|
@ -370,7 +369,12 @@ where
|
||||||
let permissions = state.borrow_mut::<FP>();
|
let permissions = state.borrow_mut::<FP>();
|
||||||
permissions.check(&path)?;
|
permissions.check(&path)?;
|
||||||
|
|
||||||
let lib = Library::open(&path).map_err(|e| anyhow!(format_error(e, path)))?;
|
let lib = Library::open(&path).map_err(|e| {
|
||||||
|
dlopen::Error::OpeningLibraryError(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::Other,
|
||||||
|
format_error(e, path),
|
||||||
|
))
|
||||||
|
})?;
|
||||||
|
|
||||||
let mut resource = DynamicLibraryResource {
|
let mut resource = DynamicLibraryResource {
|
||||||
lib,
|
lib,
|
||||||
|
|
|
@ -37,6 +37,7 @@ fn basic() {
|
||||||
println!("{:?}", output.status);
|
println!("{:?}", output.status);
|
||||||
assert!(output.status.success());
|
assert!(output.status.success());
|
||||||
let expected = "\
|
let expected = "\
|
||||||
|
dlopen doesn't panic\n\
|
||||||
something\n\
|
something\n\
|
||||||
[1, 2, 3, 4, 5, 6, 7, 8]\n\
|
[1, 2, 3, 4, 5, 6, 7, 8]\n\
|
||||||
579\n\
|
579\n\
|
||||||
|
|
|
@ -10,6 +10,14 @@ const [libPrefix, libSuffix] = {
|
||||||
const libPath = `${targetDir}/${libPrefix}test_ffi.${libSuffix}`;
|
const libPath = `${targetDir}/${libPrefix}test_ffi.${libSuffix}`;
|
||||||
|
|
||||||
const resourcesPre = Deno.resources();
|
const resourcesPre = Deno.resources();
|
||||||
|
|
||||||
|
// dlopen shouldn't panic
|
||||||
|
try {
|
||||||
|
Deno.dlopen("cli/src/main.rs", {});
|
||||||
|
} catch (_) {
|
||||||
|
console.log("dlopen doesn't panic");
|
||||||
|
}
|
||||||
|
|
||||||
const dylib = Deno.dlopen(libPath, {
|
const dylib = Deno.dlopen(libPath, {
|
||||||
"print_something": { parameters: [], result: "void" },
|
"print_something": { parameters: [], result: "void" },
|
||||||
"print_buffer": { parameters: ["buffer", "usize"], result: "void" },
|
"print_buffer": { parameters: ["buffer", "usize"], result: "void" },
|
||||||
|
|
Loading…
Reference in a new issue