Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Aug 4, 2022
1 parent 214fc14 commit 8a3bebc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 40 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dan_layer/template_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub mod models;

// TODO: we should only use stdlib if the template dev needs to include it e.g. use core::mem when stdlib is not
// available
use std::{collections::HashMap, mem, slice};
use std::{collections::HashMap, mem, ptr::copy, slice};

use tari_template_abi::{encode_with_len, Decode, Encode, FunctionDef, TemplateDef};

Expand Down
2 changes: 1 addition & 1 deletion dan_layer/template_lib/src/models/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// TODO: use the actual component id type
pub type ComponentId = ([u8; 32], u32);

use tari_template_abi::{Decode, Encode, encode_with_len, ops::OP_CREATE_COMPONENT, CreateComponentArg};
use tari_template_abi::{encode_with_len, ops::OP_CREATE_COMPONENT, CreateComponentArg, Decode, Encode};

use crate::call_engine;

Expand Down
69 changes: 35 additions & 34 deletions dan_layer/template_macros/src/template/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,40 @@ use quote::quote;

pub fn generate_dependencies() -> TokenStream {
quote! {
extern "C" {
pub fn tari_engine(op: u32, input_ptr: *const u8, input_len: usize) -> *mut u8;
}

pub fn wrap_ptr(mut v: Vec<u8>) -> *mut u8 {
use std::mem;

let ptr = v.as_mut_ptr();
mem::forget(v);
ptr
}

#[no_mangle]
pub unsafe extern "C" fn tari_alloc(len: u32) -> *mut u8 {
use std::{mem, intrinsics::copy};

let cap = (len + 4) as usize;
let mut buf = Vec::<u8>::with_capacity(cap);
let ptr = buf.as_mut_ptr();
mem::forget(buf);
copy(len.to_le_bytes().as_ptr(), ptr, 4);
ptr
}

#[no_mangle]
pub unsafe extern "C" fn tari_free(ptr: *mut u8) {
use std::intrinsics::copy;

let mut len = [0u8; 4];
copy(ptr, len.as_mut_ptr(), 4);

let cap = (u32::from_le_bytes(len) + 4) as usize;
let _ = Vec::<u8>::from_raw_parts(ptr, cap, cap);
}
use tari_template_lib::{wrap_ptr, tari_alloc, tari_free};
// extern "C" {
// pub fn tari_engine(op: u32, input_ptr: *const u8, input_len: usize) -> *mut u8;
// }
//
// pub fn wrap_ptr(mut v: Vec<u8>) -> *mut u8 {
// use std::mem;
//
// let ptr = v.as_mut_ptr();
// mem::forget(v);
// ptr
// }
//
// #[no_mangle]
// pub unsafe extern "C" fn tari_alloc(len: u32) -> *mut u8 {
// use std::{mem, intrinsics::copy};
//
// let cap = (len + 4) as usize;
// let mut buf = Vec::<u8>::with_capacity(cap);
// let ptr = buf.as_mut_ptr();
// mem::forget(buf);
// copy(len.to_le_bytes().as_ptr(), ptr, 4);
// ptr
// }
//
// #[no_mangle]
// pub unsafe extern "C" fn tari_free(ptr: *mut u8) {
// use std::intrinsics::copy;
//
// let mut len = [0u8; 4];
// copy(ptr, len.as_mut_ptr(), 4);
//
// let cap = (u32::from_le_bytes(len) + 4) as usize;
// let _ = Vec::<u8>::from_raw_parts(ptr, cap, cap);
// }
}
}

0 comments on commit 8a3bebc

Please sign in to comment.