Subject: Re: FFI c-struct convenience classes? OO, not with-
From: Erik Naggum <erik@naggum.no>
Date: 1999/05/29
Newsgroups: comp.lang.lisp
Message-ID: <3136959606626483@naggum.no>

* rurban@xarch.tu-graz.ac.at (Reini Urban)
| I'm terrible dissatisfied with the FFI's I know of,  which are ACLW FFI,
| LWW FLI, CormanLISP FFI (my favorite), CLISP (this is also nice) and also
| some scheme dialects. (found nothing better there)

  I have found Franz Inc's new FFI very convenient.  it is in Allegro CL 5
  for both Windows and Unix.  ACL for Windows is dead, but compatibility
  support exists for old applications (and programmers :).

  the only problem I have ahd with it is that since Unix is so damn focused
  on using small integers for everything, it's been a hassle to define the
  symbols that Unix functions expect.  and more often than not, the Unix
  feature is so amazingly braindamaged that providing the service is a lot
  more work than the FFI, anyway.  take sockets.  sockets suck.  making
  them not suck is hard work.  (thank goodness I'm not working in Windows.)

| my problem is that no FFI package so far abstracts c-structs enough.

  take a look at Allegro CL 5, then.

| i'll have to use masses of c-code (AutoCAD, WinUI and COM), most of it
| can be translated automatically to the implementation dependent c-type
| syntax (they are all quite similar thanksfully), but when using these c
| functions the problems arise.
| e.g. the WinAPI uses extensively structs by side effects, you have to
| malloc a struct, convert your lisp values to c-types, set the
| appropriate c-slots, call the function with this struct, and afterwards
| the reverse: 
| access the c-slots, convert them back to lisp types and free the struct
| and all indirect slots (if necessary).
| this is a pain, i could have stayed c programmer for doing this stupid
| work. and i cannot burden plain users with this.

  why free the structure?  use a closure for each type of call, allocate on
  first call and reuse the struct once allocated.  if you want reentrant
  code, cons up a list of them, instead.  it's a lot better for such
  structs to hang around than to be freed and allocated all over again.

| why not create a c-type class, and a c-struct subclass, with all the
| methods to automatically initialize, get and set the c-struct slots.

  this has been done.  take a look at Allegro CL 5.

  it's a shame people don't research the available techologies better
  before going into serious problem-solving mode.  on the other hand, it's
  a shame that so many people are so aggressively opposed to information
  from commercial actors in newsgroups that they think anything that
  doesn't come from individuals is "marketing".  however, since this
  doesn't stop Harlequin from announcing everything under the sun, it
  appears that Franz Inc's policy of not posting information about their
  new developments may actually be a disservice to the community.

#:Erik
-- 
@1999-07-22T00:37:33Z -- pi billion seconds since the turn of the century