Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.1.4 #62

Merged
merged 10 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## v1.1.4

Changes relative to [v1.1.3](#v113)

* Skip optional failing unit test on ECL (https://github.com/Zulu-Inuoe/jzon/issues/59)
* CLISP suport by removing PLN usage (https://github.com/Zulu-Inuoe/jzon/issues/53)
* Fix bogus float serialization for certain floats (thanks https://github.com/atgreen)

## v1.1.3

Changes relative to [v1.1.2](#v112)
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,20 @@ Please see the [changelog](CHANGELOG.md) for a list of changes between versions.

# Quickstart

**Note**: *Examples in this README can be copy-pasted in your REPL assuming you've got a nickname set up for jzon. Try `(uiop:add-package-local-nickname '#:jzon '#:com.inuoe.jzon)`.*
jzon is on both Quicklisp and Ultralisp, and can be loaded via

```lisp
(ql:quickload '#:com.inuoe.jzon)
```

Most users will simply use [`jzon:parse`](#jzonparse) for reading, and [`jzon:stringify`](#jzonstringify) for writing. These mirror the [JSON methods in JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON).

**Note**: Examples in this README can be copy-pasted in your REPL if you've got a nickname set up for jzon. To follow along with the examples, use

```lisp
(uiop:add-package-local-nickname '#:jzon '#:com.inuoe.jzon)
```

### Reading

[`jzon:parse`](#jzonparse) will parse JSON and produce a CL value
Expand Down Expand Up @@ -271,7 +281,7 @@ If *pretty* is true, the output is formatted with spaces and newlines.

*max-depth* limits the depth of nesting arrays/objects. Use `nil` to disable it, or `t` to set to default.

In addition to serializing `json:jzon-element` values per [Type Mappings](#type-mappings), `jzon:stringify` allows other values.
In addition to serializing `jzon:json-element` values per [Type Mappings](#type-mappings), `jzon:stringify` allows other values.
See [Additionally Supported Types For Writing](#additionally-supported-types-for-writing) and [Custom Serialization](#custom-serialization).

*max-string-length* may be an integer denoting the limit, or
Expand Down
2 changes: 1 addition & 1 deletion src/com.inuoe.jzon.asd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(defsystem #:com.inuoe.jzon
:version "1.1.3"
:version "1.1.4"
:description "A correct and safe(r) JSON RFC 8259 reader/writer with sane defaults."
:author "Wilfredo Velázquez-Rodríguez <[email protected]>"
:license "MIT"
Expand Down
5 changes: 1 addition & 4 deletions src/eisel-lemire.lisp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
(defpackage #:com.inuoe.jzon/eisel-lemire
(:use #:cl)
(:local-nicknames
#-ecl
(#:ff #:org.shirakumo.float-features))
(:export #:make-double))

(in-package #:com.inuoe.jzon/eisel-lemire)
Expand Down Expand Up @@ -98,7 +95,7 @@

(defmacro %bits-double-float (x)
#-ecl
`(ff:bits-double-float ,x)
`(org.shirakumo.float-features:bits-double-float ,x)
#+ecl
(if (find-symbol (string '#:bits-double-float) '#:si)
`(,(intern (string '#:bits-double-float) '#:si) ,x)
Expand Down
37 changes: 16 additions & 21 deletions src/jzon.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@
#:end-object*
#:with-object*
#:write-object*)
(:local-nicknames
(#:el #:com.inuoe.jzon/eisel-lemire)
(#:rtd #:com.inuoe.jzon/ratio-to-double)
(#:sf #:com.inuoe.jzon/schubfach)
(#:tgs #:trivial-gray-streams))
(:import-from #:closer-mop)
(:import-from #:flexi-streams)
(:import-from #:float-features)
Expand Down Expand Up @@ -329,8 +324,8 @@ see `json-atom'"
(if (or (null c) (%ends-token-p c))
(let ((exp10 (+ exp10 (* exp-sign exp-val))))
(return (values
(or (el:make-double mantissa exp10 (minusp sign))
(rtd:ratio-to-double (* mantissa (expt 10 exp10) sign)))
(or (com.inuoe.jzon/eisel-lemire:make-double mantissa exp10 (minusp sign))
(com.inuoe.jzon/ratio-to-double:ratio-to-double (* mantissa (expt 10 exp10) sign)))
c)))
c))))
(prog ((sign 1)
Expand Down Expand Up @@ -1185,16 +1180,16 @@ Example return value:
(with-output-to-string (s)
(macrolet ((#1=#:|| ()
`(etypecase key
(double-float (sf:write-double key s))
(single-float (sf:write-float key s))
(double-float (com.inuoe.jzon/schubfach:write-double key s))
(single-float (com.inuoe.jzon/schubfach:write-float key s))
,@(unless (%type= 'short-float 'single-float)
'((short-float (sf:write-float (coerce key 'single-float) s))))
'((short-float (com.inuoe.jzon/schubfach:write-float (coerce key 'single-float) s))))
,@(unless (%type= 'long-float 'double-float)
'((long-float (sf:write-double (coerce key 'double-float) s)))))))
'((long-float (com.inuoe.jzon/schubfach:write-double (coerce key 'double-float) s)))))))
(#1#))))
(:method ((key ratio))
(with-output-to-string (s)
(sf:write-double (rtd:ratio-to-double key) s))))
(com.inuoe.jzon/schubfach:write-double (com.inuoe.jzon/ratio-to-double:ratio-to-double key) s))))

(define-condition json-write-error (json-error) ()
(:documentation "Error signalled when there is an issue during writing JSON."))
Expand All @@ -1218,13 +1213,13 @@ Example return value:
(format stream " Limit: ~A." (%json-limit-error-limit c))))
(:documentation "Error signalled when a limit on the JSON writer has been exceeded."))

(defclass %string-output-stream (tgs:fundamental-character-output-stream)
(defclass %string-output-stream (trivial-gray-streams:fundamental-character-output-stream)
((%string :initarg :string)))

(defmethod tgs:stream-write-char ((stream %string-output-stream) character)
(defmethod trivial-gray-streams:stream-write-char ((stream %string-output-stream) character)
(vector-push-extend character (slot-value stream '%string)))

(defmethod tgs:stream-write-string ((stream %string-output-stream) string &optional start end)
(defmethod trivial-gray-streams:stream-write-string ((stream %string-output-stream) string &optional start end)
(let* ((%string (slot-value stream '%string))
(len (- (or end (length string)) (or start 0)))
(prev-len (fill-pointer %string))
Expand Down Expand Up @@ -1547,7 +1542,7 @@ see `write-values'"
((eql nil) (write-string "false" %stream))
((eql null) (write-string "null" %stream))
(integer (format %stream "~D" value))
(double-float (sf:write-double value %stream))
(double-float (com.inuoe.jzon/schubfach:write-double value %stream))
(string (%write-json-string value %stream)))))

(defgeneric write-value (writer value)
Expand Down Expand Up @@ -1622,12 +1617,12 @@ see `write-values'"
(%write-indentation writer)))
(macrolet ((#1=#:|| ()
`(etypecase value
(double-float (sf:write-double value %stream))
(single-float (sf:write-float value %stream))
(double-float (com.inuoe.jzon/schubfach:write-double value %stream))
(single-float (com.inuoe.jzon/schubfach:write-float value %stream))
,@(unless (%type= 'short-float 'single-float)
'((short-float (sf:write-float (coerce value 'single-float) %stream))))
'((short-float (com.inuoe.jzon/schubfach:write-float (coerce value 'single-float) %stream))))
,@(unless (%type= 'long-float 'double-float)
'((long-float (sf:write-double (coerce value 'double-float) %stream)))))))
'((long-float (com.inuoe.jzon/schubfach:write-double (coerce value 'double-float) %stream)))))))
(#1#))))
(:method ((writer writer) (value string))
(%write-json-atom writer value))
Expand Down Expand Up @@ -1668,7 +1663,7 @@ see `write-values'"

;; Reals
(:method ((writer writer) (value ratio))
(%write-json-atom writer (rtd:ratio-to-double value)))
(%write-json-atom writer (com.inuoe.jzon/ratio-to-double:ratio-to-double value)))

;;; Symbols
(:method ((writer writer) (value symbol))
Expand Down
5 changes: 1 addition & 4 deletions src/ratio-to-double.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@

(defpackage #:com.inuoe.jzon/ratio-to-double
(:use #:cl)
(:local-nicknames
#-ecl
(#:ff #:org.shirakumo.float-features))
(:export
#:ratio-to-double))

(in-package #:com.inuoe.jzon/ratio-to-double)

(defmacro %bits-double-float (x)
#-ecl
`(ff:bits-double-float ,x)
`(org.shirakumo.float-features:bits-double-float ,x)
#+ecl
(if (find-symbol (string '#:bits-double-float) '#:si)
`(,(intern (string '#:bits-double-float) '#:si) ,x)
Expand Down
11 changes: 4 additions & 7 deletions src/schubfach.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

(defpackage #:com.inuoe.jzon/schubfach
(:use #:cl)
(:local-nicknames
#-ecl
(#:ff #:org.shirakumo.float-features))
(:export
#:write-float
#:write-double))
Expand Down Expand Up @@ -226,7 +223,7 @@
(setf pos (- pos 2))
(when (< q0 100)
(return))

(let* ((q1 (%int32 (%>>64 (%int64 (* q0 1374389535)) 37)))
(d (aref ds (- q0 (* q1 100)))))
(setf (char buf (+ pos 0)) (code-char (ldb (byte 7 0) d)))
Expand All @@ -241,7 +238,7 @@

(defmacro %single-float-bits (x)
#-ecl
`(the (unsigned-byte 32) (ff:single-float-bits ,x))
`(the (unsigned-byte 32) (org.shirakumo.float-features:single-float-bits ,x))
#+ecl
(if (find-symbol (string '#:single-float-bits) '#:si)
`(,(intern (string '#:single-float-bits) '#:si) ,x)
Expand Down Expand Up @@ -351,7 +348,7 @@
(setf (char buf (+ pos 1)) #\-)
(incf pos)
(when (< e10 0)
(setf e10 (- 10))
(setf e10 (- e10))
(incf pos))
(cond
((< e10 10)
Expand Down Expand Up @@ -443,7 +440,7 @@

(defmacro %double-float-bits (x)
#-ecl
`(the (unsigned-byte 64) (ff:double-float-bits ,x))
`(the (unsigned-byte 64) (org.shirakumo.float-features:double-float-bits ,x))
#+ecl
(if (find-symbol (string '#:double-float-bits) '#:si)
`(,(intern (string '#:double-float-bits) '#:si) ,x)
Expand Down
Loading
Loading