ffi

Can't Find ffi.h When Installing ffi ruby gem

僤鯓⒐⒋嵵緔 提交于 2019-12-11 03:48:29
问题 Ruby version 2.2.4p230 RubyGem version 2.7.2 Ruby-devel and lib64ffi-devel installed. 64-bit OpenMandriva 3.0, urpmi and rpmdrake used. Goal: to install compass, but the gem ffi is needed first. I have scoured the internet so hard for the last two days and I'm so stumped... It's impossible for me to install an earlier version of ruby because of the dependency for an older ncurses. I feel like replacing ncurses would open a can of nasty worms. However... I am also completely open to a compass

How do I access a zero-terminated array of function pointers declared in C from Rust?

北城余情 提交于 2019-12-11 03:11:17
问题 I have the following C code with a zero-terminated array of function pointers: #include <stdio.h> void hello_register(void) { printf("hello_register called\n"); } void (*vlog_startup_routines[])() = { hello_register, 0 }; This code is compiled and linked to my Rust program using a Cargo build script. How can I call each of the function pointers in the array from Rust? 回答1: A combination of the previous two answers looks nicer: extern crate libc; type VlogStartupRoutine = Option<extern "C" fn(

Convert Haskell ByteStrings to C++ std::string

孤者浪人 提交于 2019-12-11 02:59:04
问题 I want to convert strict ByteStrings from Haskell into C++'s std::string to pass it to a C++ library via the FFI. As the ByteString may contain NULL characters, converting into a CString as an intermediate step is not viable. What is the right approach here? current solution Thanks for the answers so far. I hoped for a canonical solution for that task, but maybe it does not exist yet :) Some c++ library documentation says following: string ( const char * s, size_t n ); Content is initialized

Rust function that allocates memory and calls a C++ callback crashes

早过忘川 提交于 2019-12-11 02:56:21
问题 Rust code: #[repr(C)] pub struct Tmp { pub callback: extern "C" fn(i: i32), } #[no_mangle] pub extern "C" fn set_callback(callback: extern "C" fn(i: i32)) -> *mut Tmp { let mut tmp = Box::new(Tmp { callback }); println!("tmp as ptr: {:p}", tmp); // >> here << &mut *tmp } #[no_mangle] pub extern "C" fn use_callback(tmp_ptr: *mut Tmp) { unsafe { ((*tmp_ptr).callback)(1); ((*tmp_ptr).callback)(3); } } C++ code: struct Tmp { void (*callback)(int32_t); }; typedef Tmp*(__stdcall* set_callback_t)

Attempting a C++ binding to Haskell: getting undefined reference errors

半城伤御伤魂 提交于 2019-12-11 02:48:58
问题 I am attempting a C++ binding in Haskell and running into "undefined reference" errors when calling the binding. I've make a small project (http://github.com/deech/CPlusPlusBindings) to illustrate the problem. It includes a small C++ class, a C wrapper, a C test script and a Haskell binding and a test script. The C test script works, the Haskell one gives me: [1 of 1] Compiling Binding ( dist/build/Binding.hs, dist/build/Binding.o ) src/Binding.chs:6:26: Warning: Defined but not used: `res'

how to get the result (two prolog lists ) from prolog, given via “c++ Interface to SWI-Prolog” , and store them in a variable in c++

瘦欲@ 提交于 2019-12-11 02:12:44
问题 Hello to everyone :) The Problem i have is how to get and store(Variable X and Y) from Prolog (via interface from swi-prolog) into a variable (c++) in visual studio In short: I transfered a Puzzle with triangular puzzle parts into Prolog representation. This puzzle is solved by prolog. This works so far. The visual representation with each puzzle tile is done in visual studion. This is working also. Now i want to call via Interface the prolog engine and this will return the Solution and each

Why EnumPrintersA and EnumPrintersW request the same amount of memory?

心不动则不痛 提交于 2019-12-10 21:06:10
问题 I call EnumPrintersA / EnumPrintersW functions using node-ffi to get list of local printers accessible from my PC. You should create the buffer which will be filled with information by EnumPrinters function. But you do not know the required size of the buffer. In this case you need to execute EnumPrintersA / EnumPrintersW twice. During the first call this function calculates the amount of memory for information about printers, during the second call this function fills the buffer with

Is it valid to use ptr::NonNull in FFI?

半城伤御伤魂 提交于 2019-12-10 18:40:11
问题 Rust has the ptr::NonNull type that represents a non- NULL pointer. Is it safe to use this type in FFI? Is it guaranteed to have same binary representation (ignoring non-FFI context such as Option optimizations), alignment, register usage as *mut T ? For example, could I implement this interface: void call_me_from_c(char *without_nulls) __attribute__((nonnull)); with extern "C" fn call_me_from_c(without_nulls: ptr::NonNull<c_char>) I don't expect this to do anything (apart from causing UB

How do I create a storable instance for this structure without c2hs or other tools?

心已入冬 提交于 2019-12-10 16:26:10
问题 This structure: typedef struct Atom_ { float x; float y; float z; int col; } Atom; corresponds to this type: data Atom = Atom { pos :: V3 Float, col :: Int } How do I create a storable instance for Atom so that I can send an Atom s on Haskell to a C function that expects an Atom ? 回答1: I can't currently guarantee that this will work exactly as shown (I don't have the environment set up on this computer), but it should be a good first step towards getting it right: import Foreign.Storable

Pass a Rust trait to C

允我心安 提交于 2019-12-10 15:33:57
问题 I am building a Rust library that needs to call some C functions with Rust objects. I have a trait with a function that calls the C function, the C function is defined in Rust as follows: extern { fn process_trait(my_trait: MyTrait); } The idea is that the user can implement the trait for his struct and then call the C functions (basically, the C then calls some other Rust back, which calls some of the Trait functions). The error here is: the trait core::marker::Sized is not implemented for