* [PATCH 1/2] Use Jansson's error code support if available
@ 2017-12-18 23:17 Philipp Stephani
2017-12-18 23:17 ` [PATCH 2/2] JSON serialization: reject duplicate keys in hashtables Philipp Stephani
2017-12-19 17:11 ` [PATCH 1/2] Use Jansson's error code support if available Eli Zaretskii
0 siblings, 2 replies; 7+ messages in thread
From: Philipp Stephani @ 2017-12-18 23:17 UTC (permalink / raw)
To: emacs-devel; +Cc: Philipp Stephani
* src/json.c (json_parse_error): Use Jansson's error code support if
available.
---
src/json.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/json.c b/src/json.c
index 29e4400fc9..b996cad5a6 100644
--- a/src/json.c
+++ b/src/json.c
@@ -249,15 +249,24 @@ static _Noreturn void
json_parse_error (const json_error_t *error)
{
Lisp_Object symbol;
- /* FIXME: Upstream Jansson should have a way to return error codes
- without parsing the error messages. See
- https://github.com/akheron/jansson/issues/352. */
+#if JANSSON_VERSION_HEX >= 0x020B00
+ switch (json_error_code (error))
+ {
+ case json_error_premature_end_of_input:
+ symbol = Qjson_end_of_file;
+ case json_error_end_of_input_expected:
+ symbol = Qjson_trailing_content;
+ default:
+ symbol = Qjson_parse_error;
+ }
+#else
if (json_has_suffix (error->text, "expected near end of file"))
symbol = Qjson_end_of_file;
else if (json_has_prefix (error->text, "end of file expected"))
symbol = Qjson_trailing_content;
else
symbol = Qjson_parse_error;
+#endif
xsignal (symbol,
list5 (json_build_string (error->text),
json_build_string (error->source), make_natnum (error->line),
--
2.15.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] JSON serialization: reject duplicate keys in hashtables
2017-12-18 23:17 [PATCH 1/2] Use Jansson's error code support if available Philipp Stephani
@ 2017-12-18 23:17 ` Philipp Stephani
2017-12-24 12:53 ` Philipp Stephani
2017-12-19 17:11 ` [PATCH 1/2] Use Jansson's error code support if available Eli Zaretskii
1 sibling, 1 reply; 7+ messages in thread
From: Philipp Stephani @ 2017-12-18 23:17 UTC (permalink / raw)
To: emacs-devel; +Cc: Philipp Stephani
* src/json.c (lisp_to_json_toplevel_1): Reject duplicate keys in
hashtables.
* test/src/json-tests.el (json-serialize/object-with-duplicate-keys):
Add unit tests.
---
src/json.c | 7 ++++++-
test/src/json-tests.el | 8 ++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/json.c b/src/json.c
index b996cad5a6..3eba5c4310 100644
--- a/src/json.c
+++ b/src/json.c
@@ -340,7 +340,12 @@ lisp_to_json_toplevel_1 (Lisp_Object lisp, json_t **json)
/* We can't specify the length, so the string must be
null-terminated. */
check_string_without_embedded_nulls (key);
- int status = json_object_set_new (*json, SSDATA (key),
+ const char *key_data = SSDATA (key);
+ /* Reject duplicate keys. These are possible if the hash
+ table test is not `equal'. */
+ if (json_object_get (*json, key_data) != NULL)
+ wrong_type_argument (Qjson_value_p, lisp);
+ int status = json_object_set_new (*json, key_data,
lisp_to_json (HASH_VALUE (h, i)));
if (status == -1)
/* FIXME: A failure here might also indicate that the
diff --git a/test/src/json-tests.el b/test/src/json-tests.el
index 551f8ac5fe..4edf9d8df0 100644
--- a/test/src/json-tests.el
+++ b/test/src/json-tests.el
@@ -52,6 +52,14 @@
(should (equal (json-serialize table)
"{\"abc\":[1,2,true],\"def\":null}"))))
+(ert-deftest json-serialize/object-with-duplicate-keys ()
+ (skip-unless (fboundp 'json-serialize))
+ (let ((table (make-hash-table :test #'eq)))
+ (puthash (copy-sequence "abc") [1 2 t] table)
+ (puthash (copy-sequence "abc") :null table)
+ (should (equal (hash-table-count table) 2))
+ (should-error (json-serialize table) :type 'wrong-type-argument)))
+
(ert-deftest json-parse-string/object ()
(skip-unless (fboundp 'json-parse-string))
(let ((actual
--
2.15.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] JSON serialization: reject duplicate keys in hashtables
2017-12-18 23:17 ` [PATCH 2/2] JSON serialization: reject duplicate keys in hashtables Philipp Stephani
@ 2017-12-24 12:53 ` Philipp Stephani
0 siblings, 0 replies; 7+ messages in thread
From: Philipp Stephani @ 2017-12-24 12:53 UTC (permalink / raw)
To: emacs-devel; +Cc: Philipp Stephani
[-- Attachment #1: Type: text/plain, Size: 2255 bytes --]
Pushed to master as 3455192777459a08a38b0adb311a76202e29f48d.
Philipp Stephani <p.stephani2@gmail.com> schrieb am Di., 19. Dez. 2017 um
00:17 Uhr:
> * src/json.c (lisp_to_json_toplevel_1): Reject duplicate keys in
> hashtables.
>
> * test/src/json-tests.el (json-serialize/object-with-duplicate-keys):
> Add unit tests.
> ---
> src/json.c | 7 ++++++-
> test/src/json-tests.el | 8 ++++++++
> 2 files changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/src/json.c b/src/json.c
> index b996cad5a6..3eba5c4310 100644
> --- a/src/json.c
> +++ b/src/json.c
> @@ -340,7 +340,12 @@ lisp_to_json_toplevel_1 (Lisp_Object lisp, json_t
> **json)
> /* We can't specify the length, so the string must be
> null-terminated. */
> check_string_without_embedded_nulls (key);
> - int status = json_object_set_new (*json, SSDATA (key),
> + const char *key_data = SSDATA (key);
> + /* Reject duplicate keys. These are possible if the hash
> + table test is not `equal'. */
> + if (json_object_get (*json, key_data) != NULL)
> + wrong_type_argument (Qjson_value_p, lisp);
> + int status = json_object_set_new (*json, key_data,
> lisp_to_json (HASH_VALUE
> (h, i)));
> if (status == -1)
> /* FIXME: A failure here might also indicate that the
> diff --git a/test/src/json-tests.el b/test/src/json-tests.el
> index 551f8ac5fe..4edf9d8df0 100644
> --- a/test/src/json-tests.el
> +++ b/test/src/json-tests.el
> @@ -52,6 +52,14 @@
> (should (equal (json-serialize table)
> "{\"abc\":[1,2,true],\"def\":null}"))))
>
> +(ert-deftest json-serialize/object-with-duplicate-keys ()
> + (skip-unless (fboundp 'json-serialize))
> + (let ((table (make-hash-table :test #'eq)))
> + (puthash (copy-sequence "abc") [1 2 t] table)
> + (puthash (copy-sequence "abc") :null table)
> + (should (equal (hash-table-count table) 2))
> + (should-error (json-serialize table) :type 'wrong-type-argument)))
> +
> (ert-deftest json-parse-string/object ()
> (skip-unless (fboundp 'json-parse-string))
> (let ((actual
> --
> 2.15.1
>
>
[-- Attachment #2: Type: text/html, Size: 2872 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] Use Jansson's error code support if available
2017-12-18 23:17 [PATCH 1/2] Use Jansson's error code support if available Philipp Stephani
2017-12-18 23:17 ` [PATCH 2/2] JSON serialization: reject duplicate keys in hashtables Philipp Stephani
@ 2017-12-19 17:11 ` Eli Zaretskii
2017-12-19 17:35 ` Philipp Stephani
1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2017-12-19 17:11 UTC (permalink / raw)
To: Philipp Stephani; +Cc: phst, emacs-devel
> From: Philipp Stephani <p.stephani2@gmail.com>
> Date: Tue, 19 Dec 2017 00:17:29 +0100
> Cc: Philipp Stephani <phst@google.com>
>
> * src/json.c (json_parse_error): Use Jansson's error code support if
> available.
> ---
> src/json.c | 15 ++++++++++++---
> 1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/src/json.c b/src/json.c
> index 29e4400fc9..b996cad5a6 100644
> --- a/src/json.c
> +++ b/src/json.c
> @@ -249,15 +249,24 @@ static _Noreturn void
> json_parse_error (const json_error_t *error)
> {
> Lisp_Object symbol;
> - /* FIXME: Upstream Jansson should have a way to return error codes
> - without parsing the error messages. See
> - https://github.com/akheron/jansson/issues/352. */
> +#if JANSSON_VERSION_HEX >= 0x020B00
> + switch (json_error_code (error))
Would it be possible for you to add the few lines which would make
this work on MS-Windows? It's pretty much boilerplate (you can see
what I did for every jansson function we need, and copycat that), but
if you don't add those few lines, the Windows build will fail to link.
TIA
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] Use Jansson's error code support if available
2017-12-19 17:11 ` [PATCH 1/2] Use Jansson's error code support if available Eli Zaretskii
@ 2017-12-19 17:35 ` Philipp Stephani
2017-12-19 19:54 ` Eli Zaretskii
0 siblings, 1 reply; 7+ messages in thread
From: Philipp Stephani @ 2017-12-19 17:35 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: phst, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1304 bytes --]
Eli Zaretskii <eliz@gnu.org> schrieb am Di., 19. Dez. 2017 um 18:11 Uhr:
> > From: Philipp Stephani <p.stephani2@gmail.com>
> > Date: Tue, 19 Dec 2017 00:17:29 +0100
> > Cc: Philipp Stephani <phst@google.com>
> >
> > * src/json.c (json_parse_error): Use Jansson's error code support if
> > available.
> > ---
> > src/json.c | 15 ++++++++++++---
> > 1 file changed, 12 insertions(+), 3 deletions(-)
> >
> > diff --git a/src/json.c b/src/json.c
> > index 29e4400fc9..b996cad5a6 100644
> > --- a/src/json.c
> > +++ b/src/json.c
> > @@ -249,15 +249,24 @@ static _Noreturn void
> > json_parse_error (const json_error_t *error)
> > {
> > Lisp_Object symbol;
> > - /* FIXME: Upstream Jansson should have a way to return error codes
> > - without parsing the error messages. See
> > - https://github.com/akheron/jansson/issues/352. */
> > +#if JANSSON_VERSION_HEX >= 0x020B00
> > + switch (json_error_code (error))
>
> Would it be possible for you to add the few lines which would make
> this work on MS-Windows? It's pretty much boilerplate (you can see
> what I did for every jansson function we need, and copycat that), but
> if you don't add those few lines, the Windows build will fail to link.
>
>
The json_error_code function is inline, is it still necessary to load it
from the DLL?
[-- Attachment #2: Type: text/html, Size: 1975 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] Use Jansson's error code support if available
2017-12-19 17:35 ` Philipp Stephani
@ 2017-12-19 19:54 ` Eli Zaretskii
2017-12-19 21:49 ` Philipp Stephani
0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2017-12-19 19:54 UTC (permalink / raw)
To: Philipp Stephani; +Cc: phst, emacs-devel
> From: Philipp Stephani <p.stephani2@gmail.com>
> Date: Tue, 19 Dec 2017 17:35:48 +0000
> Cc: emacs-devel@gnu.org, phst@google.com
>
> The json_error_code function is inline, is it still necessary to load it from the DLL?
No, inline functions are okay.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] Use Jansson's error code support if available
2017-12-19 19:54 ` Eli Zaretskii
@ 2017-12-19 21:49 ` Philipp Stephani
0 siblings, 0 replies; 7+ messages in thread
From: Philipp Stephani @ 2017-12-19 21:49 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: phst, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 377 bytes --]
Eli Zaretskii <eliz@gnu.org> schrieb am Di., 19. Dez. 2017 um 20:54 Uhr:
> > From: Philipp Stephani <p.stephani2@gmail.com>
> > Date: Tue, 19 Dec 2017 17:35:48 +0000
> > Cc: emacs-devel@gnu.org, phst@google.com
> >
> > The json_error_code function is inline, is it still necessary to load it
> from the DLL?
>
> No, inline functions are okay.
>
Thanks, pushed as 24efda1d28.
[-- Attachment #2: Type: text/html, Size: 862 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-12-24 12:53 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-18 23:17 [PATCH 1/2] Use Jansson's error code support if available Philipp Stephani
2017-12-18 23:17 ` [PATCH 2/2] JSON serialization: reject duplicate keys in hashtables Philipp Stephani
2017-12-24 12:53 ` Philipp Stephani
2017-12-19 17:11 ` [PATCH 1/2] Use Jansson's error code support if available Eli Zaretskii
2017-12-19 17:35 ` Philipp Stephani
2017-12-19 19:54 ` Eli Zaretskii
2017-12-19 21:49 ` Philipp Stephani
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.