Skip to content

Commit

Permalink
Fix set_fn.
Browse files Browse the repository at this point in the history
  • Loading branch information
schungx committed Sep 3, 2023
1 parent 96b0f0e commit f4db45d
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use bitflags::bitflags;
use std::prelude::v1::*;
use std::{
any::TypeId,
collections::BTreeMap,
collections::{hash_map::Entry, BTreeMap},

Check failure on line 20 in src/module/mod.rs

View workflow job for this annotation

GitHub Actions / NoStdBuild (ubuntu-latest, --profile unix, false)

unresolved import `std::collections::hash_map`
fmt,
ops::{Add, AddAssign},
};
Expand Down Expand Up @@ -1154,6 +1154,7 @@ impl Module {
func: CallableFunction,
) -> &mut FuncInfo {
let _arg_names = arg_names;
let _comments = comments;
let is_method = func.is_method();

let param_types = arg_types
Expand Down Expand Up @@ -1202,29 +1203,38 @@ impl Module {
self.flags
.remove(ModuleFlags::INDEXED | ModuleFlags::INDEXED_GLOBAL_FUNCTIONS);

self.functions
let f = FuncInfo {
func,
metadata: FuncInfoMetadata {
hash: hash_fn,
name,
namespace,
access,
#[cfg(not(feature = "no_object"))]
this_type: None,
num_params: param_types.len(),
param_types: param_types.into_boxed_slice(),
#[cfg(feature = "metadata")]
params_info: param_names.into_boxed_slice(),
#[cfg(feature = "metadata")]
return_type: return_type_name,
#[cfg(feature = "metadata")]
comments: _comments.into_iter().map(|s| s.as_ref().into()).collect(),
}
.into(),
};

match self
.functions
.get_or_insert_with(|| new_hash_map(FN_MAP_SIZE))
.entry(hash_fn)
.or_insert_with(|| FuncInfo {
func,
metadata: FuncInfoMetadata {
hash: hash_fn,
name,
namespace,
access,
#[cfg(not(feature = "no_object"))]
this_type: None,
num_params: param_types.len(),
param_types: param_types.into_boxed_slice(),
#[cfg(feature = "metadata")]
params_info: param_names.into_boxed_slice(),
#[cfg(feature = "metadata")]
return_type: return_type_name,
#[cfg(feature = "metadata")]
comments: comments.into_iter().map(|s| s.as_ref().into()).collect(),
}
.into(),
})
{
Entry::Occupied(mut entry) => {
entry.insert(f);
entry.into_mut()
}
Entry::Vacant(entry) => entry.insert(f),
}
}

/// Set a native Rust function into the [`Module`], returning a [`u64`] hash key.
Expand Down

0 comments on commit f4db45d

Please sign in to comment.