From ... From: Erik Naggum Subject: Re: Allegro CL foreign function interface Date: 2000/06/14 Message-ID: <3170000943482820@naggum.no>#1/1 X-Deja-AN: 634579485 References: <86zooo43i5.fsf@mypp.consela.com> <86u2ewyu2c.fsf@mypp.consela.com> mail-copies-to: never Content-Type: text/plain; charset=us-ascii X-Complaints-To: newsmaster@eunet.no X-Trace: oslo-nntp.eunet.no 961012673 8384 195.0.192.66 (14 Jun 2000 19:57:53 GMT) Organization: Naggum Software; vox: +47 8800 8879; fax: +47 8800 8601; http://www.naggum.no User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.6 Mime-Version: 1.0 NNTP-Posting-Date: 14 Jun 2000 19:57:53 GMT Newsgroups: comp.lang.lisp * 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//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. #:Erik -- If this is not what you expected, please alter your expectations.