Merge pull request #351 from napi-rs/remove-useless-type-cast

Remove useless type cast
This commit is contained in:
LongYinan 2020-12-09 22:58:43 +08:00 committed by GitHub
commit 018426ad83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 20 deletions

View file

@ -7,7 +7,7 @@ license = "MIT"
name = "napi" name = "napi"
readme = "README.md" readme = "README.md"
repository = "https://github.com/napi-rs/napi-rs" repository = "https://github.com/napi-rs/napi-rs"
version = "1.0.0-alpha.0" version = "1.0.0-alpha.1"
[features] [features]
default = ["napi3"] # for most NodeJS users default = ["napi3"] # for most NodeJS users

View file

@ -21,12 +21,7 @@ impl JsBuffer {
let mut data = ptr::null_mut(); let mut data = ptr::null_mut();
let mut len: usize = 0; let mut len: usize = 0;
check_status!(unsafe { check_status!(unsafe {
sys::napi_get_buffer_info( sys::napi_get_buffer_info(self.0.env, self.0.value, &mut data, &mut len)
self.0.env,
self.0.value,
&mut data,
&mut len as *mut usize as *mut _,
)
})?; })?;
Ok(JsBufferValue { Ok(JsBufferValue {
data: mem::ManuallyDrop::new(unsafe { Vec::from_raw_parts(data as *mut _, len, len) }), data: mem::ManuallyDrop::new(unsafe { Vec::from_raw_parts(data as *mut _, len, len) }),

View file

@ -25,19 +25,18 @@ macro_rules! impl_object_methods {
let mut error_code = ptr::null_mut(); let mut error_code = ptr::null_mut();
let mut reason_string = ptr::null_mut(); let mut reason_string = ptr::null_mut();
let mut js_error = ptr::null_mut(); let mut js_error = ptr::null_mut();
debug_assert!( let create_code_status = sys::napi_create_string_utf8(
sys::napi_create_string_utf8( env,
env, error_code_string.as_ptr(),
error_code_string.as_ptr(), status_len,
status_len, &mut error_code,
&mut error_code
) == sys::Status::napi_ok
); );
debug_assert!( debug_assert!(create_code_status == sys::Status::napi_ok);
sys::napi_create_string_utf8(env, reason.as_ptr(), reason_len, &mut reason_string) let create_reason_status =
== sys::Status::napi_ok sys::napi_create_string_utf8(env, reason.as_ptr(), reason_len, &mut reason_string);
); debug_assert!(create_reason_status == sys::Status::napi_ok);
debug_assert!($kind(env, error_code, reason_string, &mut js_error) == sys::Status::napi_ok); let create_error_status = $kind(env, error_code, reason_string, &mut js_error);
debug_assert!(create_error_status == sys::Status::napi_ok);
js_error js_error
} }
@ -47,7 +46,8 @@ macro_rules! impl_object_methods {
/// This function is safety if env is not null ptr. /// This function is safety if env is not null ptr.
pub unsafe fn throw_into(self, env: sys::napi_env) { pub unsafe fn throw_into(self, env: sys::napi_env) {
let js_error = self.into_value(env); let js_error = self.into_value(env);
debug_assert!(sys::napi_throw(env, js_error) == sys::Status::napi_ok); let throw_status = sys::napi_throw(env, js_error);
debug_assert!(throw_status == sys::Status::napi_ok);
} }
#[inline(always)] #[inline(always)]