I have looked at relevant code in SBCL, and I believe
following code fixes this bug.

This uses a higher level wrapper
SB-IMPL::ALLOCATE-VECTOR-WITH-WIDETAG
to replace SB-KERNEL:ALLOCATE-VECTOR and
VECTOR-LENGTH-IN-WORDS.

The original code `(ceiling (* ,n ,n-bits) sb-vm:n-word-bits)
is wrong, it should be
`(ceiling (* ,n ,n-bits) (1- (integer-length sb-vm:n-word-bits))).

--- a/src/lisp/primitives.lisp
+++ b/src/lisp/primitives.lisp
@@ -101,22 +101,14 @@

 #+:sbcl
 (defmacro sbcl_make_sized_vector(nb n)
-    (let ((get-tag (find-symbol "%VECTOR-WIDETAG-AND-N-BITS" "SB-IMPL"))
-          (length-sym nil))
+    (let ((get-tag (find-symbol "%VECTOR-WIDETAG-AND-N-BITS" "SB-IMPL")))
         (if (null get-tag)
-            (progn
-                (setf get-tag
-                    (find-symbol "%VECTOR-WIDETAG-AND-N-BITS-SHIFT"
-                                 "SB-IMPL"))
-                (setf length-sym (find-symbol "VECTOR-LENGTH-IN-WORDS"
-                                              "SB-IMPL"))))
+            (setf get-tag
+                (find-symbol "%VECTOR-WIDETAG-AND-N-BITS-SHIFT"
+                             "SB-IMPL")))
         (multiple-value-bind (typetag n-bits)
             (FUNCALL get-tag `(unsigned-byte ,nb))
-            (let ((length-form
-                   (if length-sym
-                       `(,length-sym ,n ,n-bits)
-                       `(ceiling (* ,n ,n-bits) sb-vm:n-word-bits))))
-                `(SB-KERNEL:ALLOCATE-VECTOR ,typetag ,n ,length-form)))))
+            `(SB-IMPL::ALLOCATE-VECTOR-WITH-WIDETAG ,typetag ,n ,n-bits))))

 (defmacro DEF_SIZED_UOPS(nb)

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to