ffi

Error installing Sass (Ruby 2.5.0.1, MSYS2 20161025.0.0)

怎甘沉沦 提交于 2019-12-23 11:35:15
问题 I tried to install Sass. I installed Ruby and MSYS2 prior to that, the latest from all with Chocolatey: choco install ruby choco install msys2 Seemingly they were properly installed. ruby -v results in: ruby 2.5.0p0 (2017-12-25 revision 61468) [x64-mingw32] When I tried to run gem install sass I received the following error message: ERROR: Error installing sass: The last version of ffi (< 2, >= 0.5.0) to support your Ruby & RubyGems was 1.9.18. Try installing it with `gem install ffi -v 1.9

How to create two ByteStrings calling this external library API?

冷暖自知 提交于 2019-12-23 10:18:14
问题 I'm currently writing bindings to a cryptographic library that exposes a function for generating keypairs: const size_t PUBLICKEYBYTES = 32; const size_t SECRETKEYBYTES = 32; int random_keypair(unsigned char pk[PUBLICKEYBYTES], unsigned char sk[SECRETKEYBYTES]); This function randomly generates a secret key, computes the corresponding public key and puts the results in pk and sk . When just returning one ByteString I've found that the easiest way is to use create :: Int -> (Ptr Word8 -> IO ()

Updating a field value of a C struct from Julia

天涯浪子 提交于 2019-12-22 10:03:37
问题 My question is simple but I don't know the best way to do that (or Julia doesn't offer such a way at the moment): how can I set a field value of a C struct from Julia? Imagine you have a struct type to represent a node of a tree in a C library: typedef struct node_s { int type; node_t* next; node_t* children; node_t* parent; } node_t; and copy it in Julia: immutable node_t typ::Cint next::Ptr{node_t} children::Ptr{node_t} parent::Ptr{node_t} end Now assume that you have a pointer to node_t

Create shared C object linked to Rust dylib for use in R

戏子无情 提交于 2019-12-22 09:57:16
问题 I am trying to create a shared object I can load into R that calls Rust functions by way of R's C API. To call Rust from C, I am following this blog post. My problem arises when I try to create the shared library and link to the Rust library. The linker complains that it can't find my Rust function. I am quite new to compiled languages and have given this a couple days' worth of effort before turning to SO. In that time I have learned a lot about compiler flags and yet come no closer to a

How to publish a constant string in the Rust FFI?

对着背影说爱祢 提交于 2019-12-22 05:27:10
问题 I want to have a Rust library expose a const char * static string to C, to be compatible with an existing interface (specifically librsync). That is, the C header file has extern char const *my_string; In C, the library would simply have char const *my_string = "hi"; In Rust I've tried something like pub static my_string: *const libc::c_char = unsafe { "hi\0" as *const libc::c_char }; but this complains error: casting `&'static str` as `*const i8` is invalid It seems like I can't use CString

How to force GHC to inline FFI calls?

天大地大妈咪最大 提交于 2019-12-22 05:26:11
问题 I made small C module to improve performance, but GHC doesn't inline foreign functions, and calls cost eliminates the acceleration. For example, test.h : int inc (int x); test.c : #include "test.h" int inc(int x) {return x + 1;} Test.hc : {-# LANGUAGE ForeignFunctionInterface #-} module Test (inc) where import Foreign import Foreign.C foreign import ccall unsafe "test.h inc" c_inc :: CInt -> CInt inc = fromIntegral . c_inc . fromIntegral {-# INLINE c_inc #-} {-# INLINE inc #-} Main.hs :

Testing FFI Code (with “foreign import”s) with GHCi

99封情书 提交于 2019-12-22 04:04:29
问题 Good (your local time of day), everyone. I went through Real World Haskell's chapter on the Foreign Function Interface, and did some follow-up reading here. I'm now experimenting with binding to C functions, and I'd like some clarification on some things. The following is fairly clear: foreign import ccall unsafe "math.h sin" c_sin :: CDouble -> CDouble I can load this and code that uses it in ghci, and everything is fine. It even loads in the embedded ghci in emacs's Haskell mode. I find

How to pass a string from Haskell to C?

℡╲_俬逩灬. 提交于 2019-12-21 09:22:26
问题 All I want to do is pass a plain-text string from Haskell to C. However, it says that [Char] is an unacceptable return type. I can't find anywhere why they think it is, nor what acceptable return types are. I'm trying to make a very simple OS image that I can boot with Qemu. Does anyone know how to do this? Thanks. {-# LANGUAGE ForeignFunctionInterface #-} module Hello where import Foreign import Foreign.C.String import Foreign.C.Types hello :: String -> (CString -> IO a) -> IO a hello =

Is there a simple way to use Python libraries from Common Lisp?

ε祈祈猫儿з 提交于 2019-12-21 07:27:07
问题 One thing I really miss when writing Common Lisp code is access to Python libraries, both standard library and third party modules. CLPython provides a limited subset of Python functionality which precludes the use of most libraries, so that's not really useful to me. I would like to be able to call Python code from Common Lisp such that it runs in a Python VM like CPython or PyPy. 回答1: One solution is python-on-lisp. It should be ASDF-installable. It hasn't been maintained or updated for a

Can the FFI deal with arrays? If so, how?

安稳与你 提交于 2019-12-18 14:05:10
问题 I'm pretty sure it's possible to send arrays through the FFI, but I can't find any examples. For instance, I have a Haskell array that I send to a int foo(int*) function, or I have a C array int bar[64]; that I send to Haskell. Ideally I'd want the most efficient way - I don't want any heap allocation or unnecessary copying. Also, it would be nice if I could use Haskell's unboxed arrays in both Haskell and C. So what's the method of doing so? 回答1: If you use the Data.Vector library you could