Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename malloc to allocate to fix conflict in windows #83

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified assets/dusk_wallet_core.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{env, fs};
fn main() {
if env::var("GITHUB_ACTIONS").is_ok() {
// CI doesn't build with schemafy deterministically
return ();
return;
}

println!("cargo:rerun-if-changed=assets/schema.json");
Expand Down
3 changes: 2 additions & 1 deletion src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{key, tx, types, utils, MAX_KEY, MAX_LEN};

/// Allocates a buffer of `len` bytes on the WASM memory.
#[no_mangle]
pub fn malloc(len: i32) -> i32 {
pub fn allocate(len: i32) -> i32 {
let bytes = vec![0u8; len as usize];
let ptr = bytes.as_ptr();
mem::forget(bytes);
Expand Down Expand Up @@ -68,6 +68,7 @@ pub fn seed(args: i32, len: i32) -> i64 {
/// Will return a triplet (status, ptr, len) pointing to JSON string
/// representing [types::BalanceResult].
#[no_mangle]
#[allow(clippy::needless_range_loop)]
pub fn balance(args: i32, len: i32) -> i64 {
let types::BalanceArgs { notes, seed } = match utils::take_args(args, len) {
Some(a) => a,
Expand Down
1 change: 1 addition & 0 deletions src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ impl UnprovenTransaction {
///
/// The transaction can be sent to a prover service and it contains all the
/// data required to generate a ZK proof of validity.
#[allow(clippy::too_many_arguments)]
pub fn new<'a, Rng, I, O>(
rng: &mut Rng,
inputs: I,
Expand Down
17 changes: 6 additions & 11 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ pub fn bs58_to_psk(psk: &str) -> Option<PublicSpendKey> {
///
/// Returns a tuple containing (unspent, inputs). `unspent` contains the notes
/// that are not used.
#[allow(clippy::type_complexity)]
pub fn knapsack(
mut nodes: Vec<(Note, tx::Opening, u64, usize)>,
target_sum: u64,
Expand Down Expand Up @@ -227,13 +228,10 @@ fn knapsack_works() {
let key = SecretSpendKey::random(rng);
let blinder = JubJubScalar::random(rng);
let note3 = Note::obfuscated(rng, &key.public_spend_key(), 300, blinder);
let available = vec![
(note1.clone(), o, 100, 0),
(note2.clone(), o, 500, 1),
(note3.clone(), o, 300, 2),
];
let available =
vec![(note1, o, 100, 0), (note2, o, 500, 1), (note3, o, 300, 2)];
let unspent = vec![note1];
let inputs = vec![(note2.clone(), o, 500, 1), (note3.clone(), o, 300, 2)];
let inputs = vec![(note2, o, 500, 1), (note3, o, 300, 2)];
assert_eq!(knapsack(available, 600), Some((unspent, inputs)));

// multiple inputs, out of balance check
Expand All @@ -246,10 +244,7 @@ fn knapsack_works() {
let key = SecretSpendKey::random(rng);
let blinder = JubJubScalar::random(rng);
let note3 = Note::obfuscated(rng, &key.public_spend_key(), 300, blinder);
let available = vec![
(note1.clone(), o, 100, 0),
(note2.clone(), o, 500, 1),
(note3.clone(), o, 300, 2),
];
let available =
vec![(note1, o, 100, 0), (note2, o, 500, 1), (note3, o, 300, 2)];
assert_eq!(knapsack(available, 901), None);
}
2 changes: 1 addition & 1 deletion tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ impl Wallet {
let ptr = self
.instance
.exports
.get_function("malloc")
.get_function("allocate")
.unwrap()
.call(&mut self.store, &[len.clone()])
.unwrap()[0]
Expand Down
Loading