diff options
Diffstat (limited to 'src/lread.c')
| -rw-r--r-- | src/lread.c | 390 |
1 files changed, 236 insertions, 154 deletions
diff --git a/src/lread.c b/src/lread.c index a9b69a1977b..353f4a3064d 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Lisp parsing and input streams. | 1 | /* Lisp parsing and input streams. |
| 2 | 2 | ||
| 3 | Copyright (C) 1985-1989, 1993-1995, 1997-2011 Free Software Foundation, Inc. | 3 | Copyright (C) 1985-1989, 1993-1995, 1997-2012 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This file is part of GNU Emacs. | 5 | This file is part of GNU Emacs. |
| 6 | 6 | ||
| @@ -1124,6 +1124,22 @@ Return t if the file exists and loads successfully. */) | |||
| 1124 | handler = Ffind_file_name_handler (found, Qload); | 1124 | handler = Ffind_file_name_handler (found, Qload); |
| 1125 | if (! NILP (handler)) | 1125 | if (! NILP (handler)) |
| 1126 | return call5 (handler, Qload, found, noerror, nomessage, Qt); | 1126 | return call5 (handler, Qload, found, noerror, nomessage, Qt); |
| 1127 | #ifdef DOS_NT | ||
| 1128 | /* Tramp has to deal with semi-broken packages that prepend | ||
| 1129 | drive letters to remote files. For that reason, Tramp | ||
| 1130 | catches file operations that test for file existence, which | ||
| 1131 | makes openp think X:/foo.elc files are remote. However, | ||
| 1132 | Tramp does not catch `load' operations for such files, so we | ||
| 1133 | end up with a nil as the `load' handler above. If we would | ||
| 1134 | continue with fd = -2, we will behave wrongly, and in | ||
| 1135 | particular try reading a .elc file in the "rt" mode instead | ||
| 1136 | of "rb". See bug #9311 for the results. To work around | ||
| 1137 | this, we try to open the file locally, and go with that if it | ||
| 1138 | succeeds. */ | ||
| 1139 | fd = emacs_open (SSDATA (ENCODE_FILE (found)), O_RDONLY, 0); | ||
| 1140 | if (fd == -1) | ||
| 1141 | fd = -2; | ||
| 1142 | #endif | ||
| 1127 | } | 1143 | } |
| 1128 | 1144 | ||
| 1129 | /* Check if we're stuck in a recursive load cycle. | 1145 | /* Check if we're stuck in a recursive load cycle. |
| @@ -1247,9 +1263,17 @@ Return t if the file exists and loads successfully. */) | |||
| 1247 | GCPRO3 (file, found, hist_file_name); | 1263 | GCPRO3 (file, found, hist_file_name); |
| 1248 | 1264 | ||
| 1249 | #ifdef WINDOWSNT | 1265 | #ifdef WINDOWSNT |
| 1250 | emacs_close (fd); | ||
| 1251 | efound = ENCODE_FILE (found); | 1266 | efound = ENCODE_FILE (found); |
| 1252 | stream = fopen (SSDATA (efound), fmode); | 1267 | /* If we somehow got here with fd == -2, meaning the file is deemed |
| 1268 | to be remote, don't even try to reopen the file locally; just | ||
| 1269 | force a failure instead. */ | ||
| 1270 | if (fd >= 0) | ||
| 1271 | { | ||
| 1272 | emacs_close (fd); | ||
| 1273 | stream = fopen (SSDATA (efound), fmode); | ||
| 1274 | } | ||
| 1275 | else | ||
| 1276 | stream = NULL; | ||
| 1253 | #else /* not WINDOWSNT */ | 1277 | #else /* not WINDOWSNT */ |
| 1254 | stream = fdopen (fd, fmode); | 1278 | stream = fdopen (fd, fmode); |
| 1255 | #endif /* not WINDOWSNT */ | 1279 | #endif /* not WINDOWSNT */ |
| @@ -1260,7 +1284,7 @@ Return t if the file exists and loads successfully. */) | |||
| 1260 | } | 1284 | } |
| 1261 | 1285 | ||
| 1262 | if (! NILP (Vpurify_flag)) | 1286 | if (! NILP (Vpurify_flag)) |
| 1263 | Vpreloaded_file_list = Fcons (Fpurecopy(file), Vpreloaded_file_list); | 1287 | Vpreloaded_file_list = Fcons (Fpurecopy (file), Vpreloaded_file_list); |
| 1264 | 1288 | ||
| 1265 | if (NILP (nomessage) || force_load_messages) | 1289 | if (NILP (nomessage) || force_load_messages) |
| 1266 | { | 1290 | { |
| @@ -1772,7 +1796,7 @@ readevalloop (Lisp_Object readcharfun, | |||
| 1772 | 1796 | ||
| 1773 | /* Ignore whitespace here, so we can detect eof. */ | 1797 | /* Ignore whitespace here, so we can detect eof. */ |
| 1774 | if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r' | 1798 | if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r' |
| 1775 | || c == 0x8a0) /* NBSP */ | 1799 | || c == 0xa0) /* NBSP */ |
| 1776 | goto read_next; | 1800 | goto read_next; |
| 1777 | 1801 | ||
| 1778 | if (!NILP (Vpurify_flag) && c == '(') | 1802 | if (!NILP (Vpurify_flag) && c == '(') |
| @@ -1893,7 +1917,7 @@ which is the input stream for reading characters. | |||
| 1893 | This function does not move point. */) | 1917 | This function does not move point. */) |
| 1894 | (Lisp_Object start, Lisp_Object end, Lisp_Object printflag, Lisp_Object read_function) | 1918 | (Lisp_Object start, Lisp_Object end, Lisp_Object printflag, Lisp_Object read_function) |
| 1895 | { | 1919 | { |
| 1896 | /* FIXME: Do the eval-sexp-add-defvars danse! */ | 1920 | /* FIXME: Do the eval-sexp-add-defvars dance! */ |
| 1897 | int count = SPECPDL_INDEX (); | 1921 | int count = SPECPDL_INDEX (); |
| 1898 | Lisp_Object tem, cbuf; | 1922 | Lisp_Object tem, cbuf; |
| 1899 | 1923 | ||
| @@ -1941,6 +1965,8 @@ STREAM or the value of `standard-input' may be: | |||
| 1941 | DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0, | 1965 | DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0, |
| 1942 | doc: /* Read one Lisp expression which is represented as text by STRING. | 1966 | doc: /* Read one Lisp expression which is represented as text by STRING. |
| 1943 | Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX). | 1967 | Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX). |
| 1968 | FINAL-STRING-INDEX is an integer giving the position of the next | ||
| 1969 | remaining character in STRING. | ||
| 1944 | START and END optionally delimit a substring of STRING from which to read; | 1970 | START and END optionally delimit a substring of STRING from which to read; |
| 1945 | they default to 0 and (length STRING) respectively. */) | 1971 | they default to 0 and (length STRING) respectively. */) |
| 1946 | (Lisp_Object string, Lisp_Object start, Lisp_Object end) | 1972 | (Lisp_Object string, Lisp_Object start, Lisp_Object end) |
| @@ -2184,7 +2210,7 @@ read_escape (Lisp_Object readcharfun, int stringp) | |||
| 2184 | case 'x': | 2210 | case 'x': |
| 2185 | /* A hex escape, as in ANSI C. */ | 2211 | /* A hex escape, as in ANSI C. */ |
| 2186 | { | 2212 | { |
| 2187 | int i = 0; | 2213 | unsigned int i = 0; |
| 2188 | int count = 0; | 2214 | int count = 0; |
| 2189 | while (1) | 2215 | while (1) |
| 2190 | { | 2216 | { |
| @@ -2208,7 +2234,9 @@ read_escape (Lisp_Object readcharfun, int stringp) | |||
| 2208 | UNREAD (c); | 2234 | UNREAD (c); |
| 2209 | break; | 2235 | break; |
| 2210 | } | 2236 | } |
| 2211 | if (MAX_CHAR < i) | 2237 | /* Allow hex escapes as large as ?\xfffffff, because some |
| 2238 | packages use them to denote characters with modifiers. */ | ||
| 2239 | if ((CHAR_META | (CHAR_META - 1)) < i) | ||
| 2212 | error ("Hex character out of range: \\x%x...", i); | 2240 | error ("Hex character out of range: \\x%x...", i); |
| 2213 | count += count < 3; | 2241 | count += count < 3; |
| 2214 | } | 2242 | } |
| @@ -2327,8 +2355,7 @@ read_integer (Lisp_Object readcharfun, EMACS_INT radix) | |||
| 2327 | c = READCHAR; | 2355 | c = READCHAR; |
| 2328 | } | 2356 | } |
| 2329 | 2357 | ||
| 2330 | if (c >= 0) | 2358 | UNREAD (c); |
| 2331 | UNREAD (c); | ||
| 2332 | *p = '\0'; | 2359 | *p = '\0'; |
| 2333 | } | 2360 | } |
| 2334 | 2361 | ||
| @@ -2583,8 +2610,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) | |||
| 2583 | nskip *= 10; | 2610 | nskip *= 10; |
| 2584 | nskip += c - '0'; | 2611 | nskip += c - '0'; |
| 2585 | } | 2612 | } |
| 2586 | if (c >= 0) | 2613 | UNREAD (c); |
| 2587 | UNREAD (c); | ||
| 2588 | 2614 | ||
| 2589 | if (load_force_doc_strings | 2615 | if (load_force_doc_strings |
| 2590 | && (EQ (readcharfun, Qget_file_char) | 2616 | && (EQ (readcharfun, Qget_file_char) |
| @@ -2615,14 +2641,14 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) | |||
| 2615 | 2641 | ||
| 2616 | if (saved_doc_string_size == 0) | 2642 | if (saved_doc_string_size == 0) |
| 2617 | { | 2643 | { |
| 2644 | saved_doc_string = (char *) xmalloc (nskip + extra); | ||
| 2618 | saved_doc_string_size = nskip + extra; | 2645 | saved_doc_string_size = nskip + extra; |
| 2619 | saved_doc_string = (char *) xmalloc (saved_doc_string_size); | ||
| 2620 | } | 2646 | } |
| 2621 | if (nskip > saved_doc_string_size) | 2647 | if (nskip > saved_doc_string_size) |
| 2622 | { | 2648 | { |
| 2623 | saved_doc_string_size = nskip + extra; | ||
| 2624 | saved_doc_string = (char *) xrealloc (saved_doc_string, | 2649 | saved_doc_string = (char *) xrealloc (saved_doc_string, |
| 2625 | saved_doc_string_size); | 2650 | nskip + extra); |
| 2651 | saved_doc_string_size = nskip + extra; | ||
| 2626 | } | 2652 | } |
| 2627 | 2653 | ||
| 2628 | saved_doc_string_position = file_tell (instream); | 2654 | saved_doc_string_position = file_tell (instream); |
| @@ -2660,8 +2686,21 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) | |||
| 2660 | { | 2686 | { |
| 2661 | uninterned_symbol = 1; | 2687 | uninterned_symbol = 1; |
| 2662 | c = READCHAR; | 2688 | c = READCHAR; |
| 2663 | goto default_label; | 2689 | if (!(c > 040 |
| 2690 | && c != 0xa0 /* NBSP */ | ||
| 2691 | && (c >= 0200 | ||
| 2692 | || strchr ("\"';()[]#`,", c) == NULL))) | ||
| 2693 | { | ||
| 2694 | /* No symbol character follows, this is the empty | ||
| 2695 | symbol. */ | ||
| 2696 | UNREAD (c); | ||
| 2697 | return Fmake_symbol (build_string ("")); | ||
| 2698 | } | ||
| 2699 | goto read_symbol; | ||
| 2664 | } | 2700 | } |
| 2701 | /* ## is the empty symbol. */ | ||
| 2702 | if (c == '#') | ||
| 2703 | return Fintern (build_string (""), Qnil); | ||
| 2665 | /* Reader forms that can reuse previously read objects. */ | 2704 | /* Reader forms that can reuse previously read objects. */ |
| 2666 | if (c >= '0' && c <= '9') | 2705 | if (c >= '0' && c <= '9') |
| 2667 | { | 2706 | { |
| @@ -2783,7 +2822,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) | |||
| 2783 | So we now use the same heuristic as for backquote: old-style | 2822 | So we now use the same heuristic as for backquote: old-style |
| 2784 | unquotes are only recognized when first on a list, and when | 2823 | unquotes are only recognized when first on a list, and when |
| 2785 | followed by a space. | 2824 | followed by a space. |
| 2786 | Because it's more difficult to peak 2 chars ahead, a new-style | 2825 | Because it's more difficult to peek 2 chars ahead, a new-style |
| 2787 | ,@ can still not be used outside of a `, unless it's in the middle | 2826 | ,@ can still not be used outside of a `, unless it's in the middle |
| 2788 | of a list. */ | 2827 | of a list. */ |
| 2789 | if (new_backquote_flag | 2828 | if (new_backquote_flag |
| @@ -2841,7 +2880,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) | |||
| 2841 | next_char = READCHAR; | 2880 | next_char = READCHAR; |
| 2842 | ok = (next_char <= 040 | 2881 | ok = (next_char <= 040 |
| 2843 | || (next_char < 0200 | 2882 | || (next_char < 0200 |
| 2844 | && (strchr ("\"';()[]#?`,.", next_char)))); | 2883 | && strchr ("\"';()[]#?`,.", next_char) != NULL)); |
| 2845 | UNREAD (next_char); | 2884 | UNREAD (next_char); |
| 2846 | if (ok) | 2885 | if (ok) |
| 2847 | return make_number (c); | 2886 | return make_number (c); |
| @@ -2872,7 +2911,8 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) | |||
| 2872 | if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) | 2911 | if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) |
| 2873 | memory_full (SIZE_MAX); | 2912 | memory_full (SIZE_MAX); |
| 2874 | read_buffer = (char *) xrealloc (read_buffer, | 2913 | read_buffer = (char *) xrealloc (read_buffer, |
| 2875 | read_buffer_size *= 2); | 2914 | read_buffer_size * 2); |
| 2915 | read_buffer_size *= 2; | ||
| 2876 | p = read_buffer + offset; | 2916 | p = read_buffer + offset; |
| 2877 | end = read_buffer + read_buffer_size; | 2917 | end = read_buffer + read_buffer_size; |
| 2878 | } | 2918 | } |
| @@ -2966,11 +3006,6 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) | |||
| 2966 | /* Otherwise, READ_BUFFER contains only ASCII. */ | 3006 | /* Otherwise, READ_BUFFER contains only ASCII. */ |
| 2967 | } | 3007 | } |
| 2968 | 3008 | ||
| 2969 | /* We want readchar_count to be the number of characters, not | ||
| 2970 | bytes. Hence we adjust for multibyte characters in the | ||
| 2971 | string. ... But it doesn't seem to be necessary, because | ||
| 2972 | READCHAR *does* read multibyte characters from buffers. */ | ||
| 2973 | /* readchar_count -= (p - read_buffer) - nchars; */ | ||
| 2974 | if (read_pure) | 3009 | if (read_pure) |
| 2975 | return make_pure_string (read_buffer, nchars, p - read_buffer, | 3010 | return make_pure_string (read_buffer, nchars, p - read_buffer, |
| 2976 | (force_multibyte | 3011 | (force_multibyte |
| @@ -2987,7 +3022,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) | |||
| 2987 | 3022 | ||
| 2988 | if (next_char <= 040 | 3023 | if (next_char <= 040 |
| 2989 | || (next_char < 0200 | 3024 | || (next_char < 0200 |
| 2990 | && (strchr ("\"';([#?`,", next_char)))) | 3025 | && strchr ("\"';([#?`,", next_char) != NULL)) |
| 2991 | { | 3026 | { |
| 2992 | *pch = c; | 3027 | *pch = c; |
| 2993 | return Qnil; | 3028 | return Qnil; |
| @@ -3000,11 +3035,14 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) | |||
| 3000 | default: | 3035 | default: |
| 3001 | default_label: | 3036 | default_label: |
| 3002 | if (c <= 040) goto retry; | 3037 | if (c <= 040) goto retry; |
| 3003 | if (c == 0x8a0) /* NBSP */ | 3038 | if (c == 0xa0) /* NBSP */ |
| 3004 | goto retry; | 3039 | goto retry; |
| 3040 | |||
| 3041 | read_symbol: | ||
| 3005 | { | 3042 | { |
| 3006 | char *p = read_buffer; | 3043 | char *p = read_buffer; |
| 3007 | int quoted = 0; | 3044 | int quoted = 0; |
| 3045 | EMACS_INT start_position = readchar_count - 1; | ||
| 3008 | 3046 | ||
| 3009 | { | 3047 | { |
| 3010 | char *end = read_buffer + read_buffer_size; | 3048 | char *end = read_buffer + read_buffer_size; |
| @@ -3017,7 +3055,8 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) | |||
| 3017 | if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) | 3055 | if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) |
| 3018 | memory_full (SIZE_MAX); | 3056 | memory_full (SIZE_MAX); |
| 3019 | read_buffer = (char *) xrealloc (read_buffer, | 3057 | read_buffer = (char *) xrealloc (read_buffer, |
| 3020 | read_buffer_size *= 2); | 3058 | read_buffer_size * 2); |
| 3059 | read_buffer_size *= 2; | ||
| 3021 | p = read_buffer + offset; | 3060 | p = read_buffer + offset; |
| 3022 | end = read_buffer + read_buffer_size; | 3061 | end = read_buffer + read_buffer_size; |
| 3023 | } | 3062 | } |
| @@ -3035,10 +3074,11 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) | |||
| 3035 | else | 3074 | else |
| 3036 | *p++ = c; | 3075 | *p++ = c; |
| 3037 | c = READCHAR; | 3076 | c = READCHAR; |
| 3038 | } while (c > 040 | 3077 | } |
| 3039 | && c != 0x8a0 /* NBSP */ | 3078 | while (c > 040 |
| 3040 | && (c >= 0200 | 3079 | && c != 0xa0 /* NBSP */ |
| 3041 | || !(strchr ("\"';()[]#`,", c)))); | 3080 | && (c >= 0200 |
| 3081 | || strchr ("\"';()[]#`,", c) == NULL)); | ||
| 3042 | 3082 | ||
| 3043 | if (p == end) | 3083 | if (p == end) |
| 3044 | { | 3084 | { |
| @@ -3046,13 +3086,13 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) | |||
| 3046 | if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) | 3086 | if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) |
| 3047 | memory_full (SIZE_MAX); | 3087 | memory_full (SIZE_MAX); |
| 3048 | read_buffer = (char *) xrealloc (read_buffer, | 3088 | read_buffer = (char *) xrealloc (read_buffer, |
| 3049 | read_buffer_size *= 2); | 3089 | read_buffer_size * 2); |
| 3090 | read_buffer_size *= 2; | ||
| 3050 | p = read_buffer + offset; | 3091 | p = read_buffer + offset; |
| 3051 | end = read_buffer + read_buffer_size; | 3092 | end = read_buffer + read_buffer_size; |
| 3052 | } | 3093 | } |
| 3053 | *p = 0; | 3094 | *p = 0; |
| 3054 | if (c >= 0) | 3095 | UNREAD (c); |
| 3055 | UNREAD (c); | ||
| 3056 | } | 3096 | } |
| 3057 | 3097 | ||
| 3058 | if (!quoted && !uninterned_symbol) | 3098 | if (!quoted && !uninterned_symbol) |
| @@ -3073,19 +3113,14 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) | |||
| 3073 | if (uninterned_symbol && ! NILP (Vpurify_flag)) | 3113 | if (uninterned_symbol && ! NILP (Vpurify_flag)) |
| 3074 | name = make_pure_string (read_buffer, nchars, nbytes, multibyte); | 3114 | name = make_pure_string (read_buffer, nchars, nbytes, multibyte); |
| 3075 | else | 3115 | else |
| 3076 | name = make_specified_string (read_buffer, nchars, nbytes,multibyte); | 3116 | name = make_specified_string (read_buffer, nchars, nbytes, multibyte); |
| 3077 | result = (uninterned_symbol ? Fmake_symbol (name) | 3117 | result = (uninterned_symbol ? Fmake_symbol (name) |
| 3078 | : Fintern (name, Qnil)); | 3118 | : Fintern (name, Qnil)); |
| 3079 | 3119 | ||
| 3080 | if (EQ (Vread_with_symbol_positions, Qt) | 3120 | if (EQ (Vread_with_symbol_positions, Qt) |
| 3081 | || EQ (Vread_with_symbol_positions, readcharfun)) | 3121 | || EQ (Vread_with_symbol_positions, readcharfun)) |
| 3082 | Vread_symbol_positions_list = | 3122 | Vread_symbol_positions_list = |
| 3083 | /* Kind of a hack; this will probably fail if characters | 3123 | Fcons (Fcons (result, make_number (start_position)), |
| 3084 | in the symbol name were escaped. Not really a big | ||
| 3085 | deal, though. */ | ||
| 3086 | Fcons (Fcons (result, | ||
| 3087 | make_number (readchar_count | ||
| 3088 | - XFASTINT (Flength (Fsymbol_name (result))))), | ||
| 3089 | Vread_symbol_positions_list); | 3124 | Vread_symbol_positions_list); |
| 3090 | return result; | 3125 | return result; |
| 3091 | } | 3126 | } |
| @@ -3647,8 +3682,6 @@ static Lisp_Object initial_obarray; | |||
| 3647 | 3682 | ||
| 3648 | static size_t oblookup_last_bucket_number; | 3683 | static size_t oblookup_last_bucket_number; |
| 3649 | 3684 | ||
| 3650 | static size_t hash_string (const char *ptr, size_t len); | ||
| 3651 | |||
| 3652 | /* Get an error if OBARRAY is not an obarray. | 3685 | /* Get an error if OBARRAY is not an obarray. |
| 3653 | If it is one, return it. */ | 3686 | If it is one, return it. */ |
| 3654 | 3687 | ||
| @@ -3891,23 +3924,6 @@ oblookup (Lisp_Object obarray, register const char *ptr, EMACS_INT size, EMACS_I | |||
| 3891 | XSETINT (tem, hash); | 3924 | XSETINT (tem, hash); |
| 3892 | return tem; | 3925 | return tem; |
| 3893 | } | 3926 | } |
| 3894 | |||
| 3895 | static size_t | ||
| 3896 | hash_string (const char *ptr, size_t len) | ||
| 3897 | { | ||
| 3898 | register const char *p = ptr; | ||
| 3899 | register const char *end = p + len; | ||
| 3900 | register unsigned char c; | ||
| 3901 | register size_t hash = 0; | ||
| 3902 | |||
| 3903 | while (p != end) | ||
| 3904 | { | ||
| 3905 | c = *p++; | ||
| 3906 | if (c >= 0140) c -= 40; | ||
| 3907 | hash = (hash << 3) + (hash >> (CHAR_BIT * sizeof hash - 4)) + c; | ||
| 3908 | } | ||
| 3909 | return hash; | ||
| 3910 | } | ||
| 3911 | 3927 | ||
| 3912 | void | 3928 | void |
| 3913 | map_obarray (Lisp_Object obarray, void (*fn) (Lisp_Object, Lisp_Object), Lisp_Object arg) | 3929 | map_obarray (Lisp_Object obarray, void (*fn) (Lisp_Object, Lisp_Object), Lisp_Object arg) |
| @@ -3953,6 +3969,7 @@ void | |||
| 3953 | init_obarray (void) | 3969 | init_obarray (void) |
| 3954 | { | 3970 | { |
| 3955 | Lisp_Object oblength; | 3971 | Lisp_Object oblength; |
| 3972 | ptrdiff_t size = 100 + MAX_MULTIBYTE_LENGTH; | ||
| 3956 | 3973 | ||
| 3957 | XSETFASTINT (oblength, OBARRAY_SIZE); | 3974 | XSETFASTINT (oblength, OBARRAY_SIZE); |
| 3958 | 3975 | ||
| @@ -3967,7 +3984,7 @@ init_obarray (void) | |||
| 3967 | Qnil = intern_c_string ("nil"); | 3984 | Qnil = intern_c_string ("nil"); |
| 3968 | 3985 | ||
| 3969 | /* Fmake_symbol inits fields of new symbols with Qunbound and Qnil, | 3986 | /* Fmake_symbol inits fields of new symbols with Qunbound and Qnil, |
| 3970 | so those two need to be fixed manally. */ | 3987 | so those two need to be fixed manually. */ |
| 3971 | SET_SYMBOL_VAL (XSYMBOL (Qunbound), Qunbound); | 3988 | SET_SYMBOL_VAL (XSYMBOL (Qunbound), Qunbound); |
| 3972 | XSYMBOL (Qunbound)->function = Qunbound; | 3989 | XSYMBOL (Qunbound)->function = Qunbound; |
| 3973 | XSYMBOL (Qunbound)->plist = Qnil; | 3990 | XSYMBOL (Qunbound)->plist = Qnil; |
| @@ -3985,8 +4002,8 @@ init_obarray (void) | |||
| 3985 | 4002 | ||
| 3986 | DEFSYM (Qvariable_documentation, "variable-documentation"); | 4003 | DEFSYM (Qvariable_documentation, "variable-documentation"); |
| 3987 | 4004 | ||
| 3988 | read_buffer_size = 100 + MAX_MULTIBYTE_LENGTH; | 4005 | read_buffer = (char *) xmalloc (size); |
| 3989 | read_buffer = (char *) xmalloc (read_buffer_size); | 4006 | read_buffer_size = size; |
| 3990 | } | 4007 | } |
| 3991 | 4008 | ||
| 3992 | void | 4009 | void |
| @@ -4000,9 +4017,7 @@ defsubr (struct Lisp_Subr *sname) | |||
| 4000 | 4017 | ||
| 4001 | #ifdef NOTDEF /* use fset in subr.el now */ | 4018 | #ifdef NOTDEF /* use fset in subr.el now */ |
| 4002 | void | 4019 | void |
| 4003 | defalias (sname, string) | 4020 | defalias (struct Lisp_Subr *sname, char *string) |
| 4004 | struct Lisp_Subr *sname; | ||
| 4005 | char *string; | ||
| 4006 | { | 4021 | { |
| 4007 | Lisp_Object sym; | 4022 | Lisp_Object sym; |
| 4008 | sym = intern (string); | 4023 | sym = intern (string); |
| @@ -4094,7 +4109,46 @@ init_lread (void) | |||
| 4094 | const char *normal; | 4109 | const char *normal; |
| 4095 | int turn_off_warning = 0; | 4110 | int turn_off_warning = 0; |
| 4096 | 4111 | ||
| 4097 | /* Compute the default load-path. */ | 4112 | /* Compute the default Vload-path, with the following logic: |
| 4113 | If CANNOT_DUMP just use PATH_LOADSEARCH. | ||
| 4114 | Else if purify-flag (ie dumping) start from PATH_DUMPLOADSEARCH; | ||
| 4115 | otherwise start from PATH_LOADSEARCH. | ||
| 4116 | If !initialized, then just set both Vload_path and dump_path. | ||
| 4117 | If initialized, then if Vload_path != dump_path, do nothing. | ||
| 4118 | (Presumably the load-path has already been changed by something.) | ||
| 4119 | Also do nothing if Vinstallation_directory is nil. | ||
| 4120 | Otherwise: | ||
| 4121 | Remove site-lisp directories from the front of load-path. | ||
| 4122 | Add installation-dir/lisp (if exists and not already a member), | ||
| 4123 | at the front, and turn off warnings about missing directories | ||
| 4124 | (because we are presumably running uninstalled). | ||
| 4125 | If it does not exist, add dump_path at the end instead. | ||
| 4126 | Add installation-dir/leim (if exists and not already a member) | ||
| 4127 | at the front. | ||
| 4128 | Add installation-dir/site-lisp (if !no_site_lisp, and exists | ||
| 4129 | and not already a member) at the front. | ||
| 4130 | If installation-dir != source-dir (ie running an uninstalled, | ||
| 4131 | out-of-tree build) AND install-dir/src/Makefile exists BUT | ||
| 4132 | install-dir/src/Makefile.in does NOT exist (this is a sanity | ||
| 4133 | check), then repeat the above steps for source-dir/lisp, | ||
| 4134 | leim and site-lisp. | ||
| 4135 | Finally, add the previously removed site-lisp directories back | ||
| 4136 | at the front (if !no_site_lisp). | ||
| 4137 | |||
| 4138 | We then warn about any of the load-path elements that do not | ||
| 4139 | exist. The only ones that might not exist are those from | ||
| 4140 | PATH_LOADSEARCH, and perhaps dump_path. | ||
| 4141 | |||
| 4142 | Having done all this, we then throw it all away if purify-flag is | ||
| 4143 | nil (ie, not dumping) and EMACSLOADPATH is set, and just | ||
| 4144 | unconditionally use the latter value instead. | ||
| 4145 | So AFAICS the only net results of all the previous steps will be | ||
| 4146 | possibly to issue some irrelevant warnings. | ||
| 4147 | |||
| 4148 | FIXME? There's a case for saying that if we are running | ||
| 4149 | uninstalled, the eventual installation directories should not yet | ||
| 4150 | be included in load-path. | ||
| 4151 | */ | ||
| 4098 | #ifdef CANNOT_DUMP | 4152 | #ifdef CANNOT_DUMP |
| 4099 | normal = PATH_LOADSEARCH; | 4153 | normal = PATH_LOADSEARCH; |
| 4100 | Vload_path = decode_env_path (0, normal); | 4154 | Vload_path = decode_env_path (0, normal); |
| @@ -4104,23 +4158,28 @@ init_lread (void) | |||
| 4104 | else | 4158 | else |
| 4105 | normal = PATH_DUMPLOADSEARCH; | 4159 | normal = PATH_DUMPLOADSEARCH; |
| 4106 | 4160 | ||
| 4107 | /* In a dumped Emacs, we normally have to reset the value of | 4161 | /* In a dumped Emacs, we normally reset the value of Vload_path using |
| 4108 | Vload_path from PATH_LOADSEARCH, since the value that was dumped | 4162 | PATH_LOADSEARCH, since the value that was dumped uses lisp/ in |
| 4109 | uses ../lisp, instead of the path of the installed elisp | 4163 | the source directory, instead of the path of the installed elisp |
| 4110 | libraries. However, if it appears that Vload_path was changed | 4164 | libraries. However, if it appears that Vload_path has already been |
| 4111 | from the default before dumping, don't override that value. */ | 4165 | changed from the default that was saved before dumping, don't |
| 4166 | change it further. */ | ||
| 4112 | if (initialized) | 4167 | if (initialized) |
| 4113 | { | 4168 | { |
| 4114 | if (! NILP (Fequal (dump_path, Vload_path))) | 4169 | if (! NILP (Fequal (dump_path, Vload_path))) |
| 4115 | { | 4170 | { |
| 4116 | Vload_path = decode_env_path (0, normal); | 4171 | Vload_path = decode_env_path (0, normal); |
| 4117 | if (!NILP (Vinstallation_directory)) | 4172 | if (no_site_lisp || !NILP (Vinstallation_directory)) |
| 4118 | { | 4173 | { |
| 4119 | Lisp_Object tem, tem1, sitelisp; | 4174 | Lisp_Object tem, tem1, sitelisp; |
| 4120 | 4175 | ||
| 4121 | /* Remove site-lisp dirs from path temporarily and store | 4176 | /* Remove "site-lisp" dirs from front of path temporarily |
| 4122 | them in sitelisp, then conc them on at the end so | 4177 | and store them in sitelisp, then conc them on at the |
| 4123 | they're always first in path. */ | 4178 | end so they're always first in path. |
| 4179 | Note that this won't work if you used a | ||
| 4180 | --enable-locallisppath element that does not happen | ||
| 4181 | to contain "site-lisp" in its name. | ||
| 4182 | */ | ||
| 4124 | sitelisp = Qnil; | 4183 | sitelisp = Qnil; |
| 4125 | while (1) | 4184 | while (1) |
| 4126 | { | 4185 | { |
| @@ -4136,90 +4195,99 @@ init_lread (void) | |||
| 4136 | break; | 4195 | break; |
| 4137 | } | 4196 | } |
| 4138 | 4197 | ||
| 4139 | /* Add to the path the lisp subdir of the | 4198 | if (!NILP (Vinstallation_directory)) |
| 4140 | installation dir, if it exists. */ | ||
| 4141 | tem = Fexpand_file_name (build_string ("lisp"), | ||
| 4142 | Vinstallation_directory); | ||
| 4143 | tem1 = Ffile_exists_p (tem); | ||
| 4144 | if (!NILP (tem1)) | ||
| 4145 | { | 4199 | { |
| 4146 | if (NILP (Fmember (tem, Vload_path))) | 4200 | /* Add to the path the lisp subdir of the |
| 4201 | installation dir, if it exists. */ | ||
| 4202 | tem = Fexpand_file_name (build_string ("lisp"), | ||
| 4203 | Vinstallation_directory); | ||
| 4204 | tem1 = Ffile_exists_p (tem); | ||
| 4205 | if (!NILP (tem1)) | ||
| 4147 | { | 4206 | { |
| 4148 | turn_off_warning = 1; | 4207 | if (NILP (Fmember (tem, Vload_path))) |
| 4149 | Vload_path = Fcons (tem, Vload_path); | 4208 | { |
| 4209 | turn_off_warning = 1; | ||
| 4210 | Vload_path = Fcons (tem, Vload_path); | ||
| 4211 | } | ||
| 4150 | } | 4212 | } |
| 4151 | } | 4213 | else |
| 4152 | else | 4214 | /* That dir doesn't exist, so add the build-time |
| 4153 | /* That dir doesn't exist, so add the build-time | 4215 | Lisp dirs instead. */ |
| 4154 | Lisp dirs instead. */ | 4216 | Vload_path = nconc2 (Vload_path, dump_path); |
| 4155 | Vload_path = nconc2 (Vload_path, dump_path); | ||
| 4156 | |||
| 4157 | /* Add leim under the installation dir, if it exists. */ | ||
| 4158 | tem = Fexpand_file_name (build_string ("leim"), | ||
| 4159 | Vinstallation_directory); | ||
| 4160 | tem1 = Ffile_exists_p (tem); | ||
| 4161 | if (!NILP (tem1)) | ||
| 4162 | { | ||
| 4163 | if (NILP (Fmember (tem, Vload_path))) | ||
| 4164 | Vload_path = Fcons (tem, Vload_path); | ||
| 4165 | } | ||
| 4166 | |||
| 4167 | /* Add site-lisp under the installation dir, if it exists. */ | ||
| 4168 | tem = Fexpand_file_name (build_string ("site-lisp"), | ||
| 4169 | Vinstallation_directory); | ||
| 4170 | tem1 = Ffile_exists_p (tem); | ||
| 4171 | if (!NILP (tem1)) | ||
| 4172 | { | ||
| 4173 | if (NILP (Fmember (tem, Vload_path))) | ||
| 4174 | Vload_path = Fcons (tem, Vload_path); | ||
| 4175 | } | ||
| 4176 | |||
| 4177 | /* If Emacs was not built in the source directory, | ||
| 4178 | and it is run from where it was built, add to load-path | ||
| 4179 | the lisp, leim and site-lisp dirs under that directory. */ | ||
| 4180 | |||
| 4181 | if (NILP (Fequal (Vinstallation_directory, Vsource_directory))) | ||
| 4182 | { | ||
| 4183 | Lisp_Object tem2; | ||
| 4184 | 4217 | ||
| 4185 | tem = Fexpand_file_name (build_string ("src/Makefile"), | 4218 | /* Add leim under the installation dir, if it exists. */ |
| 4219 | tem = Fexpand_file_name (build_string ("leim"), | ||
| 4186 | Vinstallation_directory); | 4220 | Vinstallation_directory); |
| 4187 | tem1 = Ffile_exists_p (tem); | 4221 | tem1 = Ffile_exists_p (tem); |
| 4188 | 4222 | if (!NILP (tem1)) | |
| 4189 | /* Don't be fooled if they moved the entire source tree | ||
| 4190 | AFTER dumping Emacs. If the build directory is indeed | ||
| 4191 | different from the source dir, src/Makefile.in and | ||
| 4192 | src/Makefile will not be found together. */ | ||
| 4193 | tem = Fexpand_file_name (build_string ("src/Makefile.in"), | ||
| 4194 | Vinstallation_directory); | ||
| 4195 | tem2 = Ffile_exists_p (tem); | ||
| 4196 | if (!NILP (tem1) && NILP (tem2)) | ||
| 4197 | { | 4223 | { |
| 4198 | tem = Fexpand_file_name (build_string ("lisp"), | ||
| 4199 | Vsource_directory); | ||
| 4200 | |||
| 4201 | if (NILP (Fmember (tem, Vload_path))) | 4224 | if (NILP (Fmember (tem, Vload_path))) |
| 4202 | Vload_path = Fcons (tem, Vload_path); | 4225 | Vload_path = Fcons (tem, Vload_path); |
| 4226 | } | ||
| 4203 | 4227 | ||
| 4204 | tem = Fexpand_file_name (build_string ("leim"), | 4228 | /* Add site-lisp under the installation dir, if it exists. */ |
| 4205 | Vsource_directory); | 4229 | if (!no_site_lisp) |
| 4230 | { | ||
| 4231 | tem = Fexpand_file_name (build_string ("site-lisp"), | ||
| 4232 | Vinstallation_directory); | ||
| 4233 | tem1 = Ffile_exists_p (tem); | ||
| 4234 | if (!NILP (tem1)) | ||
| 4235 | { | ||
| 4236 | if (NILP (Fmember (tem, Vload_path))) | ||
| 4237 | Vload_path = Fcons (tem, Vload_path); | ||
| 4238 | } | ||
| 4239 | } | ||
| 4206 | 4240 | ||
| 4207 | if (NILP (Fmember (tem, Vload_path))) | 4241 | /* If Emacs was not built in the source directory, |
| 4208 | Vload_path = Fcons (tem, Vload_path); | 4242 | and it is run from where it was built, add to load-path |
| 4243 | the lisp, leim and site-lisp dirs under that directory. */ | ||
| 4209 | 4244 | ||
| 4210 | tem = Fexpand_file_name (build_string ("site-lisp"), | 4245 | if (NILP (Fequal (Vinstallation_directory, Vsource_directory))) |
| 4211 | Vsource_directory); | 4246 | { |
| 4247 | Lisp_Object tem2; | ||
| 4248 | |||
| 4249 | tem = Fexpand_file_name (build_string ("src/Makefile"), | ||
| 4250 | Vinstallation_directory); | ||
| 4251 | tem1 = Ffile_exists_p (tem); | ||
| 4252 | |||
| 4253 | /* Don't be fooled if they moved the entire source tree | ||
| 4254 | AFTER dumping Emacs. If the build directory is indeed | ||
| 4255 | different from the source dir, src/Makefile.in and | ||
| 4256 | src/Makefile will not be found together. */ | ||
| 4257 | tem = Fexpand_file_name (build_string ("src/Makefile.in"), | ||
| 4258 | Vinstallation_directory); | ||
| 4259 | tem2 = Ffile_exists_p (tem); | ||
| 4260 | if (!NILP (tem1) && NILP (tem2)) | ||
| 4261 | { | ||
| 4262 | tem = Fexpand_file_name (build_string ("lisp"), | ||
| 4263 | Vsource_directory); | ||
| 4212 | 4264 | ||
| 4213 | if (NILP (Fmember (tem, Vload_path))) | 4265 | if (NILP (Fmember (tem, Vload_path))) |
| 4214 | Vload_path = Fcons (tem, Vload_path); | 4266 | Vload_path = Fcons (tem, Vload_path); |
| 4215 | } | 4267 | |
| 4216 | } | 4268 | tem = Fexpand_file_name (build_string ("leim"), |
| 4269 | Vsource_directory); | ||
| 4270 | |||
| 4271 | if (NILP (Fmember (tem, Vload_path))) | ||
| 4272 | Vload_path = Fcons (tem, Vload_path); | ||
| 4273 | |||
| 4274 | if (!no_site_lisp) | ||
| 4275 | { | ||
| 4276 | tem = Fexpand_file_name (build_string ("site-lisp"), | ||
| 4277 | Vsource_directory); | ||
| 4278 | |||
| 4279 | if (NILP (Fmember (tem, Vload_path))) | ||
| 4280 | Vload_path = Fcons (tem, Vload_path); | ||
| 4281 | } | ||
| 4282 | } | ||
| 4283 | } /* Vinstallation_directory != Vsource_directory */ | ||
| 4284 | } /* if Vinstallation_directory */ | ||
| 4217 | if (!NILP (sitelisp) && !no_site_lisp) | 4285 | if (!NILP (sitelisp) && !no_site_lisp) |
| 4218 | Vload_path = nconc2 (Fnreverse (sitelisp), Vload_path); | 4286 | Vload_path = nconc2 (Fnreverse (sitelisp), Vload_path); |
| 4219 | } | 4287 | } /* if Vinstallation_directory || no_site_lisp */ |
| 4220 | } | 4288 | } /* if dump_path == Vload_path */ |
| 4221 | } | 4289 | } |
| 4222 | else | 4290 | else /* !initialized */ |
| 4223 | { | 4291 | { |
| 4224 | /* NORMAL refers to the lisp dir in the source directory. */ | 4292 | /* NORMAL refers to the lisp dir in the source directory. */ |
| 4225 | /* We used to add ../lisp at the front here, but | 4293 | /* We used to add ../lisp at the front here, but |
| @@ -4229,7 +4297,7 @@ init_lread (void) | |||
| 4229 | Vload_path = decode_env_path (0, normal); | 4297 | Vload_path = decode_env_path (0, normal); |
| 4230 | dump_path = Vload_path; | 4298 | dump_path = Vload_path; |
| 4231 | } | 4299 | } |
| 4232 | #endif | 4300 | #endif /* CANNOT_DUMP */ |
| 4233 | 4301 | ||
| 4234 | #if (!(defined (WINDOWSNT) || (defined (HAVE_NS)))) | 4302 | #if (!(defined (WINDOWSNT) || (defined (HAVE_NS)))) |
| 4235 | /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is | 4303 | /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is |
| @@ -4237,6 +4305,8 @@ init_lread (void) | |||
| 4237 | confuses users. Since PATH_LOADSEARCH is always overridden by the | 4305 | confuses users. Since PATH_LOADSEARCH is always overridden by the |
| 4238 | EMACSLOADPATH environment variable below, disable the warning on NT. */ | 4306 | EMACSLOADPATH environment variable below, disable the warning on NT. */ |
| 4239 | 4307 | ||
| 4308 | /* HAVE_NS also uses EMACSLOADPATH. */ | ||
| 4309 | |||
| 4240 | /* Warn if dirs in the *standard* path don't exist. */ | 4310 | /* Warn if dirs in the *standard* path don't exist. */ |
| 4241 | if (!turn_off_warning) | 4311 | if (!turn_off_warning) |
| 4242 | { | 4312 | { |
| @@ -4251,6 +4321,10 @@ init_lread (void) | |||
| 4251 | if (STRINGP (dirfile)) | 4321 | if (STRINGP (dirfile)) |
| 4252 | { | 4322 | { |
| 4253 | dirfile = Fdirectory_file_name (dirfile); | 4323 | dirfile = Fdirectory_file_name (dirfile); |
| 4324 | /* Do we really need to warn about missing site-lisp dirs? | ||
| 4325 | It's true that the installation should have created | ||
| 4326 | them and added subdirs.el, but it's harmless if they | ||
| 4327 | are not there. */ | ||
| 4254 | if (access (SSDATA (dirfile), 0) < 0) | 4328 | if (access (SSDATA (dirfile), 0) < 0) |
| 4255 | dir_warning ("Warning: Lisp directory `%s' does not exist.\n", | 4329 | dir_warning ("Warning: Lisp directory `%s' does not exist.\n", |
| 4256 | XCAR (path_tail)); | 4330 | XCAR (path_tail)); |
| @@ -4284,14 +4358,20 @@ init_lread (void) | |||
| 4284 | void | 4358 | void |
| 4285 | dir_warning (const char *format, Lisp_Object dirname) | 4359 | dir_warning (const char *format, Lisp_Object dirname) |
| 4286 | { | 4360 | { |
| 4287 | char *buffer | ||
| 4288 | = (char *) alloca (SCHARS (dirname) + strlen (format) + 5); | ||
| 4289 | |||
| 4290 | fprintf (stderr, format, SDATA (dirname)); | 4361 | fprintf (stderr, format, SDATA (dirname)); |
| 4291 | sprintf (buffer, format, SDATA (dirname)); | 4362 | |
| 4292 | /* Don't log the warning before we've initialized!! */ | 4363 | /* Don't log the warning before we've initialized!! */ |
| 4293 | if (initialized) | 4364 | if (initialized) |
| 4294 | message_dolog (buffer, strlen (buffer), 0, STRING_MULTIBYTE (dirname)); | 4365 | { |
| 4366 | char *buffer; | ||
| 4367 | ptrdiff_t message_len; | ||
| 4368 | USE_SAFE_ALLOCA; | ||
| 4369 | SAFE_ALLOCA (buffer, char *, | ||
| 4370 | SBYTES (dirname) + strlen (format) - (sizeof "%s" - 1) + 1); | ||
| 4371 | message_len = esprintf (buffer, format, SDATA (dirname)); | ||
| 4372 | message_dolog (buffer, message_len, 0, STRING_MULTIBYTE (dirname)); | ||
| 4373 | SAFE_FREE (); | ||
| 4374 | } | ||
| 4295 | } | 4375 | } |
| 4296 | 4376 | ||
| 4297 | void | 4377 | void |
| @@ -4511,10 +4591,12 @@ to load. See also `load-dangerous-libraries'. */); | |||
| 4511 | Qlexical_binding = intern ("lexical-binding"); | 4591 | Qlexical_binding = intern ("lexical-binding"); |
| 4512 | staticpro (&Qlexical_binding); | 4592 | staticpro (&Qlexical_binding); |
| 4513 | DEFVAR_LISP ("lexical-binding", Vlexical_binding, | 4593 | DEFVAR_LISP ("lexical-binding", Vlexical_binding, |
| 4514 | doc: /* If non-nil, use lexical binding when evaluating code. | 4594 | doc: /* Whether to use lexical binding when evaluating code. |
| 4515 | This only applies to code evaluated by `eval-buffer' and `eval-region'. | 4595 | Non-nil means that the code in the current buffer should be evaluated |
| 4516 | This variable is automatically set from the file variables of an interpreted | 4596 | with lexical binding. |
| 4517 | Lisp file read using `load'. */); | 4597 | This variable is automatically set from the file variables of an |
| 4598 | interpreted Lisp file read using `load'. Unlike other file local | ||
| 4599 | variables, this must be set in the first line of a file. */); | ||
| 4518 | Fmake_variable_buffer_local (Qlexical_binding); | 4600 | Fmake_variable_buffer_local (Qlexical_binding); |
| 4519 | 4601 | ||
| 4520 | DEFVAR_LISP ("eval-buffer-list", Veval_buffer_list, | 4602 | DEFVAR_LISP ("eval-buffer-list", Veval_buffer_list, |