From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Accept plists when serializing and parsing JSON Date: Fri, 01 Jun 2018 12:39:38 +0300 Message-ID: <83o9gug811.fsf@gnu.org> References: <87sh6awls5.fsf@gmail.com> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1527845897 11428 195.159.176.226 (1 Jun 2018 09:38:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 1 Jun 2018 09:38:17 +0000 (UTC) Cc: emacs-devel@gnu.org To: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jun 01 11:38:13 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fOgVg-0002sj-AZ for ged-emacs-devel@m.gmane.org; Fri, 01 Jun 2018 11:38:12 +0200 Original-Received: from localhost ([::1]:54458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOgXn-0008Dj-Dm for ged-emacs-devel@m.gmane.org; Fri, 01 Jun 2018 05:40:23 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58423) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOgX7-0007pG-Ho for emacs-devel@gnu.org; Fri, 01 Jun 2018 05:39:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fOgX4-0006Sx-B0 for emacs-devel@gnu.org; Fri, 01 Jun 2018 05:39:41 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:40472) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOgX4-0006Sp-7D; Fri, 01 Jun 2018 05:39:38 -0400 Original-Received: from [176.228.60.248] (port=4161 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1fOgX3-00023j-JK; Fri, 01 Jun 2018 05:39:38 -0400 In-reply-to: <87sh6awls5.fsf@gmail.com> (message from =?utf-8?B?Sm/Do28g?= =?utf-8?B?VMOhdm9yYQ==?= on Tue, 29 May 2018 15:59:06 +0100) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:225886 Archived-At: > From: João Távora > Date: Tue, 29 May 2018 15:59:06 +0100 > > So I found this other thread > > https://lists.gnu.org/archive/html/emacs-devel/2017-12/msg00667.html > > where plist support for json.c is briefly requested and discussed, but > there didn't seem to be an overwhelming argument against it, so I had > another look at the file and it didn't seem very hard or problematic to > implement. > > Anyway, I had a go. Thanks, please see a few comments below. > +@vindex json-serialize-use-plists > +@cindex serializing plists as json > + For the serialization function, the variable > +@var{json-serialize-use-plists} controls the converse process, json-serialize-use-plists is the literal name of a variable, so it should have the @code markup, not @var. > +resolving the ambiguity when a list is found in the Lisp object to > +serialize. If @code{nil}, its default, the list is interpreted as an ^^ Two spaces between sentences, please. > + if ( EQ (Vjson_serialize_use_plists, Qt) ) { > + key_symbol = XCAR (tail); > + tail = XCDR(tail); > + CHECK_CONS (tail); > + value = XCAR (tail); > + if (EQ (tail, li.tortoise)) circular_list (lisp); > + } else { > + Lisp_Object pair = XCAR (tail); Our style is to write if (something) { then-part; } else { else-part; } Also, please don't leav any whitespace between the opening parenthesis and the following character, and similarly with closing parens. IOW, this: if ( EQ (Vjson_serialize_use_plists, Qt) ) should be this instead: if (EQ (Vjson_serialize_use_plists, Qt)) > + json_object_foreach (json, key_str, value) > + { > + /* No idea if using AUTO_STRING and Fconcat for > + making keywords is idiomatic, but seems to work > + nicely */ > + AUTO_STRING (colon, ":"); > + Lisp_Object key = > + Fintern (CALLN (Fconcat, colon, json_build_string (key_str)) > + , Qnil); > + result = Fcons (key, result); /* build the plist as > + value-key since > + we're going to > + reverse it in the > + end.*/ > + result = Fcons (json_to_lisp (value, object_type), result); > + } Here I'd use intern_1 instead, it would allow you to avoid unnecessarily consing Lisp objects. (Yes, I realize that the same comment applies to the existing code.) > + /* If non-nil use plists instead of alists in json-serialize.*/); ^ Comma is missing there.