Skip to content

Commit ebbb843

Browse files
committed
Fix non-conforming code.
According to the LOAD-TIME-VALUE entry for CLHS http://clhs.lisp.se/Body/s_ld_tim.htm, "It is guaranteed that the evaluation of form will take place only once when the file is loaded, but the order of evaluation with respect to the evaluation of top level forms in the file is implementation-dependent." Therefore, doing LOAD-TIME-VALUE of a function call where the function is defined in the same file is not portable code. This is important to fix because old versions of CMU CL do take advantage of this fact, and future versions of SBCL may as well.
1 parent 8b63e00 commit ebbb843

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

quicklisp/deflate.lisp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,26 +121,28 @@
121121
(defconstant +crc-32-start-value+ 0
122122
"Start value for CRC-32 checksums as per RFC 1952.")
123123

124-
(defconstant +crc-32-polynomial+ #xedb88320
125-
"CRC-32 Polynomial as per RFC 1952.")
124+
(eval-when (:compile-toplevel :load-toplevel :execute)
125+
(defconstant +crc-32-polynomial+ #xedb88320
126+
"CRC-32 Polynomial as per RFC 1952."))
126127

127128
(declaim (ftype #-lispworks (function () (simple-array (unsigned-byte 32) (256)))
128129
#+lispworks (function () (sys:simple-int32-vector 256))
129130
generate-crc32-table))
130-
(defun generate-crc32-table ()
131-
(let ((result #-lispworks (make-array 256 :element-type '(unsigned-byte 32))
132-
#+lispworks (sys:make-simple-int32-vector 256)))
133-
(dotimes (i #-lispworks (length result) #+lispworks 256 result)
134-
(let ((cur i))
135-
(dotimes (k 8)
136-
(setq cur (if (= 1 (logand cur 1))
137-
(logxor (ash cur -1) +crc-32-polynomial+)
138-
(ash cur -1))))
139-
#-lispworks (setf (aref result i) cur)
140-
#+lispworks (setf (sys:int32-aref result i)
141-
(sys:integer-to-int32
142-
(dpb (ldb (byte 32 0) cur) (byte 32 0)
143-
(if (logbitp 31 cur) -1 0))))))))
131+
(eval-when (:compile-toplevel :load-toplevel :execute)
132+
(defun generate-crc32-table ()
133+
(let ((result #-lispworks (make-array 256 :element-type '(unsigned-byte 32))
134+
#+lispworks (sys:make-simple-int32-vector 256)))
135+
(dotimes (i #-lispworks (length result) #+lispworks 256 result)
136+
(let ((cur i))
137+
(dotimes (k 8)
138+
(setq cur (if (= 1 (logand cur 1))
139+
(logxor (ash cur -1) +crc-32-polynomial+)
140+
(ash cur -1))))
141+
#-lispworks (setf (aref result i) cur)
142+
#+lispworks (setf (sys:int32-aref result i)
143+
(sys:integer-to-int32
144+
(dpb (ldb (byte 32 0) cur) (byte 32 0)
145+
(if (logbitp 31 cur) -1 0)))))))))
144146

145147
(declaim (ftype
146148
(function ((unsigned-byte 32) (simple-array (unsigned-byte 8) (*)) fixnum)
@@ -153,7 +155,7 @@
153155
(type fixnum end)
154156
(optimize (speed 3) (debug 0) (space 0) (safety 0))
155157
#+sbcl (sb-ext:muffle-conditions sb-ext:compiler-note))
156-
(let ((table (load-time-value (generate-crc32-table)))
158+
(let ((table #.(generate-crc32-table))
157159
(cur (logxor crc #xffffffff)))
158160
(declare (type (simple-array (unsigned-byte 32) (256)) table)
159161
(type (unsigned-byte 32) cur))
@@ -170,7 +172,7 @@
170172
(type (simple-array (unsigned-byte 8) (*)) buffer)
171173
(type fixnum end)
172174
(optimize (speed 3) (debug 0) (space 0) (safety 0) (float 0)))
173-
(let ((table (load-time-value (generate-crc32-table)))
175+
(let ((table #.(generate-crc32-table))
174176
(cur (sys:int32-lognot (sys:integer-to-int32
175177
(dpb (ldb (byte 32 0) crc) (byte 32 0)
176178
(if (logbitp 31 crc) -1 0))))))

0 commit comments

Comments
 (0)