Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions tagged [ffi]

A foreign function interface (FFI) is a mechanism for one language to interact with software written in another language.

0
votes
0answers
31 views

ERROR: HRESULT: 0x8007007E System.IO.FileNotFoundException on Prolog and C# integration

I'm trying to call Prolog script file from C# program using SWI Prolog. I downloaded the code package from github (using this link). But, when I'm trying to run the HelloWorldDemo program the ...
4
votes
0answers
57 views

Haskell DLL causes memory leak

I am working on a C++ project that uses a Haskell DLL (GHC version is 8.0.1 x64). I've noticed, that the executing program consumes much memory. I investigated into the matter and that's what I've ...
2
votes
1answer
61 views

What is a correct way of getting and setting last error message through FFI?

I'm wrapping a C API (dylib) that exposes a setter and getter API for the last error message: extern "C" { /// GetLastError is thread-safe pub fn GetLastError() -> *const ::std::os::raw::...
4
votes
1answer
166 views

How to return an array from Go[lang] to Python using ctypes?

I am trying to write some code that creates an array in GoLang, and returns it to a python script ctypes (and some numpy). What I have got so far doesn't work, and I cannot figure out why... I would ...
2
votes
0answers
56 views

C2HS Pointer Type Correspondences

I have some conceptual questions about how C2HS generates type correspondences from {#pointer …} declarations. First, let ~ denote a type correspondence operator between C types and Haskell types. ...
0
votes
1answer
79 views

Statically linking libvips to a Rust program in Windows

There is a lib-sys for libvips on crates.io, however it uses pkg-config which searches the system for the library to link to dynamically, not statically. I want to provide libvips with the final ...
2
votes
1answer
53 views

Exporting a list of record to a JavaScript array of object without tags

Say I have the following ReasonML types: type xEntry = {title: string}; type yEntry = {value: int}; type entry = | X(xEntry) | Y(yEntry); and I want to export the following value to the ...
32
votes
2answers
12k views

How do I convert a C string into a Rust string and back via FFI?

I'm trying to get a C string returned by a C library and convert it to a Rust string via FFI. mylib.c const char* hello(){ return "Hello World!"; } main.rs #![feature(link_args)] extern crate ...
0
votes
1answer
22 views

Return Ruby's Fiddle::Pointer from C function

I am currently working on a high-performance Vector/Matrix Ruby gem C extension, as I find the built-in implementation cumbersome and not ideal for most cases that I have personally encountered, as ...
2
votes
2answers
485 views

What is the right way to allocate data to pass to an FFI call?

After discussing/learning about the correct way to call a FFI of the Windows-API from Rust, I played with it a little bit further and would like to double-check my understanding. I have a Windows ...
4
votes
0answers
67 views

how to work with references using ffi?

I have folowing c++ function compiled with node-gyp. void InterfaceTestOne(const string & mytest) { const string *ptr = &mytest; printf("The variable X is at 0x%p\n", (...
1
vote
1answer
74 views

How can I link libraries to my C code and use that in a Rust binary?

I am trying to include a C file in my Rust project. The C file uses system dependencies. Below is a minimal example that does not compile when I run cargo build. If I take the failing command that ...
2
votes
3answers
111 views

Is there any trait in Rust that gets notified if a structure is moved to a different location?

In a mixture of Rust and C code for a microcontroller, I have a Rust data structure that I have to make known to the C part of my program. I got this working. pub struct SerialPort { // ... some ...
-1
votes
1answer
74 views

Returning array from c++ to rust in Rust FFI [duplicate]

I have a function which is written in C++ that will be called from Rust. This function constructs an array and must return it to Rust: main.rs extern crate libc; use libc::c_void; extern { fn ...
3
votes
1answer
84 views

What is the correct way to fill a C string pointer from Rust?

I have a FFI signature I need to implement: pub unsafe extern fn f(header_size: u32, header_ptr: *mut u8) -> i32; A FFI caller is expected to provide a buffer header_ptr and the size of that ...
0
votes
1answer
38 views

bind to abstract types for c struct with idris

I can not find how to treat this typedef struct TF_Status TF_Status; as abstract types and bind to that the c function is TF_Status* TF_NewStatus(); data TF_Status tfNewStatus : IO TF_Status ...
1
vote
1answer
83 views

Jekyll install with Ruby 2.5

I got a problem when i was installing Jekyll on win10. When I finished deployment for ruby and wanna install Jekyll, it needs to install bundle first. Fetching ffi 1.9.17 (x64-mingw32) Installing ...
8
votes
1answer
62 views

Dealing with problematic parent-child relationships enforced by C FFI

I have a C library with an interface similar to this: (I have represented the C API within Rust, so that all of the code in this question can be concatenated in a single .rs file and easily tested) //...
4
votes
1answer
218 views

Can Rust struct alignment be controlled on the stable compiler? [duplicate]

I want to write a Rust FFI for a C struct using the aligned attribute. On nightly, one can use #[feature(repr_simd)] as in this question. The same technique without #[repr(simd)] appears to be ...
0
votes
0answers
20 views

How to call a FFI function that uses va args in javascript-nodejs

The FFI function is like printf(...), type of parameter and number of parameter are both variable. How to call the function in javascript. the code below can't work correctly, the param is unvariable. ...
0
votes
1answer
97 views

What is the best practice to follow in order to use Python to call functions from inside a Rust program?

I want to implement a system which consists of a Python UI and some Rust datastore and functions. The user executes the python code which in turn executes the Rust program in a subprocess. I want the ...
3
votes
1answer
581 views

Rust code cannot link with a C library compiled on Windows because there is an unresolved external symbol

I've been trying to get Rust to link with a C library on Windows, but Rust is unable to find the functions I need. It seems like my function signature is wrong, but Rust can find the .lib file. I ...
15
votes
12answers
32k views

ERROR: Error installing ffi: ERROR: Failed to build gem native extension

Got the DevKit installed and re-ran the ffi install….got this as an output: C:\Documents and Settings\******>gem install ffi Temporarily enhancing PATH to include DevKit... Building native ...
5
votes
2answers
634 views

Calling PyPy sandbox from another language

I'll preface this by saying I am quite new to PyPy, though fairly experienced with Python. I'm looking to run a web app where I run untrusted Python code. The PyPy sandboxing features look ideal for ...
0
votes
1answer
34 views

Add storyboard or xib file in iOS FFI for Kony

I'm done a project using kony visualizer for a specific task, I need to use ios FFI as third party. I just created an ios app for the FFI and it is working fine. But the problem is I am using ...
1
vote
1answer
41 views

How to assign function to Rebol struct member

I first define a function ADD: add: func [ a [integer!] b [integer!] ] [a + b] Then a struct: s: make struct! [ sadd [ function! ] ] add But Rebol struct does not support the FUNCTION! ...
19
votes
2answers
343 views

How to properly link object files written in Haskell?

Roughly following this tutorial, I managed to get this toy project working. It calls a Haskell function from a C++ program. Foo.hs {-# LANGUAGE ForeignFunctionInterface #-} module Foo where ...
3
votes
2answers
500 views

How to transfer ownership of a value to C code from Rust?

I'm trying to write some Rust code with FFI that involves C taking ownership of a struct: fn some_function() { let c = SomeStruct::new(); unsafe { c_function(&mut c); } } I ...
2
votes
1answer
41 views

Record with optional and mutable fields

In the docs: https://bucklescript.github.io/docs/en/object.html there are examples for a record with mutable fields and optional fields. When I try to use both it fails: Compiles: type person = { ...
-1
votes
2answers
46 views

bucklescript method definition = string

Pretty much all bucklescript examples have something that has a syntax like this: [@bs.send.pipe : t('options)] external parse : array(string) => 'options = "parse"; or like this: [@bs.module "...
0
votes
1answer
90 views

Writing a &str to the console using winapi goes wrong when using CString

I want to write a &str to the console using WriteConsoleOutputAttribute from the winapi crate. I only have an u8 array which will be passed from the std::io::Write implementation of a struct to my ...
5
votes
1answer
1k views

Error installing Sass (Ruby 2.5.0.1, MSYS2 20161025.0.0)

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 ...
1
vote
1answer
53 views

Segmentation fault when using C callback user data to store a boxed Rust closure

I am creating a Rust wrapper around a C API. One function in this C API sets a callback and accepts a void pointer which will be passed to the callback. It stores a reference to the callback and user ...
0
votes
1answer
37 views

Ruby/FFI: String not getting to *char function argument

I'm trying to implement with FFI a few functions from the Darknet library: require 'ffi' class Image < FFI::Struct layout :w, :int layout :h, :int layout :c, :int layout :data, :pointer ...
3
votes
1answer
81 views

How do I handle an FFI unsized type that could be owned or borrowed?

c_strange_t is an opaque C type that is only seen behind a pointer. When wrapping this type, there are times when it is our responsibility to free memory using c_free_strange_t(*c_strange_t), and ...
0
votes
0answers
86 views

FFI callback and segfault

I’m learning Rust and experimenting with FFI callbacks. I wrote a library that does the following: Initializes a C data structure. Initializes a wrapper Rust struct for this data structure. The ...
0
votes
0answers
20 views

Calling a function of a C library with high frequency in browser

I have a C library which is calculating some splines. And I need a web app (maybe something with angular) where I click to draw the start point and then calls this C library with every mouse movement. ...
2
votes
1answer
59 views

How do I make an FFI call with a char** pointer?

I'm trying to make an FFI call but I get a segmentation fault inside the function called by ffi_call (gtk_init in this case). I'm not sure where I screwed up. /* * gtk_init.cc */ #include <ffi....
12
votes
1answer
168 views

Squeezing more performance out of monadic streams in Haskell

The most straightforward monadic 'stream' is just a list of monadic actions Monad m => [m a]. The sequence :: [m a] -> m [a] function evaluates each monadic action and collects the results. As ...
1
vote
2answers
117 views

Luajit equivalent for string.pack and string.unpack?

I need to save a list of lua float nubers in byte form and attach that to a string. I know string.pack exists for Lua 5.3 but I'm limited to Luajit. I'm not too familiar with FFI and I'd appreciate ...
2
votes
1answer
144 views

common lisp sbcl manual ffi example failed

I read sbcl manual,and have a problem at the 8.5 Foreign Data Structure Examples chapter. I use following examples to verify whether it can run correct. ...
16
votes
1answer
3k views

Understand foreign function interface (FFI) and language binding

Mixing different programming languages has long been something I don't quite understand. According to this Wikipedia article, a foreign function interface (or FFI) can be done in several ways: ...
0
votes
1answer
59 views

LuaJIT FFI: Uploading Steamworks leaderboards

How to use SteamAPICall_t with a SteamLeaderboard_t handle with LuaJIT FFI? I use LÖVE2D framework & Steamworks Lua Integration (SLI) Links: FindLeaderboard / UploadLeaderboardScore / ...
3
votes
0answers
60 views

cabal: ghc build with -dynamic and shared library

I'm trying to build a dynamic application with GHC, this is my cabal file: executable app main-is: Main.hs c-sources: cbits/foo.cpp cc-options: -shared -fPIC include-dirs: /usr/local/lib/llvm-...
0
votes
0answers
26 views

Dynamic Linking Error; Invalid ELF header

Trying to link my shared library to a node wrapper and getting this error: Error: Dynamic Linking Error: /home/jonahren/nmayya/ToroDll/libToroNew.so: invalid ELF header at new DynamicLibrary (/home/...
4
votes
1answer
80 views

Re-dress a ST monad as something similar to the State monad

Here's the scenario: Given is a C library, with some struct at its core and operations thereon provided by an abundance of C functions. Step 1: Using Haskell's FFI a wrapper is created. It has ...
1
vote
1answer
171 views

How can I specify linker flags/arguments in a build script?

I'm using Rust, bindgen, and a build script to work on some FFI bindings to a library. This library is built using OpenMP, so when linking against it, I'd normally pass the -fopenmp flag to the ...
0
votes
0answers
35 views

Is there a way to expose and call function defined in LLVM IR into Clang C++?

I would like to define a function in LLVM IR and somehow expose it into Clang so I can call it from C++. Is there a way to do this? For example, in LLVM IR: declare { i64, i64 } @divrem(i64, i64) ...
0
votes
2answers
54 views

What are the different ways of specifying the linking path to FFI libraries in Rust?

Using the below code as an example: extern crate libc; #[link(name = "adder")] extern { fn double_input(input: libc::c_int) -> libc::c_int; } fn main() { let input = 4; let output = ...
0
votes
1answer
85 views

How to use a C typedef struct and functions with that struct from Rust?

I have these C files and I want to use pair_add, add and PAIR from Rust. adder.c #include <stdlib.h> #include "adder.h" int pair_add(PAIR * ppair) { return ppair->x + ppair->y; } ...