aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias EngdegÄrd2024-05-26 11:13:50 +0200
committerMattias EngdegÄrd2024-05-26 13:04:51 +0200
commit236034a24d0e93e1796224e2ff4a14819fcfd559 (patch)
tree17cbd8f643e1c03b61fdb5725600b04873a3b27b /src
parentcfd654c418658adacd6ab3717dc1b8cc95d99d44 (diff)
downloademacs-236034a24d0e93e1796224e2ff4a14819fcfd559.tar.gz
emacs-236034a24d0e93e1796224e2ff4a14819fcfd559.zip
Clean up legacy bytecode loading
Complete some unfinished work from the elimination of lazy bytecode loading in 9bcc9690a8: remove code which became unreachable by that reform. This simplifies some of the lower-level parts of the reader which helps performance somewhat. * src/doc.c (read_bytecode_pointer, read_bytecode_char) (read_doc_string): Remove. (get_doc_string): Remove last argument, all callers adapted. Simplify. * src/lread.c (readbyte_for_lambda, readbyte_from_string) (readbyte_for_lambda, readbyte_from_string): Remove. (readchar, unreadchar): Remove unused code paths for Qlambda and cons arguments. (bytecode_from_rev_list): Remove last use of a quirky code path, decoding force-loaded lazy bytecode explicitly.
Diffstat (limited to 'src')
-rw-r--r--src/doc.c47
-rw-r--r--src/lisp.h4
-rw-r--r--src/lread.c77
3 files changed, 18 insertions, 110 deletions
diff --git a/src/doc.c b/src/doc.c
index 36633a920c6..f516db3bbcc 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -74,24 +74,8 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
74static char *get_doc_string_buffer; 74static char *get_doc_string_buffer;
75static ptrdiff_t get_doc_string_buffer_size; 75static ptrdiff_t get_doc_string_buffer_size;
76 76
77static unsigned char *read_bytecode_pointer;
78
79static char const sibling_etc[] = "../etc/"; 77static char const sibling_etc[] = "../etc/";
80 78
81/* `readchar' in lread.c calls back here to fetch the next byte.
82 If UNREADFLAG is 1, we unread a byte. */
83
84int
85read_bytecode_char (bool unreadflag)
86{
87 if (unreadflag)
88 {
89 read_bytecode_pointer--;
90 return 0;
91 }
92 return *read_bytecode_pointer++;
93}
94
95#ifdef USE_ANDROID_ASSETS 79#ifdef USE_ANDROID_ASSETS
96 80
97/* Like `close_file_unwind'. However, PTR is a pointer to an Android 81/* Like `close_file_unwind'. However, PTR is a pointer to an Android
@@ -120,15 +104,10 @@ close_file_unwind_android_fd (void *ptr)
120 (e.g. because the file has been modified and the location is stale), 104 (e.g. because the file has been modified and the location is stale),
121 return nil. 105 return nil.
122 106
123 If UNIBYTE, always make a unibyte string. 107 If UNIBYTE, always make a unibyte string. */
124
125 If DEFINITION, assume this is for reading
126 a dynamic function definition; convert the bytestring
127 and the constants vector with appropriate byte handling,
128 and return a cons cell. */
129 108
130Lisp_Object 109Lisp_Object
131get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) 110get_doc_string (Lisp_Object filepos, bool unibyte)
132{ 111{
133 char *from, *to, *name, *p, *p1; 112 char *from, *to, *name, *p, *p1;
134 Lisp_Object file, pos; 113 Lisp_Object file, pos;
@@ -312,14 +291,6 @@ Invalid data in documentation file -- %c followed by code %03o",
312 *to++ = *from++; 291 *to++ = *from++;
313 } 292 }
314 293
315 /* If DEFINITION, read from this buffer
316 the same way we would read bytes from a file. */
317 if (definition)
318 {
319 read_bytecode_pointer = (unsigned char *) get_doc_string_buffer + offset;
320 return Fread (Qlambda);
321 }
322
323 if (unibyte) 294 if (unibyte)
324 return make_unibyte_string (get_doc_string_buffer + offset, 295 return make_unibyte_string (get_doc_string_buffer + offset,
325 to - (get_doc_string_buffer + offset)); 296 to - (get_doc_string_buffer + offset));
@@ -336,16 +307,6 @@ Invalid data in documentation file -- %c followed by code %03o",
336 } 307 }
337} 308}
338 309
339/* Get a string from position FILEPOS and pass it through the Lisp reader.
340 We use this for fetching the bytecode string and constants vector
341 of a compiled function from the .elc file. */
342
343Lisp_Object
344read_doc_string (Lisp_Object filepos)
345{
346 return get_doc_string (filepos, 0, 1);
347}
348
349static bool 310static bool
350reread_doc_file (Lisp_Object file) 311reread_doc_file (Lisp_Object file)
351{ 312{
@@ -406,7 +367,7 @@ string is passed through `substitute-command-keys'. */)
406 if (FIXNUMP (doc) || CONSP (doc)) 367 if (FIXNUMP (doc) || CONSP (doc))
407 { 368 {
408 Lisp_Object tem; 369 Lisp_Object tem;
409 tem = get_doc_string (doc, 0, 0); 370 tem = get_doc_string (doc, 0);
410 if (NILP (tem) && try_reload) 371 if (NILP (tem) && try_reload)
411 { 372 {
412 /* The file is newer, we need to reset the pointers. */ 373 /* The file is newer, we need to reset the pointers. */
@@ -481,7 +442,7 @@ aren't strings. */)
481 if (FIXNUMP (tem) || (CONSP (tem) && FIXNUMP (XCDR (tem)))) 442 if (FIXNUMP (tem) || (CONSP (tem) && FIXNUMP (XCDR (tem))))
482 { 443 {
483 Lisp_Object doc = tem; 444 Lisp_Object doc = tem;
484 tem = get_doc_string (tem, 0, 0); 445 tem = get_doc_string (tem, 0);
485 if (NILP (tem) && try_reload) 446 if (NILP (tem) && try_reload)
486 { 447 {
487 /* The file is newer, we need to reset the pointers. */ 448 /* The file is newer, we need to reset the pointers. */
diff --git a/src/lisp.h b/src/lisp.h
index 534a36499f1..f8d59b1e9fd 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -5273,10 +5273,8 @@ extern void set_initial_environment (void);
5273extern void syms_of_callproc (void); 5273extern void syms_of_callproc (void);
5274 5274
5275/* Defined in doc.c. */ 5275/* Defined in doc.c. */
5276extern Lisp_Object read_doc_string (Lisp_Object); 5276extern Lisp_Object get_doc_string (Lisp_Object, bool);
5277extern Lisp_Object get_doc_string (Lisp_Object, bool, bool);
5278extern void syms_of_doc (void); 5277extern void syms_of_doc (void);
5279extern int read_bytecode_char (bool);
5280 5278
5281/* Defined in bytecode.c. */ 5279/* Defined in bytecode.c. */
5282extern void syms_of_bytecode (void); 5280extern void syms_of_bytecode (void);
diff --git a/src/lread.c b/src/lread.c
index c92b2ede932..233f08b0727 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -256,15 +256,13 @@ static Lisp_Object oblookup_considering_shorthand (Lisp_Object, const char *,
256 ptrdiff_t *); 256 ptrdiff_t *);
257 257
258 258
259/* Functions that read one byte from the current source READCHARFUN 259/* Function that reads one byte from the current source READCHARFUN
260 or unreads one byte. If the integer argument C is -1, it returns 260 or unreads one byte. If the integer argument C is -1, it returns
261 one read byte, or -1 when there's no more byte in the source. If C 261 one read byte, or -1 when there's no more byte in the source. If C
262 is 0 or positive, it unreads C, and the return value is not 262 is 0 or positive, it unreads C, and the return value is not
263 interesting. */ 263 interesting. */
264 264
265static int readbyte_for_lambda (int, Lisp_Object);
266static int readbyte_from_file (int, Lisp_Object); 265static int readbyte_from_file (int, Lisp_Object);
267static int readbyte_from_string (int, Lisp_Object);
268 266
269/* Handle unreading and rereading of characters. 267/* Handle unreading and rereading of characters.
270 Write READCHAR to read a character, 268 Write READCHAR to read a character,
@@ -278,8 +276,8 @@ static int readbyte_from_string (int, Lisp_Object);
278/* Same as READCHAR but set *MULTIBYTE to the multibyteness of the source. */ 276/* Same as READCHAR but set *MULTIBYTE to the multibyteness of the source. */
279#define READCHAR_REPORT_MULTIBYTE(multibyte) readchar (readcharfun, multibyte) 277#define READCHAR_REPORT_MULTIBYTE(multibyte) readchar (readcharfun, multibyte)
280 278
281/* When READCHARFUN is Qget_file_char, Qget_emacs_mule_file_char, 279/* When READCHARFUN is Qget_file_char or Qget_emacs_mule_file_char,
282 Qlambda, or a cons, we use this to keep an unread character because 280 we use this to keep an unread character because
283 a file stream can't handle multibyte-char unreading. The value -1 281 a file stream can't handle multibyte-char unreading. The value -1
284 means that there's no unread character. */ 282 means that there's no unread character. */
285static int unread_char = -1; 283static int unread_char = -1;
@@ -365,12 +363,6 @@ readchar (Lisp_Object readcharfun, bool *multibyte)
365 return c; 363 return c;
366 } 364 }
367 365
368 if (EQ (readcharfun, Qlambda))
369 {
370 readbyte = readbyte_for_lambda;
371 goto read_multibyte;
372 }
373
374 if (EQ (readcharfun, Qget_file_char)) 366 if (EQ (readcharfun, Qget_file_char))
375 { 367 {
376 eassert (infile); 368 eassert (infile);
@@ -400,20 +392,6 @@ readchar (Lisp_Object readcharfun, bool *multibyte)
400 return c; 392 return c;
401 } 393 }
402 394
403 if (CONSP (readcharfun) && STRINGP (XCAR (readcharfun)))
404 {
405 /* This is the case that read_vector is reading from a unibyte
406 string that contains a byte sequence previously skipped
407 because of #@NUMBER. The car part of readcharfun is that
408 string, and the cdr part is a value of readcharfun given to
409 read_vector. */
410 readbyte = readbyte_from_string;
411 eassert (infile);
412 if (EQ (XCDR (readcharfun), Qget_emacs_mule_file_char))
413 emacs_mule_encoding = 1;
414 goto read_multibyte;
415 }
416
417 if (EQ (readcharfun, Qget_emacs_mule_file_char)) 395 if (EQ (readcharfun, Qget_emacs_mule_file_char))
418 { 396 {
419 readbyte = readbyte_from_file; 397 readbyte = readbyte_from_file;
@@ -545,14 +523,6 @@ unreadchar (Lisp_Object readcharfun, int c)
545 read_from_string_index_byte 523 read_from_string_index_byte
546 = string_char_to_byte (readcharfun, read_from_string_index); 524 = string_char_to_byte (readcharfun, read_from_string_index);
547 } 525 }
548 else if (CONSP (readcharfun) && STRINGP (XCAR (readcharfun)))
549 {
550 unread_char = c;
551 }
552 else if (EQ (readcharfun, Qlambda))
553 {
554 unread_char = c;
555 }
556 else if (FROM_FILE_P (readcharfun)) 526 else if (FROM_FILE_P (readcharfun))
557 { 527 {
558 unread_char = c; 528 unread_char = c;
@@ -562,13 +532,6 @@ unreadchar (Lisp_Object readcharfun, int c)
562} 532}
563 533
564static int 534static int
565readbyte_for_lambda (int c, Lisp_Object readcharfun)
566{
567 return read_bytecode_char (c >= 0);
568}
569
570
571static int
572readbyte_from_stdio (void) 535readbyte_from_stdio (void)
573{ 536{
574 if (infile->lookahead) 537 if (infile->lookahead)
@@ -638,26 +601,6 @@ readbyte_from_file (int c, Lisp_Object readcharfun)
638 return readbyte_from_stdio (); 601 return readbyte_from_stdio ();
639} 602}
640 603
641static int
642readbyte_from_string (int c, Lisp_Object readcharfun)
643{
644 Lisp_Object string = XCAR (readcharfun);
645
646 if (c >= 0)
647 {
648 read_from_string_index--;
649 read_from_string_index_byte
650 = string_char_to_byte (string, read_from_string_index);
651 }
652
653 return (read_from_string_index < read_from_string_limit
654 ? fetch_string_char_advance (string,
655 &read_from_string_index,
656 &read_from_string_index_byte)
657 : -1);
658}
659
660
661/* Signal Qinvalid_read_syntax error. 604/* Signal Qinvalid_read_syntax error.
662 S is error string of length N (if > 0) */ 605 S is error string of length N (if > 0) */
663 606
@@ -3517,12 +3460,18 @@ bytecode_from_rev_list (Lisp_Object elems, Lisp_Object readcharfun)
3517 3460
3518 /* Lazily-loaded bytecode is represented by the constant slot being nil 3461 /* Lazily-loaded bytecode is represented by the constant slot being nil
3519 and the bytecode slot a (lazily loaded) string containing the 3462 and the bytecode slot a (lazily loaded) string containing the
3520 print representation of (BYTECODE . CONSTANTS). Unpack the 3463 print representation of (BYTECODE . CONSTANTS). */
3521 pieces by coerceing the string to unibyte and reading the result. */
3522 if (NILP (vec[CLOSURE_CONSTANTS]) && STRINGP (vec[CLOSURE_CODE])) 3464 if (NILP (vec[CLOSURE_CONSTANTS]) && STRINGP (vec[CLOSURE_CODE]))
3523 { 3465 {
3524 Lisp_Object enc = vec[CLOSURE_CODE]; 3466 Lisp_Object enc = vec[CLOSURE_CODE];
3525 Lisp_Object pair = Fread (Fcons (enc, readcharfun)); 3467 eassert (!STRING_MULTIBYTE (enc));
3468 /* The string (always unibyte) must be decoded to be parsed. */
3469 enc = Fdecode_coding_string (enc,
3470 EQ (readcharfun,
3471 Qget_emacs_mule_file_char)
3472 ? Qemacs_mule : Qutf_8_emacs,
3473 Qt, Qnil);
3474 Lisp_Object pair = Fread (enc);
3526 if (!CONSP (pair)) 3475 if (!CONSP (pair))
3527 invalid_syntax ("Invalid byte-code object", readcharfun); 3476 invalid_syntax ("Invalid byte-code object", readcharfun);
3528 3477
@@ -3772,7 +3721,7 @@ get_lazy_string (Lisp_Object val)
3772 && !(pos >= ss->position && pos < ss->position + ss->length)) 3721 && !(pos >= ss->position && pos < ss->position + ss->length))
3773 ss++; 3722 ss++;
3774 if (ss >= ssend) 3723 if (ss >= ssend)
3775 return get_doc_string (val, 1, 0); 3724 return get_doc_string (val, 1);
3776 3725
3777 ptrdiff_t start = pos - ss->position; 3726 ptrdiff_t start = pos - ss->position;
3778 char *str = ss->string; 3727 char *str = ss->string;