merge trunk
[bpt/emacs.git] / src / lread.c
index d7a16f8..3ca644b 100644 (file)
@@ -201,6 +201,9 @@ readchar (Lisp_Object readcharfun, bool *multibyte)
 
       ptrdiff_t pt_byte = BUF_PT_BYTE (inbuffer);
 
+      if (! BUFFER_LIVE_P (inbuffer))
+       return -1;
+
       if (pt_byte >= BUF_ZV_BYTE (inbuffer))
        return -1;
 
@@ -375,6 +378,19 @@ skip_dyn_bytes (Lisp_Object readcharfun, ptrdiff_t n)
     }
 }
 
+static void
+skip_dyn_eof (Lisp_Object readcharfun)
+{
+  if (FROM_FILE_P (readcharfun))
+    {
+      block_input ();          /* FIXME: Not sure if it's needed.  */
+      fseek (instream, 0, SEEK_END);
+      unblock_input ();
+    }
+  else
+    while (READCHAR >= 0);
+}
+
 /* Unread the character C in the way appropriate for the stream READCHARFUN.
    If the stream is a user function, call it with the char as argument.  */
 
@@ -1976,7 +1992,9 @@ STREAM or the value of `standard-input' may be:
   if (EQ (stream, Qt))
     stream = Qread_char;
   if (EQ (stream, Qread_char))
-    return Fread_minibuffer (build_string ("Lisp expression: "), Qnil);
+    /* FIXME: ¿¡ When is this used !?  */
+    return call1 (intern ("read-minibuffer"),
+                 build_string ("Lisp expression: "));
 
   return read_internal_start (stream, Qnil, Qnil);
 }
@@ -2617,7 +2635,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
       if (c == '@')
        {
          enum { extra = 100 };
-         ptrdiff_t i, nskip = 0;
+         ptrdiff_t i, nskip = 0, digits = 0;
 
          /* Read a decimal integer.  */
          while ((c = READCHAR) >= 0
@@ -2625,8 +2643,14 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
            {
              if ((STRING_BYTES_BOUND - extra) / 10 <= nskip)
                string_overflow ();
+             digits++;
              nskip *= 10;
              nskip += c - '0';
+             if (digits == 2 && nskip == 0)
+               { /* We've just seen #@00, which means "skip to end".  */
+                 skip_dyn_eof (readcharfun);
+                 return Qnil;
+               }
            }
          if (nskip > 0)
            /* We can't use UNREAD here, because in the code below we side-step
@@ -2636,7 +2660,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
            nskip--;
          else
            UNREAD (c);
-           
+
          if (load_force_doc_strings
              && (FROM_FILE_P (readcharfun)))
            {
@@ -2731,8 +2755,8 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
          /* Read a non-negative integer.  */
          while (c >= '0' && c <= '9')
            {
-             if (n > MOST_POSITIVE_FIXNUM / 10
-                 || n * 10 + c - '0' > MOST_POSITIVE_FIXNUM)
+             if (MOST_POSITIVE_FIXNUM / 10 < n
+                 || MOST_POSITIVE_FIXNUM < n * 10 + c - '0')
                n = MOST_POSITIVE_FIXNUM + 1;
              else
                n = n * 10 + c - '0';
@@ -2930,7 +2954,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
            if (end - p < MAX_MULTIBYTE_LENGTH)
              {
                ptrdiff_t offset = p - read_buffer;
-               if (read_buffer_size > min (PTRDIFF_MAX, SIZE_MAX) / 2)
+               if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
                  memory_full (SIZE_MAX);
                read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
                read_buffer_size *= 2;
@@ -3064,7 +3088,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
              if (end - p < MAX_MULTIBYTE_LENGTH)
                {
                  ptrdiff_t offset = p - read_buffer;
-                 if (read_buffer_size > min (PTRDIFF_MAX, SIZE_MAX) / 2)
+                 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
                    memory_full (SIZE_MAX);
                  read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
                  read_buffer_size *= 2;
@@ -3094,7 +3118,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
          if (p == end)
            {
              ptrdiff_t offset = p - read_buffer;
-             if (read_buffer_size > min (PTRDIFF_MAX, SIZE_MAX) / 2)
+             if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
                memory_full (SIZE_MAX);
              read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
              read_buffer_size *= 2;
@@ -3533,7 +3557,7 @@ read_list (bool flag, Lisp_Object readcharfun)
        {
          if (NILP (Vdoc_file_name))
            /* We have not yet called Snarf-documentation, so assume
-              this file is described in the DOC-MM.NN file
+              this file is described in the DOC file
               and Snarf-documentation will fill in the right value later.
               For now, replace the whole list with 0.  */
            doc_reference = 1;