[Openmcl-devel] Apparent displaced array type bug

Gary Byers gb at clozure.com
Fri Sep 23 02:38:14 PDT 2005


The type declaration on the DATA slot asserts that the value of that
slot should be a (SIMPLE-ARRAY (MOD 129)) of two (unspecified)
dimensions.  In OpenMCL, arrays that're explicitly displaced are not
SIMPLE-ARRAYs; your code is trying to assign a value to a slot that is
not of the slot's declared type, and the results of such an attempt
are undefined.

OpenMCL tries to signal an error when it can determine that a slot's
type declaration is being violated by an assignment or an
initialization.  I think that this is useful behavior (either the
declaration's wrong or the assignment/initialization is), though

(a) it would be no more or less correct to ignore this
(b) there are ways of violating type declarations that OpenMCL
     doesn't check for.

Is the error message below unclear ?


On Fri, 23 Sep 2005, David Steuber wrote:

> Hi OpenMCL developers,
>
> Please see LispPaste:  http://paste.lisp.org/display/11910
>
> david at interloper:~/usr/src/apress-fractal/src
> $ openmcl
> Welcome to OpenMCL Version 1.0-test-050914 (DarwinPPC32)!
> ? (load (compile-file "apress-fractal.lisp"))
> Performing compile-time optimization.. please wait.
> Done.
> #P"/Users/david/usr/src/apress-fractal/src/apress-fractal.dfsl"
> ? (time (generate-fractals-from-input-file "../sampleinput.txt"))
>> Error in process listener(1): The value #<ARRAY 600x800 type (UNSIGNED-BYTE 
> 8), displaced> can not be used to set the value of the slot DATA in 
> #<MSET-MAP [-1.0 1.0 1.0 -1.0] 800x600 #x8405A0E>, because it is not of type 
> (SIMPLE-ARRAY (MOD 129) (* *)).
>> While executing: CCL::%MAYBE-STD-SETF-SLOT-VALUE-USING-CLASS
>> Type :POP to abort.
> Type :? for other options.
> 1 > :pop
>
> ? (quit)
>
>
> This is code that works in both SBCL 0.9.4.0 and CLisp 2.33.2 on OS X 10.3.9. 
> The relevant portion I think is this:
>
> (defclass mset-map ()
>  ((left           :type single-float       :initarg :left           :reader 
> mset-map-left)
>   (right          :type single-float       :initarg :right          :reader 
> mset-map-right)
>   (top            :type single-float       :initarg :top            :reader 
> mset-map-top)
>   (bottom         :type single-float       :initarg :bottom         :reader 
> mset-map-bottom)
>   (width          :type (integer 1 4096)   :initarg :width          :reader 
> mset-map-width)
>   (height         :type (integer 1 4096)   :initarg :height         :reader 
> mset-map-height)
>   (x-axis         :type simple-vector)
>   (y-axis         :type simple-vector)
>   (data           :type (simple-array (integer 0 #.+max-iterations+) (* *)))
>   (data-alias     :type (simple-array (integer 0 #.+max-iterations+) *))))
>
> (defmethod shared-initialize :after ((o mset-map) slot-names &rest init-args)
>  (declare (ignore slot-names init-args))
>  (flet ((make-axis-array (len min max)
>           (let ((my-array (make-array len)))
>             (loop for i below len
>                with pixelsize = (/ (- max min) len)
>                with start = min
>                do (setf (svref my-array i) (+ start (* i pixelsize))))
>             my-array)))
>    (with-slots (left right top bottom x-axis y-axis data data-alias height 
> width) o
>      (setf x-axis (make-axis-array width left right)
>            y-axis (nreverse (make-axis-array height bottom top))
>            data-alias (make-array (* height width)
>                                   :element-type '(integer 0 
> #.+max-iterations+)
>                                   :initial-element 0)
>            data (make-array (list height width)
>                               :element-type '(integer 0 #.+max-iterations+)
>                               :displaced-to data-alias)))))
>
> Just in case I am wrong, the complete code is here:
>
> http://www.david-steuber.com/Lisp/Apress-Fractal-Contest/apress- 
> fractal.lisp.txt
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>



More information about the Openmcl-devel mailing list