From f8ab90839fe64b2ec8b398a50e8fb4f33e8e95e1 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 8 Jul 2019 17:50:39 -0700 Subject: Use fewer locks when accessing stdio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * src/alloc.c, src/bidi.c, src/emacs-module.c, src/pdumper.c: * src/regex-emacs.c, src/unexhp9k800.c, src/unexmacosx.c: * src/widget.c, src/xdisp.c, src/xselect.c, src/xterm.c: Include sysstdio.h instead of stdio.h, to avoid locking stdio streams in many cases. * src/alloc.c (test_setjmp): * src/bidi.c (bidi_dump_cached_states): * src/cm.c (calccost): * src/dispnew.c (init_display_interactive): * src/emacs.c (main): * src/image.c (convert_mono_to_color_image): * src/minibuf.c (read_minibuf_noninteractive): * src/nsfont.m (ns_descriptor_to_entity) (ns_dump_glyphstring): * src/nsterm.h (NSTRACE_MSG_NO_DASHES): * src/nsterm.m (ns_mouse_position) (sendEvent:, keyDown:, performDragOperation:): * src/pdumper.c (dump_fingerprint, print_paths_to_root_1): * src/print.c (debug_print): * src/regex-emacs.c (debug_putchar, print_fastmap) (print_partial_compiled_pattern, print_compiled_pattern) (print_double_string, regex_compile): * src/term.c (vfatal): * src/unexhp9k800.c (read_header): * src/unexmacosx.c (unexec_error): * src/widget.c (EmacsFrameInitialize): * src/xdisp.c (message_to_stderr, vmessage, dump_glyph_row) (Fdump_glyph_matrix, Fdump_frame_glyph_matrix, dump_glyph_string): * src/xfaces.c (Fdump_colors, Fdump_face): * src/xselect.c (x_clipboard_manager_error_2): * src/xterm.c (x_initialize): * src/xwidget.c (WEBKIT_FN_INIT): Prefer unlocked calls like fputs to locked calls like fprintf. * src/charset.c (read_hex): * src/cm.c (cmputc, cmcheckmagic): * src/dispnew.c (update_frame, update_frame_with_menu) (update_frame_1, Fsend_string_to_terminal, Fding) (bitch_at_user): * src/emacs.c (main, Fdump_emacs): * src/emacs-module.c (module_abort): * src/fileio.c (Fdo_auto_save): * src/image.c (slurp_file) (png_read_from_file, png_load_body, our_stdio_fill_input_buffer): * src/keyboard.c (record_char, kbd_buffer_get_event) (handle_interrupt): * src/lread.c (readbyte_from_stdio, read1): * src/minibuf.c (read_minibuf_noninteractive): * src/print.c (printchar_to_stream, strout) (Fredirect_debugging_output): * src/sysdep.c (reset_sys_modes, close_output_streams) (procfs_ttyname, procfs_get_total_memory): * src/term.c (tty_ring_bell, tty_send_additional_strings) (tty_set_terminal_modes, tty_reset_terminal_modes) (tty_update_end, tty_clear_end_of_line, tty_write_glyphs) (tty_write_glyphs_with_face, tty_insert_glyphs) (tty_menu_activate): * src/xfaces.c (Fx_load_color_file): Simplify by using ordinary calls like putc to explicitly-unlocked calls like putc_unlocked, since the ordinary calls are now unlocked anyway. * src/emacs.c (main, Fdump_emacs): * src/pdumper.c (Fdump_emacs_portable): Coalesce adjacent printfs. * src/nsterm.h: Include sysstdio.h as this file’s macros rely on it. * src/regex-emacs.c (print_compiled_pattern): Omit redundant fflush. * src/sysstdio.h: Include unlocked-io.h. (clearerr_unlocked, feof_unlocked, ferror_unlocked) (fflush_unlocked, fgets_unlocked, fputc_unlocked) (fputs_unlocked, fread_unlocked, fwrite_unlocked) (getc_unlocked, getchar_unlocked, putc_unlocked) (putchar_unlocked): Remove these macros; now done by unlocked-io.h. * src/xwidget.c: Include sysstdio.h. --- src/alloc.c | 6 ++--- src/bidi.c | 12 ++++----- src/charset.c | 10 +++---- src/cm.c | 16 ++++++------ src/dispnew.c | 30 +++++++++++---------- src/emacs-module.c | 4 +-- src/emacs.c | 76 ++++++++++++++++++++++++++++-------------------------- src/fileio.c | 14 +++++----- src/image.c | 11 ++++---- src/keyboard.c | 17 ++++++------ src/lread.c | 7 +++-- src/minibuf.c | 10 +++---- src/nsfont.m | 13 ++++------ src/nsterm.h | 3 ++- src/nsterm.m | 8 +++--- src/pdumper.c | 16 ++++++------ src/print.c | 12 ++++----- src/regex-emacs.c | 65 +++++++++++++++++++++++----------------------- src/sysdep.c | 12 ++++----- src/sysstdio.h | 42 +----------------------------- src/term.c | 46 +++++++++++++++------------------ src/unexhp9k800.c | 4 +-- src/unexmacosx.c | 6 ++--- src/widget.c | 5 ++-- src/xdisp.c | 29 ++++++++++----------- src/xfaces.c | 20 ++++++-------- src/xselect.c | 9 ++++--- src/xterm.c | 6 ++--- src/xwidget.c | 4 ++- 29 files changed, 231 insertions(+), 282 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 64aaa8acdfa..90817da5974 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -22,7 +22,6 @@ along with GNU Emacs. If not, see . */ #include #include -#include #include #include /* For CHAR_BIT. */ #include /* For SIGABRT, SIGDANGER. */ @@ -38,6 +37,7 @@ along with GNU Emacs. If not, see . */ #include "ptr-bounds.h" #include "puresize.h" #include "sheap.h" +#include "sysstdio.h" #include "systime.h" #include "character.h" #include "buffer.h" @@ -4813,10 +4813,10 @@ test_setjmp (void) taking place, or the setjmp just didn't save the register. */ if (x == 1) - fprintf (stderr, SETJMP_WILL_LIKELY_WORK); + fputs (SETJMP_WILL_LIKELY_WORK, stderr); else { - fprintf (stderr, SETJMP_WILL_NOT_WORK); + fputs (SETJMP_WILL_NOT_WORK, stderr); exit (1); } } diff --git a/src/bidi.c b/src/bidi.c index c530d49c107..1430d223313 100644 --- a/src/bidi.c +++ b/src/bidi.c @@ -238,13 +238,13 @@ along with GNU Emacs. If not, see . */ necessary. */ #include -#include #include "lisp.h" #include "character.h" #include "buffer.h" #include "dispextern.h" #include "region-cache.h" +#include "sysstdio.h" static bool bidi_initialized = 0; @@ -3586,7 +3586,7 @@ bidi_dump_cached_states (void) if (bidi_cache_idx == 0) { - fprintf (stderr, "The cache is empty.\n"); + fputs ("The cache is empty.\n", stderr); return; } fprintf (stderr, "Total of %"pD"d state%s in cache:\n", @@ -3597,13 +3597,11 @@ bidi_dump_cached_states (void) fputs ("ch ", stderr); for (i = 0; i < bidi_cache_idx; i++) fprintf (stderr, "%*c", ndigits, bidi_cache[i].ch); - fputs ("\n", stderr); - fputs ("lvl ", stderr); + fputs ("\nlvl ", stderr); for (i = 0; i < bidi_cache_idx; i++) fprintf (stderr, "%*d", ndigits, bidi_cache[i].resolved_level); - fputs ("\n", stderr); - fputs ("pos ", stderr); + fputs ("\npos ", stderr); for (i = 0; i < bidi_cache_idx; i++) fprintf (stderr, "%*"pD"d", ndigits, bidi_cache[i].charpos); - fputs ("\n", stderr); + putc ('\n', stderr); } diff --git a/src/charset.c b/src/charset.c index c0700f972ee..85535e8bff1 100644 --- a/src/charset.c +++ b/src/charset.c @@ -415,23 +415,23 @@ load_charset_map (struct charset *charset, struct charset_map_entries *entries, static unsigned read_hex (FILE *fp, int lookahead, int *terminator, bool *overflow) { - int c = lookahead < 0 ? getc_unlocked (fp) : lookahead; + int c = lookahead < 0 ? getc (fp) : lookahead; while (true) { if (c == '#') do - c = getc_unlocked (fp); + c = getc (fp); while (0 <= c && c != '\n'); else if (c == '0') { - c = getc_unlocked (fp); + c = getc (fp); if (c < 0 || c == 'x') break; } if (c < 0) break; - c = getc_unlocked (fp); + c = getc (fp); } unsigned n = 0; @@ -440,7 +440,7 @@ read_hex (FILE *fp, int lookahead, int *terminator, bool *overflow) if (0 <= c) while (true) { - c = getc_unlocked (fp); + c = getc (fp); int digit = char_hexdigit (c); if (digit < 0) break; diff --git a/src/cm.c b/src/cm.c index 71cc94759fb..e09216a854b 100644 --- a/src/cm.c +++ b/src/cm.c @@ -45,8 +45,8 @@ int cmputc (int c) { if (current_tty->termscript) - putc_unlocked (c & 0177, current_tty->termscript); - putc_unlocked (c & 0177, current_tty->output); + putc (c & 0177, current_tty->termscript); + putc (c & 0177, current_tty->output); return c; } @@ -117,11 +117,11 @@ cmcheckmagic (struct tty_display_info *tty) if (!MagicWrap (tty) || curY (tty) >= FrameRows (tty) - 1) emacs_abort (); if (tty->termscript) - putc_unlocked ('\r', tty->termscript); - putc_unlocked ('\r', tty->output); + putc ('\r', tty->termscript); + putc ('\r', tty->output); if (tty->termscript) - putc_unlocked ('\n', tty->termscript); - putc_unlocked ('\n', tty->output); + putc ('\n', tty->termscript); + putc ('\n', tty->output); curX (tty) = 0; curY (tty)++; } @@ -205,7 +205,7 @@ calccost (struct tty_display_info *tty, p = tty->Wcm->cm_down, c = tty->Wcm->cc_down; if (c == BIG) { /* caint get thar from here */ if (doit) - printf ("OOPS"); + fputs ("OOPS", stdout); return c; } totalcost = c * deltay; @@ -288,7 +288,7 @@ dodelta: if (c == BIG) { /* caint get thar from here */ fail: if (doit) - printf ("OOPS"); + fputs ("OOPS", stdout); return BIG; } totalcost += c * deltax; diff --git a/src/dispnew.c b/src/dispnew.c index 956f3ea3573..0131b63767b 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -3126,9 +3126,9 @@ update_frame (struct frame *f, bool force_p, bool inhibit_hairy_id_p) if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) { if (FRAME_TTY (f)->termscript) - fflush_unlocked (FRAME_TTY (f)->termscript); + fflush (FRAME_TTY (f)->termscript); if (FRAME_TERMCAP_P (f)) - fflush_unlocked (FRAME_TTY (f)->output); + fflush (FRAME_TTY (f)->output); } /* Check window matrices for lost pointers. */ @@ -3181,8 +3181,8 @@ update_frame_with_menu (struct frame *f, int row, int col) update_end (f); if (FRAME_TTY (f)->termscript) - fflush_unlocked (FRAME_TTY (f)->termscript); - fflush_unlocked (FRAME_TTY (f)->output); + fflush (FRAME_TTY (f)->termscript); + fflush (FRAME_TTY (f)->output); /* Check window matrices for lost pointers. */ #if GLYPH_DEBUG #if 0 @@ -4621,7 +4621,7 @@ update_frame_1 (struct frame *f, bool force_p, bool inhibit_id_p, ptrdiff_t outq = __fpending (display_output); if (outq > 900 || (outq > 20 && ((i - 1) % preempt_count == 0))) - fflush_unlocked (display_output); + fflush (display_output); } } @@ -5745,13 +5745,13 @@ when TERMINAL is nil. */) if (tty->termscript) { - fwrite_unlocked (SDATA (string), 1, SBYTES (string), tty->termscript); - fflush_unlocked (tty->termscript); + fwrite (SDATA (string), 1, SBYTES (string), tty->termscript); + fflush (tty->termscript); } out = tty->output; } - fwrite_unlocked (SDATA (string), 1, SBYTES (string), out); - fflush_unlocked (out); + fwrite (SDATA (string), 1, SBYTES (string), out); + fflush (out); unblock_input (); return Qnil; } @@ -5766,7 +5766,7 @@ terminate any keyboard macro currently executing. */) if (!NILP (arg)) { if (noninteractive) - putchar_unlocked (07); + putchar (07); else ring_bell (XFRAME (selected_frame)); } @@ -5780,7 +5780,7 @@ void bitch_at_user (void) { if (noninteractive) - putchar_unlocked (07); + putchar (07); else if (!INTERACTIVE) /* Stop executing a keyboard macro. */ { const char *msg @@ -6205,12 +6205,14 @@ init_display_interactive (void) #endif if (!terminal_type) { + char const *msg + = "Please set the environment variable TERM; see 'tset'.\n"; #ifdef HAVE_WINDOW_SYSTEM if (! inhibit_window_system) - fprintf (stderr, "Please set the environment variable DISPLAY or TERM (see 'tset').\n"); - else + msg = ("Please set the environment variable DISPLAY or TERM; " + "see 'tset'.\n"); #endif /* HAVE_WINDOW_SYSTEM */ - fprintf (stderr, "Please set the environment variable TERM; see 'tset'.\n"); + fputs (msg, stderr); exit (1); } diff --git a/src/emacs-module.c b/src/emacs-module.c index c856663d2ff..8c09ea6bb6c 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c @@ -81,7 +81,6 @@ To add a new module function, proceed as follows: #include #include #include -#include #include #include @@ -91,6 +90,7 @@ To add a new module function, proceed as follows: #include "coding.h" #include "keyboard.h" #include "syssignal.h" +#include "sysstdio.h" #include "thread.h" #include @@ -1304,7 +1304,7 @@ module_abort (const char *format, ...) va_start (args, format); vfprintf (stderr, format, args); va_end (args); - fputc ('\n', stderr); + putc ('\n', stderr); fflush (NULL); emacs_abort (); } diff --git a/src/emacs.c b/src/emacs.c index 0f03dd656d3..9c93748a0f5 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1125,12 +1125,12 @@ main (int argc, char **argv) tem2 = Fsymbol_value (intern_c_string ("emacs-copyright")); if (!STRINGP (tem)) { - fprintf (stderr, "Invalid value of 'emacs-version'\n"); + fputs ("Invalid value of 'emacs-version'\n", stderr); exit (1); } if (!STRINGP (tem2)) { - fprintf (stderr, "Invalid value of 'emacs-copyright'\n"); + fputs ("Invalid value of 'emacs-copyright'\n", stderr); exit (1); } else @@ -1144,13 +1144,14 @@ main (int argc, char **argv) version = emacs_version; copyright = emacs_copyright; } - printf ("%s %s\n", PACKAGE_NAME, version); - printf ("%s\n", copyright); - printf ("%s comes with ABSOLUTELY NO WARRANTY.\n", PACKAGE_NAME); - printf ("You may redistribute copies of %s\n", PACKAGE_NAME); - printf ("under the terms of the GNU General Public License.\n"); - printf ("For more information about these matters, "); - printf ("see the file named COPYING.\n"); + printf (("%s %s\n" + "%s\n" + "%s comes with ABSOLUTELY NO WARRANTY.\n" + "You may redistribute copies of %s\n" + "under the terms of the GNU General Public License.\n" + "For more information about these matters, " + "see the file named COPYING.\n"), + PACKAGE_NAME, version, copyright, PACKAGE_NAME, PACKAGE_NAME); exit (0); } @@ -1246,7 +1247,7 @@ main (int argc, char **argv) } #endif /* HAVE_SETRLIMIT and RLIMIT_STACK and not CYGWIN */ - clearerr_unlocked (stdin); + clearerr (stdin); emacs_backtrace (-1); @@ -1344,7 +1345,7 @@ main (int argc, char **argv) int i; printf ("Usage: %s [OPTION-OR-FILENAME]...\n", argv[0]); for (i = 0; i < ARRAYELTS (usage_message); i++) - fputs_unlocked (usage_message[i], stdout); + fputs (usage_message[i], stdout); exit (0); } @@ -1402,7 +1403,7 @@ main (int argc, char **argv) before exiting. */ if (emacs_pipe (daemon_pipe) != 0) { - fprintf (stderr, "Cannot pipe!\n"); + fputs ("Cannot pipe!\n", stderr); exit (1); } } /* daemon_type == 2 */ @@ -1412,10 +1413,10 @@ main (int argc, char **argv) int systemd_socket = sd_listen_fds (1); if (systemd_socket > 1) - fprintf (stderr, - ("\n" - "Warning: systemd passed more than one socket to Emacs.\n" - "Try 'Accept=false' in the Emacs socket unit file.\n")); + fputs (("\n" + "Warning: systemd passed more than one socket to Emacs.\n" + "Try 'Accept=false' in the Emacs socket unit file.\n"), + stderr); else if (systemd_socket == 1 && (0 < sd_is_socket (SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1))) @@ -1423,9 +1424,10 @@ main (int argc, char **argv) #endif /* HAVE_LIBSYSTEMD */ #ifdef USE_GTK - fprintf (stderr, "\nWarning: due to a long standing Gtk+ bug\nhttps://gitlab.gnome.org/GNOME/gtk/issues/221\n\ + fputs ("\nWarning: due to a long standing Gtk+ bug\nhttps://gitlab.gnome.org/GNOME/gtk/issues/221\n\ Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.\n\ -Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.\n"); +Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.\n", + stderr); #endif /* USE_GTK */ if (daemon_type == 2) @@ -1457,12 +1459,12 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem if (retval < 0) { - fprintf (stderr, "Error reading status from child\n"); + fputs ("Error reading status from child\n", stderr); exit (1); } else if (retval == 0) { - fprintf (stderr, "Error: server did not start correctly\n"); + fputs ("Error: server did not start correctly\n", stderr); exit (1); } @@ -1488,7 +1490,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem if (! (0 <= fdStrlen && fdStrlen < sizeof fdStr)) { - fprintf (stderr, "daemon: child name too long\n"); + fputs ("daemon: child name too long\n", stderr); exit (EXIT_CANNOT_INVOKE); } @@ -1504,10 +1506,11 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem /* In exec'd: parse special dname into pipe and name info. */ if (!dname_arg || !*dname_arg || strnlen (dname_arg, 71) == 71 || !strchr (dname_arg, '\n')) - { - fprintf (stderr, "emacs daemon: daemon name absent or too long\n"); - exit (EXIT_CANNOT_INVOKE); - } + { + fputs ("emacs daemon: daemon name absent or too long\n", + stderr); + exit (EXIT_CANNOT_INVOKE); + } dname_arg2[0] = '\0'; sscanf (dname_arg, "\n%d,%d\n%s", &(daemon_pipe[0]), &(daemon_pipe[1]), dname_arg2); @@ -1531,7 +1534,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem exit (1); } #else /* MSDOS */ - fprintf (stderr, "This platform does not support daemon mode.\n"); + fputs ("This platform does not support daemon mode.\n", stderr); exit (1); #endif /* MSDOS */ if (dname_arg) @@ -2545,16 +2548,15 @@ You must run Emacs in batch mode in order to dump it. */) # define MAX_HEAP_BSS_DIFF (1024 * 1024) if (heap_bss_diff > MAX_HEAP_BSS_DIFF) - { - fprintf (stderr, "**************************************************\n"); - fprintf (stderr, "Warning: Your system has a gap between BSS and the\n"); - fprintf (stderr, ("heap (%"PRIuMAX" bytes). " - "This usually means that exec-shield\n"), - heap_bss_diff); - fprintf (stderr, "or something similar is in effect. The dump may\n"); - fprintf (stderr, "fail because of this. See the section about\n"); - fprintf (stderr, "exec-shield in etc/PROBLEMS for more information.\n"); - fprintf (stderr, "**************************************************\n"); + fprintf (stderr, + ("**************************************************\n" + "Warning: Your system has a gap between BSS and the\n" + "heap (%"PRIuMAX" bytes). This usually means that exec-shield\n" + "or something similar is in effect. The dump may\n" + "fail because of this. See the section about\n" + "exec-shield in etc/PROBLEMS for more information.\n" + "**************************************************\n"), + heap_bss_diff); } # endif @@ -2591,7 +2593,7 @@ You must run Emacs in batch mode in order to dump it. */) } # endif - fflush_unlocked (stdout); + fflush (stdout); /* Tell malloc where start of impure now is. */ /* Also arrange for warnings when nearly out of space. */ # if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC && !defined WINDOWSNT diff --git a/src/fileio.c b/src/fileio.c index 8f23a305a52..cce49c43b2e 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -5787,12 +5787,12 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */) { block_input (); if (!NILP (BVAR (b, filename))) - fwrite_unlocked (SDATA (BVAR (b, filename)), 1, - SBYTES (BVAR (b, filename)), stream); - putc_unlocked ('\n', stream); - fwrite_unlocked (SDATA (BVAR (b, auto_save_file_name)), 1, - SBYTES (BVAR (b, auto_save_file_name)), stream); - putc_unlocked ('\n', stream); + fwrite (SDATA (BVAR (b, filename)), 1, + SBYTES (BVAR (b, filename)), stream); + putc ('\n', stream); + fwrite (SDATA (BVAR (b, auto_save_file_name)), 1, + SBYTES (BVAR (b, auto_save_file_name)), stream); + putc ('\n', stream); unblock_input (); } @@ -5987,7 +5987,7 @@ effect except for flushing STREAM's data. */) binmode = NILP (mode) ? O_TEXT : O_BINARY; if (fp != stdin) - fflush_unlocked (fp); + fflush (fp); return (set_binary_mode (fileno (fp), binmode) == O_BINARY) ? Qt : Qnil; } diff --git a/src/image.c b/src/image.c index b4b6c1bac1c..e898a7364a8 100644 --- a/src/image.c +++ b/src/image.c @@ -2991,7 +2991,7 @@ slurp_file (int fd, ptrdiff_t *size) This can happen if the file grows as we read it. */ ptrdiff_t buflen = st.st_size; buf = xmalloc (buflen + 1); - if (fread_unlocked (buf, 1, buflen + 1, fp) == buflen) + if (fread (buf, 1, buflen + 1, fp) == buflen) *size = buflen; else { @@ -3338,7 +3338,7 @@ convert_mono_to_color_image (struct frame *f, struct image *img, DeleteDC (new_img_dc); DeleteObject (img->pixmap); if (new_pixmap == 0) - fprintf (stderr, "Failed to convert image to color.\n"); + fputs ("Failed to convert image to color.\n", stderr); else img->pixmap = new_pixmap; } @@ -6427,7 +6427,7 @@ png_read_from_file (png_structp png_ptr, png_bytep data, png_size_t length) { FILE *fp = png_get_io_ptr (png_ptr); - if (fread_unlocked (data, 1, length, fp) < length) + if (fread (data, 1, length, fp) < length) png_error (png_ptr, "Read error"); } @@ -6490,7 +6490,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c) } /* Check PNG signature. */ - if (fread_unlocked (sig, 1, sizeof sig, fp) != sizeof sig + if (fread (sig, 1, sizeof sig, fp) != sizeof sig || png_sig_cmp (sig, 0, sizeof sig)) { fclose (fp); @@ -7100,8 +7100,7 @@ our_stdio_fill_input_buffer (j_decompress_ptr cinfo) { ptrdiff_t bytes; - bytes = fread_unlocked (src->buffer, 1, JPEG_STDIO_BUFFER_SIZE, - src->file); + bytes = fread (src->buffer, 1, JPEG_STDIO_BUFFER_SIZE, src->file); if (bytes > 0) src->mgr.bytes_in_buffer = bytes; else diff --git a/src/keyboard.c b/src/keyboard.c index 56916e0cb4e..c47eecab9fb 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -3311,7 +3311,7 @@ record_char (Lisp_Object c) if (FIXNUMP (c)) { if (XUFIXNUM (c) < 0x100) - putc_unlocked (XUFIXNUM (c), dribble); + putc (XUFIXNUM (c), dribble); else fprintf (dribble, " 0x%"pI"x", XUFIXNUM (c)); } @@ -3324,15 +3324,14 @@ record_char (Lisp_Object c) if (SYMBOLP (dribblee)) { - putc_unlocked ('<', dribble); - fwrite_unlocked (SDATA (SYMBOL_NAME (dribblee)), sizeof (char), - SBYTES (SYMBOL_NAME (dribblee)), - dribble); - putc_unlocked ('>', dribble); + putc ('<', dribble); + fwrite (SDATA (SYMBOL_NAME (dribblee)), sizeof (char), + SBYTES (SYMBOL_NAME (dribblee)), dribble); + putc ('>', dribble); } } - fflush_unlocked (dribble); + fflush (dribble); unblock_input (); } } @@ -3769,7 +3768,7 @@ kbd_buffer_get_event (KBOARD **kbp, detaching from the terminal. */ || (IS_DAEMON && DAEMON_RUNNING)) { - int c = getchar_unlocked (); + int c = getchar (); XSETINT (obj, c); *kbp = current_kboard; return obj; @@ -10394,7 +10393,7 @@ handle_interrupt (bool in_signal_handler) sigemptyset (&blocked); sigaddset (&blocked, SIGINT); pthread_sigmask (SIG_BLOCK, &blocked, 0); - fflush_unlocked (stdout); + fflush (stdout); } reset_all_sys_modes (); diff --git a/src/lread.c b/src/lread.c index 27529c3d630..e06eafcf6cf 100644 --- a/src/lread.c +++ b/src/lread.c @@ -490,13 +490,12 @@ readbyte_from_stdio (void) block_input (); /* Interrupted reads have been observed while reading over the network. */ - while ((c = getc_unlocked (instream)) == EOF && errno == EINTR - && ferror_unlocked (instream)) + while ((c = getc (instream)) == EOF && errno == EINTR && ferror (instream)) { unblock_input (); maybe_quit (); block_input (); - clearerr_unlocked (instream); + clearerr (instream); } unblock_input (); @@ -3063,7 +3062,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list) = c = infile->buf[--infile->lookahead]; block_input (); for (; i < nskip && 0 <= c; i++) - saved_doc_string[i] = c = getc_unlocked (instream); + saved_doc_string[i] = c = getc (instream); unblock_input (); saved_doc_string_length = i; diff --git a/src/minibuf.c b/src/minibuf.c index d932dbe8e20..d9a6e15b05d 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -206,15 +206,15 @@ read_minibuf_noninteractive (Lisp_Object prompt, bool expflag, suppress_echo_on_tty (STDIN_FILENO); } - fwrite_unlocked (SDATA (prompt), 1, SBYTES (prompt), stdout); - fflush_unlocked (stdout); + fwrite (SDATA (prompt), 1, SBYTES (prompt), stdout); + fflush (stdout); val = Qnil; size = 100; len = 0; line = xmalloc (size); - while ((c = getchar_unlocked ()) != '\n' && c != '\r') + while ((c = getchar ()) != '\n' && c != '\r') { if (c == EOF) { @@ -224,7 +224,7 @@ read_minibuf_noninteractive (Lisp_Object prompt, bool expflag, else { if (hide_char) - fprintf (stdout, "%c", hide_char); + putchar (hide_char); if (len == size) line = xpalloc (line, &size, 1, -1, sizeof *line); line[len++] = c; @@ -234,7 +234,7 @@ read_minibuf_noninteractive (Lisp_Object prompt, bool expflag, /* Reset tty. */ if (hide_char) { - fprintf (stdout, "\n"); + putc ('\n', stdout); if (etty_valid) { emacs_set_tty (STDIN_FILENO, &etty, 0); diff --git a/src/nsfont.m b/src/nsfont.m index eca97ab86cc..e22a954e63f 100644 --- a/src/nsfont.m +++ b/src/nsfont.m @@ -212,7 +212,7 @@ ns_descriptor_to_entity (NSFontDescriptor *desc, if (NSFONT_TRACE) { - fprintf (stderr, "created font_entity:\n "); + fputs ("created font_entity:\n ", stderr); debug_print (font_entity); } @@ -1472,16 +1472,13 @@ ns_dump_glyphstring (struct glyph_string *s) { int i; - fprintf (stderr, "Glyph string len = %d at (%d, %d) overhang (%d, %d)," -"overlap = %d, bg_filled = %d:", + fprintf (stderr, ("Glyph string len = %d at (%d, %d) overhang (%d, %d)," + "overlap = %d, bg_filled = %d:"), s->nchars, s->x, s->y, s->left_overhang, s->right_overhang, s->row->overlapping_p, s->background_filled_p); for (i =0; inchars; i++) - { - int c = s->first_glyph[i].u.ch; - fprintf (stderr, "%c", c); - } - fprintf (stderr, "\n"); + putc (s->first_glyph[i].u.ch, stderr); + putc ('\n', stderr); } static void syms_of_nsfont_for_pdumper (void); diff --git a/src/nsterm.h b/src/nsterm.h index 567f462ec69..9773eb3e662 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -23,6 +23,7 @@ along with GNU Emacs. If not, see . */ #include "character.h" #include "font.h" #include "sysselect.h" +#include "sysstdio.h" #ifdef HAVE_NS #ifdef __OBJC__ @@ -180,7 +181,7 @@ char const * nstrace_fullscreen_type_name (int); __FILE__, __LINE__, nstrace_num++, \ 2*nstrace_depth, " | | | | | | | | | | | | | | | .."); \ fprintf (stderr, __VA_ARGS__); \ - fprintf (stderr, "\n"); \ + putc ('\n', stderr); \ } \ } \ while(0) diff --git a/src/nsterm.m b/src/nsterm.m index bc1c7860aac..02331826d9b 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -2466,7 +2466,7 @@ ns_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, if (*fp == NULL) { - fprintf (stderr, "Warning: ns_mouse_position () called with null *fp.\n"); + fputs ("Warning: ns_mouse_position () called with null *fp.\n", stderr); return; } @@ -5613,7 +5613,7 @@ ns_term_shutdown (int sig) if (type == NSEventTypeCursorUpdate && window == nil) { - fprintf (stderr, "Dropping external cursor update event.\n"); + fputs ("Dropping external cursor update event.\n", stderr); return; } @@ -6333,7 +6333,7 @@ not_in_argv (NSString *arg) https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/HandlingKeyEvents.html. */ if (NS_KEYLOG && !processingCompose) - fprintf (stderr, "keyDown: Begin compose sequence.\n"); + fputs ("keyDown: Begin compose sequence.\n", stderr); /* FIXME: interpretKeyEvents doesn’t seem to send insertText if ⌘ is used as shift-like modifier, at least on El Capitan. Mask it @@ -8291,7 +8291,7 @@ not_in_argv (NSString *arg) } else { - fprintf (stderr, "Invalid data type in dragging pasteboard\n"); + fputs ("Invalid data type in dragging pasteboard\n", stderr); return NO; } diff --git a/src/pdumper.c b/src/pdumper.c index c00f8a0af54..8b630d221b1 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -23,7 +23,6 @@ along with GNU Emacs. If not, see . */ #include #include #include -#include #include #include #include @@ -42,6 +41,7 @@ along with GNU Emacs. If not, see . */ #include "lisp.h" #include "pdumper.h" #include "window.h" +#include "sysstdio.h" #include "systime.h" #include "thread.h" #include "bignum.h" @@ -329,7 +329,7 @@ dump_fingerprint (const char *label, unsigned char const *xfingerprint) fprintf (stderr, "%s: ", label); for (int i = 0; i < 32; ++i) fprintf (stderr, "%02x", (unsigned) xfingerprint[i]); - fprintf (stderr, "\n"); + putc ('\n', stderr); } /* Format of an Emacs portable dump file. All offsets are relative to @@ -1404,9 +1404,9 @@ print_paths_to_root_1 (struct dump_context *ctx, referrers = XCDR (referrers); Lisp_Object repr = Fprin1_to_string (referrer, Qnil); for (int i = 0; i < level; ++i) - fputc (' ', stderr); + putc (' ', stderr); fwrite (SDATA (repr), 1, SBYTES (repr), stderr); - fputc ('\n', stderr); + putc ('\n', stderr); print_paths_to_root_1 (ctx, referrer, level + 1); } } @@ -4226,14 +4226,14 @@ types. */) dump_seek (ctx, 0); dump_write (ctx, &ctx->header, sizeof (ctx->header)); - fprintf (stderr, "Dump complete\n"); fprintf (stderr, - "Byte counts: header=%lu hot=%lu discardable=%lu cold=%lu\n", + ("Dump complete\n" + "Byte counts: header=%lu hot=%lu discardable=%lu cold=%lu\n" + "Reloc counts: hot=%u discardable=%u\n"), (unsigned long) (header_end - header_start), (unsigned long) (hot_end - hot_start), (unsigned long) (discardable_end - ctx->header.discardable_start), - (unsigned long) (cold_end - ctx->header.cold_start)); - fprintf (stderr, "Reloc counts: hot=%u discardable=%u\n", + (unsigned long) (cold_end - ctx->header.cold_start), number_hot_relocations, number_discardable_relocations); diff --git a/src/print.c b/src/print.c index dc44b1e89e0..6623244c598 100644 --- a/src/print.c +++ b/src/print.c @@ -233,7 +233,7 @@ printchar_to_stream (unsigned int ch, FILE *stream) { if (ASCII_CHAR_P (ch)) { - putc_unlocked (ch, stream); + putc (ch, stream); #ifdef WINDOWSNT /* Send the output to a debugger (nothing happens if there isn't one). */ @@ -251,7 +251,7 @@ printchar_to_stream (unsigned int ch, FILE *stream) if (encode_p) encoded_ch = code_convert_string_norecord (encoded_ch, coding_system, true); - fwrite_unlocked (SSDATA (encoded_ch), 1, SBYTES (encoded_ch), stream); + fwrite (SSDATA (encoded_ch), 1, SBYTES (encoded_ch), stream); #ifdef WINDOWSNT if (print_output_debug_flag && stream == stderr) OutputDebugString (SSDATA (encoded_ch)); @@ -303,7 +303,7 @@ printchar (unsigned int ch, Lisp_Object fun) if (DISP_TABLE_P (Vstandard_display_table)) printchar_to_stream (ch, stdout); else - fwrite_unlocked (str, 1, len, stdout); + fwrite (str, 1, len, stdout); noninteractive_need_newline = 1; } else @@ -374,7 +374,7 @@ strout (const char *ptr, ptrdiff_t size, ptrdiff_t size_byte, } } else - fwrite_unlocked (ptr, 1, size_byte, stdout); + fwrite (ptr, 1, size_byte, stdout); noninteractive_need_newline = 1; } @@ -825,7 +825,7 @@ append to existing target file. */) report_file_error ("Cannot open debugging output stream", file); } - fflush_unlocked (stderr); + fflush (stderr); if (dup2 (fd, STDERR_FILENO) < 0) report_file_error ("dup2", file); if (fd != stderr_dup) @@ -840,7 +840,7 @@ void debug_print (Lisp_Object arg) { Fprin1 (arg, Qexternal_debugging_output); - fprintf (stderr, "\r\n"); + fputs ("\r\n", stderr); } void safe_debug_print (Lisp_Object) EXTERNALLY_VISIBLE; diff --git a/src/regex-emacs.c b/src/regex-emacs.c index ac9f91dacbc..bf2ad072f56 100644 --- a/src/regex-emacs.c +++ b/src/regex-emacs.c @@ -436,7 +436,7 @@ extract_number_and_incr (re_char **source) #ifdef REGEX_EMACS_DEBUG /* Use standard I/O for debugging. */ -# include +# include "sysstdio.h" static int regex_emacs_debug = -100000; @@ -453,7 +453,7 @@ static void debug_putchar (int c) { if (c >= 32 && c <= 126) - fputc (c, stderr); + putc (c, stderr); else { unsigned int uc = c; @@ -482,12 +482,12 @@ print_fastmap (char *fastmap) } if (was_a_range) { - fprintf (stderr, "-"); + debug_putchar ('-'); debug_putchar (i - 1); } } } - fputc ('\n', stderr); + putc ('\n', stderr); } @@ -503,7 +503,7 @@ print_partial_compiled_pattern (re_char *start, re_char *end) if (start == NULL) { - fprintf (stderr, "(null)\n"); + fputs ("(null)\n", stderr); return; } @@ -515,11 +515,11 @@ print_partial_compiled_pattern (re_char *start, re_char *end) switch ((re_opcode_t) *p++) { case no_op: - fprintf (stderr, "/no_op"); + fputs ("/no_op", stderr); break; case succeed: - fprintf (stderr, "/succeed"); + fputs ("/succeed", stderr); break; case exactn: @@ -527,7 +527,7 @@ print_partial_compiled_pattern (re_char *start, re_char *end) fprintf (stderr, "/exactn/%d", mcnt); do { - fprintf (stderr, "/"); + debug_putchar ('/'); debug_putchar (*p++); } while (--mcnt); @@ -546,7 +546,7 @@ print_partial_compiled_pattern (re_char *start, re_char *end) break; case anychar: - fprintf (stderr, "/anychar"); + fputs ("/anychar", stderr); break; case charset: @@ -561,7 +561,7 @@ print_partial_compiled_pattern (re_char *start, re_char *end) (re_opcode_t) *(p - 1) == charset_not ? "^" : ""); if (p + *p >= pend) - fprintf (stderr, " !extends past end of pattern! "); + fputs (" !extends past end of pattern! ", stderr); for (c = 0; c < 256; c++) if (c / 8 < length @@ -570,7 +570,7 @@ print_partial_compiled_pattern (re_char *start, re_char *end) /* Are we starting a range? */ if (last + 1 == c && ! in_range) { - fprintf (stderr, "-"); + debug_putchar ('-'); in_range = true; } /* Have we broken a range? */ @@ -589,14 +589,14 @@ print_partial_compiled_pattern (re_char *start, re_char *end) if (in_range) debug_putchar (last); - fprintf (stderr, "]"); + debug_putchar (']'); p += 1 + length; if (has_range_table) { int count; - fprintf (stderr, "has-range-table"); + fputs ("has-range-table", stderr); /* ??? Should print the range table; for now, just skip it. */ p += 2; /* skip range table bits */ @@ -607,11 +607,11 @@ print_partial_compiled_pattern (re_char *start, re_char *end) break; case begline: - fprintf (stderr, "/begline"); + fputs ("/begline", stderr); break; case endline: - fprintf (stderr, "/endline"); + fputs ("/endline", stderr); break; case on_failure_jump: @@ -670,70 +670,70 @@ print_partial_compiled_pattern (re_char *start, re_char *end) break; case wordbound: - fprintf (stderr, "/wordbound"); + fputs ("/wordbound", stderr); break; case notwordbound: - fprintf (stderr, "/notwordbound"); + fputs ("/notwordbound", stderr); break; case wordbeg: - fprintf (stderr, "/wordbeg"); + fputs ("/wordbeg", stderr); break; case wordend: - fprintf (stderr, "/wordend"); + fputs ("/wordend", stderr); break; case symbeg: - fprintf (stderr, "/symbeg"); + fputs ("/symbeg", stderr); break; case symend: - fprintf (stderr, "/symend"); + fputs ("/symend", stderr); break; case syntaxspec: - fprintf (stderr, "/syntaxspec"); + fputs ("/syntaxspec", stderr); mcnt = *p++; fprintf (stderr, "/%d", mcnt); break; case notsyntaxspec: - fprintf (stderr, "/notsyntaxspec"); + fputs ("/notsyntaxspec", stderr); mcnt = *p++; fprintf (stderr, "/%d", mcnt); break; case at_dot: - fprintf (stderr, "/at_dot"); + fputs ("/at_dot", stderr); break; case categoryspec: - fprintf (stderr, "/categoryspec"); + fputs ("/categoryspec", stderr); mcnt = *p++; fprintf (stderr, "/%d", mcnt); break; case notcategoryspec: - fprintf (stderr, "/notcategoryspec"); + fputs ("/notcategoryspec", stderr); mcnt = *p++; fprintf (stderr, "/%d", mcnt); break; case begbuf: - fprintf (stderr, "/begbuf"); + fputs ("/begbuf", stderr); break; case endbuf: - fprintf (stderr, "/endbuf"); + fputs ("/endbuf", stderr); break; default: fprintf (stderr, "?%d", *(p-1)); } - fprintf (stderr, "\n"); + putc ('\n', stderr); } fprintf (stderr, "%td:\tend of pattern.\n", p - start); @@ -751,14 +751,13 @@ print_compiled_pattern (struct re_pattern_buffer *bufp) if (bufp->fastmap_accurate && bufp->fastmap) { - fprintf (stderr, "fastmap: "); + fputs ("fastmap: ", stderr); print_fastmap (bufp->fastmap); } fprintf (stderr, "re_nsub: %td\t", bufp->re_nsub); fprintf (stderr, "regs_alloc: %d\t", bufp->regs_allocated); fprintf (stderr, "can_be_null: %d\n", bufp->can_be_null); - fflush (stderr); /* Perhaps we should print the translate table? */ } @@ -768,7 +767,7 @@ print_double_string (re_char *where, re_char *string1, ptrdiff_t size1, re_char *string2, ptrdiff_t size2) { if (where == NULL) - fprintf (stderr, "(null)"); + fputs ("(null)", stderr); else { int i; @@ -1751,7 +1750,7 @@ regex_compile (re_char *pattern, ptrdiff_t size, { for (ptrdiff_t debug_count = 0; debug_count < size; debug_count++) debug_putchar (pattern[debug_count]); - fputc ('\n', stderr); + putc ('\n', stderr); } #endif diff --git a/src/sysdep.c b/src/sysdep.c index c7d7eefc2ab..99d3ee60698 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -1472,7 +1472,7 @@ reset_sys_modes (struct tty_display_info *tty_out) { if (noninteractive) { - fflush_unlocked (stdout); + fflush (stdout); return; } if (!tty_out->term_initted) @@ -1495,11 +1495,11 @@ reset_sys_modes (struct tty_display_info *tty_out) tty_turn_off_insert (tty_out); for (int i = cursorX (tty_out); i < FrameCols (tty_out) - 1; i++) - fputc_unlocked (' ', tty_out->output); + putc (' ', tty_out->output); } cmgoto (tty_out, FrameRows (tty_out) - 1, 0); - fflush_unlocked (tty_out->output); + fflush (tty_out->output); if (tty_out->terminal->reset_terminal_modes_hook) tty_out->terminal->reset_terminal_modes_hook (tty_out->terminal); @@ -2783,7 +2783,7 @@ close_output_streams (void) /* Do not close stderr if addresses are being sanitized, as the sanitizer might report to stderr after this function is invoked. */ if (ADDRESS_SANITIZER - ? fflush_unlocked (stderr) != 0 || ferror (stderr) + ? fflush (stderr) != 0 || ferror (stderr) : close_stream (stderr) != 0) _exit (EXIT_FAILURE); } @@ -3184,7 +3184,7 @@ procfs_ttyname (int rdev) char minor[25]; /* 2 32-bit numbers + dash */ char *endp; - for (; !feof_unlocked (fdev) && !ferror_unlocked (fdev); name[0] = 0) + for (; !feof (fdev) && !ferror (fdev); name[0] = 0) { if (fscanf (fdev, "%*s %s %u %s %*s\n", name, &major, minor) >= 3 && major == MAJOR (rdev)) @@ -3234,7 +3234,7 @@ procfs_get_total_memory (void) break; case 0: - while ((c = getc_unlocked (fmem)) != EOF && c != '\n') + while ((c = getc (fmem)) != EOF && c != '\n') continue; done = c == EOF; break; diff --git a/src/sysstdio.h b/src/sysstdio.h index a2364c4e1fb..68ae043fe33 100644 --- a/src/sysstdio.h +++ b/src/sysstdio.h @@ -22,6 +22,7 @@ along with GNU Emacs. If not, see . */ #include #include +#include "unlocked-io.h" extern FILE *emacs_fopen (char const *, char const *); extern void close_output_streams (void); @@ -34,45 +35,4 @@ extern void close_output_streams (void); # define FOPEN_TEXT "" #endif -/* These are compatible with unlocked-io.h, if both files are included. */ -#if !HAVE_DECL_CLEARERR_UNLOCKED -# define clearerr_unlocked(x) clearerr (x) -#endif -#if !HAVE_DECL_FEOF_UNLOCKED -# define feof_unlocked(x) feof (x) -#endif -#if !HAVE_DECL_FERROR_UNLOCKED -# define ferror_unlocked(x) ferror (x) -#endif -#if !HAVE_DECL_FFLUSH_UNLOCKED -# define fflush_unlocked(x) fflush (x) -#endif -#if !HAVE_DECL_FGETS_UNLOCKED -# define fgets_unlocked(x,y,z) fgets (x,y,z) -#endif -#if !HAVE_DECL_FPUTC_UNLOCKED -# define fputc_unlocked(x,y) fputc (x,y) -#endif -#if !HAVE_DECL_FPUTS_UNLOCKED -# define fputs_unlocked(x,y) fputs (x,y) -#endif -#if !HAVE_DECL_FREAD_UNLOCKED -# define fread_unlocked(w,x,y,z) fread (w,x,y,z) -#endif -#if !HAVE_DECL_FWRITE_UNLOCKED -# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z) -#endif -#if !HAVE_DECL_GETC_UNLOCKED -# define getc_unlocked(x) getc (x) -#endif -#if !HAVE_DECL_GETCHAR_UNLOCKED -# define getchar_unlocked() getchar () -#endif -#if !HAVE_DECL_PUTC_UNLOCKED -# define putc_unlocked(x,y) putc (x,y) -#endif -#if !HAVE_DECL_PUTCHAR_UNLOCKED -# define putchar_unlocked(x) putchar (x) -#endif - #endif /* EMACS_SYSSTDIO_H */ diff --git a/src/term.c b/src/term.c index 8b5a710d80a..b058d8bdad0 100644 --- a/src/term.c +++ b/src/term.c @@ -145,7 +145,7 @@ tty_ring_bell (struct frame *f) OUTPUT (tty, (tty->TS_visible_bell && visible_bell ? tty->TS_visible_bell : tty->TS_bell)); - fflush_unlocked (tty->output); + fflush (tty->output); } } @@ -170,10 +170,9 @@ tty_send_additional_strings (struct terminal *terminal, Lisp_Object sym) Lisp_Object string = XCAR (extra_codes); if (STRINGP (string)) { - fwrite_unlocked (SDATA (string), 1, SBYTES (string), tty->output); + fwrite (SDATA (string), 1, SBYTES (string), tty->output); if (tty->termscript) - fwrite_unlocked (SDATA (string), 1, SBYTES (string), - tty->termscript); + fwrite (SDATA (string), 1, SBYTES (string), tty->termscript); } } } @@ -201,7 +200,7 @@ tty_set_terminal_modes (struct terminal *terminal) OUTPUT_IF (tty, tty->TS_keypad_mode); losecursor (tty); tty_send_additional_strings (terminal, Qtty_mode_set_strings); - fflush_unlocked (tty->output); + fflush (tty->output); } } @@ -224,7 +223,7 @@ tty_reset_terminal_modes (struct terminal *terminal) /* Output raw CR so kernel can track the cursor hpos. */ current_tty = tty; cmputc ('\r'); - fflush_unlocked (tty->output); + fflush (tty->output); } } @@ -239,7 +238,7 @@ tty_update_end (struct frame *f) tty_show_cursor (tty); tty_turn_off_insert (tty); tty_background_highlight (tty); - fflush_unlocked (tty->output); + fflush (tty->output); } /* The implementation of set_terminal_window for termcap frames. */ @@ -501,8 +500,8 @@ tty_clear_end_of_line (struct frame *f, int first_unused_hpos) for (i = curX (tty); i < first_unused_hpos; i++) { if (tty->termscript) - fputc_unlocked (' ', tty->termscript); - fputc_unlocked (' ', tty->output); + putc (' ', tty->termscript); + putc (' ', tty->output); } cmplus (tty, first_unused_hpos - curX (tty)); } @@ -775,11 +774,10 @@ tty_write_glyphs (struct frame *f, struct glyph *string, int len) if (coding->produced > 0) { block_input (); - fwrite_unlocked (conversion_buffer, 1, coding->produced, tty->output); - clearerr_unlocked (tty->output); + fwrite (conversion_buffer, 1, coding->produced, tty->output); + clearerr (tty->output); if (tty->termscript) - fwrite_unlocked (conversion_buffer, 1, coding->produced, - tty->termscript); + fwrite (conversion_buffer, 1, coding->produced, tty->termscript); unblock_input (); } string += n; @@ -836,11 +834,10 @@ tty_write_glyphs_with_face (register struct frame *f, register struct glyph *str if (coding->produced > 0) { block_input (); - fwrite_unlocked (conversion_buffer, 1, coding->produced, tty->output); - clearerr_unlocked (tty->output); + fwrite (conversion_buffer, 1, coding->produced, tty->output); + clearerr (tty->output); if (tty->termscript) - fwrite_unlocked (conversion_buffer, 1, coding->produced, - tty->termscript); + fwrite (conversion_buffer, 1, coding->produced, tty->termscript); unblock_input (); } @@ -922,11 +919,10 @@ tty_insert_glyphs (struct frame *f, struct glyph *start, int len) if (coding->produced > 0) { block_input (); - fwrite_unlocked (conversion_buffer, 1, coding->produced, tty->output); - clearerr_unlocked (tty->output); + fwrite (conversion_buffer, 1, coding->produced, tty->output); + clearerr (tty->output); if (tty->termscript) - fwrite_unlocked (conversion_buffer, 1, coding->produced, - tty->termscript); + fwrite (conversion_buffer, 1, coding->produced, tty->termscript); unblock_input (); } @@ -3331,7 +3327,7 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx, which calls tty_show_cursor. Re-hide it, so it doesn't show through the menus. */ tty_hide_cursor (tty); - fflush_unlocked (tty->output); + fflush (tty->output); } sf->mouse_moved = 0; @@ -3339,7 +3335,7 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx, while (statecount--) free_saved_screen (state[statecount].screen_behind); tty_show_cursor (tty); /* Turn cursor back on. */ - fflush_unlocked (tty->output); + fflush (tty->output); /* Clean up any mouse events that are waiting inside Emacs event queue. These events are likely to be generated before the menu was even @@ -4398,10 +4394,10 @@ use the Bourne shell command 'TERM=...; export TERM' (C-shell:\n\ static void vfatal (const char *str, va_list ap) { - fprintf (stderr, "emacs: "); + fputs ("emacs: ", stderr); vfprintf (stderr, str, ap); if (! (str[0] && str[strlen (str) - 1] == '\n')) - fprintf (stderr, "\n"); + putc ('\n', stderr); exit (1); } diff --git a/src/unexhp9k800.c b/src/unexhp9k800.c index cbf1835b9ee..d2943eb18c9 100644 --- a/src/unexhp9k800.c +++ b/src/unexhp9k800.c @@ -52,8 +52,8 @@ #include #include "unexec.h" #include "lisp.h" +#include "sysstdio.h" -#include #include #include #include @@ -167,7 +167,7 @@ read_header (int file, struct header *hdr, struct som_exec_auxhdr *auxhdr) if (hdr->a_magic != EXEC_MAGIC && hdr->a_magic != SHARE_MAGIC && hdr->a_magic != DEMAND_MAGIC) { - fprintf (stderr, "a.out file doesn't have valid magic number\n"); + fputs ("a.out file doesn't have valid magic number\n", stderr); exit (1); } diff --git a/src/unexmacosx.c b/src/unexmacosx.c index a94c0cccb6b..5f52cedb2b7 100644 --- a/src/unexmacosx.c +++ b/src/unexmacosx.c @@ -97,9 +97,9 @@ along with GNU Emacs. If not, see . */ #include "unexec.h" #include "lisp.h" +#include "sysstdio.h" #include -#include #include #include #include @@ -303,9 +303,9 @@ unexec_error (const char *format, ...) va_list ap; va_start (ap, format); - fprintf (stderr, "unexec: "); + fputs ("unexec: ", stderr); vfprintf (stderr, format, ap); - fprintf (stderr, "\n"); + putc ('\n', stderr); va_end (ap); exit (1); } diff --git a/src/widget.c b/src/widget.c index e662dd3ecdf..c3d396ddab0 100644 --- a/src/widget.c +++ b/src/widget.c @@ -31,10 +31,10 @@ along with GNU Emacs. If not, see . */ #include #include "widget.h" -#include #include #include "lisp.h" +#include "sysstdio.h" #include "xterm.h" #include "frame.h" @@ -364,8 +364,7 @@ EmacsFrameInitialize (Widget request, Widget new, ArgList dum1, Cardinal *dum2) if (!ew->emacs_frame.frame) { - fprintf (stderr, - "can't create an emacs frame widget without a frame\n"); + fputs ("can't create an emacs frame widget without a frame\n", stderr); exit (1); } diff --git a/src/xdisp.c b/src/xdisp.c index 75cc97df1c0..2711e54382d 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -302,7 +302,6 @@ along with GNU Emacs. If not, see . */ buffer_posn_from_coords in dispnew.c for how this is handled. */ #include -#include #include #include #include @@ -311,6 +310,7 @@ along with GNU Emacs. If not, see . */ #include "atimer.h" #include "composite.h" #include "keyboard.h" +#include "sysstdio.h" #include "systime.h" #include "frame.h" #include "window.h" @@ -10714,7 +10714,7 @@ message_to_stderr (Lisp_Object m) if (noninteractive_need_newline) { noninteractive_need_newline = false; - fputc ('\n', stderr); + putc ('\n', stderr); } if (STRINGP (m)) { @@ -10728,7 +10728,7 @@ message_to_stderr (Lisp_Object m) else s = m; - /* We want to write this out with a single fwrite call so that + /* We want to write this out with a single call so that output doesn't interleave with other processes writing to stderr at the same time. */ { @@ -10742,9 +10742,7 @@ message_to_stderr (Lisp_Object m) } } else if (!cursor_in_echo_area) - fputc ('\n', stderr); - - fflush (stderr); + putc ('\n', stderr); } /* The non-logging version of message3. @@ -10889,11 +10887,11 @@ vmessage (const char *m, va_list ap) if (m) { if (noninteractive_need_newline) - fputc ('\n', stderr); + putc ('\n', stderr); noninteractive_need_newline = false; vfprintf (stderr, m, ap); if (!cursor_in_echo_area) - fputc ('\n', stderr); + putc ('\n', stderr); fflush (stderr); } } @@ -19648,9 +19646,9 @@ dump_glyph_row (struct glyph_row *row, int vpos, int glyphs) { if (glyphs != 1) { - fprintf (stderr, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n"); - fprintf (stderr, "==============================================================================\n"); - + fputs (("Row Start End Used oE><\\CTZFesm X Y W H V A P\n" + "==============================================================================\n"), + stderr); fprintf (stderr, "%3d %9"pD"d %9"pD"d %4d %1.1d%1.1d%1.1d%1.1d\ %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n", vpos, @@ -19701,7 +19699,8 @@ dump_glyph_row (struct glyph_row *row, int vpos, int glyphs) ++glyph_end; if (glyph < glyph_end) - fprintf (stderr, " Glyph# Type Pos O W Code C Face LR\n"); + fputs (" Glyph# Type Pos O W Code C Face LR\n", + stderr); for (; glyph < glyph_end; ++glyph) dump_glyph (row, glyph, area); @@ -19761,7 +19760,7 @@ with numeric argument, its value is passed as the GLYPHS flag. */) BUF_PT (buffer), BUF_BEGV (buffer), BUF_ZV (buffer)); fprintf (stderr, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n", w->cursor.x, w->cursor.y, w->cursor.hpos, w->cursor.vpos); - fprintf (stderr, "=============================================\n"); + fputs ("=============================================\n", stderr); dump_glyph_matrix (w->current_matrix, TYPE_RANGED_FIXNUMP (int, glyphs) ? XFIXNUM (glyphs) : 0); return Qnil; @@ -19778,7 +19777,7 @@ Only text-mode frames have frame glyph matrices. */) if (f->current_matrix) dump_glyph_matrix (f->current_matrix, 1); else - fprintf (stderr, "*** This frame doesn't have a frame glyph matrix ***\n"); + fputs ("*** This frame doesn't have a frame glyph matrix ***\n", stderr); return Qnil; } @@ -25974,7 +25973,7 @@ extern void dump_glyph_string (struct glyph_string *) EXTERNALLY_VISIBLE; void dump_glyph_string (struct glyph_string *s) { - fprintf (stderr, "glyph string\n"); + fputs ("glyph string\n", stderr); fprintf (stderr, " x, y, w, h = %d, %d, %d, %d\n", s->x, s->y, s->width, s->height); fprintf (stderr, " ybase = %d\n", s->ybase); diff --git a/src/xfaces.c b/src/xfaces.c index d9e66eaf2d1..c3cae7e2a68 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -418,21 +418,18 @@ DEFUN ("dump-colors", Fdump_colors, Sdump_colors, 0, 0, 0, { int i, n; - fputc ('\n', stderr); + putc ('\n', stderr); for (i = n = 0; i < ARRAYELTS (color_count); ++i) if (color_count[i]) { fprintf (stderr, "%3d: %5d", i, color_count[i]); ++n; - if (n % 5 == 0) - fputc ('\n', stderr); - else - fputc ('\t', stderr); + putc (n % 5 == 0 ? '\n' : '\t', stderr); } if (n % 5 != 0) - fputc ('\n', stderr); + putc ('\n', stderr); return Qnil; } @@ -6363,7 +6360,7 @@ where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */) int red, green, blue; int num; - while (fgets_unlocked (buf, sizeof (buf), fp) != NULL) { + while (fgets (buf, sizeof (buf), fp) != NULL) if (sscanf (buf, "%d %d %d %n", &red, &green, &blue, &num) == 3) { #ifdef HAVE_NTGUI @@ -6377,7 +6374,6 @@ where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */) cmap = Fcons (Fcons (make_string (name, len), make_fixnum (color)), cmap); } - } fclose (fp); } unblock_input (); @@ -6429,14 +6425,14 @@ DEFUN ("dump-face", Fdump_face, Sdump_face, 0, 1, 0, doc: /* */) { int i; - fprintf (stderr, "font selection order: "); + fputs ("font selection order: ", stderr); for (i = 0; i < ARRAYELTS (font_sort_order); ++i) fprintf (stderr, "%d ", font_sort_order[i]); - fprintf (stderr, "\n"); + putc ('\n', stderr); - fprintf (stderr, "alternative fonts: "); + fputs ("alternative fonts: ", stderr); debug_print (Vface_alternative_font_family_alist); - fprintf (stderr, "\n"); + putc ('\n', stderr); for (i = 0; i < FRAME_FACE_CACHE (SELECTED_FRAME ())->used; ++i) Fdump_face (make_fixnum (i)); diff --git a/src/xselect.c b/src/xselect.c index ed68e4b1a6d..d74f064a1c7 100644 --- a/src/xselect.c +++ b/src/xselect.c @@ -21,7 +21,6 @@ along with GNU Emacs. If not, see . */ #include #include -#include /* TRACE_SELECTION needs this. */ #ifdef HAVE_SYS_TYPES_H #include @@ -33,6 +32,7 @@ along with GNU Emacs. If not, see . */ #include "xterm.h" /* for all of the X includes */ #include "frame.h" /* Need this to get the X window of selected_frame */ #include "blockinput.h" +#include "sysstdio.h" /* TRACE_SELECTION needs this. */ #include "termhooks.h" #include "keyboard.h" #include "pdumper.h" @@ -2172,9 +2172,10 @@ If the problem persists, set `%s' to nil."); static Lisp_Object x_clipboard_manager_error_2 (Lisp_Object err) { - fprintf (stderr, "Error saving to X clipboard manager.\n\ -If the problem persists, set '%s' \ -to nil.\n", "x-select-enable-clipboard-manager"); + fputs (("Error saving to X clipboard manager.\n" + "If the problem persists," + " set 'x-select-enable-clipboard-manager' to nil.\n"), + stderr); return Qnil; } diff --git a/src/xterm.c b/src/xterm.c index 38bc17de973..c96aa74a7a6 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -21,12 +21,12 @@ along with GNU Emacs. If not, see . */ /* Xt features made by Fred Pierresteguy. */ #include -#include #include #include #include "lisp.h" #include "blockinput.h" +#include "sysstdio.h" /* This may include sys/types.h, and that somehow loses if this is not done before the other system files. */ @@ -13441,8 +13441,8 @@ x_initialize (void) #if THREADS_ENABLED /* This must be called before any other Xlib routines. */ if (XInitThreads () == 0) - fprintf (stderr, - "Warning: An error occurred initializing X11 thread support!\n"); + fputs ("Warning: An error occurred initializing X11 thread support!\n", + stderr); #endif #ifdef USE_X_TOOLKIT diff --git a/src/xwidget.c b/src/xwidget.c index 2486a2d4da8..121510ebac0 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -26,6 +26,7 @@ along with GNU Emacs. If not, see . */ #include "frame.h" #include "keyboard.h" #include "gtkutil.h" +#include "sysstdio.h" #include #include @@ -690,7 +691,8 @@ x_draw_xwidget_glyph_string (struct glyph_string *s) struct xwidget *xw = XXWIDGET (xwidget); \ if (!xw->widget_osr || !WEBKIT_IS_WEB_VIEW (xw->widget_osr)) \ { \ - printf ("ERROR xw->widget_osr does not hold a webkit instance\n"); \ + fputs ("ERROR xw->widget_osr does not hold a webkit instance\n", \ + stdout); \ return Qnil; \ } -- cgit v1.2.1