From bc38ceb5085e3fd6de096bd5ee97c40b1eaa0378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wilfredo=20Vel=C3=A1zquez-Rodr=C3=ADguez?= Date: Fri, 7 Apr 2023 09:54:27 -0400 Subject: [PATCH 1/5] Fix printing non-square multidimensional arrays Fixes #43 --- CHANGELOG.md | 6 ++++++ src/jzon.lisp | 22 ++++++++++++++-------- test/jzon-tests.lisp | 6 ++++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23a06ee..ac2adc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## PENDING v1.2.0 + +Changes relative to [v1.1.0](#v110) + +* Fix printing non-square multidimensional arrays https://github.com/Zulu-Inuoe/jzon/issues/43 + ## v1.1.0 Changes relative to [v1.0.0](#v100) diff --git a/src/jzon.lisp b/src/jzon.lisp index f1f1ed3..287d573 100644 --- a/src/jzon.lisp +++ b/src/jzon.lisp @@ -1678,16 +1678,22 @@ see `write-values'" (:method ((writer writer) (value array)) (let ((dimensions (array-dimensions value))) (if (null dimensions) - (write-value writer (aref value)) - (labels ((recurse (dimensions acc) + (write-value writer (aref value)) + (labels ((recurse (dimensions head tail) + (if (null dimensions) + (write-value writer (apply #'aref value head)) (destructuring-bind (d . rest) dimensions (with-array writer - (if (null rest) - (loop :for i :below d - :do (write-value writer (row-major-aref value (+ acc i)))) - (loop :for i :below d - :do (recurse rest (+ acc (* i d))))))))) - (recurse dimensions 0))))) + (let ((cell (setf (cdr tail) (cons 0 nil)))) + (dotimes (i d) + (setf (car cell) i) + (recurse rest head cell)))))))) + (destructuring-bind (d . rest) dimensions + (with-array writer + (let ((cell (cons 0 nil))) + (dotimes (i d) + (setf (car cell) i) + (recurse rest cell cell))))))))) ;;; Sequence support (:method ((writer writer) (value sequence)) diff --git a/test/jzon-tests.lisp b/test/jzon-tests.lisp index 457a9c1..26a5b82 100644 --- a/test/jzon-tests.lisp +++ b/test/jzon-tests.lisp @@ -1217,6 +1217,12 @@ (test stringify-multidimensional-array (is (string= "[[1,2],[3,4]]" (jzon:stringify #2A((1 2) (3 4)))))) +(test stringify-non-square-multidimensional-arrays-2×3 + (is (string= "[[0,1,2],[3,4,5]]" (jzon:stringify #2A((0 1 2) (3 4 5)))))) + +(test stringify-non-square-multidimensional-arrays-3x2 + (is (string= "[[0,1],[2,3],[4,5]]" (jzon:stringify #2A((0 1) (2 3) (4 5)))))) + (test 0-dimension-array (is (string= "42" (jzon:stringify #0A42)))) From 5f9932c737c169e940f592576aa23c6c668ac957 Mon Sep 17 00:00:00 2001 From: kilianmh Date: Mon, 28 Aug 2023 23:37:36 +0200 Subject: [PATCH 2/5] Feat: support asdf:test-system Now jzon can be tested with (asdf:test-system 'com.inuoe.jzon). --- src/com.inuoe.jzon.asd | 1 + test/com.inuoe.jzon-tests.asd | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/com.inuoe.jzon.asd b/src/com.inuoe.jzon.asd index 7dc6d07..0e34cf8 100644 --- a/src/com.inuoe.jzon.asd +++ b/src/com.inuoe.jzon.asd @@ -8,6 +8,7 @@ (:feature (:not :ecl) #:float-features) #:trivial-gray-streams #:uiop) + :in-order-to ((test-op (test-op "com.inuoe.jzon-tests"))) :components ((:file "eisel-lemire") (:file "ratio-to-double") (:file "schubfach") diff --git a/test/com.inuoe.jzon-tests.asd b/test/com.inuoe.jzon-tests.asd index d2426fa..52380dc 100644 --- a/test/com.inuoe.jzon-tests.asd +++ b/test/com.inuoe.jzon-tests.asd @@ -5,6 +5,8 @@ :license "MIT" :components ((:file "jzon-tests")) + :perform + (test-op (o c) (symbol-call '#:com.inuoe.jzon-tests '#:run)) :depends-on (#:alexandria #:fiveam From c2f5f75c7930af9564d0cf8c704bfeaef0035b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wilfredo=20Vel=C3=A1zquez-Rodr=C3=ADguez?= Date: Mon, 28 Aug 2023 18:50:16 -0400 Subject: [PATCH 3/5] Minor performance tweaks --- src/schubfach.lisp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/schubfach.lisp b/src/schubfach.lisp index 78d00ad..cf20622 100644 --- a/src/schubfach.lisp +++ b/src/schubfach.lisp @@ -166,6 +166,7 @@ (the (values null &optional) (let ((q0 q) (pos p)) + (declare (type (signed-byte 32) q0)) (loop :while (> pos pos-lim) :do (let* ((q1 (%int32 (%>>64 (* q0 1374389535) 37))) (d (aref ds (- q0 (* q1 100))))) @@ -183,6 +184,7 @@ (let* ((q0 q) (q1 0) (pos p)) + (declare (type (signed-byte 32) q0)) (loop :while (let ((qp (%int64 (* q0 1374389535)))) (setf q1 (%int32 (%>>64 qp 37))) (zerop (logand qp #x1FC0000000))) @@ -219,6 +221,7 @@ (type (simple-array (unsigned-byte 16) (100)) ds)) (let ((q0 q) (pos p)) + (declare (type (signed-byte 32) q0)) (loop (setf pos (- pos 2)) (when (< q0 100) From 4f16067a69b5708953e3be60bf364f73fa563a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wilfredo=20Vel=C3=A1zquez-Rodr=C3=ADguez?= Date: Mon, 28 Aug 2023 18:58:37 -0400 Subject: [PATCH 4/5] Bump changelog and version --- CHANGELOG.md | 9 ++++++++- src/com.inuoe.jzon.asd | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bae50a4..6a8f410 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,15 @@ -## PENDING v1.2.0 +## PENDING v1.1.3 + +Changes relative to [v1.1.2](#v112) + +## v1.1.2 Changes relative to [v1.1.1](#v111) * Fix printing non-square multidimensional arrays https://github.com/Zulu-Inuoe/jzon/issues/43 +* Fix serializing CLOS objects on LispWorks https://github.com/Zulu-Inuoe/jzon/issues/49 +* `jzon:span` support for `cl:stream` +* Fix serializing non-square multidimensional arrays https://github.com/Zulu-Inuoe/jzon/pull/44 ## v1.1.1 diff --git a/src/com.inuoe.jzon.asd b/src/com.inuoe.jzon.asd index 7dc6d07..7c95cdb 100644 --- a/src/com.inuoe.jzon.asd +++ b/src/com.inuoe.jzon.asd @@ -1,5 +1,5 @@ (defsystem #:com.inuoe.jzon - :version "1.1.1" + :version "1.1.2" :description "A correct and safe(er) JSON RFC 8259 parser with sane defaults." :author "Wilfredo Velázquez-Rodríguez " :license "MIT" From 06f3c5529be272ab065d5870d8653b22e65e3955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wilfredo=20Vel=C3=A1zquez-Rodr=C3=ADguez?= Date: Mon, 28 Aug 2023 19:02:23 -0400 Subject: [PATCH 5/5] Bump changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a8f410..9a6e4e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Changes relative to [v1.1.1](#v111) * Fix serializing CLOS objects on LispWorks https://github.com/Zulu-Inuoe/jzon/issues/49 * `jzon:span` support for `cl:stream` * Fix serializing non-square multidimensional arrays https://github.com/Zulu-Inuoe/jzon/pull/44 +* Can now test jzon via `asdf:test-system` https://github.com/Zulu-Inuoe/jzon/pull/51 ## v1.1.1