From 1739fecd7b7d23aa4b3d61823d801f4ffad11250 Mon Sep 17 00:00:00 2001 From: Cyrus Harmon Date: Thu, 20 Oct 2016 12:37:58 -0700 Subject: [PATCH] fix handling of 0-dimension arrays * in the binary type interpreters for arrays, we weren't properly handling zero-dimension arrays. One question is whether a zero-dimension array should return NIL or (make-array nil). --- cl-postgres/interpret.lisp | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/cl-postgres/interpret.lisp b/cl-postgres/interpret.lisp index 70987c5..680335c 100644 --- a/cl-postgres/interpret.lisp +++ b/cl-postgres/interpret.lisp @@ -187,22 +187,26 @@ executing body so that row values will be returned as t." (has-null (read-uint4 stream)) (element-type (read-uint4 stream))) (declare (ignore has-null)) - (let* ((array-dims - (loop for i below num-dims - collect (let ((dim (read-uint4 stream)) - (lb (read-uint4 stream))) - (declare (ignore lb)) - dim))) - (num-items (reduce #'* array-dims))) - (let ((results (make-array array-dims))) - (loop for i below num-items - do (let ((size (read-int4 stream))) - (declare (type (signed-byte 32) size)) - (setf (row-major-aref results i) - (if (eq size -1) - :null - (funcall (interpreter-reader (get-type-interpreter element-type)) stream size))))) - results)))) + ;; FIXME: + ;; should we return nil or a (make-array nil) when num-dims is + ;; 0? Returning nil for now. + (when (plusp num-dims) + (let* ((array-dims + (loop for i below num-dims + collect (let ((dim (read-uint4 stream)) + (lb (read-uint4 stream))) + (declare (ignore lb)) + dim))) + (num-items (reduce #'* array-dims))) + (let ((results (make-array array-dims))) + (loop for i below num-items + do (let ((size (read-int4 stream))) + (declare (type (signed-byte 32) size)) + (setf (row-major-aref results i) + (if (eq size -1) + :null + (funcall (interpreter-reader (get-type-interpreter element-type)) stream size))))) + results))))) (dolist (oid '( 1000 ;; boolean array -- 2.11.4.GIT