comparison src/lread.c @ 5605:cc7f8a0e569a

Accept bignums unambiguously in the syntax for object labels, lread.c. src/ChangeLog addition: 2011-12-03 Aidan Kehoe <kehoea@parhasard.net> * lread.c (read1): Don't wrap when reading expressions that use bignums as object labels, that can lead to ambiguity and it's not actually that hard to use parse_integer() to avoid it. tests/ChangeLog addition: 2011-12-03 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-reader-tests.el: Check that integer object labels (using the #N=... syntax) treat bignums as such, rather than as fixnums that have wrapped.
author Aidan Kehoe <kehoea@parhasard.net>
date Sat, 03 Dec 2011 15:13:55 +0000
parents 56144c8593a8
children 7c383c5784ed
comparison
equal deleted inserted replaced
5604:e9f58d024c3c 5605:cc7f8a0e569a
2695 #endif 2695 #endif
2696 case '0': case '1': case '2': case '3': case '4': 2696 case '0': case '1': case '2': case '3': case '4':
2697 case '5': case '6': case '7': case '8': case '9': 2697 case '5': case '6': case '7': case '8': case '9':
2698 /* Reader forms that can reuse previously read objects. */ 2698 /* Reader forms that can reuse previously read objects. */
2699 { 2699 {
2700 int n = 0; 2700 Lisp_Object parsed, found;
2701 Lisp_Object found; 2701
2702 Lstream_rewind (XLSTREAM (Vread_buffer_stream));
2702 2703
2703 /* Using read_integer() here is impossible, because it 2704 /* Using read_integer() here is impossible, because it
2704 chokes on `='. Using parse_integer() is too hard. 2705 chokes on `='. */
2705 So we simply read it in, and ignore overflows, which
2706 is safe. */
2707 while (c >= '0' && c <= '9') 2706 while (c >= '0' && c <= '9')
2708 { 2707 {
2709 n *= 10; 2708 Lstream_put_ichar (XLSTREAM (Vread_buffer_stream), c);
2710 n += c - '0'; 2709 QUIT;
2711 c = readchar (readcharfun); 2710 c = readchar (readcharfun);
2712 } 2711 }
2713 found = assq_no_quit (make_fixnum (n), Vread_objects); 2712
2713 Lstream_flush (XLSTREAM (Vread_buffer_stream));
2714
2715 parsed
2716 = parse_integer (resizing_buffer_stream_ptr
2717 (XLSTREAM (Vread_buffer_stream)),
2718 Lstream_byte_count (XLSTREAM
2719 (Vread_buffer_stream)),
2720 10);
2721
2722 found = assoc_no_quit (parsed, Vread_objects);
2714 if (c == '=') 2723 if (c == '=')
2715 { 2724 {
2716 /* #n=object returns object, but associates it with 2725 /* #n=object returns object, but associates it with
2717 n for #n#. */ 2726 n for #n#. */
2718 if (CONSP (found)) 2727 if (CONSP (found))
2719 { 2728 {
2720 return Fsignal (Qinvalid_read_syntax, 2729 return Fsignal (Qinvalid_read_syntax,
2721 list2 (build_msg_string 2730 list2 (build_msg_string
2722 ("Multiply defined object label"), 2731 ("Multiply defined object label"),
2723 make_fixnum (n))); 2732 parsed));
2724 } 2733 }
2725 else 2734 else
2726 { 2735 {
2727 Lisp_Object object; 2736 Lisp_Object object;
2728 2737
2729 found = Fcons (make_fixnum (n), Qnil); 2738 found = Fcons (parsed, Qnil);
2730 /* Make FOUND a placeholder for the object that will 2739 /* Make FOUND a placeholder for the object that will
2731 be read. (We've just consed it, and it's not 2740 be read. (We've just consed it, and it's not
2732 visible from Lisp, so there's no possibility of 2741 visible from Lisp, so there's no possibility of
2733 confusing it with something else in the read 2742 confusing it with something else in the read
2734 structure.) */ 2743 structure.) */
2749 return XCDR (found); 2758 return XCDR (found);
2750 else 2759 else
2751 return Fsignal (Qinvalid_read_syntax, 2760 return Fsignal (Qinvalid_read_syntax,
2752 list2 (build_msg_string 2761 list2 (build_msg_string
2753 ("Undefined symbol label"), 2762 ("Undefined symbol label"),
2754 make_fixnum (n))); 2763 parsed));
2755 } 2764 }
2756 return Fsignal (Qinvalid_read_syntax, 2765 return Fsignal (Qinvalid_read_syntax,
2757 list1 (build_ascstring ("#"))); 2766 list1 (build_ascstring ("#")));
2758 } 2767 }
2759 default: 2768 default: