1. 03 Jun, 2013 1 commit
    • Paul Eggert's avatar
      Fix minor problems found by static checking. · 3d5ee10a
      Paul Eggert authored
      * data.c (pure_write_error):
      Use xsignal2, not Fsignal, as Fsignal might return.
      * eval.c (set_backtrace_debug_on_exit): Now static.
      (backtrace_p, backtrace_top, backtrace_next, record_in_backtrace):
      No longer inline.  EXTERN_INLINE is needed only for functions
      defined in .h files.  Reindent function header as per GNU style.
      (backtrace_p, backtrace_top, backtrace_next):
      Mark EXTERNALLY_VISIBLE so they don't get optimized away by the
      compiler or linker.  Add extern decls to pacify gcc -Wall.
      * frame.c, frame.h (Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource):
      Now static.
      * frame.c (free_monitors): Define only on platforms that need it.
      * nsterm.m (ns_term_init):
      * process.c (catch_child_signal):
      Don't worry about whether SIGCHLD is defined, as SIGCHLD is
      defined on all porting targets these days.
      * process.c, process.h (catch_child_signal):
      Make it extern only if NS_IMPL_GNUSTEP is defined.
      3d5ee10a
  2. 02 Jun, 2013 1 commit
    • Jan Djärv's avatar
      Update the GNUStep port so it works OK. Redraw and sizing bugs remain. · c0342369
      Jan Djärv authored
      * nextstep/templates/Info-gnustep.plist.in: Add NSDocumentClass EmacsDocument.
      
      * src/nsfns.m (x_set_foreground_color, x_set_background_color): Use
      EmacsCGFloat.
      (ns_implicitly_set_icon_type, Fx_create_frame): Make static, remove
      unused variables.
      (Fns_read_file_name): Keep track if panel is for save.  Use
      ns_filename_from_panel/ns_directory_from_panel.
      (Fns_list_services): delegate only used for COCOA.
      (Fns_convert_utf8_nfd_to_nfc): Remove warning for GNUStep.  Just
      return the input if GNUStep.
      (x_screen_planes): Remove.
      (Fxw_color_values): Use EmacsCGFloat
      (Fns_display_monitor_attributes_list): Only get screen number for
      Cocoa.
      (getDirectory, getFilename): Removed from EmacsOpenPanel and
      EmacsSavePanel.
      (EmacsOpenPanel:ok:): Use ns_filename_from_panel and
      ns_directory_from_panel.
      
      * src/nsfont.m (ns_attribute_fvalue, ns_spec_to_descriptor)
      (ns_charset_covers, ns_get_covering_families, nsfont_open):
      Use F suffix on floats.
      (ns_char_width): Returns CGFloat.
      (ns_ascii_average_width): w is CGFloat instead of float.
      (nsfont_draw): cbuf and c are unsigned. Cast to char* in call to
      DPSxshow.
      (ns_glyph_metrics): CGFloat instead of float.
      
      * src/nsimage.m (setXBMColor:, getPixelAtX:Y:): Use EmacsCGFloat.
      
      * src/nsmenu.m (ns_update_menubar): Make static.
      (x_activate_menubar): Surround with ifdef NS_IMPL_COCOA
      (fillWithWidgetValue:): Add cast to SEL for setAction.
      (addSubmenuWithTitle:forFrame:): Add cast to SEL for action.
      (update_frame_tool_bar): Update code for GNUStep.
      (clearAll): New method.
      (addDisplayItemWithImage:idx:tag:helpText:enabled:): Handle new tag
      argument. Call insertItemWithItemIdentifier when NS_IMPL_GNUSTEP. Move
      identifierToItem setObject and activeIdentifiers addObject before
      call to insertItemWithItemIdentifier.
      (validateVisibleItems): Fix indentation.
      (toolbarAllowedItemIdentifiers:): Return activeIdentifiers.
      (initWithContentRect:styleMask:backing:defer:): Add ClosableWindow and
      UtilityWindow to aStyle, remove call to setStyleMask.
      
      * src/nsselect.m (ns_get_local_selection): Remove unused variable type.
      
      * src/nsterm.h (EmacsCGFloat): Typedef for OSX and GNUStep when the size
      of CGFloat differs.
      (EmacsApp): New variable nextappdefined.  Declare sendFromMainThread
      when NS_IMPL_GNUSTEP.
      (EmacsDocument): Declare when NS_IMPL_GNUSTEP.
      (EmacsView): Remove unlockFocusNeedsFlush, add windowDidMove.
      (EmacsToolbar): Add clearAll.  Add tag argument to
      addDisplayItemWithImage.
      (EmacsSavePanel, EmacsOpenPanel): Remove getFilename and getDirectory.
      
      * src/nsterm.m: Include src/process.h if NS_IMPL_GNUSTEP.
      (ns_menu_bar_is_hidden, menu_will_open_state): Define only if
      NS_IMPL_COCOA.
      (x_set_cursor_type): Remove declaration.
      (ns_update_begin): Only use r and bp if NS_IMPL_COCOA.
      (ns_update_end, ns_focus, ns_unfocus): Remove GNUStep specific code.
      (x_set_window_size): Remove 3 pixels from toolbar if NS_IMPL_GNUSTEP.
      (ns_get_color): Use F suffix on float.
      (ns_color_to_lisp, ns_query_color): Use EmacsCGFloat.
      (ns_get_rgb_color): Remove.
      (x_set_frame_alpha): Move view inside NS_IMPL_COCOA.
      (note_mouse_movement): x and y are CGFloat.
      (ns_draw_fringe_bitmap): Remove unused rowY.
      Change #if to COCOA && >= 10_6.
      (ns_draw_window_cursor): Remove unused overspill.
      (ns_draw_underwave): width and x are EamcsCGFloat.
      (ns_draw_box): thickness is CGFloat.
      (ns_dumpglyphs_image): Change #if to COCOA && >= 10_6.
      (ns_send_appdefined): When NS_IMPL_GNUSTEP, redirect to main thread
      if not in main thread.
      (ns_get_pending_menu_title, ns_check_menu_open)
      (ns_check_pending_open_menu): Put inside #if COCOA && >= 10_5.
      (ns_term_init): Call catch_child_signal if NS_IMPL_GNUSTEP && SIGCHLD.
      (sendFromMainThread:): New method.
      (changeFont:): size is CGFloat.
      (keyDown:): Check for Delete when NS_IMPL_GNUSTEP.
      Disable warning about permanent text.
      (characterIndexForPoint:): Adjust return type depending on GNUStep
      version.
      (mouseDown:): delta is CGFloat.
      (updateFrameSize): Remove unised variable f.
      (initFrameFromEmacs): Move toggleButton inside NS_IMPL_COCOA.
      Cast float to EmacsCGFloat.
      (windowWillUseStandardFrame:defaultFrame:): Set maximized_height
      also to -1 when restoring.
      (windowDidExitFullScreen:): Put call to updateCollectionBehaviour
      inside NS_IMPL_COCOA.
      (toggleFullScreen:): Put call to toggleFullScreen inside
      NS_IMPL_COCOA.  Cast float to EmacsCGFloat.
      (setPosition:portion:whole:): por is CGFloat.
      (getMouseMotionPart:window:x:y:): Add F suffix to float.
      (mouseDown:): Use CGFloat.
      (mouseDragged:): Remove unised variable edge.
      (EmacsDocument): Implement for NS_IMPL_GNUSTEP.
      
      * src/process.c (catch_child_signal): New function.
      (init_process_emacs): Call it.
      
      * src/process.h (catch_child_signal): Declare.
      c0342369
  3. 01 Jun, 2013 1 commit
  4. 15 May, 2013 1 commit
    • Stefan Monnier's avatar
      * src/process.c: Export default filters and sentinels to Elisp. · 1aa8d505
      Stefan Monnier authored
      (Qinternal_default_process_sentinel, Qinternal_default_process_filter):
      New constants.
      (pset_filter, pset_sentinel, make_process, Fset_process_filter)
      (Fset_process_sentinel, Fformat_network_address):
      Default to them instead of nil.
      (server_accept_connection): Sentinels can't be nil any more.
      (read_and_dispose_of_process_output): New function, extracted from
      read_process_output.
      (read_process_output): Use it; filters can't be nil.
      (Finternal_default_process_filter): New function, extracted from
      read_process_output.
      (exec_sentinel_unwind): Remove function.
      (exec_sentinel): Don't zilch sentinel while running.
      (status_notify): Sentinels can't be nil.
      (Finternal_default_process_sentinel): New function extracted from
      status_notify.
      (setup_process_coding_systems): Default filter is not nil any more.
      (syms_of_process): Export new Elisp functions and initialize
      new constants.
      * src/lisp.h (make_lisp_proc): New function.
      1aa8d505
  5. 02 Apr, 2013 1 commit
    • Paul Eggert's avatar
      Prefer < to > in range checks such as 0 <= i && i < N. · 7216e43b
      Paul Eggert authored
      This makes it easier to visualize quantities on a number line.
      This patch doesn't apply to all such range checks,
      only to the range checks affected by the 2013-03-24 change.
      This patch reverts most of the 2013-03-24 change.
      * alloc.c (xpalloc, Fgarbage_collect):
      * ccl.c (ccl_driver, resolve_symbol_ccl_program):
      * character.c (string_escape_byte8):
      * charset.c (read_hex):
      * data.c (cons_to_unsigned):
      * dispnew.c (update_frame_1):
      * doc.c (Fsubstitute_command_keys):
      * doprnt.c (doprnt):
      * editfns.c (hi_time, decode_time_components):
      * fileio.c (file_offset):
      * fns.c (larger_vector, make_hash_table, Fmake_hash_table):
      * font.c (font_intern_prop):
      * frame.c (x_set_alpha):
      * gtkutil.c (get_utf8_string):
      * indent.c (check_display_width):
      * keymap.c (Fkey_description):
      * lisp.h (FIXNUM_OVERFLOW_P, vcopy):
      * lread.c (read1):
      * minibuf.c (read_minibuf_noninteractive):
      * process.c (wait_reading_process_output):
      * search.c (Freplace_match):
      * window.c (get_phys_cursor_glyph):
      * xdisp.c (redisplay_internal):
      * xsmfns.c (smc_save_yourself_CB):
      Prefer < to > for range checks.
      * dispnew.c (sit_for): Don't mishandle NaNs.
      This fixes a bug introduced in the 2013-03-24 change.
      * editfns.c (decode_time_components): Don't hoist comparison.
      This fixes another bug introduced in the 2013-03-24 change.
      7216e43b
  6. 24 Mar, 2013 2 commits
    • Andreas Schwab's avatar
      Reorder conditions that are written backwards · 908589fd
      Andreas Schwab authored
      * alloc.c (xpalloc, Fgarbage_collect): Reorder conditions that are
      written backwards.
      * blockinput.h (input_blocked_p): Likewise.
      * bytecode.c (exec_byte_code): Likewise.
      * callproc.c (call_process_kill, call_process_cleanup)
      (Fcall_process): Likewise.
      * ccl.c (ccl_driver, resolve_symbol_ccl_program)
      (Fccl_execute_on_string): Likewise.
      * character.c (string_escape_byte8): Likewise.
      * charset.c (read_hex): Likewise.
      * cm.c (calccost): Likewise.
      * data.c (cons_to_unsigned): Likewise.
      * dired.c (directory_files_internal, file_name_completion):
      Likewise.
      * dispnew.c (scrolling_window, update_frame_1, Fsleep_for)
      (sit_for): Likewise.
      * doc.c (Fsubstitute_command_keys): Likewise.
      * doprnt.c (doprnt): Likewise.
      * editfns.c (hi_time, decode_time_components, Fformat): Likewise.
      * emacsgtkfixed.c: Likewise.
      * fileio.c (file_offset, Fwrite_region): Likewise.
      * floatfns.c (Fexpt, fmod_float): Likewise.
      * fns.c (larger_vector, make_hash_table, Fmake_hash_table):
      Likewise.
      * font.c (font_intern_prop): Likewise.
      * frame.c (x_set_alpha): Likewise.
      * gtkutil.c (get_utf8_string): Likewise.
      * indent.c (check_display_width): Likewise.
      * intervals.c (create_root_interval, rotate_right, rotate_left)
      (split_interval_right, split_interval_left)
      (adjust_intervals_for_insertion, delete_node)
      (interval_deletion_adjustment, adjust_intervals_for_deletion)
      (merge_interval_right, merge_interval_left, copy_intervals)
      (set_intervals_multibyte_1): Likewise.
      * keyboard.c (gobble_input, append_tool_bar_item): Likewise.
      * keymap.c (Fkey_description): Likewise.
      * lisp.h (FIXNUM_OVERFLOW_P, vcopy): Likewise.
      * lread.c (openp, read_integer, read1, string_to_number):
      Likewise.
      * menu.c (ensure_menu_items): Likewise.
      * minibuf.c (read_minibuf_noninteractive): Likewise.
      * print.c (printchar, strout): Likewise.
      * process.c (create_process, Faccept_process_output)
      (wait_reading_process_output, read_process_output, send_process)
      (wait_reading_process_output): Likewise.
      * profiler.c (make_log, handle_profiler_signal): Likewise.
      * regex.c (re_exec): Likewise.
      * regex.h: Likewise.
      * search.c (looking_at_1, Freplace_match): Likewise.
      * sysdep.c (get_child_status, procfs_ttyname)
      (procfs_get_total_memory): Likewise.
      * systime.h (EMACS_TIME_VALID_P): Likewise.
      * term.c (dissociate_if_controlling_tty): Likewise.
      * window.c (get_phys_cursor_glyph): Likewise.
      * xdisp.c (init_iterator, redisplay_internal, redisplay_window)
      (try_window_reusing_current_matrix, try_window_id, pint2hrstr):
      Likewise.
      * xfns.c (Fx_window_property): Likewise.
      * xmenu.c (set_frame_menubar): Likewise.
      * xselect.c (x_get_window_property, x_handle_dnd_message):
      Likewise.
      * xsmfns.c (smc_save_yourself_CB): Likewise.
      * xterm.c (x_scroll_bar_set_handle): Likewise.
      908589fd
    • Paul Eggert's avatar
      Static checking by GCC 4.8-20130319. · a9ebfa0b
      Paul Eggert authored
      * image.c (gif_load): Assume pass < 3 to pacify GCC.
      * process.c (Fset_process_datagram_address)
      (Fmake_network_process): Check get_lisp_to_sockaddr_size return value.
      * xdisp.c (get_char_face_and_encoding):
      (get_glyph_face_and_encoding): Ensure that *CHAR2B is initialized.
      (get_glyph_face_and_encoding): Prepare face before possibly using it.
      (get_per_char_metric): Don't use CHAR2B if it might not be initialized.
      a9ebfa0b
  7. 08 Mar, 2013 1 commit
    • Paul Eggert's avatar
      print.c, process.c: Use bool for booleans. · 0bce5d9e
      Paul Eggert authored
      * lisp.h (wait_reading_process_output):
      * print.c (print_output_debug_flag, PRINTDECLARE, printchar)
      (strout, debug_output_compilation_hack, float_to_string, print)
      (print_object):
      * process.c (kbd_is_on_hold, inhibit_sentinels, process_output_skip)
      (decode_status, status_message, create_process, create_pty)
      (Fmake_network_process, Fnetwork_interface_info)
      (wait_reading_process_output, read_process_output)
      (write_queue_push, write_queue_pop, process_send_signal)
      (handle_child_signal, keyboard_bit_set, kbd_on_hold_p):
      * process.h (struct Lisp_Process, inhibit_sentinels, kbd_on_hold_p):
      Use bool for booleans.
      * process.c (Fnetwork_interface_list): Remove unused local.
      (connect_counter): Now EMACS_INT, not int.
      0bce5d9e
  8. 17 Feb, 2013 1 commit
    • Stefan Monnier's avatar
      Prefer `message1' over `message'. · 2f73da9c
      Stefan Monnier authored
      * src/xml.c (init_libxml2_functions):
      * src/sound.c (sound_warning):
      * src/sheap.c (report_sheap_usage):
      * src/process.c (wait_reading_process_output):
      * src/msdos.c (XMenuActivate):
      * src/macros.c (Fstart_kbd_macro, Fend_kbd_macro):
      * src/keyboard.c (top_level_1):
      * src/editfns.c (Fmessage, Fmessage_box):
      * src/callint.c (Fcall_interactively):
      * src/fns.c (Fyes_or_no_p): Prefer `message1' over `message'.
      2f73da9c
  9. 15 Feb, 2013 1 commit
  10. 01 Jan, 2013 1 commit
  11. 20 Dec, 2012 1 commit
    • Dmitry Antipov's avatar
      Avoid calls to CHAR_TO_BYTE if byte position is known. · 13002885
      Dmitry Antipov authored
      * editfns.c (make_buffer_string_both): Use move_gap_both.
      (Fbuffer_string): Use make_buffer_string_both.
      * marker.c (buf_charpos_to_bytepos): Convert to eassert.
      Adjust comment.
      (buf_bytepos_to_charpos): Likewise.
      (charpos_to_bytepos): Remove.
      * fileio.c (Finsert_file_contents): Use move_gap_both.
      * search.c (Freplace_match): Likewise.
      * process.c (process_send_region): Likewise. Use convenient
      names for byte positions.
      * lisp.h (charpos_to_bytepos): Remove prototype.
      * indent.c (scan_for_column): Use CHAR_TO_BYTE.
      * insdel.c (move_gap): Likewise.
      13002885
  12. 17 Dec, 2012 1 commit
    • Paul Eggert's avatar
      Don't reraise SIGCHLD, as that can now lose. · 207a7ef0
      Paul Eggert authored
      With the 2012-12-03 fix for Bug#12980 in place, an old workaround
      for some of that bug's symptoms can now cause Emacs to abort.
      Remove the workaround.
      * process.c (wait_reading_process_output): Don't reraise SIGCHLD.
      The bug that caused SIGCHLD to get lost has been fixed, and the
      workaround for it can now cause Emacs to abort.
      
      Fixes: debbugs:13192
      207a7ef0
  13. 08 Dec, 2012 1 commit
    • Paul Eggert's avatar
      Assume POSIX 1003.1-1988 or later for signal.h. · d983a10b
      Paul Eggert authored
      Exceptions: do not assume SIGCONT, SIGSTOP, SIGTSTP, SIGTTIN,
      SIGTTOU, SIGUSR1, SIGUSR2, as Microsoft platforms lack these.
      * admin/CPP-DEFINES (SIGALRM, SIGCHLD, SIGHUP, SIGKILL, SIGPIPE, SIGQUIT):
      Remove.
      (SIGTRAP): Remove this one too, as config.h no longer defines it.
      * admin/merge-gnulib (GNULIB_MODULES): Add sig2str.
      * configure.ac (PTY_OPEN, PTY_TTY_NAME_SPRINTF):
      Use SIGCHLD rather than SIGCLD.
      * lib/sig2str.c, lib/sig2str.h, m4/sig2str.m4: New files, from gnulib.
      * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
      * lib/makefile.w32-in (GNULIBOBJS): Add $(BUILD)/sig2str.$(O).
      * src/process.c [subprocesses]: Include <c-ctype.h>, <sig2str.h>.
      (deleted_pid_list, Fdelete_process, create_process)
      (record_child_status_change, handle_child_signal, deliver_child_signal)
      (init_process_emacs, syms_of_process):
      Assume SIGCHLD is defined.
      (parse_signal): Remove.  All uses removed.
      (abbr_to_signal): New static function.
      (Fsignal_process): Use it to convert signal names to ints.
      * src/sysdep.c (sys_suspend) [!DOS_NT]: Use kill (0, ...) rather than
      kill (getpgrp (), ...).
      (emacs_sigaction_init): Assume SIGCHLD is defined.
      (init_signals): Assume SIGALRM, SIGCHLD, SIGHUP, SIGKILL,
      SIGPIPE, and SIGQUIT are defined.  Do not worry about SIGCLD any more.
      * src/syssignal.h (EMACS_KILLPG): Remove.
      All uses replaced by 'kill' with a negative pid.
      (SIGCHLD): Remove definition, as we now assume SIGCHLD.
      * src/w32proc.c (sys_kill): Support negative pids compatibly with POSIX.
      
      Fixes: debbugs:13026
      d983a10b
  14. 06 Dec, 2012 1 commit
    • Paul Eggert's avatar
      Fix a recently-introduced delete-process race condition. · 35fb8050
      Paul Eggert authored
      * callproc.c, process.h (record_kill_process):
      New function, containing part of the old call_process_kill.
      (call_process_kill): Use it.
      This does not change call_process_kill's behavior.
      * process.c (Fdelete_process): Use record_kill_process to fix a
      race condition that could cause Emacs to lose track of a child.
      35fb8050
  15. 03 Dec, 2012 1 commit
    • Paul Eggert's avatar
      Don't let call-process be a zombie factory. · bb5f74ee
      Paul Eggert authored
      Fixing this bug required some cleanup of the signal-handling code.
      As a side effect, this change also fixes a longstanding rare race
      condition whereby Emacs could mistakenly kill unrelated processes,
      and it fixes a bug where a second C-g does not kill a recalcitrant
      synchronous process in GNU/Linux and similar platforms.
      The patch should also fix the last vestiges of Bug#9488,
      a bug which has mostly been fixed on the trunk by other changes.
      * callproc.c, process.h (synch_process_alive, synch_process_death)
      (synch_process_termsig, sync_process_retcode):
      Remove.  All uses removed, to simplify analysis and so that
      less consing is done inside critical sections.
      * callproc.c (call_process_exited): Remove.  All uses replaced
      with !synch_process_pid.
      * callproc.c (synch_process_pid, synch_process_fd): New static vars.
      These take the role of what used to be in unwind-protect arg.
      All uses changed.
      (block_child_signal, unblock_child_signal):
      New functions, to avoid races that could kill innocent-victim processes.
      (call_process_kill, call_process_cleanup, Fcall_process): Use them.
      (call_process_kill): Record killed processes as deleted, so that
      zombies do not clutter up the system.  Do this inside a critical
      section, to avoid a race that would allow the clutter.
      (call_process_cleanup): Fix code so that the second C-g works again
      on common platforms such as GNU/Linux.
      (Fcall_process): Create the child process in a critical section,
      to fix a race condition.  If creating an asynchronous process,
      record it as deleted so that zombies do not clutter up the system.
      Do unwind-protect for WINDOWSNT too, as that's simpler in the
      light of these changes.  Omit unnecessary call to emacs_close
      before failure, as the unwind-protect code does that.
      * callproc.c (call_process_cleanup):
      * w32proc.c (waitpid): Simplify now that synch_process_alive is gone.
      * process.c (record_deleted_pid): New function, containing
      code refactored out of Fdelete_process.
      (Fdelete_process): Use it.
      (process_status_retrieved): Remove.  All callers changed to use
      child_status_change.
      (record_child_status_change): Remove, folding its contents into ...
      (handle_child_signal): ... this signal handler.  Now, this
      function is purely a handler for SIGCHLD, and is not called after
      a synchronous waitpid returns; the synchronous code is moved to
      wait_for_termination.  There is no need to worry about reaping
      more than one child now.
      * sysdep.c (get_child_status, child_status_changed): New functions.
      (wait_for_termination): Now takes int * status and bool
      interruptible arguments, too.  Do not record child status change;
      that's now the caller's responsibility.  All callers changed.
      Reimplement in terms of get_child_status.
      (wait_for_termination_1, interruptible_wait_for_termination):
      Remove.  All callers changed to use wait_for_termination.
      * syswait.h: Include <stdbool.h>, for bool.
      (record_child_status_change, interruptible_wait_for_termination):
      Remove decls.
      (record_deleted_pid, child_status_changed): New decls.
      (wait_for_termination): Adjust to API changes noted above.
      
      Fixes: debbugs:12980
      bb5f74ee
  16. 02 Dec, 2012 1 commit
    • Paul Eggert's avatar
      Use execve to avoid need to munge environ. · 21e54a94
      Paul Eggert authored
      * callproc.c (Fcall_process):
      * process.c (create_process):
      Don't save and restore environ;	no longer needed.
      * callproc.c (child_setup):
      Use execve, not execvp, to preserve environ.
      
      Fixes: debbugs:13054
      21e54a94
  17. 27 Nov, 2012 1 commit
    • Paul Eggert's avatar
      Assume POSIX 1003.1-1988 or later for errno.h. · 22626a85
      Paul Eggert authored
      * lib-src/movemail.c (main): Assume EAGAIN and EBUSY.
      * src/dired.c (directory_files_internal, file_name_completion):
      Assume EAGAIN and EINTR are defined.
      * src/fileio.c (Fcopy_file): Assume EISDIR is defined.
      * src/gmalloc.c (ENOMEM, EINVAL): Assume they're defined.
      * src/gnutls.c (emacs_gnutls_write): Assume EAGAIN is defined.
      * src/lread.c (readbyte_from_file): Assume EINTR is defined.
      * src/process.c (wait_reading_process_output, send_process) [subprocesses]:
      Assume EIO and EAGAIN are defined.
      * src/unexcoff.c (write_segment): Assume EFAULT is defined.
      
      Fixes: debbugs:12968
      22626a85
  18. 24 Nov, 2012 1 commit
  19. 23 Nov, 2012 1 commit
    • Paul Eggert's avatar
      Fix a race condition with glib (Bug#8855). · 6d4e8f62
      Paul Eggert authored
      This is a backport from the trunk, consisting of:
      
      2012-11-17  Eli Zaretskii  <eliz@gnu.org>
      
      * nt/inc/sys/wait.h: New file, with prototype of waitpid and
      definitions of macros it needs.
      * nt/inc/ms-w32.h (wait): Don't define, 'wait' is not used anymore.
      (sys_wait): Remove prototype.
      * nt/config.nt (HAVE_SYS_WAIT_H): Define to 1.
      * src/w32proc.c (create_child): Don't clip the PID of the child
      process to fit into an Emacs integer, as this is no longer a
      restriction.
      (waitpid): Rename from sys_wait.  Emulate a Posix 'waitpid' by
      reaping only the process specified by PID argument, if that is
      positive.  Use PID instead of dead_child to know which process to
      reap.  Wait for the child to die only if WNOHANG is not in
      OPTIONS.
      (sys_select): Don't set dead_child.
      * src/sysdep.c (wait_for_termination_1): Remove the WINDOWSNT portion,
      as it is no longer needed.
      * src/process.c (waitpid, WUNTRACED) [!WNOHANG]: Remove definitions,
      no longer needed.
      (record_child_status_change): Remove the setting of
      record_at_most_one_child for the !WNOHANG case.
      
      2012-11-03  Paul Eggert  <eggert@cs.ucla.edu>
      
      Fix a race condition that causes Emacs to mess up glib (Bug#8855).
      This is a backport from the trunk.
      The symptom is a diagnostic "GLib-WARNING **: In call to
      g_spawn_sync(), exit status of a child process was requested but
      SIGCHLD action was set to SIG_IGN and ECHILD was received by
      waitpid(), so exit status can't be returned."  The diagnostic
      is partly wrong, as the SIGCHLD action is not set to SIG_IGN.
      The real bug is a race condition between Emacs and glib: Emacs
      does a waitpid (-1, ...) and reaps glib's subprocess by mistake,
      so that glib can't find it.  Work around the bug by invoking
      waitpid only on subprocesses that Emacs itself creates.
      * src/process.c (create_process, record_child_status_change):
      Don't use special value -1 in pid field, as the caller now must
      know the pid rather than having the callee infer it.  The
      inference was sometimes incorrect anyway, due to another race.
      (create_process): Set new 'alive' member if child is created.
      (process_status_retrieved): New function.
      (record_child_status_change): Use it.
      Accept negative 1st argument, which means to wait for the
      processes that Emacs already knows about.  Move special-case code
      for DOS_NT (which lacks WNOHANG) here, from caller.  Keep track of
      processes that have already been waited for, by testing and
      clearing new 'alive' member.
      (CAN_HANDLE_MULTIPLE_CHILDREN): Remove, as record_child_status_change
      now does this internally.
      (handle_child_signal): Let record_child_status_change do all
      the work, since we do not want to reap all exited child processes,
      only the child processes that Emacs itself created.
      * src/process.h (Lisp_Process): New boolean member 'alive'.
      6d4e8f62
  20. 17 Nov, 2012 3 commits
    • Paul Eggert's avatar
      Assume POSIX 1003.1-1988 or later for fcntl.h. · 49cdacda
      Paul Eggert authored
      * admin/CPP-DEFINES (O_RDONLY, O_RDWR, HAVE_FCNTL_H): Remove.
      * admin/merge-gnulib (GNULIB_MODULES): Add fcntl-h.
      * configure.ac: Do not check for fcntl.h.
      * lib/gnulib.mk: Regenerate.
      * lib-src/movemail.c, lib-src/update-game-score.c: Assume <fcntl.h> exists.
      * nt/inc/sys/socket.h (O_NONBLOCK): Rename from O_NDELAY, since the
      POSIX name for this flag is O_NONBLOCK.  All uses changed.
      * nt/inc/unistd.h (O_RDWR, O_NOCTTY): New macros.  Like AT_FDCWD etc.
      these really should be moved to a replacement <fcntl.h> if and
      when that gets implemented.  In the meantime, include <fcntl.h>
      to make sure we don't override its definitions.
      * src/callproc.c (relocate_fd): Assume F_DUPFD.
      * src/emacs.c, src/term.c (O_RDWR): Remove.
      * src/keyboard.c (tty_read_avail_input): Use O_NONBLOCK rather than
      O_NDELAY, since O_NONBLOCK is the standard name for this flag.
      * src/nsterm.m: Assume <fcntl.h> exists.
      * src/process.c (NON_BLOCKING_CONNECT, allocate_pty, create_process)
      (create_pty, Fmake_network_process, server_accept_connection)
      (wait_reading_process_output, init_process_emacs):
      Assume O_NONBLOCK.
      (wait_reading_process_output): Put in a special case for WINDOWSNT
      to mimick the older behavior where it had O_NDELAY but not O_NONBLOCK.
      It's not clear this is needed, but it's a more-conservative change.
      (create_process): Assume FD_CLOEXEC.
      (create_process, create_pty): Assume O_NOCTTY.
      * src/sysdep.c (init_sys_modes, reset_sys_modes): Assume F_SETFL.
      (reset_sys_modes): Use O_NONBLOCK rather than O_NDELAY.
      Omit if not DOS_NT, since F_GETFL is not defined there.
      (serial_open): Assume O_NONBLOCK and O_NOCTTY.
      * src/term.c: Include <fcntl.h>, for flags like O_NOCTTY.
      (O_NOCTTY): Remove.
      (init_tty): Assume O_IGNORE_CTTY is defined to 0 on platforms that
      lack it, since gnulib guarantees this.
      * src/w32.c (fcntl): Test for O_NONBLOCK rather than O_NDELAY.
      
      Fixes: debbugs:12881
      49cdacda
    • Paul Eggert's avatar
      Update comment to match recent change. · 9fa3ccd9
      Paul Eggert authored
      9fa3ccd9
    • Eli Zaretskii's avatar
      Fix bug #12829 with aborts on MS-Windows when several child processes die. · 22bae83f
      Eli Zaretskii authored
       nt/inc/sys/wait.h: New file, with prototype of waitpid and
       definitions of macros it needs.
       nt/inc/ms-w32.h (wait): Don't define, 'wait' is not used anymore.
       (sys_wait): Remove prototype.
       nt/config.nt (HAVE_SYS_WAIT_H): Define to 1.
      
       src/w32proc.c (create_child): Don't clip the PID of the child
       process to fit into an Emacs integer, as this is no longer a
       restriction.
       (waitpid): Rename from sys_wait.  Emulate a Posix 'waitpid' by
       reaping only the process specified by PID argument, if that is
       positive.  Use PID instead of dead_child to know which process to
       reap.  Wait for the child to die only if WNOHANG is not in
       OPTIONS.
       (sys_select): Don't set dead_child.
       src/sysdep.c (wait_for_termination_1): Remove the WINDOWSNT portion,
       as it is no longer needed.
       src/process.c (waitpid, WUNTRACED) [!WNOHANG]: Remove definitions,
       no longer needed.
       (record_child_status_change): Remove the setting of
       record_at_most_one_child for the !WNOHANG case.
      22bae83f
  21. 16 Nov, 2012 1 commit
    • Paul Eggert's avatar
      Remove no-longer-used pty_max_bytes variable. · 3d082a26
      Paul Eggert authored
      * configure.ac (fpathconf): Remove unnecessary check.
      * admin/CPP-DEFINES (HAVE_FPATHCONF): Remove.
      * src/process.c (pty_max_bytes): Remove; unused.
      (send_process): Do not set it.
      3d082a26
  22. 14 Nov, 2012 1 commit
    • Paul Eggert's avatar
      Use faccessat, not access, when checking file permissions. · 73dcdb9f
      Paul Eggert authored
      This fixes a bug that has been present in Emacs since its creation.
      It was reported by Chris Torek in 1983 even before GNU Emacs existed,
      which must set some sort of record.  (Torek's bug report was against
      a predecessor of GNU Emacs, but GNU Emacs happened to have the
      same common flaw.)  See Torek's Usenet posting
      "setuid/setgid programs & Emacs" Article-I.D.: sri-arpa.858
      Posted: Fri Apr  8 14:18:56 1983.
      * .bzrignore: Add lib/fcntl.h.
      * configure.ac (euidaccess): Remove check; gnulib does this for us now.
      (gl_FCNTL_O_FLAGS): Define a dummy version.
      * lib/at-func.c, lib/euidaccess.c, lib/faccessat.c, lib/fcntl.in.h:
      * lib/getgroups.c, lib/group-member.c, lib/root-uid.h:
      * lib/xalloc-oversized.h, m4/euidaccess.m4, m4/faccessat.m4:
      * m4/fcntl_h.m4, m4/getgroups.m4, m4/group-member.m4:
      New files, from gnulib.
      * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
      * admin/merge-gnulib (GNULIB_MODULES): Add faccessat.
      (GNULIB_TOOL_FLAGS): Avoid at-internal, fchdir, malloc-posix,
      openat-die, openat-h, save-cwd.  Do not avoid fcntl-h.
      Omit gnulib's m4/fcntl-o.m4.
      * nt/inc/ms-w32.h (AT_FDCWD, AT_EACCESS): New symbols.
      (access): Remove.
      (faccessat): New macro.
      * src/Makefile.in (LIB_EACCESS): New macro.
      (LIBES): Use it.
      * src/callproc.c (init_callproc):
      * src/charset.c (init_charset):
      * src/fileio.c (check_existing, check_executable, check_writable)
      (Ffile_readable_p):
      * src/lread.c (openp, load_path_check):
      * src/process.c (allocate_pty):
      * src/xrdb.c (file_p):
      Use effective UID when checking permissions, not real UID.
      * src/callproc.c (init_callproc):
      * src/charset.c (init_charset):
      * src/lread.c (load_path_check, init_lread):
      Test whether directories are accessible, not merely whether they exist.
      * src/conf_post.h (GNULIB_SUPPORT_ONLY_AT_FDCWD): New macro.
      * src/fileio.c (check_existing, check_executable, check_writable)
      (Ffile_readable_p):
      Use symbolic names instead of integers for the flags, as they're
      portable now.
      (check_writable): New arg AMODE.  All uses changed.
      Set errno on failure.
      (Ffile_readable_p): Use faccessat, not stat + open + close.
      (Ffile_writable_p): No need to call check_existing + check_writable.
      Just call check_writable and then look at errno.  This saves a syscall.
      dir should never be nil; replace an unnecessary runtime check
      with an eassert.  When checking the parent directory of a nonexistent
      file, check that the directory is searchable as well as writable, as
      we can't create files in unsearchable directories.
      (file_directory_p): New function, which uses 'stat' on most platforms
      but faccessat with D_OK (for efficiency) if WINDOWSNT.
      (Ffile_directory_p, Fset_file_times): Use it.
      (file_accessible_directory_p): New function, which uses a single
      syscall for efficiency.
      (Ffile_accessible_directory_p): Use it.
      * src/xrdb.c (file_p): Use file_directory_p.
      * src/lisp.h (file_directory_p, file_accessible_directory_p): New decls.
      * src/lread.c (openp): When opening a file, use fstat rather than
      stat, as that avoids a permissions race.  When not opening a file,
      use file_directory_p rather than stat.
      (dir_warning): First arg is now a usage string, not a format.
      Use errno.  All uses changed.
      * src/nsterm.m (ns_term_init): Remove unnecessary call to file-readable
      that merely introduced a race.
      * src/process.c, src/sysdep.c, src/term.c: All uses of '#ifdef O_NONBLOCK'
      changed to '#if O_NONBLOCK', to accommodate gnulib O_* style,
      and similarly for the other O_* flags.
      * src/w32.c (sys_faccessat): Rename from sys_access and switch to
      faccessat's API.  All uses changed.
      * src/xrdb.c: Do not include <sys/stat.h>; no longer needed.
      (magic_db): Rename from magic_file_p.
      (magic_db, search_magic_path): Return an XrmDatabase rather than a
      char *, so that we don't have to test for file existence
      separately from opening the file for reading.  This removes a race
      fixes a permission-checking problem, and simplifies the code.
      All uses changed.
      (file_p): Remove; no longer needed.
      
      Fixes: debbugs:12632
      73dcdb9f
  23. 05 Nov, 2012 2 commits
    • Chong Yidong's avatar
    • Paul Eggert's avatar
      Assume at least POSIX.1-1988 for getpgrp, setpgid, setsid. · dd0333b6
      Paul Eggert authored
      This removes code that has been obsolete since around 1990.
      * admin/CPP-DEFINES (HAVE_SETPGID, HAVE_SETSID, SETPGRP_RELEASES_CTTY):
      Remove; obsolete.
      * configure.ac (setpgid, setsid): Assume their existence.
      (AC_FUNC_GETPGRP, SETPGRP_RELEASES_CTTY): Remove; obsolete.
      * src/callproc.c (Fcall_process):
      * src/emacs.c (main):
      * src/process.c (create_process):
      * src/term.c (dissociate_if_controlling_tty):
      Assume setsid exists.
      * src/callproc.c (child_setup): Assume setpgid exists and behaves as
      per POSIX.1-1988 or later.
      * src/conf_post.h (setpgid) [!HAVE_SETPGID]: Remove.
      * src/emacs.c (shut_down_emacs):
      * src/sysdep.c (sys_suspend, init_foreground_group):
      Assume getpgrp behaves as per POSIX.1-1998 or later.
      * src/msdos.c (setpgrp): Remove.
      (tcgetpgrp, setpgid, setsid): New functions.
      * src/systty.h (EMACS_GETPGRP): Remove.  All callers now use getpgrp.
      * src/term.c (no_controlling_tty): Remove; unused.
      * src/w32proc.c (setpgrp): Remove.
      (setsid, tcgetpgrp): New functions.
      
      Fixes: debbugs:12800
      dd0333b6
  24. 03 Nov, 2012 3 commits
    • Paul Eggert's avatar
      Fix a race condition that causes Emacs to mess up glib. · 0b3d4a47
      Paul Eggert authored
      The symptom is a diagnostic "GLib-WARNING **: In call to
      g_spawn_sync(), exit status of a child process was requested but
      SIGCHLD action was set to SIG_IGN and ECHILD was received by
      waitpid(), so exit status can't be returned."  The diagnostic
      is partly wrong, as the SIGCHLD action is not set to SIG_IGN.
      The real bug is a race condition between Emacs and glib: Emacs
      does a waitpid (-1, ...) and reaps glib's subprocess by mistake,
      so that glib can't find it.  Work around the bug by invoking
      waitpid only on subprocesses that Emacs itself creates.
      * process.c (create_process, record_child_status_change):
      Don't use special value -1 in pid field, as the caller now must
      know the pid rather than having the callee infer it.  The
      inference was sometimes incorrect anyway, due to another race.
      (create_process): Set new 'alive' member if child is created.
      (process_status_retrieved): New function.
      (record_child_status_change): Use it.
      Accept negative 1st argument, which means to wait for the
      processes that Emacs already knows about.  Move special-case code
      for DOS_NT (which lacks WNOHANG) here, from caller.  Keep track of
      processes that have already been waited for, by testing and
      clearing new 'alive' member.
      (CAN_HANDLE_MULTIPLE_CHILDREN): Remove, as record_child_status_change
      now does this internally.
      (handle_child_signal): Let record_child_status_change do all
      the work, since we do not want to reap all exited child processes,
      only the child processes that Emacs itself created.
      * process.h (Lisp_Process): New boolean member 'alive'.
      
      Fixes: debbugs:8855
      0b3d4a47
    • Chong Yidong's avatar
    • Chong Yidong's avatar
      Fix a race condition in wait_reading_process_output (tiny change). · 893cc455
      Chong Yidong authored
      * src/process.c (wait_reading_process_output): Avoid a race condition
      with SIGIO delivery.
      
      Fixes: debbugs:11536
      893cc455
  25. 31 Oct, 2012 1 commit
    • Paul Eggert's avatar
      Fix crash when using Emacs as commit editor for git. · 322aea6d
      Paul Eggert authored
      * callproc.c (setpgrp): Remove macro, as we now use setpgid
      and it is configured in conf_post.h.
      (Fcall_process): Don't invoke both setsid and setpgid; the former
      is enough, if it exists.
      * callproc.c (Fcall_process, child_setup):
      * process.c (create_process): Use setpgid.
      * conf_post.h (setpgid) [!HAVE_SETPGID]: New macro, which substitutes
      for the real thing.
      * dispnew.c (init_display): Initialize the foreground group
      if we are running a tty display.
      * emacs.c (main): Do not worry about setpgrp; init_display does it now.
      * lisp.h (init_foreground_group): New decl.
      * sysdep.c (inherited_pgroup): New static var.
      (init_foreground_group, tcsetpgrp_without_stopping)
      (narrow_foreground_group, widen_foreground_group): New functions.
      (init_sys_modes): Narrow foreground group.
      (reset_sys_modes): Widen foreground group.
      
      Fixes: debbugs:12697
      322aea6d
  26. 19 Oct, 2012 2 commits
    • Paul Eggert's avatar
      Undo faccessat change. · f0a80175
      Paul Eggert authored
      f0a80175
    • Paul Eggert's avatar
      Use faccessat, not access, when checking file permissions. · e752e0b0
      Paul Eggert authored
      * .bzrignore: Add lib/fcntl.h.
      * configure.ac (euidaccess): Remove check; gnulib does this for us now.
      (gl_FCNTL_O_FLAGS): Define a dummy version.
      * lib/at-func.c, lib/euidaccess.c, lib/faccessat.c, lib/fcntl.in.h:
      * lib/getgroups.c, lib/group-member.c, lib/root-uid.h:
      * lib/xalloc-oversized.h, m4/euidaccess.m4, m4/faccessat.m4:
      * m4/fcntl_h.m4, m4/getgroups.m4, m4/group-member.m4:
      New files, from gnulib.
      * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
      * admin/merge-gnulib (GNULIB_MODULES): Add faccessat.
      (GNULIB_TOOL_FLAGS): Avoid at-internal, fchdir, malloc-posix,
      openat-die, openat-h, save-cwd.  Do not avoid fcntl-h.
      Omit gnulib's m4/fcntl-o.m4.
      * nt/inc/ms-w32.h (AT_FDCWD, AT_EACCESS): New symbols.
      (access): Remove.
      (faccessat): New macro.
      * src/Makefile.in (LIB_EACCESS): New macro.
      (LIBES): Use it.
      * src/callproc.c (init_callproc):
      * src/charset.c (init_charset):
      * src/fileio.c (check_existing, check_executable):
      * src/lread.c (openp, load_path_check):
      * src/process.c (allocate_pty):
      * src/xrdb.c (file_p):
      Use faccessat, not access or euidaccess.  Use symbolic names
      instead of integers for the flags, as they're portable now.
      * src/charset.c, src/xrdb.c: Include <fcntl.h>, for the new flags used.
      * src/fileio.c (Ffile_readable_p):
      Use faccessat, not stat + open + close.
      (file_directory_p): New function, which uses 'stat' on most places
      but 'access' (for efficiency) if WINDOWSNT.
      * src/fileio.c (Ffile_directory_p, Fset_file_times):
      * src/xrdb.c (file_p): Use file_directory_p.
      * src/lisp.h (file_directory_p): New decl.
      * src/lread.c (openp): When opening a file, use fstat rather than
      stat, as that avoids a permissions race.  When not opening a file,
      use file_directory_p rather than stat.
      * src/process.c, src/sysdep.c, src/term.c: All uses of '#ifdef O_NONBLOCK'
      changed to '#if O_NONBLOCK', to accommodate gnulib O_* tyle.
      * src/w32.c (sys_faccessat): Rename from sys_access and switch to
      faccessat's API.  All uses changed.
      
      Fixes: debbugs:12632
      e752e0b0
  27. 17 Oct, 2012 1 commit
    • Eli Zaretskii's avatar
      Fix warnings when compiling on MS-Windows with -std=gnu99. · a68089e4
      Eli Zaretskii authored
       src/makefile.w32-in ($(BLD)/w32.$(O)): 
       ($(BLD)/vm-limit.$(O)): 
       ($(BLD)/term.$(O)): 
       ($(BLD)/unexw32.$(O)): 
       ($(BLD)/fileio.$(O)): 
       ($(BLD)/dispnew.$(O)): Update dependencies.
       src/w32term.h (w32_initialize_display_info, initialize_w32_display):
       Add prototypes.
       src/w32proc.c: Include ctype.h.
       src/w32.h (init_environment, check_windows_init_file)
       (syms_of_ntproc, syms_of_ntterm, dostounix_filename)
       (unixtodos_filename, init_winsock, srandom, random, sys_pipe)
       (set_process_dir, sys_spawnve, register_child, sys_sleep, getwd)
       (sys_link): Add prototypes.
       src/w32.c: Include w32select.h.
       (sys_access, e_malloc, sys_select): Add prototypes.
       (emacs_gnutls_pull): 'timeout' is now EMACS_TIME, not struct timeval.
       src/vm-limit.c [WINDOWSNT]: Include w32heap.h.
       src/unexw32.c: Include lisp.h and w32.h.
       src/term.c [WINDOWSNT]: Include w32term.h.
       src/process.c [WINDOWSNT]: Add prototype of sys_select.
       src/fileio.c [WINDOWSNT]: Include w32.h.
       src/dispnew.c [WINDOWSNT]: Include w32.h.
      
       nt/inc/pwd.h (getuid, geteuid): Add prototypes.
       nt/inc/ms-w32.h (sys_wait, _getpid, gmtgime_r, localtime_r)
       (signal_handler, sys_signal, sigemptyset, sigfillset, sigprocmask)
       (pthread_sigmask, sigismember, setpgrp, sigaction, alarm)
       (sys_kill, getpagesize): Add prototypes for emulated functions.
       nt/inc/grp.h (getgid, getegid): Add prototypes.
       nt/gmake.defs (DEBUG_CFLAGS) [NOOPT]: Add -std=gnu99.
       nt/configure.bat (chkapiN): Avoid compiler warning in junk.c when
       compiling with -std=gnu99.
       nt/config.nt (CHECK_LISP_OBJECT_TYPE): Don't undef, so that it
       could be used via --cflags switch to configure.bat.
      a68089e4
  28. 13 Oct, 2012 1 commit
    • Paul Eggert's avatar
      Fix some stat-related races. · d6453ce4
      Paul Eggert authored
      * fileio.c (Fwrite_region): Avoid race condition if a file is
      removed or renamed by some other process immediately after Emacs
      writes it but before Emacs stats it.  Do not assume that stat (or
      fstat) succeeds.
      * image.c (slurp_file): Resolve the file name with fopen + fstat
      rather than stat + fopen.
      (pbm_read_file) [0]: Remove unused code with stat race.
      * process.c (allocate_pty) [HAVE_PTYS && !PTY_ITERATION && !PTY_OPEN]:
      Remove ineffective code with stat race.
      d6453ce4
  29. 10 Oct, 2012 1 commit
    • Paul Eggert's avatar
      keyboard.c, keymap.c: Use bool for booleans. · 9fa1de30
      Paul Eggert authored
      * dispnew.c (sit_for): Distinguish between 3-way display_option
      and boolean do_display.
      * keyboard.c (single_kboard, this_command_key_count_reset)
      (waiting_for_input, echoing, immediate_quit, input_pending)
      (interrupt_input, interrupts_deferred, pop_kboard)
      (temporarily_switch_to_single_kboard, ignore_mouse_drag_p)
      (command_loop_1, adjust_point_for_property)
      (safe_run_hooks_error, input_polling_used, read_char):
      (help_char_p, readable_events, kbd_buffer_events_waiting)
      (kbd_buffer_get_event, timer_check_2, make_lispy_event)
      (lucid_event_type_list_p, get_input_pending):
      (gobble_input, menu_separator_name_p, menu_bar_item)
      (parse_menu_item, parse_tool_bar_item, read_char_x_menu_prompt)
      (read_char_minibuf_menu_prompt, access_keymap_keyremap)
      (keyremap_step, test_undefined, read_key_sequence)
      (detect_input_pending, detect_input_pending_ignore_squeezables)
      (detect_input_pending_run_timers, requeued_events_pending_p)
      (quit_throw_to_read_char, Fset_input_interrupt_mode):
      * keymap.c (get_keymap, keymap_parent, keymap_memberp)
      (access_keymap_1, access_keymap, map_keymap, get_keyelt)
      (Fdefine_key, Flookup_key, struct accessible_keymaps_data)
      (accessible_keymaps_1, Fkey_description, push_key_description):
      (shadow_lookup, struct where_is_internal_data)
      (where_is_internal, Fwhere_is_internal, where_is_internal_1)
      (Fdescribe_buffer_bindings, describe_map_tree, struct describe_map_elt)
      (describe_map, describe_vector):
      * menu.c (single_menu_item):
      * nsmenu.m (ns_update_menubar):
      * process.c (wait_reading_process_output):
      * search.c (scan_buffer, scan_newline):
      Use bool for boolean.
      * keyboard.c (timers_run, swallow_events)
      (detect_input_pending_run_timers):
      * process.c (wait_reading_process_output):
      Use unsigned for counter where wraparound-on-overflow is desired,
      since unsigned is guaranteed to have that behavior and signed is not.
      (read_char): Use ptrdiff_t for string length.
      (get_input_pending): Remove first argument, since it was always
      the same pointer-to-int (now pointer-to-boolean) &input_pending,
      and behave as if it had that value.  Return new value of
      input_pending.  All callers changed.
      * keyboard.h (struct kboard): Use unsigned : 1 for boolean member
      immediate_echo.  Use ptrdiff_t for echo_after_prompt, since it's
      a string length.
      * keymap.c (push_key_description): Omit last arg, which was always 1.
      All callers changed.
      9fa1de30
  30. 01 Oct, 2012 2 commits
    • Paul Eggert's avatar
      Fix a malloc race condition involving strsignal. · aa1ba90e
      Paul Eggert authored
      A signal can arrive in the middle of a malloc, and Emacs's signal
      handler can invoke strsignal, which can invoke malloc, which is
      not portable.  This race condition bug makes Emacs hang on GNU/Linux.
      Fix it by altering the signal handler so that it does not invoke
      strsignal.
      * emacs.c (shut_down_emacs): Use safe_strsignal, not strsignal.
      * process.c (status_message): Use const pointer, in case strsignal
      is #defined to safe_strsignal.
      * sysdep.c (sys_siglist, init_signals): Always define and
      initialize a substitute sys_siglist if the system does not define
      one, even if HAVE_STRSIGNAL.
      (safe_strsignal): Rename from strsignal.  Always define,
      using sys_siglist.  Return a const pointer.
      * syssignal.h (safe_strsignal): New decl.
      (strsignal) [!HAVE_STRSIGNAL]: Define in terms of safe_strsignal.
      aa1ba90e
    • Paul Eggert's avatar
      Prefer plain 'static' to 'static inline'. · b0ab8123
      Paul Eggert authored
      With static functions, modern compilers inline pretty well by
      themselves; advice from programmers often hurts as much as it helps.
      On my host (x86-64, Fedora 17, GCC 4.7.2, default 'configure'),
      this change shrinks the text size of the Emacs executable by 1.1%
      without affecting CPU significantly in my benchmark.
      * alloc.c (mem_find, live_string_p, live_cons_p, live_symbol_p)
      (live_float_p, live_misc_p, live_vector_p, live_buffer_p)
      (mark_maybe_object, mark_maybe_pointer, bounded_number):
      * buffer.c (bset_abbrev_mode, bset_abbrev_table)
      (bset_auto_fill_function, bset_auto_save_file_format)
      (bset_auto_save_file_name, bset_backed_up, bset_begv_marker)
      (bset_bidi_display_reordering, bset_buffer_file_coding_system)
      (bset_cache_long_line_scans, bset_case_fold_search)
      (bset_ctl_arrow, bset_cursor_in_non_selected_windows)
      (bset_cursor_type, bset_display_table, bset_extra_line_spacing)
      (bset_file_format, bset_file_truename, bset_fringe_cursor_alist)
      (bset_fringe_indicator_alist, bset_fringes_outside_margins)
      (bset_header_line_format, bset_indicate_buffer_boundaries)
      (bset_indicate_empty_lines, bset_invisibility_spec)
      (bset_left_fringe_width, bset_major_mode, bset_mark)
      (bset_minor_modes, bset_mode_line_format, bset_mode_name)
      (bset_name, bset_overwrite_mode, bset_pt_marker)
      (bset_right_fringe_width, bset_save_length)
      (bset_scroll_bar_width, bset_scroll_down_aggressively)
      (bset_scroll_up_aggressively, bset_selective_display)
      (bset_selective_display_ellipses, bset_vertical_scroll_bar_type)
      (bset_word_wrap, bset_zv_marker, set_buffer_overlays_before)
      (set_buffer_overlays_after):
      * category.c (bset_category_table):
      * charset.c (read_hex):
      * coding.c (produce_composition, produce_charset)
      (handle_composition_annotation, handle_charset_annotation)
      (char_encodable_p):
      * dispnew.c (swap_glyph_pointers, copy_row_except_pointers)
      (assign_row, set_frame_matrix_frame, make_current)
      (add_row_entry):
      * eval.c (set_specpdl_symbol, set_specpdl_old_value):
      * fns.c (maybe_resize_hash_table):
      * frame.c (fset_buffer_predicate, fset_minibuffer_window):
      * gmalloc.c (register_heapinfo):
      * image.c (lookup_image_type):
      * intervals.c (set_interval_object, set_interval_left)
      (set_interval_right, copy_interval_parent, rotate_right)
      (rotate_left, balance_possible_root_interval):
      * keyboard.c (kset_echo_string, kset_kbd_queue)
      (kset_keyboard_translate_table, kset_last_prefix_arg)
      (kset_last_repeatable_command, kset_local_function_key_map)
      (kset_overriding_terminal_local_map, kset_real_last_command)
      (kset_system_key_syms, clear_event, set_prop):
      * lread.c (digit_to_number):
      * marker.c (attach_marker, live_buffer, set_marker_internal):
      * nsterm.m (ns_compute_glyph_string_overhangs):
      * process.c (pset_buffer, pset_command)
      (pset_decode_coding_system, pset_decoding_buf)
      (pset_encode_coding_system, pset_encoding_buf, pset_filter)
      (pset_log, pset_mark, pset_name, pset_plist, pset_sentinel)
      (pset_status, pset_tty_name, pset_type, pset_write_queue):
      * syntax.c (bset_syntax_table, dec_bytepos):
      * terminal.c (tset_param_alist):
      * textprop.c (interval_has_some_properties)
      (interval_has_some_properties_list):
      * window.c (wset_combination_limit, wset_dedicated)
      (wset_display_table, wset_hchild, wset_left_fringe_width)
      (wset_left_margin_cols, wset_new_normal, wset_new_total)
      (wset_normal_cols, wset_normal_lines, wset_parent, wset_pointm)
      (wset_right_fringe_width, wset_right_margin_cols)
      (wset_scroll_bar_width, wset_start, wset_temslot, wset_vchild)
      (wset_vertical_scroll_bar_type, wset_window_parameters):
      * xdisp.c (wset_base_line_number, wset_base_line_pos)
      (wset_column_number_displayed, wset_region_showing)
      (window_box_edges, run_window_scroll_functions)
      (append_glyph_string_lists, prepend_glyph_string_lists)
      (append_glyph_string, set_glyph_string_background_width)
      (append_glyph, append_composite_glyph)
      (take_vertical_position_into_account):
      * xfaces.c (x_create_gc, x_free_gc, merge_face_vectors)
      (face_attr_equal_p, lface_equal_p, hash_string_case_insensitive)
      (lface_hash, lface_same_font_attributes_p, lookup_face):
      * xml.c (libxml2_loaded_p):
      * xterm.c (x_set_mode_line_face_gc, x_set_glyph_string_gc)
      (x_set_glyph_string_clipping, x_clear_glyph_string_rect):
      Now 'static', not 'static inline'.
      
      Fixes: debbugs:12541
      b0ab8123
  31. 23 Sep, 2012 1 commit
    • Paul Eggert's avatar
      Simplify and avoid signal-handling races. · 4d7e6e51
      Paul Eggert authored
      * nt/inc/ms-w32.h (emacs_raise): New macro.
      * src/alloc.c (die):
      * src/sysdep.c (emacs_abort) [HAVE_NTGUI]:
      Avoid recursive loop if there's a fatal error in the function itself.
      * src/atimer.c (pending_atimers):
      * src/blockinput.h: Don't include "atimer.h"; no longer needed.
      (interrupt_input_pending): Remove.  All uses removed.
      pending_signals now counts both atimers and ordinary interrupts.
      This is less racy than having three separate pending-signal flags.
      (block_input, unblock_input, totally_unblock_input, unblock_input_to)
      (input_blocked_p):
      Rename from their upper-case counterparts BLOCK_INPUT,
      UNBLOCK_INPUT, TOTALLY_UNBLOCK_INPUT, UNBLOCK_INPUT_TO,
      INPUT_BLOCKED_P, and turn into functions.  All uses changed.
      This makes it easier to access volatile variables more accurately.
      (BLOCK_INPUT_RESIGNAL): Remove.  All uses replaced by unblock_input ().
      (input_blocked_p): Prefer this to 'interrupt_input_blocked', as
      that's more reliable if the code is buggy and sets
      interrupt_input_blocked to a negative value.  All uses changed.
      * src/atimer.c (deliver_alarm_signal):
      Remove.  No need to deliver this to the parent; any thread can
      handle this signal now.  All uses replaced by underlying handler.
      * src/atimer.c (turn_on_atimers):
      * src/dispnew.c (handle_window_change_signal):
      * src/emacs.c (handle_danger_signal):
      * src/keyboard.c (kbd_buffer_get_event):
      Don't reestablish signal handler; not needed with sigaction.
      * src/blockinput.h (UNBLOCK_INPUT_TO, TOTALLY_UNBLOCK_INPUT)
      (UNBLOCK_INPUT_TO):
      Rework to avoid unnecessary accesses to volatile variables.
      (UNBLOCK_INPUT_TO): Now a function.
      (totally_unblock_input, unblock_input): New decls.
      * src/data.c (handle_arith_signal, deliver_arith_signal): Move to sysdep.c
      (init_data): Remove.  Necessary stuff now done in init_signal.
      * src/emacs.c, src/xdisp.c: Include "atimer.h", since we invoke atimer functions.
      * src/emacs.c (handle_fatal_signal, deliver_fatal_signal): Move to sysdep.c.
      (fatal_error_code): Remove; no longer needed.
      (terminate_due_to_signal): Rename from fatal_error_backtrace, since
      it doesn't always backtrace.  All uses changed.  No need to reset
      signal to default, since sigaction and/or die does that for us now.
      Use emacs_raise (FOO), not kill (getpid (), FOO).
      (main): Check more-accurately whether we're dumping.
      Move fatal-error setup to sysdep.c
      * src/floatfns.c: Do not include "syssignal.h"; no longer needed.
      * src/gtkutil.c (xg_get_file_name, xg_get_font):
      Remove no-longer-needed signal-mask manipulation.
      * src/keyboard.c, src/process.c (POLL_FOR_INPUT):
      Don't depend on USE_ASYNC_EVENTS, a symbol that is never defined.
      * src/keyboard.c (read_avail_input): Remove.
      All uses replaced by gobble_input.
      (Ftop_level): Use TOTALLY_UNBLOCK_INPUT rather than open code.
      (kbd_buffer_store_event_hold, gobble_input):
      (record_asynch_buffer_change) [USABLE_SIGIO]:
      (store_user_signal_events):
      No need to mess with signal mask.
      (gobble_input): If blocking input and there are terminals, simply
      set pending_signals to 1 and return.  All hooks changed to not
      worry about whether input is blocked.
      (process_pending_signals): Clear pending_signals before processing
      them, in case a signal comes in while we're processing.
      By convention callers now test pending_signals before calling us.
      (UNBLOCK_INPUT_TO, unblock_input, totally_unblock_input):
      New functions, to support changes to blockinput.h.
      (handle_input_available_signal): Now extern.
      (reinvoke_input_signal): Remove.  All uses replaced by
      handle_async_input.
      (quit_count): Now volatile, since a signal handler uses it.
      (handle_interrupt): Now takes bool IN_SIGNAL_HANDLER as arg.  All
      callers changed.  Block SIGINT only if not already blocked.
      Clear sigmask reliably, even if Fsignal returns, which it can.
      Omit unnecessary accesses to volatile var.
      (quit_throw_to_read_char): No need to restore sigmask.
      * src/keyboard.c (gobble_input, handle_user_signal):
      * src/process.c (wait_reading_process_output):
      Call signal-handling code rather than killing ourselves.
      * src/lisp.h: Include <float.h>, for...
      (IEEE_FLOATING_POINT): New macro, moved here to avoid duplication.
      (pending_signals): Now volatile.
      (syms_of_data): Now const if IEEE floating point.
      (handle_input_available_signal) [USABLE_SIGIO]:
      (terminate_due_to_signal, record_child_status_change): New decls.
      * src/process.c (create_process): Avoid disaster if memory is exhausted
      while we're processing a vfork, by tightening the critical section
      around the vfork.
      (send_process_frame, process_sent_to, handle_pipe_signal)
      (deliver_pipe_signal): Remove.  No longer needed, as Emacs now
      ignores SIGPIPE.
      (send_process): No need for setjmp/longjmp any more, since the
      SIGPIPE stuff is now gone.  Instead, report an error if errno
      is EPIPE.
      (record_child_status_change): Now extern.  PID and W are now args.
      Return void, not bool.  All callers changed.
      * src/sysdep.c (wait_debugging) [(BSD_SYSTEM || HPUX) && !defined (__GNU__)]:
      Remove.  All uses removed.  This bug should be fixed now in a
      different way.
      (wait_for_termination_1): Use waitpid rather than sigsuspend,
      and record the child status change directly.  This avoids the
      need to futz with the signal mask.
      (process_fatal_action): Move here from emacs.c.
      (emacs_sigaction_flags): New function, containing
      much of what used to be in emacs_sigaction_init.
      (emacs_sigaction_init): Use it.  Block nonfatal system signals that are
      caught by emacs, to make races less likely.
      (deliver_process_signal): Rename from handle_on_main_thread.
      All uses changed.
      (BACKTRACE_LIMIT_MAX): Now at top level.
      (thread_backtrace_buffer, threadback_backtrace_pointers):
      New static vars.
      (deliver_thread_signal, deliver_fatal_thread_signal):
      New functions, for more-accurate delivery of thread-specific signals.
      (handle_fatal_signal, deliver_fatal_signal): Move here from emacs.c.
      (deliver_arith_signal): Handle in this thread, not
      in the main thread, since it's triggered by this thread.
      (maybe_fatal_sig): New function.
      (init_signals): New arg DUMPING so that we can be more accurate
      about whether we're dumping.  Caller changed.
      Treat thread-specific signals differently from process-general signals.
      Block all signals while handling fatal error; that's safer.
      xsignal from SIGFPE only on non-IEEE hosts, treating it as fatal
      on IEEE hosts.
      When batch, ignore SIGHUP, SIGINT, SIGTERM if they were already ignored.
      Ignore SIGPIPE unless batch.
      (emacs_backtrace): Output backtrace for the appropriate thread,
      which is not necessarily the main thread.
      * src/syssignal.h: Include <stdbool.h>.
      (emacs_raise): New macro.
      * src/xterm.c (x_connection_signal): Remove; no longer needed
      now that we use sigaction.
      (x_connection_closed): No need to mess with sigmask now.
      (x_initialize): No need to reset SIGPIPE handler here, since
      init_signals does this for us now.
      
      Fixes: debbugs:12471
      4d7e6e51
  32. 17 Sep, 2012 1 commit
    • Daniel Colascione's avatar
      Implement cygw32 · 0fda9b75
      Daniel Colascione authored
      Here, we use the generic window-system configuration system we just
      implemented to support the w32 window-system in the mainline build
      under Cygwin.  (Previously, the w32 window system could only be
      compiled as part of the NT-native Emacs build process.)
      
      The changes in this patch need to be applied atomically in order to
      avoid breaking Emacs.  The changes include:
      
        - Changes throughout the Lisp and C code to not assume that
            NT Emacs and the w32 window system are synonymous.
      
        - Wiring up the regular select(2) event loop to Windows messages
      
        - Cleaning up the w32 drag-and-drop receiving code.
      
        - Exposing Cygwin path conversion functions to elisp.
      
        - Unicode file dialog support when compiling for Cygwin.
      
        - Splitting the w32 term lisp initialization code into code
          applicable to any w32 window-system and code specific to
          system-type windows-nt.
      
        - Integrating the old and new w32 code into the build system.
      0fda9b75