Skip to content

Instantly share code, notes, and snippets.

@mwotton
Last active May 12, 2018 23:52
Show Gist options
  • Save mwotton/0a192a4a06118ba82e8b6f33daccec58 to your computer and use it in GitHub Desktop.
Save mwotton/0a192a4a06118ba82e8b6f33daccec58 to your computer and use it in GitHub Desktop.
[Running cargo run]
Compiling eris v0.1.0 (file:///home/mark/projects/eris)
warning: unused import: `std::io::Cursor`
--> src/main.rs:13:5
|
13 | use std::io::Cursor;
| ^^^^^^^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default
warning: unused import: `serde::Deserialize`
--> src/main.rs:14:5
|
14 | use serde::Deserialize;
| ^^^^^^^^^^^^^^^^^^
warning: unused import: `rmps::Deserializer`
--> src/main.rs:15:5
|
15 | use rmps::Deserializer;
| ^^^^^^^^^^^^^^^^^^
error[E0308]: mismatched types
--> src/main.rs:20:5
|
20 | / unsafe {
21 | | let init_ghc: lib::Symbol<unsafe extern fn(u32,u32) -> u32> = lib.get(b"hs_init")?;
22 | | let hs_fib: lib::Symbol<unsafe extern fn(*const u8) -> *const u8 > = lib.get(b"fib_export")?;
23 | | let mut buf = Vec::new();
... |
40 | | // Deserialize::deserialize(&mut de).map_err(|_x| std::io::Error.new("something broke"))
41 | | }
| |_____^ expected enum `serde::export::Result`, found ()
|
= note: expected type `serde::export::Result<u32, std::io::Error>`
found type `()`
error: aborting due to previous error
error: Could not compile `eris`.
extern crate libloading as lib;
// extern crate serde_derive;
extern crate serde;
extern crate rmp_serde as rmps;
#[macro_use]
extern crate structure;
use rmps::Serializer;
use serde::Serialize;
use std::io::Cursor;
use serde::Deserialize;
use rmps::Deserializer;
fn call_dynamic() -> lib::Result<u32> {
let lib = lib::Library::new("./call-haskell-from-anything.so")?;
unsafe {
let init_ghc: lib::Symbol<unsafe extern fn(u32,u32) -> u32> = lib.get(b"hs_init")?;
let hs_fib: lib::Symbol<unsafe extern fn(*const u8) -> *const u8 > = lib.get(b"fib_export")?;
let mut buf = Vec::new();
let input: [i32;1] = [12];
input.serialize(&mut Serializer::new(&mut buf));
println!("serialized = {:?}", buf);
let mut appended = structure!("q").pack(buf.len() as i64)?;
appended.append(&mut buf);
println!("appended = {:?}", appended);
init_ghc(0,0);
let outbuf = hs_fib(appended.as_ptr());
println!("raw = {:?}", outbuf);
//breakage begins
let cur = Cursor::new(outbuf); //outbuf[..]);
let mut de = Deserializer::new(cur);
Deserialize::deserialize(&mut de).map_err(|_x| std::io::Error.new("something broke"))
}
}
fn main() {
match call_dynamic() {
Ok(t) => println!("number is {}", t),
Err(e) => println!("something went terribly wrong ({})", e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment