Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Apr 23, 2019
1 parent 610f520 commit 429ed9b
Showing 1 changed file with 0 additions and 45 deletions.
45 changes: 0 additions & 45 deletions bindings/rust/evmc-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,51 +170,6 @@ extern "C" fn release_stack_result(result: *const ffi::evmc_result) {
}
}

/// Returns a pointer to a stack-allocated evmc_result.
impl Into<ffi::evmc_result> for ExecutionResult {
fn into(self) -> ffi::evmc_result {
let (buffer, len) = if let Some(buf) = self.output {
let buf_len = buf.len();

// Manually allocate heap memory for the new home of the output buffer.
let memlayout = std::alloc::Layout::from_size_align(buf_len, 1).expect("Bad layout");
let new_buf = unsafe { std::alloc::alloc(memlayout) };
unsafe {
// Copy the data into the allocated buffer.
std::ptr::copy(buf.as_ptr(), new_buf, buf_len);
}

(new_buf as *const u8, buf_len)
} else {
(std::ptr::null(), 0)
};

ffi::evmc_result {
status_code: self.status_code,
gas_left: self.gas_left,
output_data: buffer,
output_size: len,
//release: None,
// This still crashes.
release: Some(release_stack_result),
create_address: self.create_address,
padding: [0u8; 4],
}
}
}

/// Callback to pass across FFI, de-allocating the struct.
extern "C" fn release_stack_result(result: *const ffi::evmc_result) {
unsafe {
let tmp = *result;
if !tmp.output_data.is_null() {
let buf_layout =
std::alloc::Layout::from_size_align(tmp.output_size, 1).expect("Bad layout");
std::alloc::dealloc(tmp.output_data as *mut u8, buf_layout);
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 429ed9b

Please sign in to comment.