Sfoglia il codice sorgente

org-element-cache: Add more self-consistency checks

* lisp/org-element.el (org-element--parse-to):
(org-element--cache-verify-element): Add check asserting that all the
parsed elements are assigned with non-nil parent (except org-data).
Ihor Radchenko 3 anni fa
parent
commit
bb8aa14923
1 ha cambiato i file con 11 aggiunte e 0 eliminazioni
  1. 11 0
      lisp/org-element.el

+ 11 - 0
lisp/org-element.el

@@ -6447,6 +6447,13 @@ If you observe Emacs hangs frequently, please report this to Org mode mailing li
                    (setq element (or (org-element--cache-put element) element))
                  ;; Nothing to parse (i.e. empty file).
                  (throw 'exit parent))
+               (unless (or (not (org-element--cache-active-p)) parent)
+                 (org-element--cache-warn "Got empty parent while parsing. Please report it to Org mode mailing list (M-x org-submit-bug-report).\n Backtrace:\n%S"
+                               (when (and (fboundp 'backtrace-get-frames)
+                                          (fboundp 'backtrace-to-string))
+                                 (backtrace-to-string (backtrace-get-frames 'backtrace))
+                                 (org-element-cache-reset)
+                                 (error "org-element--cache: Emergency exit"))))
 	       (org-element-put-property element :parent parent))
 	     (let ((elem-end (org-element-property :end element))
 	           (type (org-element-type element)))
@@ -6988,6 +6995,10 @@ change, as an integer."
 
 Return non-nil when verification failed."
   ;; Verify correct parent for the element.
+  (unless (or (org-element-property :parent element)
+              (eq 'org-data (org-element-type element)))
+    (org-element--cache-warn "Got element without parent (cache active?: %S). Please report it to Org mode mailing list (M-x org-submit-bug-report).\n%S" (org-element--cache-active-p)  element)
+    (org-element-cache-reset))
   (let ((org-element--cache-self-verify (or org-element--cache-self-verify
                                  (and (boundp 'org-batch-test) org-batch-test)))
         (org-element--cache-self-verify-frequency (if (and (boundp 'org-batch-test) org-batch-test)