aboutsummaryrefslogtreecommitdiffstats
path: root/src/lread.c
diff options
context:
space:
mode:
authorJoakim Verona2012-07-27 02:22:03 +0200
committerJoakim Verona2012-07-27 02:22:03 +0200
commit5fb63197843dcae66f2fe0ddd6f4a9d560e9db2f (patch)
tree5c55f1096a656a9759f0b53a0b5d1a2289bd366f /src/lread.c
parent0c5c85cf2b350c965bb1ffa5b2d77c2adebc406b (diff)
parent562157c814037dcba58a20cd6908a95992c22283 (diff)
downloademacs-5fb63197843dcae66f2fe0ddd6f4a9d560e9db2f.tar.gz
emacs-5fb63197843dcae66f2fe0ddd6f4a9d560e9db2f.zip
upstream
Diffstat (limited to 'src/lread.c')
-rw-r--r--src/lread.c582
1 files changed, 284 insertions, 298 deletions
diff --git a/src/lread.c b/src/lread.c
index a6d77204cf8..39378bb11dd 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -26,6 +26,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26#include <errno.h> 26#include <errno.h>
27#include <limits.h> /* For CHAR_BIT. */ 27#include <limits.h> /* For CHAR_BIT. */
28#include <setjmp.h> 28#include <setjmp.h>
29#include <stat-time.h>
29#include "lisp.h" 30#include "lisp.h"
30#include "intervals.h" 31#include "intervals.h"
31#include "character.h" 32#include "character.h"
@@ -44,6 +45,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
44#include "msdos.h" 45#include "msdos.h"
45#endif 46#endif
46 47
48#ifdef HAVE_NS
49#include "nsterm.h"
50#endif
51
47#include <unistd.h> 52#include <unistd.h>
48#include <math.h> 53#include <math.h>
49 54
@@ -154,10 +159,6 @@ static void readevalloop (Lisp_Object, FILE*, Lisp_Object, int,
154 Lisp_Object, Lisp_Object); 159 Lisp_Object, Lisp_Object);
155static Lisp_Object load_unwind (Lisp_Object); 160static Lisp_Object load_unwind (Lisp_Object);
156static Lisp_Object load_descriptor_unwind (Lisp_Object); 161static Lisp_Object load_descriptor_unwind (Lisp_Object);
157
158static void invalid_syntax (const char *) NO_RETURN;
159static void end_of_file_error (void) NO_RETURN;
160
161 162
162/* Functions that read one byte from the current source READCHARFUN 163/* Functions that read one byte from the current source READCHARFUN
163 or unreads one byte. If the integer argument C is -1, it returns 164 or unreads one byte. If the integer argument C is -1, it returns
@@ -601,18 +602,9 @@ read_filtered_event (int no_switch_frame, int ascii_required,
601 /* Compute timeout. */ 602 /* Compute timeout. */
602 if (NUMBERP (seconds)) 603 if (NUMBERP (seconds))
603 { 604 {
604 EMACS_TIME wait_time;
605 int sec, usec;
606 double duration = extract_float (seconds); 605 double duration = extract_float (seconds);
607 606 EMACS_TIME wait_time = EMACS_TIME_FROM_DOUBLE (duration);
608 if (0 < duration) 607 end_time = add_emacs_time (current_emacs_time (), wait_time);
609 duration_to_sec_usec (duration, &sec, &usec);
610 else
611 sec = usec = 0;
612
613 EMACS_GET_TIME (end_time);
614 EMACS_SET_SECS_USECS (wait_time, sec, usec);
615 EMACS_ADD_TIME (end_time, end_time, wait_time);
616 } 608 }
617 609
618/* Read until we get an acceptable event. */ 610/* Read until we get an acceptable event. */
@@ -914,7 +906,7 @@ safe_to_load_p (int fd)
914 906
915 if (i >= nbytes 907 if (i >= nbytes
916 || fast_c_string_match_ignore_case (Vbytecomp_version_regexp, 908 || fast_c_string_match_ignore_case (Vbytecomp_version_regexp,
917 buf + i) < 0) 909 buf + i, nbytes - i) < 0)
918 safe_p = 0; 910 safe_p = 0;
919 } 911 }
920 if (safe_p) 912 if (safe_p)
@@ -1226,7 +1218,8 @@ Return t if the file exists and loads successfully. */)
1226 SSET (efound, SBYTES (efound) - 1, 'c'); 1218 SSET (efound, SBYTES (efound) - 1, 'c');
1227 } 1219 }
1228 1220
1229 if (result == 0 && s1.st_mtime < s2.st_mtime) 1221 if (result == 0
1222 && EMACS_TIME_LT (get_stat_mtime (&s1), get_stat_mtime (&s2)))
1230 { 1223 {
1231 /* Make the progress messages mention that source is newer. */ 1224 /* Make the progress messages mention that source is newer. */
1232 newer = 1; 1225 newer = 1;
@@ -1489,36 +1482,26 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto
1489 this path element/specified file name and any possible suffix. */ 1482 this path element/specified file name and any possible suffix. */
1490 want_length = max_suffix_len + SBYTES (filename); 1483 want_length = max_suffix_len + SBYTES (filename);
1491 if (fn_size <= want_length) 1484 if (fn_size <= want_length)
1492 fn = (char *) alloca (fn_size = 100 + want_length); 1485 fn = alloca (fn_size = 100 + want_length);
1493 1486
1494 /* Loop over suffixes. */ 1487 /* Loop over suffixes. */
1495 for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : suffixes; 1488 for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : suffixes;
1496 CONSP (tail); tail = XCDR (tail)) 1489 CONSP (tail); tail = XCDR (tail))
1497 { 1490 {
1498 ptrdiff_t lsuffix = SBYTES (XCAR (tail)); 1491 ptrdiff_t fnlen, lsuffix = SBYTES (XCAR (tail));
1499 Lisp_Object handler; 1492 Lisp_Object handler;
1500 int exists; 1493 int exists;
1501 1494
1502 /* Concatenate path element/specified name with the suffix. 1495 /* Concatenate path element/specified name with the suffix.
1503 If the directory starts with /:, remove that. */ 1496 If the directory starts with /:, remove that. */
1504 if (SCHARS (filename) > 2 1497 int prefixlen = ((SCHARS (filename) > 2
1505 && SREF (filename, 0) == '/' 1498 && SREF (filename, 0) == '/'
1506 && SREF (filename, 1) == ':') 1499 && SREF (filename, 1) == ':')
1507 { 1500 ? 2 : 0);
1508 strncpy (fn, SSDATA (filename) + 2, 1501 fnlen = SBYTES (filename) - prefixlen;
1509 SBYTES (filename) - 2); 1502 memcpy (fn, SDATA (filename) + prefixlen, fnlen);
1510 fn[SBYTES (filename) - 2] = 0; 1503 memcpy (fn + fnlen, SDATA (XCAR (tail)), lsuffix + 1);
1511 } 1504 fnlen += lsuffix;
1512 else
1513 {
1514 strncpy (fn, SSDATA (filename),
1515 SBYTES (filename));
1516 fn[SBYTES (filename)] = 0;
1517 }
1518
1519 if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */
1520 strncat (fn, SSDATA (XCAR (tail)), lsuffix);
1521
1522 /* Check that the file exists and is not a directory. */ 1505 /* Check that the file exists and is not a directory. */
1523 /* We used to only check for handlers on non-absolute file names: 1506 /* We used to only check for handlers on non-absolute file names:
1524 if (absolute) 1507 if (absolute)
@@ -1527,7 +1510,7 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto
1527 handler = Ffind_file_name_handler (filename, Qfile_exists_p); 1510 handler = Ffind_file_name_handler (filename, Qfile_exists_p);
1528 It's not clear why that was the case and it breaks things like 1511 It's not clear why that was the case and it breaks things like
1529 (load "/bar.el") where the file is actually "/bar.el.gz". */ 1512 (load "/bar.el") where the file is actually "/bar.el.gz". */
1530 string = build_string (fn); 1513 string = make_string (fn, fnlen);
1531 handler = Ffind_file_name_handler (string, Qfile_exists_p); 1514 handler = Ffind_file_name_handler (string, Qfile_exists_p);
1532 if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate)) 1515 if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate))
1533 { 1516 {
@@ -1664,7 +1647,7 @@ readevalloop_1 (Lisp_Object old)
1664/* Signal an `end-of-file' error, if possible with file name 1647/* Signal an `end-of-file' error, if possible with file name
1665 information. */ 1648 information. */
1666 1649
1667static void 1650static _Noreturn void
1668end_of_file_error (void) 1651end_of_file_error (void)
1669{ 1652{
1670 if (STRINGP (Vload_file_name)) 1653 if (STRINGP (Vload_file_name))
@@ -2032,7 +2015,7 @@ read_internal_start (Lisp_Object stream, Lisp_Object start, Lisp_Object end)
2032/* Signal Qinvalid_read_syntax error. 2015/* Signal Qinvalid_read_syntax error.
2033 S is error string of length N (if > 0) */ 2016 S is error string of length N (if > 0) */
2034 2017
2035static void 2018static _Noreturn void
2036invalid_syntax (const char *s) 2019invalid_syntax (const char *s)
2037{ 2020{
2038 xsignal1 (Qinvalid_read_syntax, build_string (s)); 2021 xsignal1 (Qinvalid_read_syntax, build_string (s));
@@ -2635,13 +2618,12 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2635 2618
2636 if (saved_doc_string_size == 0) 2619 if (saved_doc_string_size == 0)
2637 { 2620 {
2638 saved_doc_string = (char *) xmalloc (nskip + extra); 2621 saved_doc_string = xmalloc (nskip + extra);
2639 saved_doc_string_size = nskip + extra; 2622 saved_doc_string_size = nskip + extra;
2640 } 2623 }
2641 if (nskip > saved_doc_string_size) 2624 if (nskip > saved_doc_string_size)
2642 { 2625 {
2643 saved_doc_string = (char *) xrealloc (saved_doc_string, 2626 saved_doc_string = xrealloc (saved_doc_string, nskip + extra);
2644 nskip + extra);
2645 saved_doc_string_size = nskip + extra; 2627 saved_doc_string_size = nskip + extra;
2646 } 2628 }
2647 2629
@@ -2688,13 +2670,13 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2688 /* No symbol character follows, this is the empty 2670 /* No symbol character follows, this is the empty
2689 symbol. */ 2671 symbol. */
2690 UNREAD (c); 2672 UNREAD (c);
2691 return Fmake_symbol (build_string ("")); 2673 return Fmake_symbol (empty_unibyte_string);
2692 } 2674 }
2693 goto read_symbol; 2675 goto read_symbol;
2694 } 2676 }
2695 /* ## is the empty symbol. */ 2677 /* ## is the empty symbol. */
2696 if (c == '#') 2678 if (c == '#')
2697 return Fintern (build_string (""), Qnil); 2679 return Fintern (empty_unibyte_string, Qnil);
2698 /* Reader forms that can reuse previously read objects. */ 2680 /* Reader forms that can reuse previously read objects. */
2699 if (c >= '0' && c <= '9') 2681 if (c >= '0' && c <= '9')
2700 { 2682 {
@@ -2904,8 +2886,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2904 ptrdiff_t offset = p - read_buffer; 2886 ptrdiff_t offset = p - read_buffer;
2905 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) 2887 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
2906 memory_full (SIZE_MAX); 2888 memory_full (SIZE_MAX);
2907 read_buffer = (char *) xrealloc (read_buffer, 2889 read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
2908 read_buffer_size * 2);
2909 read_buffer_size *= 2; 2890 read_buffer_size *= 2;
2910 p = read_buffer + offset; 2891 p = read_buffer + offset;
2911 end = read_buffer + read_buffer_size; 2892 end = read_buffer + read_buffer_size;
@@ -3039,8 +3020,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
3039 ptrdiff_t offset = p - read_buffer; 3020 ptrdiff_t offset = p - read_buffer;
3040 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) 3021 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
3041 memory_full (SIZE_MAX); 3022 memory_full (SIZE_MAX);
3042 read_buffer = (char *) xrealloc (read_buffer, 3023 read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
3043 read_buffer_size * 2);
3044 read_buffer_size *= 2; 3024 read_buffer_size *= 2;
3045 p = read_buffer + offset; 3025 p = read_buffer + offset;
3046 end = read_buffer + read_buffer_size; 3026 end = read_buffer + read_buffer_size;
@@ -3070,8 +3050,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
3070 ptrdiff_t offset = p - read_buffer; 3050 ptrdiff_t offset = p - read_buffer;
3071 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) 3051 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
3072 memory_full (SIZE_MAX); 3052 memory_full (SIZE_MAX);
3073 read_buffer = (char *) xrealloc (read_buffer, 3053 read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
3074 read_buffer_size * 2);
3075 read_buffer_size *= 2; 3054 read_buffer_size *= 2;
3076 p = read_buffer + offset; 3055 p = read_buffer + offset;
3077 end = read_buffer + read_buffer_size; 3056 end = read_buffer + read_buffer_size;
@@ -3673,32 +3652,20 @@ check_obarray (Lisp_Object obarray)
3673 interned in the current obarray. */ 3652 interned in the current obarray. */
3674 3653
3675Lisp_Object 3654Lisp_Object
3676intern (const char *str) 3655intern_1 (const char *str, ptrdiff_t len)
3677{ 3656{
3678 Lisp_Object tem; 3657 Lisp_Object obarray = check_obarray (Vobarray);
3679 ptrdiff_t len = strlen (str); 3658 Lisp_Object tem = oblookup (obarray, str, len, len);
3680 Lisp_Object obarray;
3681 3659
3682 obarray = Vobarray; 3660 return SYMBOLP (tem) ? tem : Fintern (make_string (str, len), obarray);
3683 if (!VECTORP (obarray) || ASIZE (obarray) == 0)
3684 obarray = check_obarray (obarray);
3685 tem = oblookup (obarray, str, len, len);
3686 if (SYMBOLP (tem))
3687 return tem;
3688 return Fintern (make_string (str, len), obarray);
3689} 3661}
3690 3662
3691Lisp_Object 3663Lisp_Object
3692intern_c_string (const char *str) 3664intern_c_string_1 (const char *str, ptrdiff_t len)
3693{ 3665{
3694 Lisp_Object tem; 3666 Lisp_Object obarray = check_obarray (Vobarray);
3695 ptrdiff_t len = strlen (str); 3667 Lisp_Object tem = oblookup (obarray, str, len, len);
3696 Lisp_Object obarray;
3697 3668
3698 obarray = Vobarray;
3699 if (!VECTORP (obarray) || ASIZE (obarray) == 0)
3700 obarray = check_obarray (obarray);
3701 tem = oblookup (obarray, str, len, len);
3702 if (SYMBOLP (tem)) 3669 if (SYMBOLP (tem))
3703 return tem; 3670 return tem;
3704 3671
@@ -3708,7 +3675,7 @@ intern_c_string (const char *str)
3708 with the extra copy. */ 3675 with the extra copy. */
3709 abort (); 3676 abort ();
3710 3677
3711 return Fintern (make_pure_c_string (str), obarray); 3678 return Fintern (make_pure_c_string (str, len), obarray);
3712} 3679}
3713 3680
3714DEFUN ("intern", Fintern, Sintern, 1, 2, 0, 3681DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
@@ -3748,7 +3715,7 @@ it defaults to the value of `obarray'. */)
3748 SET_SYMBOL_VAL (XSYMBOL (sym), sym); 3715 SET_SYMBOL_VAL (XSYMBOL (sym), sym);
3749 } 3716 }
3750 3717
3751 ptr = &XVECTOR (obarray)->contents[XINT (tem)]; 3718 ptr = &AREF (obarray, XINT(tem));
3752 if (SYMBOLP (*ptr)) 3719 if (SYMBOLP (*ptr))
3753 XSYMBOL (sym)->next = XSYMBOL (*ptr); 3720 XSYMBOL (sym)->next = XSYMBOL (*ptr);
3754 else 3721 else
@@ -3827,18 +3794,18 @@ OBARRAY defaults to the value of the variable `obarray'. */)
3827 3794
3828 hash = oblookup_last_bucket_number; 3795 hash = oblookup_last_bucket_number;
3829 3796
3830 if (EQ (XVECTOR (obarray)->contents[hash], tem)) 3797 if (EQ (AREF (obarray, hash), tem))
3831 { 3798 {
3832 if (XSYMBOL (tem)->next) 3799 if (XSYMBOL (tem)->next)
3833 XSETSYMBOL (XVECTOR (obarray)->contents[hash], XSYMBOL (tem)->next); 3800 XSETSYMBOL (AREF (obarray, hash), XSYMBOL (tem)->next);
3834 else 3801 else
3835 XSETINT (XVECTOR (obarray)->contents[hash], 0); 3802 XSETINT (AREF (obarray, hash), 0);
3836 } 3803 }
3837 else 3804 else
3838 { 3805 {
3839 Lisp_Object tail, following; 3806 Lisp_Object tail, following;
3840 3807
3841 for (tail = XVECTOR (obarray)->contents[hash]; 3808 for (tail = AREF (obarray, hash);
3842 XSYMBOL (tail)->next; 3809 XSYMBOL (tail)->next;
3843 tail = following) 3810 tail = following)
3844 { 3811 {
@@ -3868,16 +3835,13 @@ oblookup (Lisp_Object obarray, register const char *ptr, ptrdiff_t size, ptrdiff
3868 register Lisp_Object tail; 3835 register Lisp_Object tail;
3869 Lisp_Object bucket, tem; 3836 Lisp_Object bucket, tem;
3870 3837
3871 if (!VECTORP (obarray) 3838 obarray = check_obarray (obarray);
3872 || (obsize = ASIZE (obarray)) == 0) 3839 obsize = ASIZE (obarray);
3873 { 3840
3874 obarray = check_obarray (obarray);
3875 obsize = ASIZE (obarray);
3876 }
3877 /* This is sometimes needed in the middle of GC. */ 3841 /* This is sometimes needed in the middle of GC. */
3878 obsize &= ~ARRAY_MARK_FLAG; 3842 obsize &= ~ARRAY_MARK_FLAG;
3879 hash = hash_string (ptr, size_byte) % obsize; 3843 hash = hash_string (ptr, size_byte) % obsize;
3880 bucket = XVECTOR (obarray)->contents[hash]; 3844 bucket = AREF (obarray, hash);
3881 oblookup_last_bucket_number = hash; 3845 oblookup_last_bucket_number = hash;
3882 if (EQ (bucket, make_number (0))) 3846 if (EQ (bucket, make_number (0)))
3883 ; 3847 ;
@@ -3905,7 +3869,7 @@ map_obarray (Lisp_Object obarray, void (*fn) (Lisp_Object, Lisp_Object), Lisp_Ob
3905 CHECK_VECTOR (obarray); 3869 CHECK_VECTOR (obarray);
3906 for (i = ASIZE (obarray) - 1; i >= 0; i--) 3870 for (i = ASIZE (obarray) - 1; i >= 0; i--)
3907 { 3871 {
3908 tail = XVECTOR (obarray)->contents[i]; 3872 tail = AREF (obarray, i);
3909 if (SYMBOLP (tail)) 3873 if (SYMBOLP (tail))
3910 while (1) 3874 while (1)
3911 { 3875 {
@@ -3949,7 +3913,7 @@ init_obarray (void)
3949 initial_obarray = Vobarray; 3913 initial_obarray = Vobarray;
3950 staticpro (&initial_obarray); 3914 staticpro (&initial_obarray);
3951 3915
3952 Qunbound = Fmake_symbol (make_pure_c_string ("unbound")); 3916 Qunbound = Fmake_symbol (build_pure_c_string ("unbound"));
3953 /* Set temporary dummy values to Qnil and Vpurify_flag to satisfy the 3917 /* Set temporary dummy values to Qnil and Vpurify_flag to satisfy the
3954 NILP (Vpurify_flag) check in intern_c_string. */ 3918 NILP (Vpurify_flag) check in intern_c_string. */
3955 Qnil = make_number (-1); Vpurify_flag = make_number (1); 3919 Qnil = make_number (-1); Vpurify_flag = make_number (1);
@@ -3976,7 +3940,7 @@ init_obarray (void)
3976 3940
3977 DEFSYM (Qvariable_documentation, "variable-documentation"); 3941 DEFSYM (Qvariable_documentation, "variable-documentation");
3978 3942
3979 read_buffer = (char *) xmalloc (size); 3943 read_buffer = xmalloc (size);
3980 read_buffer_size = size; 3944 read_buffer_size = size;
3981} 3945}
3982 3946
@@ -4073,62 +4037,110 @@ defvar_kboard (struct Lisp_Kboard_Objfwd *ko_fwd,
4073 SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)ko_fwd); 4037 SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)ko_fwd);
4074} 4038}
4075 4039
4040/* Check that the elements of Vload_path exist. */
4041
4042static void
4043load_path_check (void)
4044{
4045 Lisp_Object path_tail;
4046
4047 /* The only elements that might not exist are those from
4048 PATH_LOADSEARCH, EMACSLOADPATH. Anything else is only added if
4049 it exists. */
4050 for (path_tail = Vload_path; !NILP (path_tail); path_tail = XCDR (path_tail))
4051 {
4052 Lisp_Object dirfile;
4053 dirfile = Fcar (path_tail);
4054 if (STRINGP (dirfile))
4055 {
4056 dirfile = Fdirectory_file_name (dirfile);
4057 if (access (SSDATA (dirfile), 0) < 0)
4058 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
4059 XCAR (path_tail));
4060 }
4061 }
4062}
4063
4076/* Record the value of load-path used at the start of dumping 4064/* Record the value of load-path used at the start of dumping
4077 so we can see if the site changed it later during dumping. */ 4065 so we can see if the site changed it later during dumping. */
4078static Lisp_Object dump_path; 4066static Lisp_Object dump_path;
4079 4067
4068/* Compute the default Vload_path, with the following logic:
4069 If CANNOT_DUMP:
4070 use EMACSLOADPATH env-var if set; otherwise use PATH_LOADSEARCH,
4071 prepending PATH_SITELOADSEARCH unless --no-site-lisp.
4072 The remainder is what happens when dumping works:
4073 If purify-flag (ie dumping) just use PATH_DUMPLOADSEARCH.
4074 Otherwise use EMACSLOADPATH if set, else PATH_LOADSEARCH.
4075
4076 If !initialized, then just set both Vload_path and dump_path.
4077 If initialized, then if Vload_path != dump_path, do nothing.
4078 (Presumably the load-path has already been changed by something.
4079 This can only be from a site-load file during dumping,
4080 or because EMACSLOADPATH is set.)
4081 If Vinstallation_directory is not nil (ie, running uninstalled):
4082 If installation-dir/lisp exists and not already a member,
4083 we must be running uninstalled. Reset the load-path
4084 to just installation-dir/lisp. (The default PATH_LOADSEARCH
4085 refers to the eventual installation directories. Since we
4086 are not yet installed, we should not use them, even if they exist.)
4087 If installation-dir/lisp does not exist, just add dump_path at the
4088 end instead.
4089 Add installation-dir/leim (if exists and not already a member) at the front.
4090 Add installation-dir/site-lisp (if !no_site_lisp, and exists
4091 and not already a member) at the front.
4092 If installation-dir != source-dir (ie running an uninstalled,
4093 out-of-tree build) AND install-dir/src/Makefile exists BUT
4094 install-dir/src/Makefile.in does NOT exist (this is a sanity
4095 check), then repeat the above steps for source-dir/lisp,
4096 leim and site-lisp.
4097 Finally, add the site-lisp directories at the front (if !no_site_lisp).
4098*/
4099
4080void 4100void
4081init_lread (void) 4101init_lread (void)
4082{ 4102{
4083 const char *normal; 4103 const char *normal;
4084 int turn_off_warning = 0; 4104
4085
4086 /* Compute the default Vload-path, with the following logic:
4087 If CANNOT_DUMP just use PATH_LOADSEARCH.
4088 Else if purify-flag (ie dumping) start from PATH_DUMPLOADSEARCH;
4089 otherwise start from PATH_LOADSEARCH.
4090 If !initialized, then just set both Vload_path and dump_path.
4091 If initialized, then if Vload_path != dump_path, do nothing.
4092 (Presumably the load-path has already been changed by something.)
4093 Also do nothing if Vinstallation_directory is nil.
4094 Otherwise:
4095 Remove site-lisp directories from the front of load-path.
4096 Add installation-dir/lisp (if exists and not already a member),
4097 at the front, and turn off warnings about missing directories
4098 (because we are presumably running uninstalled).
4099 If it does not exist, add dump_path at the end instead.
4100 Add installation-dir/leim (if exists and not already a member)
4101 at the front.
4102 Add installation-dir/site-lisp (if !no_site_lisp, and exists
4103 and not already a member) at the front.
4104 If installation-dir != source-dir (ie running an uninstalled,
4105 out-of-tree build) AND install-dir/src/Makefile exists BUT
4106 install-dir/src/Makefile.in does NOT exist (this is a sanity
4107 check), then repeat the above steps for source-dir/lisp,
4108 leim and site-lisp.
4109 Finally, add the previously removed site-lisp directories back
4110 at the front (if !no_site_lisp).
4111
4112 We then warn about any of the load-path elements that do not
4113 exist. The only ones that might not exist are those from
4114 PATH_LOADSEARCH, and perhaps dump_path.
4115
4116 Having done all this, we then throw it all away if purify-flag is
4117 nil (ie, not dumping) and EMACSLOADPATH is set, and just
4118 unconditionally use the latter value instead.
4119 So AFAICS the only net results of all the previous steps will be
4120 possibly to issue some irrelevant warnings.
4121
4122 FIXME? There's a case for saying that if we are running
4123 uninstalled, the eventual installation directories should not yet
4124 be included in load-path.
4125 */
4126#ifdef CANNOT_DUMP 4105#ifdef CANNOT_DUMP
4106#ifdef HAVE_NS
4107 const char *loadpath = ns_load_path ();
4108#endif
4109
4127 normal = PATH_LOADSEARCH; 4110 normal = PATH_LOADSEARCH;
4128 Vload_path = decode_env_path (0, normal); 4111#ifdef HAVE_NS
4112 Vload_path = decode_env_path ("EMACSLOADPATH", loadpath ? loadpath : normal);
4113#else
4114 Vload_path = decode_env_path ("EMACSLOADPATH", normal);
4115#endif
4116
4117 load_path_check ();
4118
4119 /* FIXME CANNOT_DUMP platforms should get source-dir/lisp etc added
4120 to their load-path too, AFAICS. I don't think we can tell the
4121 difference between initialized and !initialized in this case,
4122 so we'll have to do it unconditionally when Vinstallation_directory
4123 is non-nil. */
4124#ifdef HAVE_NS
4125 /* loadpath already includes the app-bundle's site-lisp. */
4126 if (!no_site_lisp && !egetenv ("EMACSLOADPATH") && !loadpath)
4127#else
4128 if (!no_site_lisp && !egetenv ("EMACSLOADPATH"))
4129#endif
4130 {
4131 Lisp_Object sitelisp;
4132 sitelisp = decode_env_path (0, PATH_SITELOADSEARCH);
4133 if (! NILP (sitelisp)) Vload_path = nconc2 (sitelisp, Vload_path);
4134 }
4129#else 4135#else
4130 if (NILP (Vpurify_flag)) 4136 if (NILP (Vpurify_flag))
4131 normal = PATH_LOADSEARCH; 4137 {
4138 normal = PATH_LOADSEARCH;
4139 /* If the EMACSLOADPATH environment variable is set, use its value.
4140 This doesn't apply if we're dumping. */
4141 if (egetenv ("EMACSLOADPATH"))
4142 Vload_path = decode_env_path ("EMACSLOADPATH", normal);
4143 }
4132 else 4144 else
4133 normal = PATH_DUMPLOADSEARCH; 4145 normal = PATH_DUMPLOADSEARCH;
4134 4146
@@ -4137,184 +4149,158 @@ init_lread (void)
4137 the source directory, instead of the path of the installed elisp 4149 the source directory, instead of the path of the installed elisp
4138 libraries. However, if it appears that Vload_path has already been 4150 libraries. However, if it appears that Vload_path has already been
4139 changed from the default that was saved before dumping, don't 4151 changed from the default that was saved before dumping, don't
4140 change it further. */ 4152 change it further. Changes can only be due to EMACSLOADPATH, or
4153 site-lisp files that were processed during dumping. */
4141 if (initialized) 4154 if (initialized)
4142 { 4155 {
4143 if (! NILP (Fequal (dump_path, Vload_path))) 4156 if (NILP (Fequal (dump_path, Vload_path)))
4157 {
4158 /* Do not make any changes, just check the elements exist. */
4159 /* Note: --no-site-lisp is ignored.
4160 I don't know what to do about this. */
4161 load_path_check ();
4162 }
4163 else
4144 { 4164 {
4165#ifdef HAVE_NS
4166 const char *loadpath = ns_load_path ();
4167 Vload_path = decode_env_path (0, loadpath ? loadpath : normal);
4168#else
4145 Vload_path = decode_env_path (0, normal); 4169 Vload_path = decode_env_path (0, normal);
4146 if (no_site_lisp || !NILP (Vinstallation_directory)) 4170#endif
4171 if (!NILP (Vinstallation_directory))
4147 { 4172 {
4148 Lisp_Object tem, tem1, sitelisp; 4173 Lisp_Object tem, tem1;
4149 4174
4150 /* Remove "site-lisp" dirs from front of path temporarily 4175 /* Add to the path the lisp subdir of the installation
4151 and store them in sitelisp, then conc them on at the 4176 dir, if it exists. Note: in out-of-tree builds,
4152 end so they're always first in path. 4177 this directory is empty save for Makefile. */
4153 Note that this won't work if you used a 4178 tem = Fexpand_file_name (build_string ("lisp"),
4154 --enable-locallisppath element that does not happen 4179 Vinstallation_directory);
4155 to contain "site-lisp" in its name. 4180 tem1 = Ffile_exists_p (tem);
4156 */ 4181 if (!NILP (tem1))
4157 sitelisp = Qnil; 4182 {
4158 while (1) 4183 if (NILP (Fmember (tem, Vload_path)))
4159 { 4184 {
4160 tem = Fcar (Vload_path); 4185 /* We are running uninstalled. The default load-path
4161 tem1 = Fstring_match (build_string ("site-lisp"), 4186 points to the eventual installed lisp, leim
4162 tem, Qnil); 4187 directories. We should not use those now, even
4163 if (!NILP (tem1)) 4188 if they exist, so start over from a clean slate. */
4164 { 4189 Vload_path = Fcons (tem, Qnil);
4165 Vload_path = Fcdr (Vload_path); 4190 }
4166 sitelisp = Fcons (tem, sitelisp); 4191 }
4167 } 4192 else
4168 else 4193 /* That dir doesn't exist, so add the build-time
4169 break; 4194 Lisp dirs instead. */
4170 } 4195 Vload_path = nconc2 (Vload_path, dump_path);
4171 4196
4172 if (!NILP (Vinstallation_directory)) 4197 /* Add leim under the installation dir, if it exists. */
4173 { 4198 tem = Fexpand_file_name (build_string ("leim"),
4174 /* Add to the path the lisp subdir of the 4199 Vinstallation_directory);
4175 installation dir, if it exists. */ 4200 tem1 = Ffile_exists_p (tem);
4176 tem = Fexpand_file_name (build_string ("lisp"), 4201 if (!NILP (tem1))
4177 Vinstallation_directory); 4202 {
4178 tem1 = Ffile_exists_p (tem); 4203 if (NILP (Fmember (tem, Vload_path)))
4179 if (!NILP (tem1)) 4204 Vload_path = Fcons (tem, Vload_path);
4180 { 4205 }
4181 if (NILP (Fmember (tem, Vload_path))) 4206
4182 { 4207 /* Add site-lisp under the installation dir, if it exists. */
4183 turn_off_warning = 1; 4208 if (!no_site_lisp)
4184 Vload_path = Fcons (tem, Vload_path); 4209 {
4185 } 4210 tem = Fexpand_file_name (build_string ("site-lisp"),
4186 } 4211 Vinstallation_directory);
4187 else 4212 tem1 = Ffile_exists_p (tem);
4188 /* That dir doesn't exist, so add the build-time 4213 if (!NILP (tem1))
4189 Lisp dirs instead. */ 4214 {
4190 Vload_path = nconc2 (Vload_path, dump_path); 4215 if (NILP (Fmember (tem, Vload_path)))
4191 4216 Vload_path = Fcons (tem, Vload_path);
4192 /* Add leim under the installation dir, if it exists. */ 4217 }
4193 tem = Fexpand_file_name (build_string ("leim"), 4218 }
4194 Vinstallation_directory); 4219
4195 tem1 = Ffile_exists_p (tem); 4220 /* If Emacs was not built in the source directory,
4196 if (!NILP (tem1)) 4221 and it is run from where it was built, add to load-path
4197 { 4222 the lisp, leim and site-lisp dirs under that directory. */
4198 if (NILP (Fmember (tem, Vload_path))) 4223
4199 Vload_path = Fcons (tem, Vload_path); 4224 if (NILP (Fequal (Vinstallation_directory, Vsource_directory)))
4200 } 4225 {
4201 4226 Lisp_Object tem2;
4202 /* Add site-lisp under the installation dir, if it exists. */ 4227
4203 if (!no_site_lisp) 4228 tem = Fexpand_file_name (build_string ("src/Makefile"),
4204 { 4229 Vinstallation_directory);
4205 tem = Fexpand_file_name (build_string ("site-lisp"), 4230 tem1 = Ffile_exists_p (tem);
4206 Vinstallation_directory); 4231
4207 tem1 = Ffile_exists_p (tem); 4232 /* Don't be fooled if they moved the entire source tree
4208 if (!NILP (tem1)) 4233 AFTER dumping Emacs. If the build directory is indeed
4209 { 4234 different from the source dir, src/Makefile.in and
4210 if (NILP (Fmember (tem, Vload_path))) 4235 src/Makefile will not be found together. */
4211 Vload_path = Fcons (tem, Vload_path); 4236 tem = Fexpand_file_name (build_string ("src/Makefile.in"),
4212 } 4237 Vinstallation_directory);
4213 } 4238 tem2 = Ffile_exists_p (tem);
4214 4239 if (!NILP (tem1) && NILP (tem2))
4215 /* If Emacs was not built in the source directory, 4240 {
4216 and it is run from where it was built, add to load-path 4241 tem = Fexpand_file_name (build_string ("lisp"),
4217 the lisp, leim and site-lisp dirs under that directory. */ 4242 Vsource_directory);
4218 4243
4219 if (NILP (Fequal (Vinstallation_directory, Vsource_directory))) 4244 if (NILP (Fmember (tem, Vload_path)))
4220 { 4245 Vload_path = Fcons (tem, Vload_path);
4221 Lisp_Object tem2; 4246
4222 4247 tem = Fexpand_file_name (build_string ("leim"),
4223 tem = Fexpand_file_name (build_string ("src/Makefile"), 4248 Vsource_directory);
4224 Vinstallation_directory); 4249
4225 tem1 = Ffile_exists_p (tem); 4250 if (NILP (Fmember (tem, Vload_path)))
4226 4251 Vload_path = Fcons (tem, Vload_path);
4227 /* Don't be fooled if they moved the entire source tree 4252
4228 AFTER dumping Emacs. If the build directory is indeed 4253 if (!no_site_lisp)
4229 different from the source dir, src/Makefile.in and 4254 {
4230 src/Makefile will not be found together. */ 4255 tem = Fexpand_file_name (build_string ("site-lisp"),
4231 tem = Fexpand_file_name (build_string ("src/Makefile.in"), 4256 Vsource_directory);
4232 Vinstallation_directory); 4257
4233 tem2 = Ffile_exists_p (tem); 4258 if (NILP (Fmember (tem, Vload_path)))
4234 if (!NILP (tem1) && NILP (tem2)) 4259 Vload_path = Fcons (tem, Vload_path);
4235 { 4260 }
4236 tem = Fexpand_file_name (build_string ("lisp"), 4261 }
4237 Vsource_directory); 4262 } /* Vinstallation_directory != Vsource_directory */
4238 4263
4239 if (NILP (Fmember (tem, Vload_path))) 4264 } /* if Vinstallation_directory */
4240 Vload_path = Fcons (tem, Vload_path); 4265
4241 4266 /* Check before adding the site-lisp directories.
4242 tem = Fexpand_file_name (build_string ("leim"), 4267 The install should have created them, but they are not
4243 Vsource_directory); 4268 required, so no need to warn if they are absent.
4244 4269 Or we might be running before installation. */
4245 if (NILP (Fmember (tem, Vload_path))) 4270 load_path_check ();
4246 Vload_path = Fcons (tem, Vload_path); 4271
4247 4272 /* Add the site-lisp directories at the front. */
4248 if (!no_site_lisp) 4273#ifdef HAVE_NS
4249 { 4274 /* loadpath already includes the app-bundle's site-lisp. */
4250 tem = Fexpand_file_name (build_string ("site-lisp"), 4275 if (!no_site_lisp && !loadpath)
4251 Vsource_directory); 4276#else
4252 4277 if (!no_site_lisp)
4253 if (NILP (Fmember (tem, Vload_path))) 4278#endif
4254 Vload_path = Fcons (tem, Vload_path); 4279 {
4255 } 4280 Lisp_Object sitelisp;
4256 } 4281 sitelisp = decode_env_path (0, PATH_SITELOADSEARCH);
4257 } /* Vinstallation_directory != Vsource_directory */ 4282 if (! NILP (sitelisp)) Vload_path = nconc2 (sitelisp, Vload_path);
4258 } /* if Vinstallation_directory */ 4283 }
4259 if (!NILP (sitelisp) && !no_site_lisp) 4284 } /* if dump_path == Vload_path */
4260 Vload_path = nconc2 (Fnreverse (sitelisp), Vload_path);
4261 } /* if Vinstallation_directory || no_site_lisp */
4262 } /* if dump_path == Vload_path */
4263 } 4285 }
4264 else /* !initialized */ 4286 else /* !initialized */
4265 { 4287 {
4266 /* NORMAL refers to the lisp dir in the source directory. */ 4288 /* NORMAL refers to PATH_DUMPLOADSEARCH, ie the lisp dir in the
4267 /* We used to add ../lisp at the front here, but 4289 source directory. We used to add ../lisp (ie the lisp dir in
4268 that caused trouble because it was copied from dump_path 4290 the build directory) at the front here, but that caused trouble
4269 into Vload_path, above, when Vinstallation_directory was non-nil. 4291 because it was copied from dump_path into Vload_path, above,
4270 It should be unnecessary. */ 4292 when Vinstallation_directory was non-nil. It should not be
4293 necessary, since in out of tree builds lisp/ is empty, save
4294 for Makefile. */
4271 Vload_path = decode_env_path (0, normal); 4295 Vload_path = decode_env_path (0, normal);
4272 dump_path = Vload_path; 4296 dump_path = Vload_path;
4297 /* No point calling load_path_check; load-path only contains essential
4298 elements from the source directory at this point. They cannot
4299 be missing unless something went extremely (and improbably)
4300 wrong, in which case the build will fail in obvious ways. */
4273 } 4301 }
4274#endif /* CANNOT_DUMP */ 4302#endif /* CANNOT_DUMP */
4275 4303
4276#if (!(defined (WINDOWSNT) || (defined (HAVE_NS))))
4277 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
4278 almost never correct, thereby causing a warning to be printed out that
4279 confuses users. Since PATH_LOADSEARCH is always overridden by the
4280 EMACSLOADPATH environment variable below, disable the warning on NT. */
4281
4282 /* HAVE_NS also uses EMACSLOADPATH. */
4283
4284 /* Warn if dirs in the *standard* path don't exist. */
4285 if (!turn_off_warning)
4286 {
4287 Lisp_Object path_tail;
4288
4289 for (path_tail = Vload_path;
4290 !NILP (path_tail);
4291 path_tail = XCDR (path_tail))
4292 {
4293 Lisp_Object dirfile;
4294 dirfile = Fcar (path_tail);
4295 if (STRINGP (dirfile))
4296 {
4297 dirfile = Fdirectory_file_name (dirfile);
4298 /* Do we really need to warn about missing site-lisp dirs?
4299 It's true that the installation should have created
4300 them and added subdirs.el, but it's harmless if they
4301 are not there. */
4302 if (access (SSDATA (dirfile), 0) < 0)
4303 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
4304 XCAR (path_tail));
4305 }
4306 }
4307 }
4308#endif /* !(WINDOWSNT || HAVE_NS) */
4309
4310 /* If the EMACSLOADPATH environment variable is set, use its value.
4311 This doesn't apply if we're dumping. */
4312#ifndef CANNOT_DUMP
4313 if (NILP (Vpurify_flag)
4314 && egetenv ("EMACSLOADPATH"))
4315#endif
4316 Vload_path = decode_env_path ("EMACSLOADPATH", normal);
4317
4318 Vvalues = Qnil; 4304 Vvalues = Qnil;
4319 4305
4320 load_in_progress = 0; 4306 load_in_progress = 0;
@@ -4427,8 +4413,8 @@ otherwise to default specified by file `epaths.h' when Emacs was built. */);
4427This list should not include the empty string. 4413This list should not include the empty string.
4428`load' and related functions try to append these suffixes, in order, 4414`load' and related functions try to append these suffixes, in order,
4429to the specified file name if a Lisp suffix is allowed or required. */); 4415to the specified file name if a Lisp suffix is allowed or required. */);
4430 Vload_suffixes = Fcons (make_pure_c_string (".elc"), 4416 Vload_suffixes = Fcons (build_pure_c_string (".elc"),
4431 Fcons (make_pure_c_string (".el"), Qnil)); 4417 Fcons (build_pure_c_string (".el"), Qnil));
4432 DEFVAR_LISP ("load-file-rep-suffixes", Vload_file_rep_suffixes, 4418 DEFVAR_LISP ("load-file-rep-suffixes", Vload_file_rep_suffixes,
4433 doc: /* List of suffixes that indicate representations of \ 4419 doc: /* List of suffixes that indicate representations of \
4434the same file. 4420the same file.
@@ -4561,7 +4547,7 @@ from the file, and matches them against this regular expression.
4561When the regular expression matches, the file is considered to be safe 4547When the regular expression matches, the file is considered to be safe
4562to load. See also `load-dangerous-libraries'. */); 4548to load. See also `load-dangerous-libraries'. */);
4563 Vbytecomp_version_regexp 4549 Vbytecomp_version_regexp
4564 = make_pure_c_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)"); 4550 = build_pure_c_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)");
4565 4551
4566 Qlexical_binding = intern ("lexical-binding"); 4552 Qlexical_binding = intern ("lexical-binding");
4567 staticpro (&Qlexical_binding); 4553 staticpro (&Qlexical_binding);