From 31dc0a30dfd05144439c63d3fc3aae93636de06c Mon Sep 17 00:00:00 2001 From: folex <0xdxdy@gmail.com> Date: Thu, 17 Dec 2020 12:47:43 +0300 Subject: [PATCH] Change 'target' from i64 to i32 in log_utf8_string (#13) --- crates/main/src/lib.rs | 2 +- crates/main/src/logger.rs | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/main/src/lib.rs b/crates/main/src/lib.rs index 534b731..b1788d0 100644 --- a/crates/main/src/lib.rs +++ b/crates/main/src/lib.rs @@ -62,7 +62,7 @@ pub(crate) fn log>(msg: S) { #[cfg(feature = "debug")] { let level = log::Level::Info as i32; - let target = 0i64; + let target = 0i32; let msg = msg.as_ref(); logger::log_utf8_string(level, target, msg.as_ptr() as i32, msg.len() as i32); } diff --git a/crates/main/src/logger.rs b/crates/main/src/logger.rs index dd07df9..58bf059 100644 --- a/crates/main/src/logger.rs +++ b/crates/main/src/logger.rs @@ -50,7 +50,11 @@ pub const WASM_LOG_ENV_NAME: &'static str = "WASM_LOG"; /// If WASM_LOG_ENV isn't set, then this level will be used as the default. const WASM_DEFAULT_LOG_LEVEL: LogLevel = LogLevel::Info; -pub type TargetMap = std::collections::HashMap<&'static str, i64>; +/// Mapping from logging namespace string to its bitmask. +/// TODO: use i64 for bitmask when wasmpack/bindgen issue with i64 is fixed. +/// Currently, i64 doesn't work on some versions of V8 because log_utf8_string function +/// isn't marked as #[wasm_bindgen]. In result, TS/JS code throws 'TypeError' on every log. +pub type TargetMap = std::collections::HashMap<&'static str, i32>; /// The Wasm Logger. /// @@ -165,12 +169,12 @@ impl log::Log for WasmLogger { } #[cfg(target_arch = "wasm32")] -pub fn log_utf8_string(level: i32, target: i64, msg_ptr: i32, msg_size: i32) { +pub fn log_utf8_string(level: i32, target: i32, msg_ptr: i32, msg_size: i32) { unsafe { log_utf8_string_impl(level, target, msg_ptr, msg_size) }; } #[cfg(not(target_arch = "wasm32"))] -pub fn log_utf8_string(level: i32, target: i64, msg_ptr: i32, msg_size: i32) { +pub fn log_utf8_string(level: i32, target: i32, msg_ptr: i32, msg_size: i32) { use std::str::from_utf8_unchecked; use core::slice::from_raw_parts; @@ -179,13 +183,14 @@ pub fn log_utf8_string(level: i32, target: i64, msg_ptr: i32, msg_size: i32) { println!("[{}] {} {}", level, target, msg); } +/// TODO: mark `log_utf8_string_impl` as #[wasm_bindgen], so it is polyfilled by bindgen /// log_utf8_string should be provided directly by a host. #[cfg(target_arch = "wasm32")] #[link(wasm_import_module = "host")] extern "C" { // Writes a byte string of size bytes that starts from ptr to a logger #[link_name = "log_utf8_string"] - fn log_utf8_string_impl(level: i32, target: i64, msg_ptr: i32, msg_size: i32); + fn log_utf8_string_impl(level: i32, target: i32, msg_ptr: i32, msg_size: i32); } #[allow(dead_code)]