Skip to content

Commit

Permalink
codegen: Fully quality std::{ptr::{null,null_mut}, mem::MaybeUninit}
Browse files Browse the repository at this point in the history
  • Loading branch information
bilelmoussaoui committed Aug 16, 2023
1 parent 3937b9f commit 7a6947e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 47 deletions.
14 changes: 0 additions & 14 deletions src/analysis/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 1 addition & 30 deletions src/analysis/out_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -126,35 +126,6 @@ pub fn analyze(
(info, unsupported_outs)
}

pub fn analyze_imports<'a>(
env: &Env,
parameters: impl IntoIterator<Item = &'a library::Parameter>,
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::*;
Expand Down
6 changes: 3 additions & 3 deletions src/writer/to_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 7a6947e

Please sign in to comment.