ffi

Rust closure as callback for C bindings receiving garbage value in captured variable

房东的猫 提交于 2019-12-12 02:44:42
问题 I'm writing Rust wrappers for C bindings so that they look more Rusty. One such C function is this: void mosquitto_connect_callback_set( struct mosquitto * mosq, void (*on_connect)(struct mosquitto *, void *, int) ) I'm using the below technique to pass a Rust closure as the user data to above binding ( void* in the callback) so that the Rust closure will be called when the C callback is invoked. // Registered callback is called when the broker sends a CONNACK message in response // to a

how to redirect the console output of prolog inclusive trace or write(…) to c++ Variable

做~自己de王妃 提交于 2019-12-11 23:25:21
问题 I hope someone can help me and thanks a lot to anybody who have an idea :) this question is related to another one for same project but thematically slightly different thats why seperated it . Project in shortform: Prolog is Solving an existing 2D puzzle which i wrot a logic for. visual studio(VS) cli visualize the puzzle/parts. And finaly the interface should be used to display the Solving process (via prolog trace or "write()")step by step in VS Goal : Get the output from Prolog code

What are the Implications of Different ReasonML External Declarations?

亡梦爱人 提交于 2019-12-11 15:49:47
问题 In the examples below, both external declarations achieve the same functionality with slightly different ReasonML function structures. Does external declaration style impact anything (e.g. performance) beyond ReasonML function structure? Also, does ReasonML have a "suggested" external declaration "style"? Type Declarations type dom; type element; External Declaration Style 1 [@bs.val] external dom: dom = "document"; [@bs.send.pipe : dom] external get_by_id: string => element = "getElementById

Dynamically create FFI methods in Racket

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 13:59:00
问题 I'm playing with idea of loading С/Rust/etc functions via FFI in Racket. I'd like to specify list of function names as strings and then just load them by some helper function. Main problem is creating identifier/word from a string. For example, it is very simple in Rebol: foo: "test1" set to-word (rejoin [foo "_result_data"]) some print test1_result_data but in Racket I have to use syntax stuff. So I've found examples like How do I define functions using Racket macros? and Racket Macro to

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

此生再无相见时 提交于 2019-12-11 12:37:43
问题 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 = unsafe { double_input(input) }; println!("{} * 2 = {}", input, output); } Should #[link(name = "adder")] include a relative path to the .o / a / .h files? For example, should it be #[link(name = "../adderlib/adder")] ? Is there another way to tell the compiler where adder is? 回答1: The answer to the first question

How do I create static C strings?

给你一囗甜甜゛ 提交于 2019-12-11 10:35:38
问题 I want to create a plugin module (shared lib) in Rust that exports a C compatible structure containing static C strings. In Sept 2014, this Stack Overflow question determined it wasn't possible. As of Jan 2015 this still was not possible as per this Reddit thread. Has anything changed since? 回答1: The following seems to do the trick. I don't really want the struct to be mutable, but I get core::marker::Sync errors if I don't mark it as mut. extern crate libc; use libc::funcs::c95::stdio::puts;

Timeout, System timeout & terminator not working for FFI based function

筅森魡賤 提交于 2019-12-11 06:16:33
问题 I have wrote a wrapper through FFI for a shared library function(third party function). This shared library tries to establish a connection with a server. During connection establishment when the server is not reachable third party function waits for 3 mins. In order to avoid that while calling in rails I used tried to use the following timeouts but unfortunately it did not work. Native Timeout System timeout Terminator Note: when I use Terminator the additional process that is created by it

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

一曲冷凌霜 提交于 2019-12-11 06:13:21
问题 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 API that is called twice. In the first call, it returns the size of the buffer that it will need for its actual out parameter. Then, it is called a second time with a buffer of sufficient size. I'm currently using a Vec as a datatype for this buffer (see example below). The code works but I'm

How to pass a boxed slice (`Box<[T]>`) to a C function?

时间秒杀一切 提交于 2019-12-11 05:08:40
问题 I want to expose a "dynamic array" to a C function. The C function will own the data and later will call a function of mine to free the data. So it'll look something like the following: fn get_something(len: *mut usize) -> *mut u8; fn dealloc_something(data: *mut u8, len: usize); Internally I have a Box<[T]> ( my_vec.to_boxed_slice() ). I can get the size/length pretty easily, but I don't know which pointer I should return. If I pass the pointer returned from boxed_slice.as_mut_ptr() to Box:

Runtime performance degradation for C FFI Callback when pthreads are enabled

一笑奈何 提交于 2019-12-11 04:37:22
问题 I am curious about the behavior of GHC runtime with threaded option in case when C FFI calls back Haskell function. I wrote code to measure overhead of a basic function callback (below). While the function callback overhead has already been discussed before, I am curious about the sharp increase in total time I observed when multi-threading is enabled in C code (even when total number of function calls to Haskell remain same). In my test, I called Haskell function f 5M times using two