Subject: Re: Allegro CL foreign function interface
From: Erik Naggum <>
Date: 2000/06/14
Newsgroups: comp.lang.lisp
Message-ID: <>

* Constantine Vetoshev <>
| I realize there are problems with indirection here.
| This results in a segfault.

  So print out the values of the "pointers" you get before you do
  something with them.  Compare with the memory map of the ACL
  process, either from the output of (room) or /proc/<pid>/maps.
  Enlightenment should ensue.

  What you're trying to do is called "in out" arguments in Ada, which
  is an unusually clean way to express it, but it is (of course!)
  implemented in the singularly most braindamaged way in C/C++.  You
  are actually trying to pass two arguments into your function and
  return two values from it, but conflate the two operations because
  it is possible through using too pointers too much.  C being what it
  is lacks support for multiple return values, so the notion that it
  is meaningful to pass pointers to memory objects into which any
  random function may write random values without having a clue where
  they point, has _not_ been debunked as the sheer idiocy it really is.

  Quite often, the problems that arise from wanting a foreign function
  interface that can deal with absolutely any crap any idiot is likely
  to do in C can be solved with a very simple wrapper function in the
  target language, as opposed to random qmagic in Common Lisp.  (Note
  to control freaks: You lose _less_ performance using a wrapper than
  by using a more complex FFI.)

  In this case, it's even worse: You are actually passing in a single
  value and returning a single value: A vector of strings, but since
  whoever invented C's main was probably stoned out of his wits and
  figured you should get _both_ a count and zero-terminated vector for
  the arguments, people everywhere have since believed in this calling
  convention.  *Sigh*

  If you can figure out a way to pass vectors of strings in both
  directions, you're all set, and can write your simple wrapper
  function in no time.  Both are fairly simple tasks, so as long as
  you do The Right Thing and forget how you would do it in C, you
  should be able to get a good grip on this.

  If this is not what you expected, please alter your expectations.