CNI for C

Andrew Haley aph@redhat.com
Wed Apr 7 12:13:00 GMT 2004


Andrew Shuttlewood writes:
 > On Wed, 2004年04月07日 at 12:23, Andrew Haley wrote:
 > > Geert Bevin writes:
 > > > 
 > > > is there anything underway to offer something similar to CNI but then
 > > > for C and not for C++?
 > > 
 > > We haven't been working on this.
 > > 
 > > How would you do it? What is the C equivalent of the this pointer, or
 > > a virtual function? I suppose we could write a bunch of macros to do
 > > the job, but would anyone use them?
 > 
 > I think maybe all anyone really needs is the equivalent of pinvoke, then
 > they can do it themselves.
 > 
 > Is there a library that allows me to dynamically call a C function
 > without generating code?
Yes, that's what libffi does.
 > Ie, if I know it has an int as the first argument, and a char * as
 > the second, can I dynamically call it? I think if there is, then
 > there is no reason that gcj can't be at least as compatible to C as
 > Mono is alleged to be.
 > 
 > > That's a very interesting idea. However, the resistance to using CNI
 > > has been that 
 > > 
 > > * We can't use VM-specific features that may be useful, such as CNI.
 > > <http://ometer.com/desktop-language.html>
 > > 
 > > So even if we did create C-CNI, wouldn't this still be the case?
 > > People would still not want to use it, because it's VM specific.
 > 
 > If you had a library that could call C functions then surely you could
 > just use JNI to attach to it, thus making everybody happy?
Well, the nice thing about pinvoke as far as I can see is that you
don't have to write anything: you can just call native DLLs directly.
It's harder to do this in the general case of ISO C, because there
aren't necessarily Java equivalents of the C types used to access
DLLs. However, in many cases, and this possibly includes all the
platforms we care about, there are.
So, we could do something like pinvoke in gcj. We'd need to figure
out how to parse the C types and make them available to Java. We
could get the C compiler to help with this.
Andrew.


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /