Questions tagged [ffi]

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

1778 questions
11
votes
3 answers

How to use LuaJIT's ffi module when embedding?

I'm trying to embed LuaJIT into a C application. The code is like this: #include #include #include #include #include int barfunc(int foo) { /* a dummy function to test with FFI */ return…
jagttt
  • 1,020
  • 1
  • 12
  • 25
11
votes
1 answer

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 it turns out, sequence is not very efficient, though,…
mcmayer
  • 1,931
  • 12
  • 22
11
votes
0 answers

Using Template Haskell to add libraries with which to link

I'm currently hacking my way through trying to make quasiquotes for writing Rust code inline in Haskell. I think I have the code generation work done (including things like marshaling Haskell types to and from generated Rust ones). I now have the…
Alec
  • 31,829
  • 7
  • 67
  • 114
11
votes
2 answers

How can I get a Path from a raw C string (CStr or *const u8)?

What's the most direct way to use a C string as Rust's Path? I've got const char * from FFI and need to use it as a filesystem path in Rust. I'd rather not enforce UTF-8 on the path, so converting through str/String is undesirable. It should work…
Kornel
  • 97,764
  • 37
  • 219
  • 309
11
votes
2 answers

Should I use libc::c_char or std::os::raw::c_char?

I am writing a FFI wrapper for Rust. I have seen usages of both libc::c_char and std::os::raw::c_char. My knowledge of C is very minimal and I wonder if there is any difference. What should I use if I would like to expose a string to Python via…
colinfang
  • 20,909
  • 19
  • 90
  • 173
11
votes
2 answers

At a language level, what exactly is `ccall`?

I'm new to Julia, and I'm trying to understand, at the language level, what ccall is. At the syntax level, it looks like a normal function, but it clearly doesn't behave the same way in how it takes its arguments: Note that the argument type tuple…
lcmylin
  • 2,552
  • 2
  • 19
  • 31
11
votes
1 answer

How do I pass a closure through raw pointers as an argument to a C function?

I'm working with WinAPI in Rust and there are some functions (like EnumWindows()) which require a callback. The callback usually accepts an additional argument (of type LPARAM which is an alias for i64), which you can use to pass some custom data to…
Daniel
  • 635
  • 1
  • 5
  • 22
11
votes
1 answer

Haskell Stack and C Libraries

This is possibly a duplicate of this post. But the only answer it got does not seem to work for me, so I post my own case here hoping to find a specific solution. I am on Linux Ubuntu Trusty. I have a proprietary C library, libMyLib.so, located in…
Janthelme
  • 989
  • 10
  • 23
11
votes
2 answers

How to create a nim dll and call it from c#

I have read almost every example I could find via google, and couldn't accomplish the simplest task creating a dll (windows) from nim Could anyone explain it step by step? I am using the nim IDE - aporia to produce the code. Does building a dll…
Avia Afer
  • 866
  • 2
  • 8
  • 29
11
votes
3 answers

Why is the lifetime important for slice::from_raw_parts?

The docs for slice::from_raw_parts warn the programmer to annotate the slice with the correct lifetime. I assume that, given some lifetime 'a, I can perform this annotation with let myslice: &'a mut [i32] = std::slice::from_raw_parts_mut(ptr,…
Jackson Loper
  • 525
  • 4
  • 10
11
votes
1 answer

When does the garbage collector run when calling Haskell exports from C?

When exporting a Haskell function to be called from C, when does Haskell's garbage get collected? If C owns main then there is no way to predict the next call in to Haskell. This question is especially pertinent when running single-threaded Haskell…
Elliot Cameron
  • 5,235
  • 2
  • 27
  • 34
11
votes
5 answers

unable to install compass

Last week I made an update in cygwin because of the bash "vulnerable problem". After that I couldn't compile sass anymore. I tried to reinstall ruby, after some install fails and reinstalling cygwin I installed it and updated with "gem update…
Kornking
  • 111
  • 1
  • 1
  • 4
11
votes
4 answers

How to force g++ to inline functions?

I have recently encountered an issue with C++ inline functions when using Haskell FFI to C/C++. Namely, g++ does not really inline functions that are declared inline, and generate symbols for them. Ultimately, this generates linker error when ghci…
thor
  • 21,418
  • 31
  • 87
  • 173
11
votes
1 answer

Testing FFI Code (with "foreign import"s) with GHCi

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…
Colin Woodbury
  • 1,799
  • 2
  • 15
  • 25
11
votes
2 answers

Generate a C struct based on a complex Haskell type

I am trying to use a Haskell library in my C code. The Haskell function I am trying to use has the type String -> IO [Reference] where Reference is a rather complex structure (see here for details). Based on reading various pieces of documentation…
Jakub Hampl
  • 39,863
  • 10
  • 77
  • 106