From 1669b3a8f106fa04d6773871d9363d460b350d6b Mon Sep 17 00:00:00 2001 From: LongYinan Date: Sat, 14 Nov 2020 00:22:10 +0800 Subject: [PATCH] fix(napi): windows-i686 release build problem --- napi/src/env.rs | 8 +++++--- napi/src/js_values/mod.rs | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/napi/src/env.rs b/napi/src/env.rs index 9438f35a..5a982b21 100644 --- a/napi/src/env.rs +++ b/napi/src/env.rs @@ -344,13 +344,15 @@ impl Env { pub fn create_function(&self, name: &str, callback: Callback) -> Result { let mut raw_result = ptr::null_mut(); + let name = CString::new(name.to_owned())?; + let len = name.as_bytes().len(); check_status(unsafe { sys::napi_create_function( self.0, - name.as_ptr() as *const c_char, - name.len() as _, + name.into_raw(), + len, Some(callback), - callback as *mut c_void, + ptr::null_mut(), &mut raw_result, ) })?; diff --git a/napi/src/js_values/mod.rs b/napi/src/js_values/mod.rs index 227fc9e1..65387f5f 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)?; + let key = CString::new(name.to_owned())?; check_status(unsafe { sys::napi_set_named_property(self.0.env, self.0.value, key.as_ptr(), value.raw()) })