Lisp HUG Maillist Archive

FLI question

Hi!

Suppose I have a C function blark I want to call declared like this:

int blark(char **);

It is supposed to be called with a NULL terminated array of strings.

What is the right way to call it from Lisp?  This seems to work:

(fli:define-foreign-function (blark "blark" :source)
    ((arg-1 (:pointer (:pointer :char))))
  :result-type :int
  :language :ansi-c)

(defun callit (args)
  (fli:with-dynamic-foreign-objects ()
    (let* ((strings (nconc (mapcar #'fli:convert-to-dynamic-foreign-string
                                   args)
                           (list nil)))
           (array (fli:allocate-dynamic-foreign-object
                   :type '(:pointer :char)
                   :initial-contents strings
                   :nelems (length strings))))
      (blark array))))

Is this ok (especially the ``nil'' as terminating NULL pointer)?

Another question: Suppose I fork off a new subprocess from a C
function called via FLI.  Do I have to waitpid for it to avoid
zombies?  Or does Lispworks handle SIGCHLD or something?

Regards,
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x42B32FC9


Updated at: 2020-12-10 09:02 UTC