}
/* Skip (and optionally remember) a lazily-loaded string
- preceded by "#@". */
-static void
+ preceded by "#@". Return true if this was a normal skip,
+ false if we read #@00 (which skips to EOF). */
+static bool
skip_lazy_string (Lisp_Object readcharfun)
{
ptrdiff_t nskip = 0;
digits++;
if (digits == 2 && nskip == 0)
{
- /* #@00 means "skip to end" */
+ /* #@00 means "read nil and skip to end" */
skip_dyn_eof (readcharfun);
- return;
+ return false;
}
}
else
/* Skip that many bytes. */
skip_dyn_bytes (readcharfun, nskip);
+
+ return true;
}
/* Given a lazy-loaded string designator VAL, return the actual string.
/* #@NUMBER is used to skip NUMBER following bytes.
That's used in .elc files to skip over doc strings
and function definitions that can be loaded lazily. */
- skip_lazy_string (readcharfun);
- goto read_obj;
+ if (skip_lazy_string (readcharfun))
+ goto read_obj;
+ obj = Qnil; /* #@00 skips to EOF and yields nil. */
+ break;
case '$':
/* #$ -- reference to lazy-loaded string */
(should (byte-code-function-p f))
(should (equal (aref f 4) "My little\ndoc string\nhere"))))))
+(ert-deftest lread-skip-to-eof ()
+ ;; Check the special #@00 syntax that, for compatibility, reads as
+ ;; nil while absorbing the remainder of the input.
+ (with-temp-buffer
+ (insert "#@00 and the rest\n"
+ "should be ignored) entirely\n")
+ (goto-char (point-min))
+ (should (equal (read (current-buffer)) nil))
+ (should (eobp))
+ ;; Add an unbalanced bracket to the beginning and try again;
+ ;; we should get an error.
+ (goto-char (point-min))
+ (insert "( ")
+ (goto-char (point-min))
+ (should-error (read (current-buffer)) :type 'end-of-file)))
+
;;; lread-tests.el ends here