ffi

bind to abstract types for c struct with idris

柔情痞子 提交于 2021-02-11 12:20:24
问题 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 tfNewStatus = foreign FFI_C "TF_NewStatus" (IO TF_Status) http://docs.idris-lang.org/en/latest/reference/ffi.html it complains that When checking argument fty to function foreign: Can't find a value of type FTy FFI_C [] (IO TF_Status) 回答1: TF_Status* TF_NewStatus(); returns a pointer to a TF_Status when

Luajit equivalent for string.pack and string.unpack?

亡梦爱人 提交于 2021-02-10 14:18:56
问题 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 help on using it if it has a solution ( using tostring(number) just uses way too many bytes for numbers and memory is limited ) Basically, I need a way to get a binary string packed form of a list of numbers (floats for now), using Luajit, and be able to store it in a string & concat that string to

How to compose props across component in reason-react bindings?

梦想的初衷 提交于 2021-02-07 20:22:08
问题 I am currently writing a material-UI reason-react binding and I want to know how I can re-use previously define Props. The Select component spreads all of the Input props into itself, in the underlying react-js lib. this is done by spreading props however this is discouraged in ReasonML as typings are lost. As a temporary solution, I have copied the props from one to another but this is not scalable. I would appreciate if someone could suggest what is the correct way of doing this in Reason

Resolve union structure in Rust FFI

谁说我不能喝 提交于 2021-02-07 14:23:20
问题 I have problem with resolving c-union structure XEvent. I'm experimenting with Xlib and X Record Extension in Rust. I'm generate ffi-bindings with rust-bindgen. All code hosted on github alxkolm/rust-xlib-record. Trouble happen on line src/main.rs:106 when I try extract data from XEvent structure. let key_event: *mut xlib::XKeyEvent = event.xkey(); println!("KeyPress {}", (*key_event).keycode); // this always print 128 on any key My program listen key events and print out keycode . But it is

How to convert a jcharArray to a char[] in c

痞子三分冷 提交于 2021-02-05 12:32:34
问题 I have a jcharArray that is passed into a C program through Java, and I need to know how to use the array in the C program. How do I convert my jcharArray bits into something I can use ( char bits[] )? I tried writing this code using JNI JNIEXPORT jint JNICALL Java_ex_NistStatisticalTestSuite_frequency (JNIEnv *env, jclass cls, jcharArray bits, jint jn) { printf("running frequency test"); int i; double f, s_obs, p_value, sum, sqrt2 = 1.41421356237309504880; int n=jn; char deletethis=(char

Is there a way to enforce that a Rust raw pointer is not used after returning from a specific stack frame?

那年仲夏 提交于 2021-02-05 06:43:27
问题 I'm writing a Rust wrapper for a (mostly C-style) C++ plug-in SDK. The plug-in host is a graphical desktop application that runs an event loop. The plug-in is regularly called as part of that event loop. Whenever this happens, the plug-in has control and can call arbitrary host functions. One C function which I want to wrap returns a raw pointer. Right after that function returns, the pointer is guaranteed to be a valid C string, so it is safe to dereference it. However, after the plug-in

Rust FFI, callbacks, and lifetimes

≡放荡痞女 提交于 2021-01-29 08:34:02
问题 I'm trying to build a nice rust wrapper around libuv, an event loop library written in C. I'm pretty much "done", but I'm having some trouble with callbacks and lifetimes. Being an event loop library, libuv relies heavily on callbacks. I have some code that can accept functions, closures, or a tuple of (obj, method-on-obj) and it handles creating an appropriate "trampoline" to get that across the FFI boundary. That all works. However, the problem I'm running into is that I cannot figure out

String becomes empty passing through FFI from rust to ruby

烈酒焚心 提交于 2021-01-28 13:55:36
问题 I have a rubygem with a native extension written in rust. The native extension supports serializing its data-structure to JSON. However, whilst I've confirmed it's generating JSON, the string is always empty on the ruby side. Here's the ruby code: module RustCuckooFilter extend FFI::Library ffi_lib 'libcuckoofilter_cabi' class Instance < FFI::AutoPointer def export(path) RustCuckooFilter.export(self) end end attach_function :export, :rcf_cuckoofilter_export, [Instance], :pointer And the rust

Ruby ffi gem issue

♀尐吖头ヾ 提交于 2021-01-06 12:27:41
问题 I installed wpscan - a Ruby programm for finding security issues on Wordpress sites. But when I tried to run it I got the following message: [ERROR] dlopen(/Library/Ruby/Gems/2.0.0/gems/ffi-1.9.2/lib/ffi_c.bundle, 9): Library not loaded: /Users/headius/.rvm/rubies/ruby-head/lib/libruby.2.1.0.dylib Referenced from: /Library/Ruby/Gems/2.0.0/gems/ffi-1.9.2/lib/ffi_c.bundle Reason: image not found - /Library/Ruby/Gems/2.0.0/gems/ffi-1.9.2/lib/ffi_c.bundle My operating system is OS X Mavericks,

Ruby ffi gem issue

戏子无情 提交于 2021-01-06 12:24:57
问题 I installed wpscan - a Ruby programm for finding security issues on Wordpress sites. But when I tried to run it I got the following message: [ERROR] dlopen(/Library/Ruby/Gems/2.0.0/gems/ffi-1.9.2/lib/ffi_c.bundle, 9): Library not loaded: /Users/headius/.rvm/rubies/ruby-head/lib/libruby.2.1.0.dylib Referenced from: /Library/Ruby/Gems/2.0.0/gems/ffi-1.9.2/lib/ffi_c.bundle Reason: image not found - /Library/Ruby/Gems/2.0.0/gems/ffi-1.9.2/lib/ffi_c.bundle My operating system is OS X Mavericks,