Avoid the use of ((lambda ...) ...) in lexical-binding code.
[bpt/emacs.git] / lisp / json.el
index 39c1fd3..468358c 100644 (file)
@@ -1,9 +1,9 @@
 ;;; json.el --- JavaScript Object Notation parser / generator
 
-;; Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 2006-2012 Free Software Foundation, Inc.
 
 ;; Author: Edward O'Connor <ted@oconnor.cx>
-;; Version: 1.2
+;; Version: 1.3
 ;; Keywords: convenience
 
 ;; This file is part of GNU Emacs.
@@ -47,6 +47,7 @@
 ;;              other cleanups, bugfixes, and improvements.
 ;; 2006-12-29 - XEmacs support, from Aidan Kehoe <kehoea@parhasard.net>.
 ;; 2008-02-21 - Installed in GNU Emacs.
+;; 2011-10-17 - Patch `json-alist-p' and `json-plist-p' to avoid recursion -tzz
 
 ;;; Code:
 
 
 (defvar json-object-type 'alist
   "Type to convert JSON objects to.
-Must be one of `alist', `plist', or `hash-table'. Consider let-binding
+Must be one of `alist', `plist', or `hash-table'.  Consider let-binding
 this around your call to `json-read' instead of `setq'ing it.")
 
 (defvar json-array-type 'vector
   "Type to convert JSON arrays to.
-Must be one of `vector' or `list'. Consider let-binding this around
+Must be one of `vector' or `list'.  Consider let-binding this around
 your call to `json-read' instead of `setq'ing it.")
 
 (defvar json-key-type nil
@@ -83,19 +84,19 @@ If nil, `json-read' will guess the type based on the value of
       `plist'                     `keyword'
 
 Note that values other than `string' might behave strangely for
-Sufficiently Weird keys. Consider let-binding this around your call to
+Sufficiently Weird keys.  Consider let-binding this around your call to
 `json-read' instead of `setq'ing it.")
 
 (defvar json-false :json-false
   "Value to use when reading JSON `false'.
 If this has the same value as `json-null', you might not be able to tell
-the difference between `false' and `null'. Consider let-binding this
+the difference between `false' and `null'.  Consider let-binding this
 around your call to `json-read' instead of `setq'ing it.")
 
 (defvar json-null nil
   "Value to use when reading JSON `null'.
 If this has the same value as `json-false', you might not be able to
-tell the difference between `false' and `null'. Consider let-binding
+tell the difference between `false' and `null'.  Consider let-binding
 this around your call to `json-read' instead of `setq'ing it.")
 
 \f
@@ -108,16 +109,20 @@ this around your call to `json-read' instead of `setq'ing it.")
 
 (defun json-alist-p (list)
   "Non-null if and only if LIST is an alist."
-  (or (null list)
-      (and (consp (car list))
-           (json-alist-p (cdr list)))))
+  (while (consp list)
+    (setq list (if (consp (car list))
+                   (cdr list)
+                 'not-alist)))
+  (null list))
 
 (defun json-plist-p (list)
   "Non-null if and only if LIST is a plist."
-  (or (null list)
-      (and (keywordp (car list))
-           (consp (cdr list))
-           (json-plist-p (cddr list)))))
+  (while (consp list)
+    (setq list (if (and (keywordp (car list))
+                        (consp (cdr list)))
+                   (cddr list)
+                 'not-plist)))
+  (null list))
 
 ;; Reader utilities
 
@@ -161,7 +166,7 @@ this around your call to `json-read' instead of `setq'ing it.")
 (put 'json-number-format 'error-conditions
      '(json-number-format json-error error))
 
-(put 'json-string-escape 'error-message "Bad unicode escape")
+(put 'json-string-escape 'error-message "Bad Unicode escape")
 (put 'json-string-escape 'error-conditions
      '(json-string-escape json-error error))
 
@@ -218,7 +223,7 @@ KEYWORD is the keyword expected."
 
 (defun json-read-number (&optional sign)
  "Read the JSON number following point.
-The optional SIGN  argument is for internal use.
+The optional SIGN argument is for internal use.
 
 N.B.: Only numbers which can fit in Emacs Lisp's native number
 representation will be parsed correctly."
@@ -526,5 +531,4 @@ Advances point just past JSON object."
 
 (provide 'json)
 
-;; arch-tag: 15f6e4c8-b831-4172-8749-bbc680c50ea1
 ;;; json.el ends here