[cells-devel] bug report w/patch for record-caller in link.lisp, in LWL 5.1

Larry Clapp larry at theclapp.org
Mon Sep 1 15:58:20 UTC 2008


Bug report:

Running Stefano's Sudoku example from his cells-doc in Lispworks for
Linux 5.1, got an error in record-caller:

  Error: The subscript 16 exceeds the limit 15 for the first dimension 
  of the array #*1111111111111111.
    1 (abort) Return to level 0.
    2 Return to top loop level 0.

Lispworks said the offending code was at the indicated line:

  (handler-case
      (setf (sbit (cd-usage *depender*) used-pos) 1)  ; <== ### here ###
    (type-error (error)
      (declare (ignorable error))
      (setf (cd-usage *depender*)
        (adjust-array (cd-usage *depender*) (+ used-pos 16) :initial-element 0))
      (setf (sbit (cd-usage *depender*) used-pos) 1))))

Fix:

The condition reported was of type CONDITIONS:SUBSCRIPT-OUT-OF-BOUNDS.
I added that to the handler-case, and then it worked:

  (handler-case
      (setf (sbit (cd-usage *depender*) used-pos) 1)
    ((or type-error conditions:subscript-out-of-bounds) (error)
    ;^^^            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      (declare (ignorable error))
      (setf (cd-usage *depender*)
        (adjust-array (cd-usage *depender*) (+ used-pos 16) :initial-element 0))
      (setf (sbit (cd-usage *depender*) used-pos) 1))))

However, this seems like a demonstrably error-prone way to handle this
particular situation, so I got rid of the handler-case entirely and
tried this:

  (let ((cd-usage (cd-usage *depender*)))
    (when (>= used-pos (array-dimension cd-usage 0))
      (setf cd-usage
            (setf (cd-usage *depender*)
                  (adjust-array (cd-usage *depender*)
                                (+ used-pos 16)
                                :initial-element 0))))
    (setf (sbit cd-usage used-pos) 1))
      
It works, doesn't depend on implementation-specific conditions, and in
my limited testing (I ran the sudoku solver three times using each
version), seems at least as fast, if not a tiny bit faster.

-- Larry




More information about the cells-devel mailing list