Mercurial > emacs
comparison src/lread.c @ 71984:bb119ed4db49
(Fload): Use xsignal2, signal_error.
(end_of_file_error): Use xsignal0, xsignal1.
(read0): Use xsignal1.
(invalid_syntax): New error function marked no-return.
(read_integer, read1, read_list): Use it.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Tue, 18 Jul 2006 13:28:34 +0000 |
parents | b4bcd3aefbe8 |
children | da0099bc0ba4 |
comparison
equal
deleted
inserted
replaced
71983:d9eba6509dd1 | 71984:bb119ed4db49 |
---|---|
211 Lisp_Object (*) (), int, | 211 Lisp_Object (*) (), int, |
212 Lisp_Object, Lisp_Object, | 212 Lisp_Object, Lisp_Object, |
213 Lisp_Object, Lisp_Object)); | 213 Lisp_Object, Lisp_Object)); |
214 static Lisp_Object load_unwind P_ ((Lisp_Object)); | 214 static Lisp_Object load_unwind P_ ((Lisp_Object)); |
215 static Lisp_Object load_descriptor_unwind P_ ((Lisp_Object)); | 215 static Lisp_Object load_descriptor_unwind P_ ((Lisp_Object)); |
216 | |
217 static void invalid_syntax P_ ((const char *, int)) NO_RETURN; | |
216 | 218 |
217 | 219 |
218 /* Handle unreading and rereading of characters. | 220 /* Handle unreading and rereading of characters. |
219 Write READCHAR to read a character, | 221 Write READCHAR to read a character, |
220 UNREAD(c) to unread c to be read again. | 222 UNREAD(c) to unread c to be read again. |
795 } | 797 } |
796 | 798 |
797 if (fd == -1) | 799 if (fd == -1) |
798 { | 800 { |
799 if (NILP (noerror)) | 801 if (NILP (noerror)) |
800 Fsignal (Qfile_error, Fcons (build_string ("Cannot open load file"), | 802 xsignal2 (Qfile_error, build_string ("Cannot open load file"), file); |
801 Fcons (file, Qnil))); | 803 return Qnil; |
802 else | |
803 return Qnil; | |
804 } | 804 } |
805 | 805 |
806 /* Tell startup.el whether or not we found the user's init file. */ | 806 /* Tell startup.el whether or not we found the user's init file. */ |
807 if (EQ (Qt, Vuser_init_file)) | 807 if (EQ (Qt, Vuser_init_file)) |
808 Vuser_init_file = found; | 808 Vuser_init_file = found; |
839 count++; | 839 count++; |
840 if (count > 3) | 840 if (count > 3) |
841 { | 841 { |
842 if (fd >= 0) | 842 if (fd >= 0) |
843 emacs_close (fd); | 843 emacs_close (fd); |
844 Fsignal (Qerror, Fcons (build_string ("Recursive load"), | 844 signal_error ("Recursive load", Fcons (found, Vloads_in_progress)); |
845 Fcons (found, Vloads_in_progress))); | |
846 } | 845 } |
847 record_unwind_protect (record_load_unwind, Vloads_in_progress); | 846 record_unwind_protect (record_load_unwind, Vloads_in_progress); |
848 Vloads_in_progress = Fcons (found, Vloads_in_progress); | 847 Vloads_in_progress = Fcons (found, Vloads_in_progress); |
849 } | 848 } |
850 | 849 |
1337 end_of_file_error () | 1336 end_of_file_error () |
1338 { | 1337 { |
1339 Lisp_Object data; | 1338 Lisp_Object data; |
1340 | 1339 |
1341 if (STRINGP (Vload_file_name)) | 1340 if (STRINGP (Vload_file_name)) |
1342 data = Fcons (Vload_file_name, Qnil); | 1341 xsignal1 (Qend_of_file, Vload_file_name); |
1343 else | 1342 |
1344 data = Qnil; | 1343 xsignal0 (Qend_of_file); |
1345 | |
1346 Fsignal (Qend_of_file, data); | |
1347 } | 1344 } |
1348 | 1345 |
1349 /* UNIBYTE specifies how to set load_convert_to_unibyte | 1346 /* UNIBYTE specifies how to set load_convert_to_unibyte |
1350 for this invocation. | 1347 for this invocation. |
1351 READFUN, if non-nil, is used instead of `read'. | 1348 READFUN, if non-nil, is used instead of `read'. |
1692 || EQ (Vread_with_symbol_positions, stream)) | 1689 || EQ (Vread_with_symbol_positions, stream)) |
1693 Vread_symbol_positions_list = Fnreverse (Vread_symbol_positions_list); | 1690 Vread_symbol_positions_list = Fnreverse (Vread_symbol_positions_list); |
1694 return retval; | 1691 return retval; |
1695 } | 1692 } |
1696 | 1693 |
1694 | |
1695 /* Signal Qinvalid_read_syntax error. | |
1696 S is error string of length N (if > 0) */ | |
1697 | |
1698 static void | |
1699 invalid_syntax (s, n) | |
1700 const char *s; | |
1701 int n; | |
1702 { | |
1703 if (!n) | |
1704 n = strlen (s); | |
1705 xsignal1 (Qinvalid_read_syntax, make_string (s, n)); | |
1706 } | |
1707 | |
1708 | |
1697 /* Use this for recursive reads, in contexts where internal tokens | 1709 /* Use this for recursive reads, in contexts where internal tokens |
1698 are not allowed. */ | 1710 are not allowed. */ |
1699 | 1711 |
1700 static Lisp_Object | 1712 static Lisp_Object |
1701 read0 (readcharfun) | 1713 read0 (readcharfun) |
1703 { | 1715 { |
1704 register Lisp_Object val; | 1716 register Lisp_Object val; |
1705 int c; | 1717 int c; |
1706 | 1718 |
1707 val = read1 (readcharfun, &c, 0); | 1719 val = read1 (readcharfun, &c, 0); |
1708 if (c) | 1720 if (!c) |
1709 Fsignal (Qinvalid_read_syntax, Fcons (Fmake_string (make_number (1), | 1721 return val; |
1710 make_number (c)), | 1722 |
1711 Qnil)); | 1723 xsignal1 (Qinvalid_read_syntax, |
1712 | 1724 Fmake_string (make_number (1), make_number (c))); |
1713 return val; | |
1714 } | 1725 } |
1715 | 1726 |
1716 static int read_buffer_size; | 1727 static int read_buffer_size; |
1717 static char *read_buffer; | 1728 static char *read_buffer; |
1718 | 1729 |
1976 c = read_multibyte (c, readcharfun); | 1987 c = read_multibyte (c, readcharfun); |
1977 return c; | 1988 return c; |
1978 } | 1989 } |
1979 } | 1990 } |
1980 | 1991 |
1981 | |
1982 /* Read an integer in radix RADIX using READCHARFUN to read | 1992 /* Read an integer in radix RADIX using READCHARFUN to read |
1983 characters. RADIX must be in the interval [2..36]; if it isn't, a | 1993 characters. RADIX must be in the interval [2..36]; if it isn't, a |
1984 read error is signaled . Value is the integer read. Signals an | 1994 read error is signaled . Value is the integer read. Signals an |
1985 error if encountering invalid read syntax or if RADIX is out of | 1995 error if encountering invalid read syntax or if RADIX is out of |
1986 range. */ | 1996 range. */ |
2036 | 2046 |
2037 if (ndigits == 0 || invalid_p) | 2047 if (ndigits == 0 || invalid_p) |
2038 { | 2048 { |
2039 char buf[50]; | 2049 char buf[50]; |
2040 sprintf (buf, "integer, radix %d", radix); | 2050 sprintf (buf, "integer, radix %d", radix); |
2041 Fsignal (Qinvalid_read_syntax, Fcons (build_string (buf), Qnil)); | 2051 invalid_syntax (buf, 0); |
2042 } | 2052 } |
2043 | 2053 |
2044 return make_number (sign * number); | 2054 return make_number (sign * number); |
2045 } | 2055 } |
2046 | 2056 |
2147 error ("Invalid size char-table"); | 2157 error ("Invalid size char-table"); |
2148 XSETCHAR_TABLE (tmp, XCHAR_TABLE (tmp)); | 2158 XSETCHAR_TABLE (tmp, XCHAR_TABLE (tmp)); |
2149 XCHAR_TABLE (tmp)->top = Qnil; | 2159 XCHAR_TABLE (tmp)->top = Qnil; |
2150 return tmp; | 2160 return tmp; |
2151 } | 2161 } |
2152 Fsignal (Qinvalid_read_syntax, | 2162 invalid_syntax ("#^^", 3); |
2153 Fcons (make_string ("#^^", 3), Qnil)); | |
2154 } | 2163 } |
2155 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#^", 2), Qnil)); | 2164 invalid_syntax ("#^", 2); |
2156 } | 2165 } |
2157 if (c == '&') | 2166 if (c == '&') |
2158 { | 2167 { |
2159 Lisp_Object length; | 2168 Lisp_Object length; |
2160 length = read1 (readcharfun, pch, first_in_list); | 2169 length = read1 (readcharfun, pch, first_in_list); |
2172 /* We used to print 1 char too many | 2181 /* We used to print 1 char too many |
2173 when the number of bits was a multiple of 8. | 2182 when the number of bits was a multiple of 8. |
2174 Accept such input in case it came from an old version. */ | 2183 Accept such input in case it came from an old version. */ |
2175 && ! (XFASTINT (length) | 2184 && ! (XFASTINT (length) |
2176 == (SCHARS (tmp) - 1) * BOOL_VECTOR_BITS_PER_CHAR)) | 2185 == (SCHARS (tmp) - 1) * BOOL_VECTOR_BITS_PER_CHAR)) |
2177 Fsignal (Qinvalid_read_syntax, | 2186 invalid_syntax ("#&...", 5); |
2178 Fcons (make_string ("#&...", 5), Qnil)); | |
2179 | 2187 |
2180 val = Fmake_bool_vector (length, Qnil); | 2188 val = Fmake_bool_vector (length, Qnil); |
2181 bcopy (SDATA (tmp), XBOOL_VECTOR (val)->data, | 2189 bcopy (SDATA (tmp), XBOOL_VECTOR (val)->data, |
2182 size_in_chars); | 2190 size_in_chars); |
2183 /* Clear the extraneous bits in the last byte. */ | 2191 /* Clear the extraneous bits in the last byte. */ |
2184 if (XINT (length) != size_in_chars * BOOL_VECTOR_BITS_PER_CHAR) | 2192 if (XINT (length) != size_in_chars * BOOL_VECTOR_BITS_PER_CHAR) |
2185 XBOOL_VECTOR (val)->data[size_in_chars - 1] | 2193 XBOOL_VECTOR (val)->data[size_in_chars - 1] |
2186 &= (1 << (XINT (length) % BOOL_VECTOR_BITS_PER_CHAR)) - 1; | 2194 &= (1 << (XINT (length) % BOOL_VECTOR_BITS_PER_CHAR)) - 1; |
2187 return val; | 2195 return val; |
2188 } | 2196 } |
2189 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#&...", 5), | 2197 invalid_syntax ("#&...", 5); |
2190 Qnil)); | |
2191 } | 2198 } |
2192 if (c == '[') | 2199 if (c == '[') |
2193 { | 2200 { |
2194 /* Accept compiled functions at read-time so that we don't have to | 2201 /* Accept compiled functions at read-time so that we don't have to |
2195 build them using function calls. */ | 2202 build them using function calls. */ |
2205 int ch; | 2212 int ch; |
2206 | 2213 |
2207 /* Read the string itself. */ | 2214 /* Read the string itself. */ |
2208 tmp = read1 (readcharfun, &ch, 0); | 2215 tmp = read1 (readcharfun, &ch, 0); |
2209 if (ch != 0 || !STRINGP (tmp)) | 2216 if (ch != 0 || !STRINGP (tmp)) |
2210 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil)); | 2217 invalid_syntax ("#", 1); |
2211 GCPRO1 (tmp); | 2218 GCPRO1 (tmp); |
2212 /* Read the intervals and their properties. */ | 2219 /* Read the intervals and their properties. */ |
2213 while (1) | 2220 while (1) |
2214 { | 2221 { |
2215 Lisp_Object beg, end, plist; | 2222 Lisp_Object beg, end, plist; |
2221 if (ch == 0) | 2228 if (ch == 0) |
2222 end = read1 (readcharfun, &ch, 0); | 2229 end = read1 (readcharfun, &ch, 0); |
2223 if (ch == 0) | 2230 if (ch == 0) |
2224 plist = read1 (readcharfun, &ch, 0); | 2231 plist = read1 (readcharfun, &ch, 0); |
2225 if (ch) | 2232 if (ch) |
2226 Fsignal (Qinvalid_read_syntax, | 2233 invalid_syntax ("Invalid string property list", 0); |
2227 Fcons (build_string ("invalid string property list"), | |
2228 Qnil)); | |
2229 Fset_text_properties (beg, end, plist, tmp); | 2234 Fset_text_properties (beg, end, plist, tmp); |
2230 } | 2235 } |
2231 UNGCPRO; | 2236 UNGCPRO; |
2232 return tmp; | 2237 return tmp; |
2233 } | 2238 } |
2376 return read_integer (readcharfun, 8); | 2381 return read_integer (readcharfun, 8); |
2377 else if (c == 'b' || c == 'B') | 2382 else if (c == 'b' || c == 'B') |
2378 return read_integer (readcharfun, 2); | 2383 return read_integer (readcharfun, 2); |
2379 | 2384 |
2380 UNREAD (c); | 2385 UNREAD (c); |
2381 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil)); | 2386 invalid_syntax ("#", 1); |
2382 | 2387 |
2383 case ';': | 2388 case ';': |
2384 while ((c = READCHAR) >= 0 && c != '\n'); | 2389 while ((c = READCHAR) >= 0 && c != '\n'); |
2385 goto retry; | 2390 goto retry; |
2386 | 2391 |
2470 && (index ("\"';()[]#?", next_char) | 2475 && (index ("\"';()[]#?", next_char) |
2471 || (!first_in_list && next_char == '`') | 2476 || (!first_in_list && next_char == '`') |
2472 || (new_backquote_flag && next_char == ',')))); | 2477 || (new_backquote_flag && next_char == ',')))); |
2473 } | 2478 } |
2474 UNREAD (next_char); | 2479 UNREAD (next_char); |
2475 if (!ok) | 2480 if (ok) |
2476 Fsignal (Qinvalid_read_syntax, Fcons (make_string ("?", 1), Qnil)); | 2481 return make_number (c); |
2477 | 2482 |
2478 return make_number (c); | 2483 invalid_syntax ("?", 1); |
2479 } | 2484 } |
2480 | 2485 |
2481 case '"': | 2486 case '"': |
2482 { | 2487 { |
2483 char *p = read_buffer; | 2488 char *p = read_buffer; |
3118 { | 3123 { |
3119 if (flag > 0) | 3124 if (flag > 0) |
3120 { | 3125 { |
3121 if (ch == ']') | 3126 if (ch == ']') |
3122 return val; | 3127 return val; |
3123 Fsignal (Qinvalid_read_syntax, | 3128 invalid_syntax (") or . in a vector", 18); |
3124 Fcons (make_string (") or . in a vector", 18), Qnil)); | |
3125 } | 3129 } |
3126 if (ch == ')') | 3130 if (ch == ')') |
3127 return val; | 3131 return val; |
3128 if (ch == '.') | 3132 if (ch == '.') |
3129 { | 3133 { |
3212 return get_doc_string (val, 0, 0); | 3216 return get_doc_string (val, 0, 0); |
3213 } | 3217 } |
3214 | 3218 |
3215 return val; | 3219 return val; |
3216 } | 3220 } |
3217 return Fsignal (Qinvalid_read_syntax, Fcons (make_string (". in wrong context", 18), Qnil)); | 3221 invalid_syntax (". in wrong context", 18); |
3218 } | 3222 } |
3219 return Fsignal (Qinvalid_read_syntax, Fcons (make_string ("] in a list", 11), Qnil)); | 3223 invalid_syntax ("] in a list", 11); |
3220 } | 3224 } |
3221 tem = (read_pure && flag <= 0 | 3225 tem = (read_pure && flag <= 0 |
3222 ? pure_cons (elt, Qnil) | 3226 ? pure_cons (elt, Qnil) |
3223 : Fcons (elt, Qnil)); | 3227 : Fcons (elt, Qnil)); |
3224 if (!NILP (tail)) | 3228 if (!NILP (tail)) |