ffi

How to convert an `IO ()` to `JSVal` in GHCJS

a 夏天 提交于 2019-12-10 15:23:20
问题 i want to execute some effectful computation on a regular basis in a program compiled with GHCJS, but GHCJS.DOM.WindowTimers.setInterval wants a JSVal as parameter. Could anybody give me some pointers for turning my IO () into a JSVal ? Edit: I was able to match the types using GHCJS.Foreign.Callback.asyncCallback and GHCJS.Types.jsval , but i have eventually got a runtime error. Luite in the GHCJS channel suggested to use threads for this task, as Erik suggested in a comment here. This is

How do I declare a static variable as a reference to a hard-coded memory address?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 14:40:11
问题 I am working on embedded Rust code for LPC82X series controllers from NXP - the exact toolchain does not matter for the question. These controllers contain peripheral drivers in ROM. I want to use these drivers, which means I need to use unsafe Rust and FFI without linking actual code. The ROM APIs expose function pointers packed into C structs at specific address locations. If somebody wants the details of this API, chapter 29 of the LPC82X manual describes the API in question. My Rust

Haskell Stack and C Libraries

旧街凉风 提交于 2019-12-10 12:38:50
问题 This is possibly a duplicate of this post. But the only answer it got does not seem to work for me, so I post my own case here hoping to find a specific solution. I am on Linux Ubuntu Trusty. I have a proprietary C library, libMyLib.so, located in /usr/local/lib (which is included in LD_LIBRARY_PATH). I wrote the haskell bindings to this C library the ususal way. Main.hs : {-# LANGUAGE ForeignFunctionInterface #-} module Main where import Foreign import Foreign.C.Types foreign import ccall

How to make library installed from OPAM available to OCaml?

与世无争的帅哥 提交于 2019-12-10 09:39:12
问题 I followed this tutorial on OCaml FFI and installed Ctypes through OPAM: opam install ctypes However, OCaml does not find the module: open Ctypes (* ... *) I receive the error: Unbound module Ctypes It looks like I need to let OCaml know where my Ctypes installation is? Do I need to update some path variable to let OCaml look for my libraries installed through OPAM? This is Ubuntu 15.04, OCaml 4.01.0, OPAM 1.2.0. 回答1: Installing something on your system doesn't make it automatically visible

I am familiar with Ruby /DL but not sure how to use the C function calls that have pointers for return parameters

半腔热情 提交于 2019-12-10 07:53:05
问题 I have this function in this Module require 'dl' require 'dl/import' module LibCalendars extend DL::Importer dlload './cal2jd.o' extern 'int iauCal2jd(int, int, int, double *, double *)' end How do I set this up in a Module to get access to the pointers? Is what I need partly in there? I'm just not sure. How is this done correctly? The exact code is at http://www.iausofa.org/2013_1202_C/sofa/cal2jd.c I need to know how to access those address pointers. The validation tests are here http://www

How do I initialize an opaque C struct when using Rust FFI?

心已入冬 提交于 2019-12-10 03:11:07
问题 Here's what I would like to do in C code: #include <some_lib.h> int main() { some_lib_struct_t x; some_lib_func(&x); } How do I make use of the library in Rust? Here's what I've got so far: extern crate libc; // 0.2.51 struct some_lib_struct_t; #[link(name = "some_lib")] extern "C" { fn some_lib_func(x: *mut some_lib_struct_t); } fn main() { let mut x: some_lib_struct_t; unsafe { some_lib_func(&mut x); } } When compiling I get an error: error[E0381]: borrow of possibly uninitialized variable:

How to catch a Haskell exception that is thrown in a Haskell callback function called by a C function?

陌路散爱 提交于 2019-12-10 01:21:11
问题 Is there any good way to catch a haskell exception, which is thrown in a haskell callback function called by a c function? For example, let me have a simple c function which just calls a given callback, void callmeback ( void (*callback) () ) { callback (); } and a haskell code which uses this function via ffi. {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE ForeignFunctionInterface #-} module Main (main) where import Foreign import Control.Exception import Data.Typeable foreign import ccall

Segmentation fault when calling a Rust lib with Ruby FFI

偶尔善良 提交于 2019-12-09 17:04:57
问题 I want to pass in a String to a Rust lib, but it always throws a segmentation fault. Here's the code: // lib.rs #[no_mangle] pub extern fn process(foo: String) -> String { foo } And the Ruby file: # embed.rb require 'ffi' module Hello extend FFI::Library ffi_lib 'target/release/libembed.dylib' attach_function :process, [ :string ], :string end puts Hello.process("foo") 回答1: Disclaimer : I've never used Ruby-FFI before; I'm going on what I can find in the documentation. According to the Ruby

Catching panic! when Rust called from C FFI, without spawning threads

筅森魡賤 提交于 2019-12-09 09:54:26
问题 I'm working on a Rust wrapper for the Duktape JavaScript interpreter. In a normal use case, the call stack will look like this: Rust: Arbitrary application code. Rust: My library wrapper. C: The Duktape interpreter. Rust: My Rust code. Rust: Arbitrary callbacks into application code. What happens if (5) calls panic! ? According to various Rust developers on IRC, attempting to panic! from inside non-Rust callframes like (3) may result in undefined behavior. But according the Rust documentation

How to link custom object file with Haskell library?

北战南征 提交于 2019-12-09 07:41:14
问题 I've created a Haskell package that makes FFI calls to functions defined in CUDA code. I'd like to compile .cu file to an object (.o) file during package build and force linker to link it in. So far, I tried to use a technique found this question. I've customized buildHook to: run nvcc run default buildHook create ar library file with nvcc compiled code. Setup.hs is available here. This solution has a major disadvantage in restricting this package to static linking. Although cabal produces a