igjoshua / coffi Goto Github PK
View Code? Open in Web Editor NEWA Foreign Function Interface in Clojure for JDK 19.
Home Page: https://igjoshua.github.io/coffi/
License: Eclipse Public License 1.0
A Foreign Function Interface in Clojure for JDK 19.
Home Page: https://igjoshua.github.io/coffi/
License: Eclipse Public License 1.0
typedef struct S1 {
char c;
void* p;
} S1;
extern void f1(S1* s){
}
(defalias ::S1
(layout/with-c-layout
[::mem/struct
[[:c ::mem/char]
[:p ::mem/pointer]]]))
(defcfn
f1
""
"f1"
[[:coffi.mem/pointer ::S1]]
:coffi.mem/void)
;; Syntax error compiling at (*cider-repl workspace/clong:localhost:58963(clj)*:40:33).
Unable to resolve symbol: scope12651 in this context
It's likely that I'm doing something dumb here, but I thought I'd file an issue just in case.
Also, I saw the following notes in the readme:
In cases where a pointer to some data is required to pass as an argument to a native function, but doesn't need to be read back in, the pointer primitive type can take a type argument.
I'm not actually sure what you mean by "doesn't need to be read back in".
I'm trying to use libclang to auto-generate struct layouts for use with coffi. As a sanity check, I wanted to make sure that the size of a struct reported by clang matched mem/size-of
. It generally does, but I noticed there's a size difference when a struct includes pointers.
For example:
#include <stdio.h>
typedef struct S1 {
char c;
void* p;
} S1;
int main(int n, char** args){
printf("size: %lu\n", sizeof(S1));
}
The above gives a size of 16, but the same struct definition in coffi gives 9:
(defalias ::S1
(layout/with-c-layout
[::mem/struct
[[:c ::mem/char]
[:p ::mem/pointer]]]))
(mem/size-of ::S1) ;; 9
It doesn't seem like there's anything wrong with the implementation. The byteAlignment of ValueLayout/ADDRESS
is 1. I'm not really sure whether I'm using clang wrong or if there's something else going on. Either way, I thought I'd report it in case there is some improvement to be made.
This interface was removed going from JDK 19 to JDK 20:
This library looks for useful! Unfortunately, my first tests hit a wall right away. If I start the JVM with the --add-modules=jdk.incubator.foreign
flag set, I get:
java.lang.module.FindException: Module jdk.incubator.foreign not found
... and if I remove that flag, I get an error telling me that it can't find the jdk.incubator.foreign.Addressable
class.
This is on an aarch64 Mac/MacOS 12.6.1. My JDK info:
java -version
openjdk version "19.0.1" 2022-10-18
OpenJDK Runtime Environment Homebrew (build 19.0.1)
OpenJDK 64-Bit Server VM Homebrew (build 19.0.1, mixed mode, sharing)
Anything I should try? Thanks in advance.
defvar
calls ensure-symbol
which is private (in develop branch)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.