Here are two problems with this code that may not matter (but may). There
are certainly others.
(defun make-standard-string (size &optional (initial #\Space))
"Return a standard-string."
(make-string size :element-type 'standard-char :initial-element initial))
This function is used to allocate a buffer the guts of which is then passed
to foreign code. I don't know for sure but I assume that SBCL's GC
relocates objects, possibly while the foreign code is running. If it can,
the results will be catastrophic. LW has options to 'pin' objects, for
just this reason. may be SBCL gets round this some other way?
(defun read-file (filename)
"Return contents of file <filename> as a string. The second value is the
number
of bytes read by read. This function uses unix read from a C object file."
(let* ((size (file-length-name filename))
(buffer (make-standard-string size))
(sap (sb-sys:vector-sap buffer))
(fd (sb-posix:open filename sb-posix:o-rdonly 0))
(res 0))
(declare (dynamic-extent buffer))
(unwind-protect
(setq res (read-nbytes fd sap size))
(sb-posix:close fd))
(values buffer res)))
This is returning an object declared DYNAMIC-EXTENT. Probably it is not
actually stack-allocated as MAKE-STANDARD-STRING is not inlined, at least,
but still, never do this.
--
tfeb.org/computer/