🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.lisp
Article #105

Re: read-file for sbcl

#105
From: tfb
Date: Tue, 01 Dec 2026 10:04
36 lines
2580 bytes
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/
Technical Details
Message-ID: <11em62r$1gota$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!news-ams.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <87ld6gl8ah.fsf@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-ams.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: tfb <tfb@work.it.out>
Newsgroups: comp.lang.lisp
Subject: Re: read-file for sbcl
Date: Tue, 1 Dec 2026 10:04:11 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <11em62r$1gota$1@dont-email.me>
References: <87ld6gl8ah.fsf@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 01 Dec 2026 10:04:12 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="1598378"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/yDo/6gcUQ5P9IWH51cQuJ"; posting-host="2124d376f87b579bbff661828eaa4a66"
User-Agent: NewsTap/5.6.3 (iPad)
Cancel-Lock: sha1:2hcBcVXyNu9hvZSFUPhlYjHpj8Y=
	sha1:4XwZ3MPxQ6pxqEk2mynkcnoJ17s= sha256:7CG7edc5+ZSwkk1D3RsWKi8vHqw691nYT2sAC0wRADo=
	sha1:j+CqhuMAzc+fR1NSd7tcQAfLdLw= sha256:GHsmUZezHv5KDR02q7Ar3o33ZbEzA6Jbvd5goM2wiMY=
X-Face: MUamY>^a5S.|?6RN|-|NWN5bt&pk2lG9&5,.QQ4