From 7a6947efcfcc18b6f4027006231ace4050792c10 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Wed, 16 Aug 2023 11:39:32 +0200 Subject: [PATCH] codegen: Fully quality std::{ptr::{null,null_mut}, mem::MaybeUninit} --- src/analysis/functions.rs | 14 -------------- src/analysis/out_parameters.rs | 31 +------------------------------ src/writer/to_code.rs | 6 +++--- 3 files changed, 4 insertions(+), 47 deletions(-) diff --git a/src/analysis/functions.rs b/src/analysis/functions.rs index 235e090d8..417b5aec8 100644 --- a/src/analysis/functions.rs +++ b/src/analysis/functions.rs @@ -849,20 +849,6 @@ fn analyze_function( func.c_identifier.as_ref().unwrap_or(&func.name) ); commented = true; - } else if status.need_generate() && !commented { - if !outs.is_empty() { - out_parameters::analyze_imports(env, &func.parameters, imports); - } - if let Some(AsyncTrampoline { - ref output_params, .. - }) = trampoline - { - out_parameters::analyze_imports( - env, - output_params.iter().map(|out| &out.lib_par), - imports, - ); - } } if r#async && status.need_generate() && !commented { diff --git a/src/analysis/out_parameters.rs b/src/analysis/out_parameters.rs index 61598b03e..6ee2d6287 100644 --- a/src/analysis/out_parameters.rs +++ b/src/analysis/out_parameters.rs @@ -5,7 +5,7 @@ use log::error; use crate::{ analysis::{ self, conversion_type::ConversionType, function_parameters::CParameter, - functions::is_carray_with_direct_elements, imports::Imports, return_value, + functions::is_carray_with_direct_elements, return_value, rust_type::RustType, }, config::{self, parameter_matchable::ParameterMatchable}, @@ -126,35 +126,6 @@ pub fn analyze( (info, unsupported_outs) } -pub fn analyze_imports<'a>( - env: &Env, - parameters: impl IntoIterator, - imports: &mut Imports, -) { - for par in parameters { - if par.direction == ParameterDirection::Out { - analyze_type_imports(env, par.typ, par.caller_allocates, imports); - } - } -} - -fn analyze_type_imports(env: &Env, typ: TypeId, caller_allocates: bool, imports: &mut Imports) { - match env.library.type_(typ) { - Type::Alias(alias) => analyze_type_imports(env, alias.typ, caller_allocates, imports), - Type::Bitfield(..) | Type::Enumeration(..) => imports.add("std::mem"), - Type::Basic(fund) if !matches!(fund, Basic::Utf8 | Basic::OsString | Basic::Filename) => { - imports.add("std::mem"); - } - _ if !caller_allocates => match ConversionType::of(env, typ) { - ConversionType::Direct - | ConversionType::Scalar - | ConversionType::Option - | ConversionType::Result { .. } => (), - _ => imports.add("std::ptr"), - }, - _ => (), - } -} pub fn can_as_return(env: &Env, par: &library::Parameter) -> bool { use super::conversion_type::ConversionType::*; diff --git a/src/writer/to_code.rs b/src/writer/to_code.rs index 8b7c16fe7..e9a3cae91 100644 --- a/src/writer/to_code.rs +++ b/src/writer/to_code.rs @@ -78,13 +78,13 @@ impl ToCode for Chunk { let s = format_block_one_line(&prefix, ";", &value_strings, "", ""); vec![s] } - Uninitialized => vec!["mem::MaybeUninit::uninit()".into()], + Uninitialized => vec!["std::mem::MaybeUninit::uninit()".into()], UninitializedNamed { ref name } => { let s = format!("{name}::uninitialized()"); vec![s] } - NullPtr => vec!["ptr::null()".into()], - NullMutPtr => vec!["ptr::null_mut()".into()], + NullPtr => vec!["std::ptr::null()".into()], + NullMutPtr => vec!["std::ptr::null_mut()".into()], Custom(ref string) => vec![string.clone()], Tuple(ref chs, ref mode) => { #[allow(deprecated)]