comparison lisp/bytecomp.el @ 4623:a9f83990e6bf

Fix a byte compiler bug with characters above ?\xFF. lisp/ChangeLog addition: 2009-02-22 Aidan Kehoe <kehoea@parhasard.net> * bytecomp.el (byte-compile-force-escape-quoted): New variable, used to force `byte-compile-insert-header' to treat the output as having characters above ?\xFF. (byte-compile-from-buffer): If the compiled output contains characters above ?\xFF, and byte-compile-dynamic-docstrings or byte-compile-dynamic is non-nil (or we're using an inappropriate coding system) recompile the file, turning off the dynamic features and using a more appropriate header. (byte-compile-insert-header): Pay attention to byte-compile-force-escape-quoted. tests/ChangeLog addition: 2009-02-22 Aidan Kehoe <kehoea@parhasard.net> * automated/mule-tests.el: Use more realistic tests for the escape-quoted mule encoding checks; update a comment, change a Known-Bug-Expect-Failure to a normal test now that we've addressed an old bug.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 22 Feb 2009 19:57:28 +0000
parents 061e030e3270
children 7757334005ae
comparison
equal deleted inserted replaced
4622:8cbca852bcd4 4623:a9f83990e6bf
436 "list of all variables encountered during compilation of this form") 436 "list of all variables encountered during compilation of this form")
437 (defvar byte-compile-bound-variables nil 437 (defvar byte-compile-bound-variables nil
438 "Alist of variables bound in the context of the current form, 438 "Alist of variables bound in the context of the current form,
439 that is, the current lexical environment. This list lives partly 439 that is, the current lexical environment. This list lives partly
440 on the specbind stack. The cdr of each cell is an integer bitmask.") 440 on the specbind stack. The cdr of each cell is an integer bitmask.")
441
442 (defvar byte-compile-force-escape-quoted nil
443 "If non-nil, `byte-compile-insert-header' always adds a coding cookie.
444
445 This is for situations where the byte compiler output file needs to be
446 able to encode character values above ?\\xFF, but this cannot be
447 easily determined from the input file.")
441 448
442 (defconst byte-compile-referenced-bit 1) 449 (defconst byte-compile-referenced-bit 1)
443 (defconst byte-compile-assigned-bit 2) 450 (defconst byte-compile-assigned-bit 2)
444 (defconst byte-compile-arglist-bit 4) 451 (defconst byte-compile-arglist-bit 4)
445 (defconst byte-compile-global-bit 8) 452 (defconst byte-compile-global-bit 8)
1708 (byte-compile-output nil) 1715 (byte-compile-output nil)
1709 ;; #### This is bound in b-c-close-variables. 1716 ;; #### This is bound in b-c-close-variables.
1710 ;; (byte-compile-warnings (if (eq byte-compile-warnings t) 1717 ;; (byte-compile-warnings (if (eq byte-compile-warnings t)
1711 ;; byte-compile-warning-types 1718 ;; byte-compile-warning-types
1712 ;; byte-compile-warnings)) 1719 ;; byte-compile-warnings))
1720 (byte-compile-force-escape-quoted byte-compile-force-escape-quoted)
1721 (byte-compile-using-dynamic nil)
1722 (byte-compile-using-escape-quoted nil)
1713 ) 1723 )
1714 (byte-compile-close-variables 1724 (byte-compile-close-variables
1715 (save-excursion 1725 (save-excursion
1716 (setq byte-compile-outbuffer 1726 (setq byte-compile-outbuffer
1717 (set-buffer (get-buffer-create " *Compiler Output*"))) 1727 (set-buffer (get-buffer-create " *Compiler Output*")))
1721 (and filename 1731 (and filename
1722 (not eval) 1732 (not eval)
1723 (byte-compile-insert-header filename 1733 (byte-compile-insert-header filename
1724 byte-compile-inbuffer 1734 byte-compile-inbuffer
1725 byte-compile-outbuffer)) 1735 byte-compile-outbuffer))
1726 1736 (setq byte-compile-using-dynamic
1737 (or (symbol-value-in-buffer 'byte-compile-dynamic
1738 byte-compile-inbuffer)
1739 (symbol-value-in-buffer 'byte-compile-dynamic-docstrings
1740 byte-compile-inbuffer)))
1727 ;; This is a kludge. Some operating systems (OS/2, DOS) need to 1741 ;; This is a kludge. Some operating systems (OS/2, DOS) need to
1728 ;; write files containing binary information specially. 1742 ;; write files containing binary information specially.
1729 ;; Under most circumstances, such files will be in binary 1743 ;; Under most circumstances, such files will be in binary
1730 ;; overwrite mode, so those OS's use that flag to guess how 1744 ;; overwrite mode, so those OS's use that flag to guess how
1731 ;; they should write their data. Advise them that .elc files 1745 ;; they should write their data. Advise them that .elc files
1732 ;; need to be written carefully. 1746 ;; need to be written carefully.
1733 (setq overwrite-mode 'overwrite-mode-binary)) 1747 (setq overwrite-mode 'overwrite-mode-binary))
1734 (displaying-byte-compile-warnings 1748 (displaying-byte-compile-warnings
1735 (save-excursion 1749 (save-excursion
1750 ;; All our save-excursions may have led to a less-than-useful
1751 ;; value for point in the outbuffer:
1752 (goto-char (point-max byte-compile-outbuffer) byte-compile-outbuffer)
1736 (set-buffer byte-compile-inbuffer) 1753 (set-buffer byte-compile-inbuffer)
1737 (goto-char 1) 1754 (goto-char 1)
1738 1755
1739 ;; Compile the forms from the input buffer. 1756 ;; Compile the forms from the input buffer.
1740 (while (progn 1757 (while (progn
1751 ;; would be useful to delay this warning until all have 1768 ;; would be useful to delay this warning until all have
1752 ;; been compiled. 1769 ;; been compiled.
1753 (setq byte-compile-unresolved-functions nil))) 1770 (setq byte-compile-unresolved-functions nil)))
1754 (save-excursion 1771 (save-excursion
1755 (set-buffer byte-compile-outbuffer) 1772 (set-buffer byte-compile-outbuffer)
1756 (goto-char (point-min)))) 1773 (goto-char (point-min))
1774 (when (and (or byte-compile-using-dynamic
1775 (eq buffer-file-coding-system 'raw-text-unix))
1776 (re-search-forward "[^\x00-\xff]" nil t))
1777 (when (or noninteractive byte-compile-verbose)
1778 (message
1779 "%s: includes char above ?\\xFF, recompiling sans dynamic features."
1780 filename))
1781 (set-symbol-value-in-buffer 'byte-compile-dynamic nil
1782 byte-compile-inbuffer)
1783 (set-symbol-value-in-buffer 'byte-compile-dynamic-docstrings nil
1784 byte-compile-inbuffer)
1785 (setq byte-compile-force-escape-quoted t
1786 byte-compile-outbuffer
1787 (byte-compile-from-buffer byte-compile-inbuffer
1788 filename eval)))))
1757 (if (not eval) 1789 (if (not eval)
1758 byte-compile-outbuffer 1790 byte-compile-outbuffer
1759 (let (form) 1791 (let (form)
1760 (while (condition-case nil 1792 (while (condition-case nil
1761 (progn (setq form (read byte-compile-outbuffer)) 1793 (progn (setq form (read byte-compile-outbuffer))
1840 ;; input file, use `escape-quoted' to make sure that both binary and 1872 ;; input file, use `escape-quoted' to make sure that both binary and
1841 ;; extended characters are output properly and distinguished properly. 1873 ;; extended characters are output properly and distinguished properly.
1842 ;; Otherwise, use `raw-text' for maximum portability with non-Mule 1874 ;; Otherwise, use `raw-text' for maximum portability with non-Mule
1843 ;; Emacsen. 1875 ;; Emacsen.
1844 (if (or (featurep '(not mule)) ;; Don't scan buffer if we are not muleized 1876 (if (or (featurep '(not mule)) ;; Don't scan buffer if we are not muleized
1845 (save-excursion 1877 (and
1846 (set-buffer byte-compile-inbuffer) 1878 (not byte-compile-force-escape-quoted)
1847 (goto-char (point-min)) 1879 (save-excursion
1848 ;; Look for any non-Latin-1 literals or Unicode character 1880 (set-buffer byte-compile-inbuffer)
1849 ;; escapes. Any such occurrences in a @#COUNT comment will lead 1881 (goto-char (point-min))
1850 ;; to an escape-quoted coding cookie being inserted, but this is 1882 ;; Look for any non-Latin-1 literals or Unicode character
1851 ;; not true of ordinary comments. 1883 ;; escapes. Any such occurrences in a @#COUNT comment will lead
1852 (let ((non-latin-1-re 1884 ;; to an escape-quoted coding cookie being inserted, but this is
1853 (concat "[^\000-\377]" 1885 ;; not true of ordinary comments.
1854 #r"\|\\u[0-9a-fA-F]\{4,4\}\|\\U[0-9a-fA-F]\{8,8\}")) 1886 (let ((non-latin-1-re
1855 (case-fold-search nil)) 1887 (concat "[^\000-\377]"
1856 (catch 'need-to-escape-quote 1888 #r"\|\\u[0-9a-fA-F]\{4,4\}\|\\U[0-9a-fA-F]\{8,8\}"))
1857 (while (re-search-forward non-latin-1-re nil t) 1889 (case-fold-search nil))
1858 (skip-chars-backward "^;" (point-at-bol)) 1890 (catch 'need-to-escape-quote
1859 (if (bolp) (throw 'need-to-escape-quote nil)) 1891 (while (re-search-forward non-latin-1-re nil t)
1860 (forward-line 1)) 1892 (skip-chars-backward "^;" (point-at-bol))
1861 t)))) 1893 (if (bolp) (throw 'need-to-escape-quote nil))
1894 (forward-line 1))
1895 t)))))
1862 (setq buffer-file-coding-system 'raw-text-unix) 1896 (setq buffer-file-coding-system 'raw-text-unix)
1863 (insert "(or (featurep 'mule) (error \"Loading this file requires Mule support\")) 1897 (insert "(or (featurep 'mule) (error \"Loading this file requires Mule support\"))
1864 ;;;###coding system: escape-quoted\n") 1898 ;;;###coding system: escape-quoted\n")
1865 (setq buffer-file-coding-system 'escape-quoted) 1899 (setq buffer-file-coding-system 'escape-quoted)
1866 ;; #### Lazy loading not yet implemented for MULE files 1900 ;; #### Lazy loading not yet implemented for MULE files