summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/ffi/build.rs7
-rw-r--r--ext/ffi/lib.rs32
2 files changed, 23 insertions, 16 deletions
diff --git a/ext/ffi/build.rs b/ext/ffi/build.rs
index 091dd9599..1debd6b9c 100644
--- a/ext/ffi/build.rs
+++ b/ext/ffi/build.rs
@@ -1,8 +1,9 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
-use std::env;
-
+#[cfg(not(target_os = "windows"))]
fn build_tcc() {
+ use std::env;
+
{
// TODO(@littledivy): Windows support for fast call.
// let tcc_path = root
@@ -58,6 +59,8 @@ fn main() {}
#[cfg(not(target_os = "windows"))]
fn main() {
+ use std::env;
+
if let Ok(tcc_path) = env::var("TCC_PATH") {
println!("cargo:rustc-link-search=native={}", tcc_path);
} else {
diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs
index 737ea9db2..ac792de44 100644
--- a/ext/ffi/lib.rs
+++ b/ext/ffi/lib.rs
@@ -518,8 +518,10 @@ pub(crate) fn format_error(e: dlopen::Error, path: String) -> String {
let arguments = [path.as_ptr()];
loop {
- unsafe {
- let length = FormatMessageW(
+ // SAFETY:
+ // winapi call to format the error message
+ let length = unsafe {
+ FormatMessageW(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY,
std::ptr::null_mut(),
err_num as DWORD,
@@ -527,22 +529,24 @@ pub(crate) fn format_error(e: dlopen::Error, path: String) -> String {
buf.as_mut_ptr(),
buf.len() as DWORD,
arguments.as_ptr() as _,
- );
-
- if length == 0 {
- let err_num = GetLastError();
- if err_num == ERROR_INSUFFICIENT_BUFFER {
- buf.resize(buf.len() * 2, 0);
- continue;
- }
+ )
+ };
- // Something went wrong, just return the original error.
- return e.to_string();
+ if length == 0 {
+ // SAFETY:
+ // winapi call to get the last error message
+ let err_num = unsafe { GetLastError() };
+ if err_num == ERROR_INSUFFICIENT_BUFFER {
+ buf.resize(buf.len() * 2, 0);
+ continue;
}
- let msg = String::from_utf16_lossy(&buf[..length as usize]);
- return msg;
+ // Something went wrong, just return the original error.
+ return e.to_string();
}
+
+ let msg = String::from_utf16_lossy(&buf[..length as usize]);
+ return msg;
}
}
_ => e.to_string(),