From: Joost Diepenmaat
Subject: Portable way to use #define'd constants in cffi?
Date: 
Message-ID: <473a26f3$0$2871$e4fe514c@dreader28.news.xs4all.nl>
Currently I'm using a few constants from Linux header files as arguments 
to C system library functions via cffi. (Specifically, in this case, 
dlopen()'s second argument)

cffi is mostly great, it just works, and I like to think my code would 
mostly work as is on any POSIX system, but C-header #define constant 
macros are a problem, since they can have basically any value and the 
values can (in theory at least) change even between versions of the 
"same" operating system.

I've done this sort of stuff a lot in perl/XS, which uses a C-like glue/
cpp-macro language that's translated to C, then compiled to libraries... 
yada yada yada... anyway, it can be a pain, but one thing that it 
achieves quite successfully, is that it works without me having to find 
out "manually" what the defined constants values are.

In short; (how) - aside from writing my own .h file parser - can I 
achieve the same thing in Common Lisp with cffi (or possibly uffi, which 
I've not used)?

Joost.

From: Ken
Subject: Re: Portable way to use #define'd constants in cffi?
Date: 
Message-ID: <a5q_i.4023$6W4.736@newsfe09.lga>
Joost Diepenmaat wrote:
> Currently I'm using a few constants from Linux header files as arguments 
> to C system library functions via cffi. (Specifically, in this case, 
> dlopen()'s second argument)
> 
> cffi is mostly great, it just works, and I like to think my code would 
> mostly work as is on any POSIX system, but C-header #define constant 
> macros are a problem, since they can have basically any value and the 
> values can (in theory at least) change even between versions of the 
> "same" operating system.
> 
> I've done this sort of stuff a lot in perl/XS, which uses a C-like glue/
> cpp-macro language that's translated to C, then compiled to libraries... 
> yada yada yada... anyway, it can be a pain, but one thing that it 
> achieves quite successfully, is that it works without me having to find 
> out "manually" what the defined constants values are.
> 
> In short; (how) - aside from writing my own .h file parser - can I 
> achieve the same thing in Common Lisp with cffi (or possibly uffi, which 
> I've not used)?
> 
> Joost.
> 

Become an OpenSource Fairy and resurrect Fetter/Verrazano (see c.l.net), 
which would suck in a .h and Do the Right Thing for you. In fact it 
might Just Work for C libs -- when I vetted it before giving it my GoC 
nod it worked.

kt
From: Joost Diepenmaat
Subject: Re: Portable way to use #define'd constants in cffi?
Date: 
Message-ID: <473a2ffc$0$2871$e4fe514c@dreader28.news.xs4all.nl>
On Tue, 13 Nov 2007 18:06:11 -0500, Ken wrote:
> Joost Diepenmaat wrote:
>> In short; (how) - aside from writing my own .h file parser - can I
>> achieve the same thing in Common Lisp with cffi (or possibly uffi,
>> which I've not used)?
>> 
> Become an OpenSource Fairy and resurrect Fetter/Verrazano (see c.l.net),
> which would suck in a .h and Do the Right Thing for you. In fact it
> might Just Work for C libs -- when I vetted it before giving it my GoC
> nod it worked.

That looks interesting, I'll definitely take a look at it - though I 
can't promise anything about becoming an OpenSource fairy :-)

Cheers,
Joost.
From: Rayiner Hashem
Subject: Re: Portable way to use #define'd constants in cffi?
Date: 
Message-ID: <1194996878.598299.247470@k79g2000hse.googlegroups.com>
> Currently I'm using a few constants from Linux header files as arguments
> to C system library functions via cffi. (Specifically, in this case,
> dlopen()'s second argument)

> In short; (how) - aside from writing my own .h file parser - can I
> achieve the same thing in Common Lisp with cffi (or possibly uffi, which
> I've not used)?
>
> Joost.

Verrazano should do this just fine for C libraries.
http://common-lisp.net/project/fetter/. Attila Lendvai has been
fighting the bit-rot, and when I tried it a few weeks ago for one of
my own projects, it seemed to work ok. The biggest thing is that it is
fiddly --- you really need to use a bleeding-edge version of C-FFI.

If you try it and run into problems, let me know (or better yet post
to the mailing list so the solution can be archived).
From: Gene
Subject: Re: Portable way to use #define'd constants in cffi?
Date: 
Message-ID: <1195000428.264282.202990@o80g2000hse.googlegroups.com>
On Nov 13, 6:34 pm, Rayiner Hashem <·······@gmail.com> wrote:
> > Currently I'm using a few constants from Linux header files as arguments
> > to C system library functions via cffi. (Specifically, in this case,
> > dlopen()'s second argument)
> > In short; (how) - aside from writing my own .h file parser - can I
> > achieve the same thing in Common Lisp with cffi (or possibly uffi, which
> > I've not used)?
>
> > Joost.
>
> Verrazano should do this just fine for C libraries.http://common-lisp.net/project/fetter/. Attila Lendvai has been
> fighting the bit-rot, and when I tried it a few weeks ago for one of
> my own projects, it seemed to work ok. The biggest thing is that it is
> fiddly --- you really need to use a bleeding-edge version of C-FFI.
>
> If you try it and run into problems, let me know (or better yet post
> to the mailing list so the solution can be archived).

I don't know much about cffi, but SWIG http://www.swig.org/ seems to
know about it.  Won't that work?  OP says he has experience with Perl,
which was an original supported language of SWIG, so perhaps he knows
it already!
From: Joost Diepenmaat
Subject: Re: Portable way to use #define'd constants in cffi?
Date: 
Message-ID: <473a453c$0$2871$e4fe514c@dreader28.news.xs4all.nl>
On Tue, 13 Nov 2007 16:33:48 -0800, Gene wrote:

> I don't know much about cffi, but SWIG http://www.swig.org/ seems to
> know about it.  Won't that work?  OP says he has experience with Perl,
> which was an original supported language of SWIG, so perhaps he knows it
> already!

I haven't tried SWIG with Lisp yet, but my experience with SWIG with Perl 
were that a) it works pretty well once you learn the whole SWIG language, 
and b) the resulting code is pretty convoluted, slow and hard to 
customize compared to "direct" perl/XS code (but most of that was IIRC 
due to the way SWIG implements class properties in perl).

But I guess I should give SWIG a fair chance, so thanks for mentioning it.

Joost.
From: Joost Diepenmaat
Subject: Re: Portable way to use #define'd constants in cffi?
Date: 
Message-ID: <473a4990$0$2871$e4fe514c@dreader28.news.xs4all.nl>
On Wed, 14 Nov 2007 00:45:48 +0000, Joost Diepenmaat wrote:
> IIRC due to the way SWIG implements class properties in perl).

Make that "object properties"

Joost.
From: ··············@gmail.com
Subject: Re: Portable way to use #define'd constants in cffi?
Date: 
Message-ID: <1195034307.300114.310210@50g2000hsm.googlegroups.com>
> I don't know much about cffi, but SWIGhttp://www.swig.org/seems to
> know about it.  Won't that work?  OP says he has experience with Perl,
> which was an original supported language of SWIG, so perhaps he knows
> it already!

i've tried SWIG. it was missing some features and had various bugs.
grabbed its source to fix the glitches. then turned around in the very
first minute and checked out verrazano to implemented what i was
missing from it...

YMMV,

- attila
From: Ken
Subject: Re: Portable way to use #define'd constants in cffi?
Date: 
Message-ID: <WWt_i.5527$xu3.5403@newsfe08.lga>
Rayiner Hashem wrote:
>> Currently I'm using a few constants from Linux header files as arguments
>> to C system library functions via cffi. (Specifically, in this case,
>> dlopen()'s second argument)
> 
>> In short; (how) - aside from writing my own .h file parser - can I
>> achieve the same thing in Common Lisp with cffi (or possibly uffi, which
>> I've not used)?
>>
>> Joost.
> 
> Verrazano should do this just fine for C libraries.
> http://common-lisp.net/project/fetter/. Attila Lendvai has been
> fighting the bit-rot, and when I tried it a few weeks ago for one of
> my own projects, it seemed to work ok. The biggest thing is that it is
> fiddly --- you really need to use a bleeding-edge version of C-FFI.
> 
> If you try it and run into problems, let me know (or better yet post
> to the mailing list so the solution can be archived).
> 

Glad to hear it is getting some attention. This would be a great project 
to have all polished up. I wonder which is better, this or cffi-grovel?

kt
From: D Herring
Subject: Re: Portable way to use #define'd constants in cffi?
Date: 
Message-ID: <xZ6dnca1rqAP5afanZ2dnUVZ_gSdnZ2d@comcast.com>
Ken wrote:
> Rayiner Hashem wrote:
>> Verrazano should do this just fine for C libraries.
>> http://common-lisp.net/project/fetter/. Attila Lendvai has been
>> fighting the bit-rot, and when I tried it a few weeks ago for one of
>> my own projects, it seemed to work ok. The biggest thing is that it is
>> fiddly --- you really need to use a bleeding-edge version of C-FFI.
>>
> Glad to hear it is getting some attention. This would be a great project 
> to have all polished up. I wonder which is better, this or cffi-grovel?

VZN is superior if you want to know a lot of things.  Grovel is best 
for a few odds and ends.

- Daniel

PS:  I took a stab at reading gcc's DWARF debugging symbols.  It works 
fairly well.  The debug symbols know almost everything needed to 
access C++ code -- everything except for how to create or destroy an 
object.  Raw C code should fare better, but I haven't hooked any code 
generation in yet.

In a stroke of genius, GCC outputs DW_AT_MIPS_linkage_name (the 
mangled names) for everything but constructors and destructors.  All 
attempts to fix this have resulted in "but we are dropping the 
linkage_name as soon as GDB doesn't need it."  (the mangled names 
often comprise 50+% of the debug info)

Cue half-finished name mangling code.  Why GCC never thought to export 
their own as a standalone library/API...
From: ··············@gmail.com
Subject: Re: Portable way to use #define'd constants in cffi?
Date: 
Message-ID: <1195034653.053372.272640@v2g2000hsf.googlegroups.com>
> Glad to hear it is getting some attention. This would be a great project
> to have all polished up. I wonder which is better, this or cffi-grovel?

verrazano and cffi-grovel are a bit overlapping efforts and it's on my
TODO (although not at the top) to get rid of the code duplication.
most probably so that the verrazano codebase should be rewritten (imho
in the cffi repo) to parse the gccxml output into CLOS instances and
use contextl and multiple dispatch to generate the output. see TODO's
in verrazano for more details.

- attila
From: Matthew D. Swank
Subject: Re: Portable way to use #define'd constants in cffi?
Date: 
Message-ID: <pan.2007.11.15.07.43.01.284239@gmail.com>
On Wed, 14 Nov 2007 10:04:13 +0000, attila.lendvai wrote:

> the verrazano codebase should be rewritten (imho
> in the cffi repo) to parse the gccxml output into CLOS instances and
> use contextl and multiple dispatch to generate the output.

This reveals a lack of understanding on my part of the verrazano
internals, but could you outline in a little more detail how that would
work?

Matt

-- 
"You do not really understand something unless you
 can explain it to your grandmother." -- Albert Einstein.
From: Stanisław Halik
Subject: Re: Portable way to use #define'd constants in cffi?
Date: 
Message-ID: <fhdk7e$cqp$1@news2.task.gda.pl>
thus spoke Joost Diepenmaat <·····@zeekat.nl>:

> Currently I'm using a few constants from Linux header files as arguments 
> to C system library functions via cffi. (Specifically, in this case, 
> dlopen()'s second argument)

> In short; (how) - aside from writing my own .h file parser - can I 
> achieve the same thing in Common Lisp with cffi (or possibly uffi, which 
> I've not used)?

cffi-grovel. http://www.cliki.net/CFFI-Grovel

-- 
"All the anti-piracy idiots are going on about how file sharing
is theft. They’re the real thieves, stealing people’s servers
like that." -- Anonymous