From: Joerg-Cyril Hoehle
Subject: CMUCL, def-alien-routine, c-string type and :in-out behaviour
Date: 
Message-ID: <3kmr1s$6a0@eurybia.rz.uni-konstanz.de>
Hi,

please consider the following piece of code:

(def-alien-routine ("select_port"  lselect-port)  integer
  (name  c-string :in-out))
(defun select-port (port-name)
  "Changes the port name for KNIPCMS"
  (declare (type  simple-string  port-name))
  ;; for this to work it is essential that CMU allocates a C string of
  ;; the length of the LISP string, not until the first \0.
  (let ((new-name (make-string (+ PORT_NAME_LENGTH 1) :initial-element #\NULL)))
    ;; #\NULL : used by C-function as end of string
    (dotimes (i (length port-name))
      (setf (schar new-name i) (schar port-name i)))
    (multiple-value-bind (num-rc old-name)
	(lselect-port new-name)
      (values (find-symbolic-rc num-rc) old-name))))

The C function select_port() receives a char** containing a new name
and copies an old name therein. The old name may be longer than the
new one so the character array must be big enough. Now we're wondering
if using the c-string type and :in-out parameter passing allocates
memory for the C function call large enough for the whole LISP string
or if it scans for a #\NULL in that LISP string and allocates space
only that large, in which case memory may be overwritten.

We couldn't get an answer to this from the documentation. Does anybody
know how much space gets allocated? We're using CMUCL17e/f on Sun machines.

Thanks for any help,
 	Joerg Hoehle.
······@inf-wiss.uni-konstanz.de