diff --git a/napi-derive/src/lib.rs b/napi-derive/src/lib.rs index 744bbf35..6954c61b 100644 --- a/napi-derive/src/lib.rs +++ b/napi-derive/src/lib.rs @@ -204,7 +204,7 @@ fn get_execute_js_code( Err(e) => { let message = format!("{}", e); unsafe { - napi::sys::napi_throw_error(raw_env, ptr::null(), CString::from_vec_unchecked(message.into()).as_ptr() as *const c_char); + napi::sys::napi_throw_error(raw_env, ptr::null(), CString::from_vec_unchecked(message.into()).into_raw()); } ptr::null_mut() } diff --git a/napi/src/env.rs b/napi/src/env.rs index 462744b9..16c842f2 100644 --- a/napi/src/env.rs +++ b/napi/src/env.rs @@ -368,11 +368,7 @@ impl Env { pub fn throw_error(&self, msg: &str) -> Result<()> { check_status(unsafe { - sys::napi_throw_error( - self.0, - ptr::null(), - CString::from_vec_unchecked(msg.into()).as_ptr() as *const _, - ) + sys::napi_throw_error(self.0, ptr::null(), CString::new(msg)?.into_raw()) }) } diff --git a/napi/src/js_values/mod.rs b/napi/src/js_values/mod.rs index 65387f5f..6b476b54 100644 --- a/napi/src/js_values/mod.rs +++ b/napi/src/js_values/mod.rs @@ -257,7 +257,7 @@ macro_rules! impl_object_methods { where T: NapiValue, { - let key = CString::new(name.to_owned())?; + let key = CString::new(name)?; check_status(unsafe { sys::napi_set_named_property(self.0.env, self.0.value, key.as_ptr(), value.raw()) }) @@ -273,12 +273,9 @@ macro_rules! impl_object_methods { })?; T::from_raw(self.0.env, raw_value) } - pub fn has_named_property(&self, name: S) -> Result - where - S: AsRef, - { + pub fn has_named_property(&self, name: &str) -> Result { let mut result = false; - let key = CString::new(name.as_ref())?; + let key = CString::new(name)?; check_status(unsafe { sys::napi_has_named_property(self.0.env, self.0.value, key.as_ptr(), &mut result) })?; @@ -299,7 +296,7 @@ macro_rules! impl_object_methods { let key_str = CString::new(name)?; let mut js_key = ptr::null_mut(); check_status(unsafe { - sys::napi_create_string_utf8(self.0.env, key_str.as_ptr(), name.len() as _, &mut js_key) + sys::napi_create_string_utf8(self.0.env, key_str.as_ptr(), name.len(), &mut js_key) })?; check_status(unsafe { sys::napi_delete_property(self.0.env, self.0.value, js_key, &mut result) @@ -311,7 +308,7 @@ macro_rules! impl_object_methods { let string = CString::new(key)?; let mut js_key = ptr::null_mut(); check_status(unsafe { - sys::napi_create_string_utf8(self.0.env, string.as_ptr(), key.len() as _, &mut js_key) + sys::napi_create_string_utf8(self.0.env, string.as_ptr(), key.len(), &mut js_key) })?; check_status(unsafe { sys::napi_has_own_property(self.0.env, self.0.value, js_key, &mut result) diff --git a/napi/src/js_values/object_property.rs b/napi/src/js_values/object_property.rs index f0c45390..fff003f8 100644 --- a/napi/src/js_values/object_property.rs +++ b/napi/src/js_values/object_property.rs @@ -37,7 +37,7 @@ impl<'env> Property<'env> { let string_value = CString::new(name)?; let mut result = ptr::null_mut(); check_status(unsafe { - sys::napi_create_string_utf8(env.0, string_value.as_ptr(), name.len() as _, &mut result) + sys::napi_create_string_utf8(env.0, string_value.as_ptr(), name.len(), &mut result) })?; Ok(Property { name, diff --git a/napi/src/lib.rs b/napi/src/lib.rs index be89dead..eac95756 100644 --- a/napi/src/lib.rs +++ b/napi/src/lib.rs @@ -188,7 +188,7 @@ macro_rules! register_module { raw_env, ptr::null(), CString::from_vec_unchecked(format!("Error initializing module: {}", e).into()) - .as_ptr() as *const _, + .into_raw() as *const _, ) }; ptr::null_mut()