From 33be50037c2b4cdb002538534e9915c6bad253b7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 1 Feb 2017 15:18:43 -0800 Subject: Remove immediate_quit. The old code that sets and clears immediate_quit was ineffective except when Emacs is running in terminal mode, and has problematic race conditions anyway, so remove it. This will introduce some hangs when Emacs runs in terminal mode, and these hangs should be fixed in followup patches. * src/keyboard.c (immediate_quit): Remove. All uses removed. --- src/fileio.c | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'src/fileio.c') diff --git a/src/fileio.c b/src/fileio.c index a46cfc7ac69..a109737240f 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -1960,9 +1960,7 @@ permissions. */) report_file_error ("Copying permissions to", newname); } #else /* not WINDOWSNT */ - immediate_quit = true; ifd = emacs_open (SSDATA (encoded_file), O_RDONLY, 0); - immediate_quit = false; if (ifd < 0) report_file_error ("Opening input file", file); @@ -2024,7 +2022,6 @@ permissions. */) oldsize = out_st.st_size; } - immediate_quit = true; maybe_quit (); if (clone_file (ofd, ifd)) @@ -2047,8 +2044,6 @@ permissions. */) if (newsize < oldsize && ftruncate (ofd, newsize) != 0) report_file_error ("Truncating output file", newname); - immediate_quit = false; - #ifndef MSDOS /* Preserve the original file permissions, and if requested, also its owner and group. */ @@ -3403,13 +3398,11 @@ read_non_regular (Lisp_Object state) { int nbytes; - immediate_quit = true; maybe_quit (); nbytes = emacs_read (XSAVE_INTEGER (state, 0), ((char *) BEG_ADDR + PT_BYTE - BEG_BYTE + XSAVE_INTEGER (state, 1)), XSAVE_INTEGER (state, 2)); - immediate_quit = false; /* Fast recycle this object for the likely next call. */ free_misc (state); return make_number (nbytes); @@ -3868,7 +3861,6 @@ by calling `format-decode', which see. */) report_file_error ("Setting file position", orig_filename); } - immediate_quit = true; maybe_quit (); /* Count how many chars at the start of the file match the text at the beginning of the buffer. */ @@ -3907,7 +3899,6 @@ by calling `format-decode', which see. */) if (bufpos != nread) break; } - immediate_quit = false; /* If the file matches the buffer completely, there's no need to replace anything. */ if (same_at_start - BEGV_BYTE == end_offset - beg_offset) @@ -3919,7 +3910,6 @@ by calling `format-decode', which see. */) del_range_1 (same_at_start, same_at_end, 0, 0); goto handled; } - immediate_quit = true; maybe_quit (); /* Count how many chars at the end of the file match the text at the end of the buffer. But, if we have @@ -3977,7 +3967,6 @@ by calling `format-decode', which see. */) if (nread == 0) break; } - immediate_quit = false; if (! giveup_match_end) { @@ -4075,11 +4064,9 @@ by calling `format-decode', which see. */) quitting while reading a huge file. */ /* Allow quitting out of the actual I/O. */ - immediate_quit = true; maybe_quit (); this = emacs_read (fd, read_buf + unprocessed, READ_BUF_SIZE - unprocessed); - immediate_quit = false; if (this <= 0) break; @@ -4294,13 +4281,11 @@ by calling `format-decode', which see. */) /* Allow quitting out of the actual I/O. We don't make text part of the buffer until all the reading is done, so a C-g here doesn't do any harm. */ - immediate_quit = true; maybe_quit (); this = emacs_read (fd, ((char *) BEG_ADDR + PT_BYTE - BEG_BYTE + inserted), trytry); - immediate_quit = false; } if (this <= 0) @@ -5002,8 +4987,6 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, } } - immediate_quit = true; - if (STRINGP (start)) ok = a_write (desc, start, 0, SCHARS (start), &annotations, &coding); else if (XINT (start) != XINT (end)) @@ -5026,8 +5009,6 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, save_errno = errno; } - immediate_quit = false; - /* fsync is not crucial for temporary files. Nor for auto-save files, since they might lose some work anyway. */ if (open_and_close_file && !auto_saving && !write_region_inhibit_fsync) -- cgit v1.2.1 From b01ac672be1277833964d2d53f6dd26560c70343 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 1 Feb 2017 15:18:44 -0800 Subject: Revamp quitting and fix infloops This fixes some infinite loops that cannot be quitted out of, e.g., (defun foo () (nth most-positive-fixnum '#1=(1 . #1#))) when byte-compiled and when run under X. See: http://lists.gnu.org/archive/html/emacs-devel/2017-01/msg00577.html This also attempts to keep the performance improvements I recently added, as much as possible under the constraint that the infloops must be caught. In some cases this fixes infloop bugs recently introduced when I removed immediate_quit. * src/alloc.c (Fmake_list): Use rarely_quit, not maybe_quit, for speed in the usual case. * src/bytecode.c (exec_byte_code): * src/editfns.c (Fcompare_buffer_substrings): * src/fns.c (Fnthcdr): * src/syntax.c (scan_words, skip_chars, skip_syntaxes) (Fbackward_prefix_chars): Use rarely_quit so that users can C-g out of long loops. * src/callproc.c (call_process_cleanup, call_process): * src/fileio.c (read_non_regular, Finsert_file_contents): * src/indent.c (compute_motion): * src/syntax.c (scan_words, Fforward_comment): Remove now-unnecessary maybe_quit calls. * src/callproc.c (call_process): * src/doc.c (get_doc_string, Fsnarf_documentation): * src/fileio.c (Fcopy_file, read_non_regular, Finsert_file_contents): * src/lread.c (safe_to_load_version): * src/sysdep.c (system_process_attributes) [GNU_LINUX]: Use emacs_read_quit instead of emacs_read in places where C-g handling is safe. * src/eval.c (maybe_quit): Move comment here from lisp.h. * src/fileio.c (Fcopy_file, e_write): Use emacs_write_quit instead of emacs_write_sig in places where C-g handling is safe. * src/filelock.c (create_lock_file): Use emacs_write, not plain write, as emacs_write no longer has a problem. (read_lock_data): Use emacs_read, not read, as emacs_read no longer has a problem. * src/fns.c (rarely_quit): Move to lisp.h and rename to incr_rarely_quit. All uses changed.. * src/fns.c (Fmemq, Fmemql, Fassq, Frassq, Fplist_put, Fplist_member): * src/indent.c (compute_motion): * src/syntax.c (find_defun_start, back_comment, forw_comment) (Fforward_comment, scan_lists, scan_sexps_forward): Use incr_rarely_quit so that users can C-g out of long loops. * src/fns.c (Fnconc): Move incr_rarely_quit call to within inner loop, so that it catches C-g there too. * src/keyboard.c (tty_read_avail_input): Remove commented-out and now-obsolete code dealing with interrupts. * src/lisp.h (rarely_quit, incr_rarely_quit): New functions, the latter moved here from fns.c and renamed from rarely_quit. (emacs_read_quit, emacs_write_quit): New decls. * src/search.c (find_newline, search_buffer, find_newline1): Add maybe_quit to catch C-g. * src/sysdep.c (get_child_status): Always invoke maybe_quit if interruptible, so that the caller need not bother. (emacs_nointr_read, emacs_read_quit, emacs_write_quit): New functions. (emacs_read): Rewrite in terms of emacs_nointr_read. Do not handle C-g or signals; that is now for emacs_read_quit. (emacs_full_write): Replace PROCESS_SIGNALS two-way arg with INTERRUPTIBLE three-way arg. All uses changed. --- src/fileio.c | 55 +++++++++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 32 deletions(-) (limited to 'src/fileio.c') diff --git a/src/fileio.c b/src/fileio.c index a109737240f..38400623793 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -2030,9 +2030,9 @@ permissions. */) { char buf[MAX_ALLOCA]; ptrdiff_t n; - for (newsize = 0; 0 < (n = emacs_read (ifd, buf, sizeof buf)); + for (newsize = 0; 0 < (n = emacs_read_quit (ifd, buf, sizeof buf)); newsize += n) - if (emacs_write_sig (ofd, buf, n) != n) + if (emacs_write_quit (ofd, buf, n) != n) report_file_error ("Write error", newname); if (n < 0) report_file_error ("Read error", file); @@ -3396,13 +3396,10 @@ decide_coding_unwind (Lisp_Object unwind_data) static Lisp_Object read_non_regular (Lisp_Object state) { - int nbytes; - - maybe_quit (); - nbytes = emacs_read (XSAVE_INTEGER (state, 0), - ((char *) BEG_ADDR + PT_BYTE - BEG_BYTE - + XSAVE_INTEGER (state, 1)), - XSAVE_INTEGER (state, 2)); + int nbytes = emacs_read_quit (XSAVE_INTEGER (state, 0), + ((char *) BEG_ADDR + PT_BYTE - BEG_BYTE + + XSAVE_INTEGER (state, 1)), + XSAVE_INTEGER (state, 2)); /* Fast recycle this object for the likely next call. */ free_misc (state); return make_number (nbytes); @@ -3746,17 +3743,17 @@ by calling `format-decode', which see. */) int nread; if (st.st_size <= (1024 * 4)) - nread = emacs_read (fd, read_buf, 1024 * 4); + nread = emacs_read_quit (fd, read_buf, 1024 * 4); else { - nread = emacs_read (fd, read_buf, 1024); + nread = emacs_read_quit (fd, read_buf, 1024); if (nread == 1024) { int ntail; if (lseek (fd, - (1024 * 3), SEEK_END) < 0) report_file_error ("Setting file position", orig_filename); - ntail = emacs_read (fd, read_buf + nread, 1024 * 3); + ntail = emacs_read_quit (fd, read_buf + nread, 1024 * 3); nread = ntail < 0 ? ntail : nread + ntail; } } @@ -3861,14 +3858,11 @@ by calling `format-decode', which see. */) report_file_error ("Setting file position", orig_filename); } - maybe_quit (); /* Count how many chars at the start of the file match the text at the beginning of the buffer. */ - while (1) + while (true) { - int nread, bufpos; - - nread = emacs_read (fd, read_buf, sizeof read_buf); + int nread = emacs_read_quit (fd, read_buf, sizeof read_buf); if (nread < 0) report_file_error ("Read error", orig_filename); else if (nread == 0) @@ -3890,7 +3884,7 @@ by calling `format-decode', which see. */) break; } - bufpos = 0; + int bufpos = 0; while (bufpos < nread && same_at_start < ZV_BYTE && FETCH_BYTE (same_at_start) == read_buf[bufpos]) same_at_start++, bufpos++; @@ -3910,7 +3904,7 @@ by calling `format-decode', which see. */) del_range_1 (same_at_start, same_at_end, 0, 0); goto handled; } - maybe_quit (); + /* Count how many chars at the end of the file match the text at the end of the buffer. But, if we have already found that decoding is necessary, don't waste time. */ @@ -3932,7 +3926,8 @@ by calling `format-decode', which see. */) total_read = nread = 0; while (total_read < trial) { - nread = emacs_read (fd, read_buf + total_read, trial - total_read); + nread = emacs_read_quit (fd, read_buf + total_read, + trial - total_read); if (nread < 0) report_file_error ("Read error", orig_filename); else if (nread == 0) @@ -4058,16 +4053,13 @@ by calling `format-decode', which see. */) inserted = 0; /* Bytes put into CONVERSION_BUFFER so far. */ unprocessed = 0; /* Bytes not processed in previous loop. */ - while (1) + while (true) { /* Read at most READ_BUF_SIZE bytes at a time, to allow quitting while reading a huge file. */ - /* Allow quitting out of the actual I/O. */ - maybe_quit (); - this = emacs_read (fd, read_buf + unprocessed, - READ_BUF_SIZE - unprocessed); - + this = emacs_read_quit (fd, read_buf + unprocessed, + READ_BUF_SIZE - unprocessed); if (this <= 0) break; @@ -4281,11 +4273,10 @@ by calling `format-decode', which see. */) /* Allow quitting out of the actual I/O. We don't make text part of the buffer until all the reading is done, so a C-g here doesn't do any harm. */ - maybe_quit (); - this = emacs_read (fd, - ((char *) BEG_ADDR + PT_BYTE - BEG_BYTE - + inserted), - trytry); + this = emacs_read_quit (fd, + ((char *) BEG_ADDR + PT_BYTE - BEG_BYTE + + inserted), + trytry); } if (this <= 0) @@ -5398,7 +5389,7 @@ e_write (int desc, Lisp_Object string, ptrdiff_t start, ptrdiff_t end, : (STRINGP (coding->dst_object) ? SSDATA (coding->dst_object) : (char *) BYTE_POS_ADDR (coding->dst_pos_byte))); - coding->produced -= emacs_write_sig (desc, buf, coding->produced); + coding->produced -= emacs_write_quit (desc, buf, coding->produced); if (coding->raw_destination) { -- cgit v1.2.1