Subject: [clisp-list] execl, et al.: unneeded, please use execv!

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Tue Dec 10 06:10:04 2002

Hi,

[Sam: to be included into CLISP if Pascal confirm it works.]

>execl,  execle,  and  other  functions  taking a  variable  number  of
>arguments  are  missing,  because  the  FFI package  does  not  handle

1. You could use
(def-call-out execl% ... #|0 or 1 arg template #|
(defun execl (...)
 (WITH-FOREIGN-OBJECT (exec `(C-FUNCTION ...,(construct varargs)) #'execl%
  (funcall #|the foreign-function object|# path args)
I.e. apply CAST, either implicitly or explicitly.
Or
(apply (FOREIGN-ADDRESS-FUNCTION "execl" (foreign-address ...)
            `(C-FUNCTION ... ,(construct varargs)))
       args)

2. However execl() is for C programmers only. It uses variable numbers of arguments. Most language bindings use execv(), which passes the argument as a pointer to an array.
No problem at all with CLISP and a very nice use of the C-ARRAY-PTR declaration.

Note to programmers for interoperability: design your interfaces this way instead of "only callable from C (and few others) because it uses varargs".

; from the Solaris 2.5 manpage I suggest
(def-c-call-out execv (:arguments (path c-string) (argv (c-array-ptr c-string)))
                       (:return-type int)
                       (:name "execv")
)
(def-c-call-out execve (:arguments (path c-string) (argv (c-array-ptr c-string)) (envp (c-array-ptr c-string)))
                       (:return-type int)
                       (:name "execv")
)
(def-c-call-out execvp (:arguments (file c-string) (argv (c-array-ptr c-string)))
                       (:return-type int)
                       (:name "execvp")
)

Now somebody go figure out why the appropriate and unfinished lines for execvyx() are commented out in clisp/src/modules/bindings/linuxlibcx/

(execv "echo" (vector "echo" "arg1" "arg2"))
(defun myexec (path &rest args)
  (execv path (apply #'vector path args)))
; all untested

A note on Pascal's original macro code: it looked like DEF-LIB-CALL might be invoked for each call. This is usually a bad thing to do. Looking even closely, there are several things wrong with that macro (like FBOUNDP being invoked at macroexpansion time). A lot more could be written on Lisp macros.

Regards,
	Jörg Höhle.