On Jan 8, 8:53 pm, Rob Wolfe <[email protected]> wrote:
> mac <[email protected]> writes:
> > Hello all.
> > I've started work on a clojure library for interoperating with C. It's
> > always been a pain to do in Java but recently JNA (java native access)
> > has taken away most of that pain.
> > When using clojure however, it's nice to be able to stay in clojure
> > and not drop to java (or C *shudder*).
> > It's possible to use JNA from dynamic jvm languages already but those
> > interfaces are slower and less type safe than the "direct mapping" way
> > of doing things.
> > Since I wanted this to be as fast and safe as possible but still
> > clojure code only I have resorted to all kinds of voodoo, including
> > bytecode generation and eval usage (oh the horror) so be warned :)
> > Currently it is very rough but it can already handle all primitive
> > types and also typed pointer arguments as nio buffers. I have included
> > jna type support for structs, unions and callbacks (c function
> > pointers) but that's completely untested yet.
>
> > Here it is:
> >http://github.com/bagucode/clj-native
>
> Yes, there is a lot of voodoo. ;)
> Have you seen this library:http://github.com/Chouser/clojure-jna?
> I'm using this one right now (it is really simple) and I'm wondering
> what will be the advantage of using your implementation?
>
> Br,
> Rob

Yes I have seen that library and I've used it as well.
The benefits of using my version are speed and safety.
I'm using the direct mapping technique described on the JNA front page
which is supposedly almost as fast as making custom JNI bindings. An
additional (and perhaps more important) benefit of my approach is that
it gives some measure of type and arity safety since the arguments
must be of the correct type and the correct number of arguments on the
java side for a call to succeed. It's very easy to crash the jvm if
you mess up the arguments to a C function.
This library is something I started because I had a need to wrap a
rather large C library with many small functions so I wanted the call
overhead to be small (hence the direct mapping) and errors to be
comprehensible when I made a mistake instead of just getting a
segfault.
But interface-wise on the clojure side I guess my lib and clojure-jna
are kind of similar so if clojure-jna good enough there is no reason
to switch to my lib. I was certainly inspired by clojure-jna since I
had used it before :)
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to