aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1998-05-13 00:03:19 +0000
committerRichard M. Stallman1998-05-13 00:03:19 +0000
commit1596952ed411fbc2f01850f93b805a88e05080c4 (patch)
tree8da7d49b2ad4b2119dbe6cf1dfa94876b14def77
parent313aaa0cc9bb5d124ce17525f73d3adcc87be658 (diff)
downloademacs-1596952ed411fbc2f01850f93b805a88e05080c4.tar.gz
emacs-1596952ed411fbc2f01850f93b805a88e05080c4.zip
(byte-compile-from-buffer):
Insert the output file header after compiling all the input. (byte-compile-output-file-form): Major cleanup. If output file contains multibyte chars, insist on Emacs 20 when loading.
-rw-r--r--lisp/emacs-lisp/bytecomp.el100
1 files changed, 63 insertions, 37 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 22be3b04b5d..437c0493063 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -9,7 +9,7 @@
9 9
10;;; This version incorporates changes up to version 2.10 of the 10;;; This version incorporates changes up to version 2.10 of the
11;;; Zawinski-Furuseth compiler. 11;;; Zawinski-Furuseth compiler.
12(defconst byte-compile-version "$Revision: 2.41 $") 12(defconst byte-compile-version "$Revision: 2.42 $")
13 13
14;; This file is part of GNU Emacs. 14;; This file is part of GNU Emacs.
15 15
@@ -1408,8 +1408,6 @@ With argument, insert value in current buffer after the form."
1408 (erase-buffer) 1408 (erase-buffer)
1409 ;; (emacs-lisp-mode) 1409 ;; (emacs-lisp-mode)
1410 (setq case-fold-search nil) 1410 (setq case-fold-search nil)
1411 (and filename (byte-compile-insert-header filename inbuffer outbuffer))
1412
1413 ;; This is a kludge. Some operating systems (OS/2, DOS) need to 1411 ;; This is a kludge. Some operating systems (OS/2, DOS) need to
1414 ;; write files containing binary information specially. 1412 ;; write files containing binary information specially.
1415 ;; Under most circumstances, such files will be in binary 1413 ;; Under most circumstances, such files will be in binary
@@ -1436,29 +1434,40 @@ With argument, insert value in current buffer after the form."
1436 ;; Should we always do this? When calling multiple files, it 1434 ;; Should we always do this? When calling multiple files, it
1437 ;; would be useful to delay this warning until all have 1435 ;; would be useful to delay this warning until all have
1438 ;; been compiled. 1436 ;; been compiled.
1439 (setq byte-compile-unresolved-functions nil)))) 1437 (setq byte-compile-unresolved-functions nil)))
1438 ;; Insert the header at the front of the output.
1439 ;; We do this last, so we can check for the presence
1440 ;; of multibyte characters in the compiled code.
1441 (and filename (byte-compile-insert-header filename inbuffer outbuffer)))
1440 outbuffer)) 1442 outbuffer))
1441 1443
1442(defun byte-compile-insert-header (filename inbuffer outbuffer) 1444(defun byte-compile-insert-header (filename inbuffer outbuffer)
1443 (set-buffer inbuffer) 1445 (set-buffer inbuffer)
1444 (let ((dynamic-docstrings byte-compile-dynamic-docstrings) 1446 (let ((dynamic-docstrings byte-compile-dynamic-docstrings)
1445 (dynamic byte-compile-dynamic)) 1447 (dynamic byte-compile-dynamic)
1448 (some-multibyte-characters
1449 (save-excursion
1450 (goto-char 1)
1451 ;; See if the buffer has any multibyte characters.
1452 (skip-chars-forward "\0-\377")
1453 (setq some-multibyte-characters (not (eobp))))))
1454
1446 (set-buffer outbuffer) 1455 (set-buffer outbuffer)
1447 (goto-char 1) 1456 (goto-char 1)
1448 ;; 1457 ;; The magic number of .elc files is ";ELC", or 0x3B454C43. After
1449 ;; The magic number of .elc files is ";ELC", or 0x3B454C43. After that is 1458 ;; that is the file-format version number (18, 19 or 20) as a
1450 ;; the file-format version number (18 or 19) as a byte, followed by some 1459 ;; byte, followed by some nulls. The primary motivation for doing
1451 ;; nulls. The primary motivation for doing this is to get some binary 1460 ;; this is to get some binary characters up in the first line of
1452 ;; characters up in the first line of the file so that `diff' will simply 1461 ;; the file so that `diff' will simply say "Binary files differ"
1453 ;; say "Binary files differ" instead of actually doing a diff of two .elc 1462 ;; instead of actually doing a diff of two .elc files. An extra
1454 ;; files. An extra benefit is that you can add this to /etc/magic: 1463 ;; benefit is that you can add this to /etc/magic:
1455 ;; 1464
1456 ;; 0 string ;ELC GNU Emacs Lisp compiled file, 1465 ;; 0 string ;ELC GNU Emacs Lisp compiled file,
1457 ;; >4 byte x version %d 1466 ;; >4 byte x version %d
1458 ;; 1467
1459 (insert 1468 (insert
1460 ";ELC" 1469 ";ELC"
1461 (if (byte-compile-version-cond byte-compile-compatibility) 18 19) 1470 (if (byte-compile-version-cond byte-compile-compatibility) 18 20)
1462 "\000\000\000\n" 1471 "\000\000\000\n"
1463 ) 1472 )
1464 (insert ";;; Compiled by " 1473 (insert ";;; Compiled by "
@@ -1481,29 +1490,46 @@ With argument, insert value in current buffer after the form."
1481 ".\n")) 1490 ".\n"))
1482 (if dynamic 1491 (if dynamic
1483 (insert ";;; Function definitions are lazy-loaded.\n")) 1492 (insert ";;; Function definitions are lazy-loaded.\n"))
1484 (if (not (byte-compile-version-cond byte-compile-compatibility)) 1493 (if (or some-multibyte-characters
1485 (insert ";;; This file uses opcodes which do not exist in Emacs 18.\n" 1494 dynamic-docstrings
1486 ;; Have to check if emacs-version is bound so that this works 1495 (not (byte-compile-version-cond byte-compile-compatibility)))
1487 ;; in files loaded early in loadup.el. 1496 (let (intro-string minimum-version)
1488 "\n(if (and (boundp 'emacs-version)\n" 1497 ;; Figure out which Emacs version to require,
1489 ;; If there is a name at the end of emacs-version, 1498 ;; and what comment to use to explain why.
1490 ;; don't try to check the version number. 1499 (if some-multibyte-characters
1491 "\t (< (aref emacs-version (1- (length emacs-version))) ?A)\n" 1500 (setq intro-string
1492 "\t (or (and (boundp 'epoch::version) epoch::version)\n" 1501 (concat
1493 (if dynamic-docstrings 1502 ";;; This file contains multibyte non-ASCII characters\n"
1494 "\t (string-lessp emacs-version \"19.29\")))\n" 1503 ";;; and therefore cannot be loaded into Emacs 19.\n")
1495 "\t (string-lessp emacs-version \"19\")))\n") 1504 minimum-version "20")
1496 " (error \"`" 1505 (if dynamic-docstrings
1497 ;; prin1-to-string is used to quote backslashes. 1506 (setq intro-string
1498 (substring (prin1-to-string (file-name-nondirectory filename)) 1507 ";;; This file uses dynamic docstrings, first added in Emacs 19.29.\n"
1499 1 -1) 1508 minimum-version "19.29")
1500 (if dynamic-docstrings 1509 (setq intro-string
1501 "' was compiled for Emacs 19.29 or later\"))\n\n" 1510 ";;; This file uses opcodes which do not exist in Emacs 18.\n"
1502 "' was compiled for Emacs 19\"))\n\n")) 1511 minimum-version "19")))
1512 ;; Now insert the comment and the error check.
1513 (insert
1514 intro-string
1515 ;; Have to check if emacs-version is bound so that this works
1516 ;; in files loaded early in loadup.el.
1517 "\n(if (and (boundp 'emacs-version)\n"
1518 ;; If there is a name at the end of emacs-version,
1519 ;; don't try to check the version number.
1520 "\t (< (aref emacs-version (1- (length emacs-version))) ?A)\n"
1521 "\t (or (and (boundp 'epoch::version) epoch::version)\n"
1522 (format "\t (string-lessp emacs-version \"%s\")))\n"
1523 minimum-version)
1524 " (error \"`"
1525 ;; prin1-to-string is used to quote backslashes.
1526 (substring (prin1-to-string (file-name-nondirectory filename))
1527 1 -1)
1528 (format "' was compiled for Emacs %s or later\"))\n\n"
1529 minimum-version)))
1530 ;; Here if we want Emacs 18 compatibility.
1503 (insert "(or (boundp 'current-load-list) (setq current-load-list nil))\n" 1531 (insert "(or (boundp 'current-load-list) (setq current-load-list nil))\n"
1504 "\n") 1532 "\n"))))
1505 )))
1506
1507 1533
1508(defun byte-compile-output-file-form (form) 1534(defun byte-compile-output-file-form (form)
1509 ;; writes the given form to the output buffer, being careful of docstrings 1535 ;; writes the given form to the output buffer, being careful of docstrings