comparison src/lread.c @ 16:0293115a14e9 r19-15b91

Import from CVS: tag r19-15b91
author cvs
date Mon, 13 Aug 2007 08:49:20 +0200
parents 376386a54a3c
children 859a2309aef8
comparison
equal deleted inserted replaced
15:ad457d5f7d04 16:0293115a14e9
131 131
132 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK 132 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
133 Lisp_Object Vcurrent_compiled_function_annotation; 133 Lisp_Object Vcurrent_compiled_function_annotation;
134 #endif 134 #endif
135 135
136 static int load_byte_code_version;
137
136 /* An array describing all known built-in structure types */ 138 /* An array describing all known built-in structure types */
137 static Structure_type_dynarr *the_structure_type_dynarr; 139 static Structure_type_dynarr *the_structure_type_dynarr;
138 140
139 #if 0 /* FSFmacs defun hack */ 141 #if 0 /* FSFmacs defun hack */
140 /* When nonzero, read conses in pure space */ 142 /* When nonzero, read conses in pure space */
228 230
229 return c; 231 return c;
230 } 232 }
231 else if (LSTREAMP (readcharfun)) 233 else if (LSTREAMP (readcharfun))
232 { 234 {
233 return Lstream_get_emchar (XLSTREAM (readcharfun)); 235 Emchar c = Lstream_get_emchar (XLSTREAM (readcharfun));
236 #ifdef DEBUG_XEMACS /* testing Mule */
237 static int testing_mule = 0; /* Change via debugger */
238 if (testing_mule) {
239 if (c >= 0x20 && c <= 0x7E) fprintf (stderr, "%c", c);
240 else if (c == '\n') fprintf (stderr, "\\n\n");
241 else fprintf (stderr, "\\%o ", c);
242 }
243 #endif
244 return c;
234 } 245 }
235 else if (MARKERP (readcharfun)) 246 else if (MARKERP (readcharfun))
236 { 247 {
237 Emchar c; 248 Emchar c;
238 Bufpos mpos = marker_position (readcharfun); 249 Bufpos mpos = marker_position (readcharfun);
267 else if (BUFFERP (readcharfun)) 278 else if (BUFFERP (readcharfun))
268 BUF_SET_PT (XBUFFER (readcharfun), BUF_PT (XBUFFER (readcharfun)) - 1); 279 BUF_SET_PT (XBUFFER (readcharfun), BUF_PT (XBUFFER (readcharfun)) - 1);
269 else if (LSTREAMP (readcharfun)) 280 else if (LSTREAMP (readcharfun))
270 { 281 {
271 Lstream_unget_emchar (XLSTREAM (readcharfun), c); 282 Lstream_unget_emchar (XLSTREAM (readcharfun), c);
283 #ifdef DEBUG_XEMACS /* testing Mule */
284 {
285 static int testing_mule = 0; /* Set this using debugger */
286 if (testing_mule)
287 fprintf (stderr,
288 (c >= 0x20 && c <= 0x7E) ? "UU%c" :
289 ((c == '\n') ? "UU\\n\n" : "UU\\%o"), c);
290 }
291 #endif
272 } 292 }
273 else if (MARKERP (readcharfun)) 293 else if (MARKERP (readcharfun))
274 set_marker_position (readcharfun, marker_position (readcharfun) - 1); 294 set_marker_position (readcharfun, marker_position (readcharfun) - 1);
275 else 295 else
276 call1 (readcharfun, make_char (c)); 296 call1 (readcharfun, make_char (c));
475 int source_only = 0; 495 int source_only = 0;
476 Lisp_Object newer = Qnil; 496 Lisp_Object newer = Qnil;
477 Lisp_Object handler = Qnil; 497 Lisp_Object handler = Qnil;
478 Lisp_Object found = Qnil; 498 Lisp_Object found = Qnil;
479 struct gcpro gcpro1, gcpro2, gcpro3; 499 struct gcpro gcpro1, gcpro2, gcpro3;
500 int reading_elc = 0;
501 int message_p = NILP (nomessage);
480 #ifdef DEBUG_XEMACS 502 #ifdef DEBUG_XEMACS
503 static Lisp_Object last_file_loaded;
481 int pure_usage = 0; 504 int pure_usage = 0;
482 #endif 505 #endif
483 #ifdef DOS_NT 506 #ifdef DOS_NT
484 int dosmode = O_TEXT; 507 int dosmode = O_TEXT;
485 #endif /* DOS_NT */ 508 #endif /* DOS_NT */
487 510
488 CHECK_STRING (file); 511 CHECK_STRING (file);
489 512
490 #ifdef DEBUG_XEMACS 513 #ifdef DEBUG_XEMACS
491 if (purify_flag && noninteractive) 514 if (purify_flag && noninteractive)
492 pure_usage = purespace_usage (); 515 {
493 #endif 516 message_p = 1;
517 last_file_loaded = file;
518 pure_usage = purespace_usage ();
519 }
520 #endif /* DEBUG_XEMACS */
494 521
495 /* If file name is magic, call the handler. */ 522 /* If file name is magic, call the handler. */
496 handler = Ffind_file_name_handler (file, Qload); 523 handler = Ffind_file_name_handler (file, Qload);
497 if (!NILP (handler)) 524 if (!NILP (handler))
498 { 525 RETURN_UNGCPRO (call5 (handler, Qload, file, no_error,
499 RETURN_UNGCPRO (call5 (handler, Qload, file, no_error, nomessage, 526 nomessage, nosuffix));
500 nosuffix));
501 }
502 527
503 /* Do this after the handler to avoid 528 /* Do this after the handler to avoid
504 the need to gcpro noerror, nomessage and nosuffix. 529 the need to gcpro noerror, nomessage and nosuffix.
505 (Below here, we care only whether they are nil or not.) */ 530 (Below here, we care only whether they are nil or not.) */
506 file = Fsubstitute_in_file_name (file); 531 file = Fsubstitute_in_file_name (file);
507 532
533
508 /* Avoid weird lossage with null string as arg, 534 /* Avoid weird lossage with null string as arg,
509 since it would try to load a directory as a Lisp file. 535 since it would try to load a directory as a Lisp file.
510 Unix truly sucks. */ 536 Unix truly sucks. */
511 if (string_length (XSTRING (file)) > 0) 537 if (XSTRING_LENGTH (file) > 0)
512 { 538 {
513 char *foundstr; 539 char *foundstr;
514 int foundlen; 540 int foundlen;
515 541
516 fd = locate_file (Vload_path, file, 542 fd = locate_file (Vload_path, file,
529 UNGCPRO; 555 UNGCPRO;
530 return Qnil; 556 return Qnil;
531 } 557 }
532 } 558 }
533 559
534 foundstr = (char *) alloca (string_length (XSTRING (found)) + 1); 560 foundstr = (char *) alloca (XSTRING_LENGTH (found) + 1);
535 strcpy (foundstr, (char *) string_data (XSTRING (found))); 561 strcpy (foundstr, (char *) XSTRING_DATA (found));
536 foundlen = strlen (foundstr); 562 foundlen = strlen (foundstr);
537 563
538 /* The omniscient JWZ thinks this is worthless, but I beg to 564 /* The omniscient JWZ thinks this is worthless, but I beg to
539 differ. --ben */ 565 differ. --ben */
540 if (load_ignore_elc_files) 566 if (load_ignore_elc_files)
568 else if (load_warn_when_source_only && 594 else if (load_warn_when_source_only &&
569 /* `found' ends in ".el" */ 595 /* `found' ends in ".el" */
570 !memcmp (".el", foundstr + foundlen - 3, 3) && 596 !memcmp (".el", foundstr + foundlen - 3, 3) &&
571 /* `file' does not end in ".el" */ 597 /* `file' does not end in ".el" */
572 memcmp (".el", 598 memcmp (".el",
573 string_data (XSTRING (file)) + 599 XSTRING_DATA (file) + XSTRING_LENGTH (file) - 3,
574 string_length (XSTRING (file)) - 3,
575 3)) 600 3))
576 { 601 {
577 source_only = 1; 602 source_only = 1;
578 } 603 }
604
605 if (!memcmp (".elc", foundstr + foundlen - 4, 4))
606 reading_elc = 1;
579 } 607 }
580 608
581 #ifdef DOS_NT 609 #ifdef DOS_NT
582 /* The file was opened as binary, because that's what we'll 610 /* The file was opened as binary, because that's what we'll
583 encounter most of the time. If we're loading a .el, we need 611 encounter most of the time. If we're loading a .el, we need
584 to reopen it in text mode. */ 612 to reopen it in text mode. */
585 if (!memcmp (".elc", foundstr + foundlen - 4, 4)) 613 if (!reading_elc)
586 ;
587 else
588 fd = open (foundstr, O_RDONLY | O_TEXT); 614 fd = open (foundstr, O_RDONLY | O_TEXT);
589 #endif /* not DOS_NT */ 615 #endif /* DOS_NT */
590 616
591 if (load_ignore_elc_files) 617 #define PRINT_LOADING_MESSAGE(done) do { \
592 { 618 if (load_ignore_elc_files) \
593 if (noninteractive || NILP (nomessage)) 619 { \
594 message ("Loading %s...", string_data (XSTRING (newer))); 620 if (message_p) \
595 } 621 message ("Loading %s..." done, XSTRING_DATA (newer)); \
596 else if (!NILP (newer)) 622 } \
597 { 623 else if (!NILP (newer)) \
598 message ("Loading %s... (file %s is newer)", 624 message ("Loading %s..." done " (file %s is newer)", \
599 string_data (XSTRING (file)), 625 XSTRING_DATA (file), \
600 string_data (XSTRING (newer))); 626 XSTRING_DATA (newer)); \
601 nomessage = Qnil; /* we printed the first one, so print "done" too */ 627 else if (source_only) \
602 } 628 message ("Loading %s..." done " (file %s.elc does not exist)", \
603 else if (source_only) 629 XSTRING_DATA (file), \
604 { 630 XSTRING_DATA (Ffile_name_nondirectory (file))); \
605 message ("Loading %s... (file %s.elc does not exist)", 631 else if (message_p) \
606 string_data (XSTRING (file)), 632 message ("Loading %s..." done, XSTRING_DATA (file)); \
607 string_data (XSTRING (Ffile_name_nondirectory (file)))); 633 } while (0)
608 nomessage = Qnil; 634
609 } 635 PRINT_LOADING_MESSAGE ("");
610 else if (noninteractive || NILP (nomessage))
611 message ("Loading %s...", string_data (XSTRING (file)));
612 636
613 { 637 {
614 /* Lisp_Object's must be malloc'ed, not stack-allocated */ 638 /* Lisp_Object's must be malloc'ed, not stack-allocated */
615 Lisp_Object lispstream = Qnil; 639 Lisp_Object lispstream = Qnil;
616 CONST int block_size = 8192; 640 CONST int block_size = 8192;
633 record_unwind_protect (load_force_doc_string_unwind, 657 record_unwind_protect (load_force_doc_string_unwind,
634 Vload_force_doc_string_list); 658 Vload_force_doc_string_list);
635 Vload_file_name_internal = found; 659 Vload_file_name_internal = found;
636 Vload_file_name_internal_the_purecopy = Qnil; 660 Vload_file_name_internal_the_purecopy = Qnil;
637 specbind (Qload_file_name, found); 661 specbind (Qload_file_name, found);
638 Vload_descriptor_list 662 Vload_descriptor_list = Fcons (make_int (fd), Vload_descriptor_list);
639 = Fcons (make_int (fd), Vload_descriptor_list);
640 Vload_force_doc_string_list = Qnil; 663 Vload_force_doc_string_list = Qnil;
641 #ifdef I18N3 664 #ifdef I18N3
642 record_unwind_protect (restore_file_domain, Vfile_domain); 665 record_unwind_protect (restore_file_domain, Vfile_domain);
643 Vfile_domain = Qnil; /* set it to nil; a call to #'domain will set it. */ 666 Vfile_domain = Qnil; /* set it to nil; a call to #'domain will set it. */
644 #endif 667 #endif
665 NUNGCPRO; 688 NUNGCPRO;
666 } 689 }
667 } 690 }
668 691
669 #ifdef DEBUG_XEMACS 692 #ifdef DEBUG_XEMACS
670 if (noninteractive && purify_flag) 693 if (purify_flag && noninteractive)
671 { 694 {
672 int this_pure_usage = purespace_usage () - pure_usage; 695 if (EQ (last_file_loaded, file))
673 message_append (" (%d)", this_pure_usage); 696 message_append (" (%d)", purespace_usage() - pure_usage);
674 } 697 else
675 #endif 698 message ("Loading %s ...done (%d)", XSTRING_DATA (file),
676 699 purespace_usage() - pure_usage);
677 if (noninteractive || !NILP (nomessage)) 700 }
678 ; 701 #endif
679 else if (!NILP (newer)) 702
680 message ("Loading %s...done (file %s is newer)", 703 if (!noninteractive)
681 string_data (XSTRING (file)), 704 PRINT_LOADING_MESSAGE ("done");
682 string_data (XSTRING (newer))); 705
683 else
684 message ("Loading %s...done", string_data (XSTRING (file)));
685
686 UNGCPRO; 706 UNGCPRO;
687 return Qt; 707 return Qt;
688 } 708 }
689 709
690 710
691 #if 0 /* FSFmacs */ 711 #if 0 /* FSFmacs */
692 /* not used */ 712 /* not used */
693 static int 713 static int
694 complete_filename_p (Lisp_Object pathname) 714 complete_filename_p (Lisp_Object pathname)
695 { 715 {
696 REGISTER unsigned char *s = string_data (XSTRING (pathname)); 716 REGISTER unsigned char *s = XSTRING_DATA (pathname);
697 return (IS_DIRECTORY_SEP (s[0]) 717 return (IS_DIRECTORY_SEP (s[0])
698 || (string_length (XSTRING (pathname)) > 2 718 || (XSTRING_LENGTH (pathname) > 2
699 && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2])) 719 && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2]))
700 #ifdef ALTOS 720 #ifdef ALTOS
701 || *s == '@' 721 || *s == '@'
702 #endif 722 #endif
703 #ifdef VMS 723 #ifdef VMS
732 } 752 }
733 if (!(NILP (mode) || (INTP (mode) && XINT (mode) >= 0))) 753 if (!(NILP (mode) || (INTP (mode) && XINT (mode) >= 0)))
734 mode = wrong_type_argument (Qnatnump, mode); 754 mode = wrong_type_argument (Qnatnump, mode);
735 locate_file (path_list, filename, 755 locate_file (path_list, filename,
736 ((NILP (suffixes)) ? "" : 756 ((NILP (suffixes)) ? "" :
737 (char *) (string_data (XSTRING (suffixes)))), 757 (char *) (XSTRING_DATA (suffixes))),
738 &tp, (NILP (mode) ? R_OK : XINT (mode))); 758 &tp, (NILP (mode) ? R_OK : XINT (mode)));
739 return tp; 759 return tp;
740 } 760 }
741 761
742 /* recalculate the hash table for the given string */ 762 /* recalculate the hash table for the given string */
743 763
744 static Lisp_Object 764 static Lisp_Object
745 locate_file_refresh_hashing (Lisp_Object str) 765 locate_file_refresh_hashing (Lisp_Object str)
746 { 766 {
747 Lisp_Object hash = 767 Lisp_Object hash =
748 make_directory_hash_table ((char *) string_data (XSTRING (str))); 768 make_directory_hash_table ((char *) XSTRING_DATA (str));
749 Fput (str, Qlocate_file_hash_table, hash); 769 Fput (str, Qlocate_file_hash_table, hash);
750 return hash; 770 return hash;
751 } 771 }
752 772
753 /* find the hash table for the given string, recalculating if necessary */ 773 /* find the hash table for the given string, recalculating if necessary */
800 return -1; 820 return -1;
801 } 821 }
802 } 822 }
803 /* Calculate maximum size of any filename made from 823 /* Calculate maximum size of any filename made from
804 this path element/specified file name and any possible suffix. */ 824 this path element/specified file name and any possible suffix. */
805 want_size = strlen (suffix) + 825 want_size = strlen (suffix) + XSTRING_LENGTH (filename) + 1;
806 string_length (XSTRING (filename)) + 1;
807 if (fn_size < want_size) 826 if (fn_size < want_size)
808 fn = (char *) alloca (fn_size = 100 + want_size); 827 fn = (char *) alloca (fn_size = 100 + want_size);
809 828
810 nsuffix = suffix; 829 nsuffix = suffix;
811 830
814 { 833 {
815 char *esuffix = (char *) strchr (nsuffix, ':'); 834 char *esuffix = (char *) strchr (nsuffix, ':');
816 int lsuffix = ((esuffix) ? (esuffix - nsuffix) : strlen (nsuffix)); 835 int lsuffix = ((esuffix) ? (esuffix - nsuffix) : strlen (nsuffix));
817 836
818 /* Concatenate path element/specified name with the suffix. */ 837 /* Concatenate path element/specified name with the suffix. */
819 strncpy (fn, (char *) string_data (XSTRING (filename)), 838 strncpy (fn, (char *) XSTRING_DATA (filename),
820 string_length (XSTRING (filename))); 839 XSTRING_LENGTH (filename));
821 fn[string_length (XSTRING (filename))] = 0; 840 fn[XSTRING_LENGTH (filename)] = 0;
822 if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */ 841 if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */
823 strncat (fn, nsuffix, lsuffix); 842 strncat (fn, nsuffix, lsuffix);
824 843
825 /* Ignore file if it's a directory. */ 844 /* Ignore file if it's a directory. */
826 if (stat (fn, &st) >= 0 845 if (stat (fn, &st) >= 0
908 CONST char *nsuffix; 927 CONST char *nsuffix;
909 Lisp_Object suffixtab = Qnil; 928 Lisp_Object suffixtab = Qnil;
910 929
911 /* Calculate maximum size of any filename made from 930 /* Calculate maximum size of any filename made from
912 this path element/specified file name and any possible suffix. */ 931 this path element/specified file name and any possible suffix. */
913 want_size = strlen (suffix) + string_length (XSTRING (str)) + 1; 932 want_size = strlen (suffix) + XSTRING_LENGTH (str) + 1;
914 if (fn_size < want_size) 933 if (fn_size < want_size)
915 fn = (char *) alloca (fn_size = 100 + want_size); 934 fn = (char *) alloca (fn_size = 100 + want_size);
916 935
917 nsuffix = suffix; 936 nsuffix = suffix;
918 937
920 { 939 {
921 char *esuffix = (char *) strchr (nsuffix, ':'); 940 char *esuffix = (char *) strchr (nsuffix, ':');
922 int lsuffix = ((esuffix) ? (esuffix - nsuffix) : strlen (nsuffix)); 941 int lsuffix = ((esuffix) ? (esuffix - nsuffix) : strlen (nsuffix));
923 942
924 /* Concatenate path element/specified name with the suffix. */ 943 /* Concatenate path element/specified name with the suffix. */
925 strncpy (fn, (char *) string_data (XSTRING (str)), 944 strncpy (fn, (char *) XSTRING_DATA (str), XSTRING_LENGTH (str));
926 string_length (XSTRING (str))); 945 fn[XSTRING_LENGTH (str)] = 0;
927 fn[string_length (XSTRING (str))] = 0;
928 if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */ 946 if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */
929 strncat (fn, nsuffix, lsuffix); 947 strncat (fn, nsuffix, lsuffix);
930 948
931 suffixtab = Fcons (build_string (fn), suffixtab); 949 suffixtab = Fcons (build_string (fn), suffixtab);
932 /* Advance to next suffix. */ 950 /* Advance to next suffix. */
1406 /* Yeah, it's ugly. Gonna make something of it? 1424 /* Yeah, it's ugly. Gonna make something of it?
1407 At least our reader is reentrant ... */ 1425 At least our reader is reentrant ... */
1408 tem = 1426 tem =
1409 (Fcons (tem, make_int 1427 (Fcons (tem, make_int
1410 (bytecount_to_charcount 1428 (bytecount_to_charcount
1411 (string_data (XSTRING (string)), 1429 (XSTRING_DATA (string),
1412 startval + Lstream_byte_count (XLSTREAM (lispstream)))))); 1430 startval + Lstream_byte_count (XLSTREAM (lispstream))))));
1413 Lstream_delete (XLSTREAM (lispstream)); 1431 Lstream_delete (XLSTREAM (lispstream));
1414 UNGCPRO; 1432 UNGCPRO;
1415 return tem; 1433 return tem;
1416 } 1434 }
1565 break; 1583 break;
1566 } 1584 }
1567 } 1585 }
1568 return i; 1586 return i;
1569 } 1587 }
1588
1570 1589
1571 default: 1590 default:
1572 return c; 1591 return c;
1573 } 1592 }
1574 } 1593 }
2625 { 2644 {
2626 if (purify_flag) 2645 if (purify_flag)
2627 { 2646 {
2628 if (NILP (Vdoc_file_name)) 2647 if (NILP (Vdoc_file_name))
2629 /* We have not yet called Snarf-documentation, so 2648 /* We have not yet called Snarf-documentation, so
2630 assume this file is described in the DOC-MM.NN 2649 assume this file is described in the DOC file
2631 file and Snarf-documentation will fill in the 2650 and Snarf-documentation will fill in the right
2632 right value later. For now, replace the whole 2651 value later. For now, replace the whole list
2633 list with 0. */ 2652 with 0. */
2634 XCAR (holding_cons) = Qzero; 2653 XCAR (holding_cons) = Qzero;
2635 else 2654 else
2636 /* We have already called Snarf-documentation, so 2655 /* We have already called Snarf-documentation, so
2637 make a relative file name for this file, so it 2656 make a relative file name for this file, so it
2638 can be found properly in the installed Lisp 2657 can be found properly in the installed Lisp
2796 Lisp_Object dirfile; 2815 Lisp_Object dirfile;
2797 dirfile = Fcar (normal_path); 2816 dirfile = Fcar (normal_path);
2798 if (!NILP (dirfile)) 2817 if (!NILP (dirfile))
2799 { 2818 {
2800 dirfile = Fdirectory_file_name (dirfile); 2819 dirfile = Fdirectory_file_name (dirfile);
2801 if (access ((char *) string_data (XSTRING (dirfile)), 0) < 0) 2820 if (access ((char *) XSTRING_DATA (dirfile), 0) < 0)
2802 stdout_out ("Warning: lisp library (%s) does not exist.\n", 2821 stdout_out ("Warning: lisp library (%s) does not exist.\n",
2803 string_data (XSTRING (Fcar (normal_path)))); 2822 XSTRING_DATA (Fcar (normal_path)));
2804 } 2823 }
2805 } 2824 }
2806 } 2825 }
2807 #endif /* WINDOWSNT */ 2826 #endif /* WINDOWSNT */
2808 #endif /* 0 */ 2827 #endif /* 0 */