Skip to content

Commit

Permalink
Fix all the warnings (#562)
Browse files Browse the repository at this point in the history
* Add oom-with-hook feature to Cargo

Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>

* Remove unused import

Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>

* Fix abi of EncodedStringCallback

Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>

* Resolve ambiguous imports

Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>

---------

Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>
  • Loading branch information
gmorenz authored Mar 6, 2025
1 parent 99518a4 commit 2c59822
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions mozjs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ debugmozjs = []
profilemozjs = []
jitspew = []
crown = []
oom_with_hook = []

[dependencies]
libc.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion mozjs-sys/src/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use core::mem;

pub use generated::root::*;

pub type EncodedStringCallback = fn(*const core::ffi::c_char);
pub type EncodedStringCallback = unsafe extern "C" fn(*const core::ffi::c_char);

// manual glue stuff
unsafe impl Sync for ProxyTraps {}
Expand Down
1 change: 1 addition & 0 deletions mozjs-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![allow(unused_extern_crates)]
#![cfg_attr(feature = "crown", feature(register_tool))]
#![cfg_attr(feature = "crown", register_tool(crown))]
#![cfg_attr(feature = "oom_with_hook", feature(alloc_error_hook))]

// These extern crates are needed for linking
extern crate encoding_c;
Expand Down
1 change: 0 additions & 1 deletion mozjs-sys/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use std::sync::atomic::{
AtomicBool, AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, AtomicU16, AtomicU32,
AtomicU64, AtomicU8, AtomicUsize,
};
use std::sync::Arc;
use std::thread::JoinHandle;
use std::time::{Duration, Instant, SystemTime};

Expand Down
4 changes: 4 additions & 0 deletions mozjs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
//!
pub mod jsapi {
// Resolve ambiguous imports
pub use mozjs_sys::jsapi::js::detail;
pub use mozjs_sys::jsapi::JS::{FrontendContext, MemoryUse};

pub use mozjs_sys::jsapi::glue::*;
pub use mozjs_sys::jsapi::js::detail::*;
pub use mozjs_sys::jsapi::js::*;
Expand Down
5 changes: 3 additions & 2 deletions mozjs/tests/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ unsafe extern "C" fn puts(context: *mut JSContext, argc: u32, vp: *mut Value) ->
let arg = mozjs::rust::Handle::from_raw(args.get(0));
let js = mozjs::rust::ToString(context, arg);
rooted!(in(context) let message_root = js);
EncodeStringToUTF8(context, message_root.handle().into(), |message| {
unsafe extern "C" fn cb(message: *const core::ffi::c_char) {
let message = CStr::from_ptr(message);
let message = str::from_utf8(message.to_bytes()).unwrap();
assert_eq!(message, "Test Iñtërnâtiônàlizætiøn ┬─┬ノ( º _ ºノ) ");
println!("{}", message);
});
}
EncodeStringToUTF8(context, message_root.handle().into(), cb);

args.rval().set(UndefinedValue());
true
Expand Down

0 comments on commit 2c59822

Please sign in to comment.