aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog25
-rw-r--r--src/editfns.c12
-rw-r--r--src/insdel.c11
-rw-r--r--src/lisp.h3
-rw-r--r--src/sysdep.c26
-rw-r--r--src/term.c31
-rw-r--r--src/xml.c17
7 files changed, 85 insertions, 40 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index dd22c5388b0..13a1f1a3858 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,28 @@
12013-01-11 Dmitry Antipov <dmantipov@yandex.ru>
2
3 Avoid unnecessary byte position calculation for the gap movement.
4 Since all users of move_gap do CHAR_TO_BYTE for other purposes
5 anyway, all of them should use move_gap_both instead.
6 * lisp.h (move_gap): Remove prototype.
7 * insdel.c (move_gap): Remove.
8 (move_gap_both): Add eassert.
9 * editfns.c (Ftranspose_regions): Tweak to use move_gap_both.
10 * xml.c (parse_region): Likewise.
11
122013-01-11 Paul Eggert <eggert@cs.ucla.edu>
13
14 emacsclient -t should not suspend Emacs server (Bug#13387)
15 * lisp.h, sysdep.c (block_tty_out_signal, unblock_tty_out_signal):
16 New functions.
17 * term.c (init_tty): Use them instead of rolling our own code.
18 * sysdep.c (tcsetpgrp_without_stopping): Likewise. Here, this
19 switches from 'signal' to 'pthread_sigmask', which is safer in
20 multithreaded applications.
21 * term.c (Fresume_tty): Don't bother dissociating if O_IGNORE_CTTY,
22 which has already arranged for that.
23 (dissociate_if_controlling_tty): If setsid fails, fall back on TIOCNOTTY.
24 This is the main part of the bug fix.
25
12013-01-10 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> (tiny change) 262013-01-10 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> (tiny change)
2 27
3 * gtkutil.c (xg_initialize): Add ifdef HAVE_FREETYPE around 28 * gtkutil.c (xg_initialize): Add ifdef HAVE_FREETYPE around
diff --git a/src/editfns.c b/src/editfns.c
index 26dfdac3ba8..64269bab8df 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -4522,7 +4522,7 @@ Transposing beyond buffer boundaries is an error. */)
4522 (Lisp_Object startr1, Lisp_Object endr1, Lisp_Object startr2, Lisp_Object endr2, Lisp_Object leave_markers) 4522 (Lisp_Object startr1, Lisp_Object endr1, Lisp_Object startr2, Lisp_Object endr2, Lisp_Object leave_markers)
4523{ 4523{
4524 register ptrdiff_t start1, end1, start2, end2; 4524 register ptrdiff_t start1, end1, start2, end2;
4525 ptrdiff_t start1_byte, start2_byte, len1_byte, len2_byte; 4525 ptrdiff_t start1_byte, start2_byte, len1_byte, len2_byte, end2_byte;
4526 ptrdiff_t gap, len1, len_mid, len2; 4526 ptrdiff_t gap, len1, len_mid, len2;
4527 unsigned char *start1_addr, *start2_addr, *temp; 4527 unsigned char *start1_addr, *start2_addr, *temp;
4528 4528
@@ -4583,20 +4583,22 @@ Transposing beyond buffer boundaries is an error. */)
4583 the gap the minimum distance to get it out of the way, and then 4583 the gap the minimum distance to get it out of the way, and then
4584 deal with an unbroken array. */ 4584 deal with an unbroken array. */
4585 4585
4586 start1_byte = CHAR_TO_BYTE (start1);
4587 end2_byte = CHAR_TO_BYTE (end2);
4588
4586 /* Make sure the gap won't interfere, by moving it out of the text 4589 /* Make sure the gap won't interfere, by moving it out of the text
4587 we will operate on. */ 4590 we will operate on. */
4588 if (start1 < gap && gap < end2) 4591 if (start1 < gap && gap < end2)
4589 { 4592 {
4590 if (gap - start1 < end2 - gap) 4593 if (gap - start1 < end2 - gap)
4591 move_gap (start1); 4594 move_gap_both (start1, start1_byte);
4592 else 4595 else
4593 move_gap (end2); 4596 move_gap_both (end2, end2_byte);
4594 } 4597 }
4595 4598
4596 start1_byte = CHAR_TO_BYTE (start1);
4597 start2_byte = CHAR_TO_BYTE (start2); 4599 start2_byte = CHAR_TO_BYTE (start2);
4598 len1_byte = CHAR_TO_BYTE (end1) - start1_byte; 4600 len1_byte = CHAR_TO_BYTE (end1) - start1_byte;
4599 len2_byte = CHAR_TO_BYTE (end2) - start2_byte; 4601 len2_byte = end2_byte - start2_byte;
4600 4602
4601#ifdef BYTE_COMBINING_DEBUG 4603#ifdef BYTE_COMBINING_DEBUG
4602 if (end1 == start2) 4604 if (end1 == start2)
diff --git a/src/insdel.c b/src/insdel.c
index 905249d6714..c2a3cd42821 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -84,21 +84,14 @@ check_markers (void)
84 84
85#endif /* MARKER_DEBUG */ 85#endif /* MARKER_DEBUG */
86 86
87/* Move gap to position CHARPOS.
88 Note that this can quit! */
89
90void
91move_gap (ptrdiff_t charpos)
92{
93 move_gap_both (charpos, CHAR_TO_BYTE (charpos));
94}
95
96/* Move gap to byte position BYTEPOS, which is also char position CHARPOS. 87/* Move gap to byte position BYTEPOS, which is also char position CHARPOS.
97 Note that this can quit! */ 88 Note that this can quit! */
98 89
99void 90void
100move_gap_both (ptrdiff_t charpos, ptrdiff_t bytepos) 91move_gap_both (ptrdiff_t charpos, ptrdiff_t bytepos)
101{ 92{
93 eassert (charpos == BYTE_TO_CHAR (bytepos)
94 && bytepos == CHAR_TO_BYTE (charpos));
102 if (bytepos < GPT_BYTE) 95 if (bytepos < GPT_BYTE)
103 gap_left (charpos, bytepos, 0); 96 gap_left (charpos, bytepos, 0);
104 else if (bytepos > GPT_BYTE) 97 else if (bytepos > GPT_BYTE)
diff --git a/src/lisp.h b/src/lisp.h
index 6a22ce0b120..16f9c89e3cd 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2780,7 +2780,6 @@ extern void syms_of_image (void);
2780 2780
2781/* Defined in insdel.c. */ 2781/* Defined in insdel.c. */
2782extern Lisp_Object Qinhibit_modification_hooks; 2782extern Lisp_Object Qinhibit_modification_hooks;
2783extern void move_gap (ptrdiff_t);
2784extern void move_gap_both (ptrdiff_t, ptrdiff_t); 2783extern void move_gap_both (ptrdiff_t, ptrdiff_t);
2785extern _Noreturn void buffer_overflow (void); 2784extern _Noreturn void buffer_overflow (void);
2786extern void make_gap (ptrdiff_t); 2785extern void make_gap (ptrdiff_t);
@@ -3467,6 +3466,8 @@ extern void init_sigio (int);
3467extern void sys_subshell (void); 3466extern void sys_subshell (void);
3468extern void sys_suspend (void); 3467extern void sys_suspend (void);
3469extern void discard_tty_input (void); 3468extern void discard_tty_input (void);
3469extern void block_tty_out_signal (void);
3470extern void unblock_tty_out_signal (void);
3470extern void init_sys_modes (struct tty_display_info *); 3471extern void init_sys_modes (struct tty_display_info *);
3471extern void reset_sys_modes (struct tty_display_info *); 3472extern void reset_sys_modes (struct tty_display_info *);
3472extern void init_all_sys_modes (void); 3473extern void init_all_sys_modes (void);
diff --git a/src/sysdep.c b/src/sysdep.c
index 049eb85afe5..158d2f73eec 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -714,6 +714,27 @@ init_foreground_group (void)
714 inherited_pgroup = getpid () == pgrp ? 0 : pgrp; 714 inherited_pgroup = getpid () == pgrp ? 0 : pgrp;
715} 715}
716 716
717/* Block and unblock SIGTTOU. */
718
719void
720block_tty_out_signal (void)
721{
722#ifdef SIGTTOU
723 sigset_t blocked;
724 sigemptyset (&blocked);
725 sigaddset (&blocked, SIGTTOU);
726 pthread_sigmask (SIG_BLOCK, &blocked, 0);
727#endif
728}
729
730void
731unblock_tty_out_signal (void)
732{
733#ifdef SIGTTOU
734 pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
735#endif
736}
737
717/* Safely set a controlling terminal FD's process group to PGID. 738/* Safely set a controlling terminal FD's process group to PGID.
718 If we are not in the foreground already, POSIX requires tcsetpgrp 739 If we are not in the foreground already, POSIX requires tcsetpgrp
719 to deliver a SIGTTOU signal, which would stop us. This is an 740 to deliver a SIGTTOU signal, which would stop us. This is an
@@ -725,11 +746,10 @@ static void
725tcsetpgrp_without_stopping (int fd, pid_t pgid) 746tcsetpgrp_without_stopping (int fd, pid_t pgid)
726{ 747{
727#ifdef SIGTTOU 748#ifdef SIGTTOU
728 signal_handler_t handler;
729 block_input (); 749 block_input ();
730 handler = signal (SIGTTOU, SIG_IGN); 750 block_tty_out_signal ();
731 tcsetpgrp (fd, pgid); 751 tcsetpgrp (fd, pgid);
732 signal (SIGTTOU, handler); 752 unblock_tty_out_signal ();
733 unblock_input (); 753 unblock_input ();
734#endif 754#endif
735} 755}
diff --git a/src/term.c b/src/term.c
index d76562bb4db..f66a0bddc33 100644
--- a/src/term.c
+++ b/src/term.c
@@ -2423,7 +2423,7 @@ frame's terminal). */)
2423 if (fd == -1) 2423 if (fd == -1)
2424 error ("Can not reopen tty device %s: %s", t->display_info.tty->name, strerror (errno)); 2424 error ("Can not reopen tty device %s: %s", t->display_info.tty->name, strerror (errno));
2425 2425
2426 if (strcmp (t->display_info.tty->name, DEV_TTY)) 2426 if (!O_IGNORE_CTTY && strcmp (t->display_info.tty->name, DEV_TTY) != 0)
2427 dissociate_if_controlling_tty (fd); 2427 dissociate_if_controlling_tty (fd);
2428 2428
2429 t->display_info.tty->output = fdopen (fd, "w+"); 2429 t->display_info.tty->output = fdopen (fd, "w+");
@@ -2903,13 +2903,23 @@ set_tty_hooks (struct terminal *terminal)
2903 terminal->delete_terminal_hook = &delete_tty; 2903 terminal->delete_terminal_hook = &delete_tty;
2904} 2904}
2905 2905
2906/* Drop the controlling terminal if fd is the same device. */ 2906/* If FD is the controlling terminal, drop it. */
2907static void 2907static void
2908dissociate_if_controlling_tty (int fd) 2908dissociate_if_controlling_tty (int fd)
2909{ 2909{
2910 pid_t pgid = tcgetpgrp (fd); /* If tcgetpgrp succeeds, fd is the ctty. */ 2910 /* If tcgetpgrp succeeds, fd is the controlling terminal,
2911 if (0 <= pgid) 2911 so dissociate it by invoking setsid. */
2912 setsid (); 2912 if (0 <= tcgetpgrp (fd) && setsid () < 0)
2913 {
2914#ifdef TIOCNOTTY
2915 /* setsid failed, presumably because Emacs is already a process
2916 group leader. Fall back on the obsolescent way to dissociate
2917 a controlling tty. */
2918 block_tty_out_signal ();
2919 ioctl (fd, TIOCNOTTY, 0);
2920 unblock_tty_out_signal ();
2921#endif
2922 }
2913} 2923}
2914 2924
2915/* Create a termcap display on the tty device with the given name and 2925/* Create a termcap display on the tty device with the given name and
@@ -3030,14 +3040,9 @@ init_tty (const char *name, const char *terminal_type, int must_succeed)
3030 3040
3031 /* On some systems, tgetent tries to access the controlling 3041 /* On some systems, tgetent tries to access the controlling
3032 terminal. */ 3042 terminal. */
3033 { 3043 block_tty_out_signal ();
3034 sigset_t blocked; 3044 status = tgetent (tty->termcap_term_buffer, terminal_type);
3035 sigemptyset (&blocked); 3045 unblock_tty_out_signal ();
3036 sigaddset (&blocked, SIGTTOU);
3037 pthread_sigmask (SIG_BLOCK, &blocked, 0);
3038 status = tgetent (tty->termcap_term_buffer, terminal_type);
3039 pthread_sigmask (SIG_UNBLOCK, &blocked, 0);
3040 }
3041 3046
3042 if (status < 0) 3047 if (status < 0)
3043 { 3048 {
diff --git a/src/xml.c b/src/xml.c
index 5939c58a564..5a52b0c2a1e 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -180,8 +180,7 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html
180 xmlDoc *doc; 180 xmlDoc *doc;
181 Lisp_Object result = Qnil; 181 Lisp_Object result = Qnil;
182 const char *burl = ""; 182 const char *burl = "";
183 ptrdiff_t bytes; 183 ptrdiff_t istart, iend, istart_byte, iend_byte;
184 ptrdiff_t istart, iend;
185 184
186 fn_xmlCheckVersion (LIBXML_VERSION); 185 fn_xmlCheckVersion (LIBXML_VERSION);
187 186
@@ -189,9 +188,11 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html
189 188
190 istart = XINT (start); 189 istart = XINT (start);
191 iend = XINT (end); 190 iend = XINT (end);
191 istart_byte = CHAR_TO_BYTE (istart);
192 iend_byte = CHAR_TO_BYTE (iend);
192 193
193 if (istart < GPT && GPT < iend) 194 if (istart < GPT && GPT < iend)
194 move_gap (iend); 195 move_gap_both (iend, iend_byte);
195 196
196 if (! NILP (base_url)) 197 if (! NILP (base_url))
197 { 198 {
@@ -199,17 +200,15 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html
199 burl = SSDATA (base_url); 200 burl = SSDATA (base_url);
200 } 201 }
201 202
202 bytes = CHAR_TO_BYTE (iend) - CHAR_TO_BYTE (istart);
203
204 if (htmlp) 203 if (htmlp)
205 doc = fn_htmlReadMemory ((char *) BYTE_POS_ADDR (CHAR_TO_BYTE (istart)), 204 doc = fn_htmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte),
206 bytes, burl, "utf-8", 205 iend_byte - istart_byte, burl, "utf-8",
207 HTML_PARSE_RECOVER|HTML_PARSE_NONET| 206 HTML_PARSE_RECOVER|HTML_PARSE_NONET|
208 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR| 207 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR|
209 HTML_PARSE_NOBLANKS); 208 HTML_PARSE_NOBLANKS);
210 else 209 else
211 doc = fn_xmlReadMemory ((char *) BYTE_POS_ADDR (CHAR_TO_BYTE (istart)), 210 doc = fn_xmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte),
212 bytes, burl, "utf-8", 211 iend_byte - istart_byte, burl, "utf-8",
213 XML_PARSE_NONET|XML_PARSE_NOWARNING| 212 XML_PARSE_NONET|XML_PARSE_NOWARNING|
214 XML_PARSE_NOBLANKS |XML_PARSE_NOERROR); 213 XML_PARSE_NOBLANKS |XML_PARSE_NOERROR);
215 214