summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.in52
-rw-r--r--src/alloc.c110
-rw-r--r--src/buffer.c4
-rw-r--r--src/ccl.c5
-rw-r--r--src/charset.c4
-rw-r--r--src/coding.c48
-rw-r--r--src/conf_post.h13
-rw-r--r--src/dired.c8
-rw-r--r--src/dispnew.c4
-rw-r--r--src/doc.c12
-rw-r--r--src/editfns.c2
-rw-r--r--src/emacs-module.c134
-rw-r--r--src/emacs-module.h9
-rw-r--r--src/emacs.c50
-rw-r--r--src/eval.c15
-rw-r--r--src/filelock.c9
-rw-r--r--src/fns.c53
-rw-r--r--src/fontset.c82
-rw-r--r--src/frame.c17
-rw-r--r--src/frame.h13
-rw-r--r--src/gmalloc.c233
-rw-r--r--src/gnutls.c405
-rw-r--r--src/gnutls.h7
-rw-r--r--src/image.c159
-rw-r--r--src/keyboard.c23
-rw-r--r--src/kqueue.c24
-rw-r--r--src/lastfile.c3
-rw-r--r--src/lisp.h25
-rw-r--r--src/process.c1535
-rw-r--r--src/process.h28
-rw-r--r--src/ralloc.c30
-rw-r--r--src/regex.c33
-rw-r--r--src/sheap.c83
-rw-r--r--src/sheap.h31
-rw-r--r--src/syntax.c6
-rw-r--r--src/sysdep.c38
-rw-r--r--src/unexcw.c8
-rw-r--r--src/unexelf.c26
-rw-r--r--src/vm-limit.c11
-rw-r--r--src/w32.c165
-rw-r--r--src/w32console.c3
-rw-r--r--src/w32fns.c1001
-rw-r--r--src/w32inevt.c20
-rw-r--r--src/w32term.h10
-rw-r--r--src/window.c220
-rw-r--r--src/window.h17
-rw-r--r--src/xdisp.c146
-rw-r--r--src/xfns.c441
-rw-r--r--src/xsmfns.c4
49 files changed, 3328 insertions, 2051 deletions
diff --git a/src/Makefile.in b/src/Makefile.in
index 1f0df6f3ec8..c290a6082da 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -235,6 +235,8 @@ IMAGEMAGICK_CFLAGS= @IMAGEMAGICK_CFLAGS@
LIBXML2_LIBS = @LIBXML2_LIBS@
LIBXML2_CFLAGS = @LIBXML2_CFLAGS@
+GETADDRINFO_A_LIBS = @GETADDRINFO_A_LIBS@
+
LIBZ = @LIBZ@
## system-specific libs for dynamic modules, else empty
@@ -254,7 +256,9 @@ XFIXES_CFLAGS = @XFIXES_CFLAGS@
## widget.o if USE_X_TOOLKIT, otherwise empty.
WIDGET_OBJ=@WIDGET_OBJ@
-## sheap.o if CYGWIN, otherwise empty.
+HYBRID_MALLOC = @HYBRID_MALLOC@
+
+## cygw32.o if CYGWIN, otherwise empty.
CYGWIN_OBJ=@CYGWIN_OBJ@
## fontset.o fringe.o image.o if we have any window system
@@ -298,9 +302,6 @@ CM_OBJ=@CM_OBJ@
LIBGPM = @LIBGPM@
-## -lresolv, or empty.
-LIBRESOLV = @LIBRESOLV@
-
LIBSELINUX_LIBS = @LIBSELINUX_LIBS@
LIBGNUTLS_LIBS = @LIBGNUTLS_LIBS@
@@ -312,6 +313,9 @@ GETLOADAVG_LIBS = @GETLOADAVG_LIBS@
RUN_TEMACS = ./temacs
+# Whether builds should contain details. '--no-build-details' or empty.
+BUILD_DETAILS = @BUILD_DETAILS@
+
UNEXEC_OBJ = @UNEXEC_OBJ@
CANNOT_DUMP=@CANNOT_DUMP@
@@ -397,6 +401,8 @@ base_obj = dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \
doprnt.o intervals.o textprop.o composite.o xml.o $(NOTIFY_OBJ) \
$(XWIDGETS_OBJ) \
profiler.o decompress.o \
+ $(if $(HYBRID_MALLOC),sheap.o) \
+ $(SHEAP_OBJ) \
$(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \
$(W32_OBJ) $(WINDOW_SYSTEM_OBJ) $(XGSELOBJ)
obj = $(base_obj) $(NS_OBJC_OBJ)
@@ -479,10 +485,10 @@ LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \
$(WEBKIT_LIBS) \
$(LIB_EACCESS) $(LIB_FDATASYNC) $(LIB_TIMER_TIME) $(DBUS_LIBS) \
$(LIB_EXECINFO) $(XRANDR_LIBS) $(XINERAMA_LIBS) $(XFIXES_LIBS) \
- $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) $(CAIRO_LIBS) \
+ $(LIBXML2_LIBS) $(LIBGPM) $(LIBS_SYSTEM) $(CAIRO_LIBS) \
$(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \
$(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \
- $(LIBGNUTLS_LIBS) $(LIB_PTHREAD) \
+ $(LIBGNUTLS_LIBS) $(LIB_PTHREAD) $(GETADDRINFO_A_LIBS) \
$(NOTIFY_LIBS) $(LIB_MATH) $(LIBZ) $(LIBMODULES)
$(leimdir)/leim-list.el: bootstrap-emacs$(EXEEXT)
@@ -531,7 +537,7 @@ emacs$(EXEEXT): temacs$(EXEEXT) \
ifeq ($(CANNOT_DUMP),yes)
ln -f temacs$(EXEEXT) $@
else
- LC_ALL=C $(RUN_TEMACS) -batch -l loadup dump
+ LC_ALL=C $(RUN_TEMACS) -batch $(BUILD_DETAILS) -l loadup dump
$(PAXCTL_if_present) -zex $@
ln -f $@ bootstrap-emacs$(EXEEXT)
endif
@@ -581,7 +587,9 @@ globals.h: gl-stamp; @true
$(ALLOBJS): globals.h
-$(lib)/libgnu.a: $(config_h)
+LIBEGNU_ARCHIVE = $(lib)/lib$(if $(HYBRID_MALLOC),e)gnu.a
+
+$(LIBEGNU_ARCHIVE): $(config_h)
$(MAKE) -C $(lib) all
## We have to create $(etc) here because init_cmdargs tests its
@@ -589,9 +597,9 @@ $(lib)/libgnu.a: $(config_h)
## This goes on to affect various things, and the emacs binary fails
## to start if Vinstallation_directory has the wrong value.
temacs$(EXEEXT): $(LIBXMENU) $(ALLOBJS) \
- $(lib)/libgnu.a $(EMACSRES) ${charsets} ${charscript}
+ $(LIBEGNU_ARCHIVE) $(EMACSRES) ${charsets} ${charscript}
$(AM_V_CCLD)$(CC) $(ALL_CFLAGS) $(TEMACS_LDFLAGS) $(LDFLAGS) \
- -o temacs $(ALLOBJS) $(lib)/libgnu.a $(W32_RES_LINK) $(LIBES)
+ -o temacs $(ALLOBJS) $(LIBEGNU_ARCHIVE) $(W32_RES_LINK) $(LIBES)
$(MKDIR_P) $(etc)
ifneq ($(CANNOT_DUMP),yes)
$(PAXCTL_if_present) -r $@
@@ -663,32 +671,34 @@ extraclean: distclean
-rm -f *~ \#*
-ETAGS = ../lib-src/etags
+ETAGS = ../lib-src/etags${EXEEXT}
+
+${ETAGS}: FORCE
+ ${MAKE} -C ../lib-src $(notdir $@)
-ctagsfiles1 = [xyzXYZ]*.[hc]
-ctagsfiles2 = [a-wA-W]*.[hc]
-ctagsfiles3 = [a-zA-Z]*.m
+ctagsfiles1 = $(wildcard ${srcdir}/*.[hc])
+ctagsfiles2 = $(wildcard ${srcdir}/*.m)
## FIXME? In out-of-tree builds, should TAGS be generated in srcdir?
## This does not need to depend on ../lisp and ../lwlib TAGS files,
## because etags "--include" only includes a pointer to the file,
## rather than the file contents.
-TAGS: $(srcdir)/$(ctagsfiles1) $(srcdir)/$(ctagsfiles2) $(srcdir)/$(ctagsfiles3)
- "$(ETAGS)" --include=../lisp/TAGS --include=$(lwlibdir)/TAGS \
+TAGS: ${ETAGS} $(ctagsfiles1) $(ctagsfiles2)
+ ${ETAGS} --include=../lisp/TAGS --include=$(lwlibdir)/TAGS \
--regex='{c}/[ ]*DEFVAR_[A-Z_ (]+"\([^"]+\)"/\1/' \
--regex='{c}/[ ]*DEFVAR_[A-Z_ (]+"[^"]+",[ ]\([A-Za-z0-9_]+\)/\1/' \
- $(srcdir)/$(ctagsfiles1) $(srcdir)/$(ctagsfiles2) \
+ $(ctagsfiles1) \
--regex='{objc}/[ ]*DEFVAR_[A-Z_ (]+"\([^"]+\)"/\1/' \
--regex='{objc}/[ ]*DEFVAR_[A-Z_ (]+"[^"]+",[ ]\([A-Za-z0-9_]+\)/\1/' \
- $(srcdir)/$(ctagsfiles3)
+ $(ctagsfiles2)
## Arrange to make tags tables for ../lisp and ../lwlib,
## which the above TAGS file for the C files includes by reference.
-../lisp/TAGS:
+../lisp/TAGS: FORCE
$(MAKE) -C ../lisp TAGS ETAGS="$(ETAGS)"
-$(lwlibdir)/TAGS:
+$(lwlibdir)/TAGS: FORCE
$(MAKE) -C $(lwlibdir) TAGS ETAGS="$(ETAGS)"
tags: TAGS ../lisp/TAGS $(lwlibdir)/TAGS
@@ -733,7 +743,7 @@ bootstrap-emacs$(EXEEXT): temacs$(EXEEXT)
ifeq ($(CANNOT_DUMP),yes)
ln -f temacs$(EXEEXT) $@
else
- $(RUN_TEMACS) --batch --load loadup bootstrap
+ $(RUN_TEMACS) --batch $(BUILD_DETAILS) --load loadup bootstrap
$(PAXCTL_if_present) -zex emacs$(EXEEXT)
mv -f emacs$(EXEEXT) $@
endif
diff --git a/src/alloc.c b/src/alloc.c
index b5be0f6e69c..eaa92eeddcc 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -22,10 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <stdio.h>
#include <limits.h> /* For CHAR_BIT. */
-
-#ifdef ENABLE_CHECKING
-#include <signal.h> /* For SIGABRT. */
-#endif
+#include <signal.h> /* For SIGABRT, SIGDANGER. */
#ifdef HAVE_PTHREAD
#include <pthread.h>
@@ -35,6 +32,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "dispextern.h"
#include "intervals.h"
#include "puresize.h"
+#include "sheap.h"
#include "systime.h"
#include "character.h"
#include "buffer.h"
@@ -58,6 +56,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "dosfns.h" /* For dos_memory_info. */
#endif
+#ifdef HAVE_MALLOC_H
+# include <malloc.h>
+#endif
+
#if (defined ENABLE_CHECKING \
&& defined HAVE_VALGRIND_VALGRIND_H \
&& !defined USE_VALGRIND)
@@ -106,8 +108,6 @@ my_heap_start (void)
#ifdef DOUG_LEA_MALLOC
-#include <malloc.h>
-
/* Specify maximum number of areas to mmap. It would be nice to use a
value that explicitly means "no limit". */
@@ -117,18 +117,6 @@ my_heap_start (void)
inside glibc's malloc. */
static void *malloc_state_ptr;
-/* Get and free this pointer; useful around unexec. */
-void
-alloc_unexec_pre (void)
-{
- malloc_state_ptr = malloc_get_state ();
-}
-void
-alloc_unexec_post (void)
-{
- free (malloc_state_ptr);
-}
-
/* Restore the dumped malloc state. Because malloc can be invoked
even before main (e.g. by the dynamic linker), the dumped malloc
state must be restored as early as possible using this special hook. */
@@ -169,14 +157,40 @@ malloc_initialize_hook (void)
}
}
+/* Declare the malloc initialization hook, which runs before 'main' starts.
+ EXTERNALLY_VISIBLE works around Bug#22522. */
# ifndef __MALLOC_HOOK_VOLATILE
# define __MALLOC_HOOK_VOLATILE
# endif
-voidfuncptr __MALLOC_HOOK_VOLATILE __malloc_initialize_hook
+voidfuncptr __MALLOC_HOOK_VOLATILE __malloc_initialize_hook EXTERNALLY_VISIBLE
= malloc_initialize_hook;
#endif
+/* Allocator-related actions to do just before and after unexec. */
+
+void
+alloc_unexec_pre (void)
+{
+#ifdef DOUG_LEA_MALLOC
+ malloc_state_ptr = malloc_get_state ();
+#endif
+#ifdef HYBRID_MALLOC
+ bss_sbrk_did_unexec = true;
+#endif
+}
+
+void
+alloc_unexec_post (void)
+{
+#ifdef DOUG_LEA_MALLOC
+ free (malloc_state_ptr);
+#endif
+#ifdef HYBRID_MALLOC
+ bss_sbrk_did_unexec = false;
+#endif
+}
+
/* Mark, unmark, query mark bit of a Lisp string. S must be a pointer
to a struct Lisp_String. */
@@ -550,6 +564,8 @@ static struct Lisp_Finalizer doomed_finalizers;
Malloc
************************************************************************/
+#if defined SIGDANGER || (!defined SYSTEM_MALLOC && !defined HYBRID_MALLOC)
+
/* Function malloc calls this if it finds we are near exhausting storage. */
void
@@ -558,6 +574,7 @@ malloc_warning (const char *str)
pending_malloc_warning = str;
}
+#endif
/* Display an already-pending malloc warning. */
@@ -1111,23 +1128,14 @@ lisp_free (void *block)
unexmacosx.c, so don't use it on Darwin. */
#if ! ADDRESS_SANITIZER && !defined DARWIN_OS
-# if !defined SYSTEM_MALLOC && !defined DOUG_LEA_MALLOC && !defined HYBRID_MALLOC
-# define USE_ALIGNED_ALLOC 1
-# ifndef HAVE_ALIGNED_ALLOC
-/* Defined in gmalloc.c. */
-void *aligned_alloc (size_t, size_t);
-# endif
-# elif defined HYBRID_MALLOC
-# if defined HAVE_ALIGNED_ALLOC || defined HAVE_POSIX_MEMALIGN
-# define USE_ALIGNED_ALLOC 1
-# define aligned_alloc hybrid_aligned_alloc
-/* Defined in gmalloc.c. */
-void *aligned_alloc (size_t, size_t);
-# endif
-# elif defined HAVE_ALIGNED_ALLOC
+# if (defined HAVE_ALIGNED_ALLOC \
+ || (defined HYBRID_MALLOC \
+ ? defined HAVE_POSIX_MEMALIGN \
+ : !defined SYSTEM_MALLOC && !defined DOUG_LEA_MALLOC))
# define USE_ALIGNED_ALLOC 1
-# elif defined HAVE_POSIX_MEMALIGN
+# elif !defined HYBRID_MALLOC && defined HAVE_POSIX_MEMALIGN
# define USE_ALIGNED_ALLOC 1
+# define aligned_alloc my_aligned_alloc /* Avoid collision with lisp.h. */
static void *
aligned_alloc (size_t alignment, size_t size)
{
@@ -3391,22 +3399,13 @@ allocate_buffer (void)
DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0,
doc: /* Return a newly created vector of length LENGTH, with each element being INIT.
See also the function `vector'. */)
- (register Lisp_Object length, Lisp_Object init)
+ (Lisp_Object length, Lisp_Object init)
{
- Lisp_Object vector;
- register ptrdiff_t sizei;
- register ptrdiff_t i;
- register struct Lisp_Vector *p;
-
CHECK_NATNUM (length);
-
- p = allocate_vector (XFASTINT (length));
- sizei = XFASTINT (length);
- for (i = 0; i < sizei; i++)
+ struct Lisp_Vector *p = allocate_vector (XFASTINT (length));
+ for (ptrdiff_t i = 0; i < XFASTINT (length); i++)
p->contents[i] = init;
-
- XSETVECTOR (vector, p);
- return vector;
+ return make_lisp_ptr (p, Lisp_Vectorlike);
}
DEFUN ("vector", Fvector, Svector, 0, MANY, 0,
@@ -3415,12 +3414,9 @@ Any number of arguments, even zero arguments, are allowed.
usage: (vector &rest OBJECTS) */)
(ptrdiff_t nargs, Lisp_Object *args)
{
- ptrdiff_t i;
- register Lisp_Object val = make_uninit_vector (nargs);
- register struct Lisp_Vector *p = XVECTOR (val);
-
- for (i = 0; i < nargs; i++)
- p->contents[i] = args[i];
+ Lisp_Object val = make_uninit_vector (nargs);
+ struct Lisp_Vector *p = XVECTOR (val);
+ memcpy (p->contents, args, nargs * sizeof *args);
return val;
}
@@ -3459,9 +3455,8 @@ stack before executing the byte-code.
usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INTERACTIVE-SPEC &rest ELEMENTS) */)
(ptrdiff_t nargs, Lisp_Object *args)
{
- ptrdiff_t i;
- register Lisp_Object val = make_uninit_vector (nargs);
- register struct Lisp_Vector *p = XVECTOR (val);
+ Lisp_Object val = make_uninit_vector (nargs);
+ struct Lisp_Vector *p = XVECTOR (val);
/* We used to purecopy everything here, if purify-flag was set. This worked
OK for Emacs-23, but with Emacs-24's lexical binding code, it can be
@@ -3471,8 +3466,7 @@ usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INT
just wasteful and other times plainly wrong (e.g. those free vars may want
to be setcar'd). */
- for (i = 0; i < nargs; i++)
- p->contents[i] = args[i];
+ memcpy (p->contents, args, nargs * sizeof *args);
make_byte_code (p);
XSETCOMPILED (val, p);
return val;
diff --git a/src/buffer.c b/src/buffer.c
index f06d7e08e49..62b0bc8c6f4 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -2001,7 +2001,7 @@ the current buffer's major mode. */)
/* To select a nonfundamental mode,
select the buffer temporarily and then call the mode function. */
- record_unwind_protect (save_excursion_restore, save_excursion_save ());
+ record_unwind_current_buffer ();
Fset_buffer (buffer);
call0 (function);
@@ -5277,7 +5277,7 @@ init_buffer (int initialized)
if (NILP (BVAR (&buffer_defaults, enable_multibyte_characters)))
Fset_buffer_multibyte (Qnil);
- pwd = get_current_dir_name ();
+ pwd = emacs_get_current_dir_name ();
if (!pwd)
{
diff --git a/src/ccl.c b/src/ccl.c
index d9620340f09..b9dc52e2568 100644
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -1908,8 +1908,6 @@ ccl_get_compiled_code (Lisp_Object ccl_prog, ptrdiff_t *idx)
bool
setup_ccl_program (struct ccl_program *ccl, Lisp_Object ccl_prog)
{
- int i;
-
if (! NILP (ccl_prog))
{
struct Lisp_Vector *vp;
@@ -1931,8 +1929,7 @@ setup_ccl_program (struct ccl_program *ccl, Lisp_Object ccl_prog)
}
}
ccl->ic = CCL_HEADER_MAIN;
- for (i = 0; i < 8; i++)
- ccl->reg[i] = 0;
+ memset (ccl->reg, 0, sizeof ccl->reg);
ccl->last_block = false;
ccl->status = 0;
ccl->stack_idx = 0;
diff --git a/src/charset.c b/src/charset.c
index 8ff469e13a3..264036ae91b 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -1050,8 +1050,8 @@ usage: (define-charset-internal ...) */)
/* Here, we just copy the parent's fast_map. It's not accurate,
but at least it works for quickly detecting which character
DOESN'T belong to this charset. */
- for (i = 0; i < 190; i++)
- charset.fast_map[i] = parent_charset->fast_map[i];
+ memcpy (charset.fast_map, parent_charset->fast_map,
+ sizeof charset.fast_map);
/* We also copy these for parents. */
charset.min_char = parent_charset->min_char;
diff --git a/src/coding.c b/src/coding.c
index 9f709bea24c..e72d7b71867 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -6814,39 +6814,29 @@ decode_eol (struct coding_system *coding)
else if (EQ (eol_type, Qdos))
{
ptrdiff_t n = 0;
+ ptrdiff_t pos = coding->dst_pos;
+ ptrdiff_t pos_byte = coding->dst_pos_byte;
+ ptrdiff_t pos_end = pos_byte + coding->produced - 1;
- if (NILP (coding->dst_object))
- {
- /* Start deleting '\r' from the tail to minimize the memory
- movement. */
- for (p = pend - 2; p >= pbeg; p--)
- if (*p == '\r')
- {
- memmove (p, p + 1, pend-- - p - 1);
- n++;
- }
- }
- else
- {
- ptrdiff_t pos = coding->dst_pos;
- ptrdiff_t pos_byte = coding->dst_pos_byte;
- ptrdiff_t pos_end = pos_byte + coding->produced - 1;
+ /* This assertion is here instead of code, now deleted, that
+ handled the NILP case, which no longer happens with the
+ current codebase. */
+ eassert (!NILP (coding->dst_object));
- while (pos_byte < pos_end)
+ while (pos_byte < pos_end)
+ {
+ p = BYTE_POS_ADDR (pos_byte);
+ if (*p == '\r' && p[1] == '\n')
{
- p = BYTE_POS_ADDR (pos_byte);
- if (*p == '\r' && p[1] == '\n')
- {
- del_range_2 (pos, pos_byte, pos + 1, pos_byte + 1, 0);
- n++;
- pos_end--;
- }
- pos++;
- if (coding->dst_multibyte)
- pos_byte += BYTES_BY_CHAR_HEAD (*p);
- else
- pos_byte++;
+ del_range_2 (pos, pos_byte, pos + 1, pos_byte + 1, 0);
+ n++;
+ pos_end--;
}
+ pos++;
+ if (coding->dst_multibyte)
+ pos_byte += BYTES_BY_CHAR_HEAD (*p);
+ else
+ pos_byte++;
}
coding->produced -= n;
coding->produced_char -= n;
diff --git a/src/conf_post.h b/src/conf_post.h
index d0f04b63700..047e3575e19 100644
--- a/src/conf_post.h
+++ b/src/conf_post.h
@@ -99,12 +99,9 @@ typedef bool bool_bf;
#ifdef emacs
#define malloc hybrid_malloc
#define realloc hybrid_realloc
+#define aligned_alloc hybrid_aligned_alloc
#define calloc hybrid_calloc
#define free hybrid_free
-#if defined HAVE_GET_CURRENT_DIR_NAME && !defined BROKEN_GET_CURRENT_DIR_NAME
-#define HYBRID_GET_CURRENT_DIR_NAME 1
-#define get_current_dir_name hybrid_get_current_dir_name
-#endif
#endif
#endif /* HYBRID_MALLOC */
@@ -120,14 +117,6 @@ typedef bool bool_bf;
#undef HAVE_RINT
#endif /* HPUX */
-#ifdef IRIX6_5
-#ifdef emacs
-char *_getpty();
-#endif
-#define INET6 /* Needed for struct sockaddr_in6. */
-#undef HAVE_GETADDRINFO /* IRIX has getaddrinfo but not struct addrinfo. */
-#endif /* IRIX6_5 */
-
#ifdef MSDOS
#ifndef __DJGPP__
You lose; /* Emacs for DOS must be compiled with DJGPP */
diff --git a/src/dired.c b/src/dired.c
index e21b2273f79..ebc7029cc7f 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -861,6 +861,14 @@ below) - valid values are `string' and `integer'. The latter is the
default, but we plan to change that, so you should specify a non-nil value
for ID-FORMAT if you use the returned uid or gid.
+To access the elements returned, the following access functions are
+provided: `file-attribute-type', `file-attribute-link-number',
+`file-attribute-user-id', `file-attribute-group-id',
+`file-attribute-access-time', `file-attribute-modification-time',
+`file-attribute-status-change-time', `file-attribute-size',
+`file-attribute-modes', `file-attribute-inode-number', and
+`file-attribute-device-number'.
+
Elements of the attribute list are:
0. t for directory, string (name linked to) for symbolic link, or nil.
1. Number of links to file.
diff --git a/src/dispnew.c b/src/dispnew.c
index 3a0532a693b..9cf12f1a995 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -321,9 +321,7 @@ margin_glyphs_to_reserve (struct window *w, int total_glyphs, int margin)
int width = w->total_cols;
double d = max (0, margin);
d = min (width / 2 - 1, d);
- /* Since MARGIN is positive, we cannot possibly have less than
- one glyph for the marginal area. */
- return max (1, (int) ((double) total_glyphs / width * d));
+ return (int) ((double) total_glyphs / width * d);
}
return 0;
}
diff --git a/src/doc.c b/src/doc.c
index 1d466612c66..c5dd8d5a786 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -868,16 +868,14 @@ Otherwise, return a new string. */)
\<foo> just sets the keymap used for \[cmd]. */
else if (strp[0] == '\\' && (strp[1] == '{' || strp[1] == '<'))
{
- struct buffer *oldbuf;
- ptrdiff_t start_idx;
+ {
/* This is for computing the SHADOWS arg for describe_map_tree. */
Lisp_Object active_maps = Fcurrent_active_maps (Qnil, Qnil);
- Lisp_Object earlier_maps;
ptrdiff_t count = SPECPDL_INDEX ();
strp += 2; /* skip \{ or \< */
start = strp;
- start_idx = start - SDATA (string);
+ ptrdiff_t start_idx = start - SDATA (string);
while ((strp - SDATA (string) < SBYTES (string))
&& *strp != '}' && *strp != '>')
@@ -907,7 +905,7 @@ Otherwise, return a new string. */)
}
/* Now switch to a temp buffer. */
- oldbuf = current_buffer;
+ struct buffer *oldbuf = current_buffer;
set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
/* This is for an unusual case where some after-change
function uses 'format' or 'prin1' or something else that
@@ -932,7 +930,8 @@ Otherwise, return a new string. */)
{
/* Get the list of active keymaps that precede this one.
If this one's not active, get nil. */
- earlier_maps = Fcdr (Fmemq (tem, Freverse (active_maps)));
+ Lisp_Object earlier_maps
+ = Fcdr (Fmemq (tem, Freverse (active_maps)));
describe_map_tree (tem, 1, Fnreverse (earlier_maps),
Qnil, 0, 1, 0, 0, 1);
}
@@ -940,6 +939,7 @@ Otherwise, return a new string. */)
Ferase_buffer ();
set_buffer_internal (oldbuf);
unbind_to (count, Qnil);
+ }
subst_string:
start = SDATA (tem);
diff --git a/src/editfns.c b/src/editfns.c
index df982234977..c6441c25af9 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -4990,7 +4990,7 @@ Transposing beyond buffer boundaries is an error. */)
start2_addr = BYTE_POS_ADDR (start2_byte);
memcpy (temp, start1_addr, len1_byte);
memcpy (start1_addr, start2_addr, len2_byte);
- memcpy (start1_addr + len2_byte, start1_addr + len1_byte, len_mid);
+ memmove (start1_addr + len2_byte, start1_addr + len1_byte, len_mid);
memcpy (start1_addr + len2_byte + len_mid, temp, len1_byte);
SAFE_FREE ();
diff --git a/src/emacs-module.c b/src/emacs-module.c
index eca5af739b9..3edb943d4ca 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -64,6 +64,13 @@ enum
&& INTPTR_MAX == EMACS_INT_MAX)
};
+/* Function prototype for the module init function. */
+typedef int (*emacs_init_function) (struct emacs_runtime *);
+
+/* Function prototype for the module Lisp functions. */
+typedef emacs_value (*emacs_subr) (emacs_env *, ptrdiff_t,
+ emacs_value [], void *);
+
/* Function prototype for module user-pointer finalizers. These
should not throw C++ exceptions, so emacs-module.h declares the
corresponding interfaces with EMACS_NOEXCEPT. There is only C code
@@ -107,14 +114,12 @@ static enum emacs_funcall_exit module_non_local_exit_check (emacs_env *);
static void check_main_thread (void);
static void finalize_environment (struct emacs_env_private *);
static void initialize_environment (emacs_env *, struct emacs_env_private *priv);
-static void module_args_out_of_range (emacs_env *, Lisp_Object, Lisp_Object);
static void module_handle_signal (emacs_env *, Lisp_Object);
static void module_handle_throw (emacs_env *, Lisp_Object);
static void module_non_local_exit_signal_1 (emacs_env *, Lisp_Object, Lisp_Object);
static void module_non_local_exit_throw_1 (emacs_env *, Lisp_Object, Lisp_Object);
static void module_out_of_memory (emacs_env *);
static void module_reset_handlerlist (const int *);
-static void module_wrong_type (emacs_env *, Lisp_Object, Lisp_Object);
/* We used to return NULL when emacs_value was a different type from
Lisp_Object, but nowadays we just use Qnil instead. Although they
@@ -243,6 +248,12 @@ struct module_fun_env
return error_retval; \
MODULE_HANDLE_NONLOCAL_EXIT (error_retval)
+static void
+CHECK_USER_PTR (Lisp_Object obj)
+{
+ CHECK_TYPE (USER_PTRP (obj), Quser_ptrp, obj);
+}
+
/* Catch signals and throws only if the code can actually signal or
throw. If checking is enabled, abort if the current thread is not
the Emacs main thread. */
@@ -270,11 +281,8 @@ module_make_global_ref (emacs_env *env, emacs_value ref)
{
Lisp_Object value = HASH_VALUE (h, i);
EMACS_INT refcount = XFASTINT (value) + 1;
- if (refcount > MOST_POSITIVE_FIXNUM)
- {
- module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil);
- return module_nil;
- }
+ if (MOST_POSITIVE_FIXNUM < refcount)
+ xsignal0 (Qoverflow_error);
value = make_natnum (refcount);
set_hash_value_slot (h, i, value);
}
@@ -414,6 +422,8 @@ module_funcall (emacs_env *env, emacs_value fun, ptrdiff_t nargs,
first arg, because that's what Ffuncall takes. */
Lisp_Object *newargs;
USE_SAFE_ALLOCA;
+ if (nargs == PTRDIFF_MAX)
+ xsignal0 (Qoverflow_error);
SAFE_ALLOCA_LISP (newargs, nargs + 1);
newargs[0] = value_to_lisp (fun);
for (ptrdiff_t i = 0; i < nargs; i++)
@@ -460,11 +470,7 @@ module_extract_integer (emacs_env *env, emacs_value n)
{
MODULE_FUNCTION_BEGIN (0);
Lisp_Object l = value_to_lisp (n);
- if (! INTEGERP (l))
- {
- module_wrong_type (env, Qintegerp, l);
- return 0;
- }
+ CHECK_NUMBER (l);
return XINT (l);
}
@@ -472,11 +478,8 @@ static emacs_value
module_make_integer (emacs_env *env, intmax_t n)
{
MODULE_FUNCTION_BEGIN (module_nil);
- if (! (MOST_NEGATIVE_FIXNUM <= n && n <= MOST_POSITIVE_FIXNUM))
- {
- module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil);
- return module_nil;
- }
+ if (FIXNUM_OVERFLOW_P (n))
+ xsignal0 (Qoverflow_error);
return lisp_to_value (make_number (n));
}
@@ -485,11 +488,7 @@ module_extract_float (emacs_env *env, emacs_value f)
{
MODULE_FUNCTION_BEGIN (0);
Lisp_Object lisp = value_to_lisp (f);
- if (! FLOATP (lisp))
- {
- module_wrong_type (env, Qfloatp, lisp);
- return 0;
- }
+ CHECK_TYPE (FLOATP (lisp), Qfloatp, lisp);
return XFLOAT_DATA (lisp);
}
@@ -506,19 +505,10 @@ module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer,
{
MODULE_FUNCTION_BEGIN (false);
Lisp_Object lisp_str = value_to_lisp (value);
- if (! STRINGP (lisp_str))
- {
- module_wrong_type (env, Qstringp, lisp_str);
- return false;
- }
+ CHECK_STRING (lisp_str);
Lisp_Object lisp_str_utf8 = ENCODE_UTF_8 (lisp_str);
ptrdiff_t raw_size = SBYTES (lisp_str_utf8);
- if (raw_size == PTRDIFF_MAX)
- {
- module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil);
- return false;
- }
ptrdiff_t required_buf_size = raw_size + 1;
eassert (length != NULL);
@@ -534,8 +524,7 @@ module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer,
if (*length < required_buf_size)
{
*length = required_buf_size;
- module_non_local_exit_signal_1 (env, Qargs_out_of_range, Qnil);
- return false;
+ xsignal0 (Qargs_out_of_range);
}
*length = required_buf_size;
@@ -548,11 +537,6 @@ static emacs_value
module_make_string (emacs_env *env, const char *str, ptrdiff_t length)
{
MODULE_FUNCTION_BEGIN (module_nil);
- if (length > STRING_BYTES_BOUND)
- {
- module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil);
- return module_nil;
- }
Lisp_Object lstr = make_unibyte_string (str, length);
return lisp_to_value (code_convert_string_norecord (lstr, Qutf_8, false));
}
@@ -569,11 +553,7 @@ module_get_user_ptr (emacs_env *env, emacs_value uptr)
{
MODULE_FUNCTION_BEGIN (NULL);
Lisp_Object lisp = value_to_lisp (uptr);
- if (! USER_PTRP (lisp))
- {
- module_wrong_type (env, Quser_ptr, lisp);
- return NULL;
- }
+ CHECK_USER_PTR (lisp);
return XUSER_PTR (lisp)->p;
}
@@ -582,12 +562,8 @@ module_set_user_ptr (emacs_env *env, emacs_value uptr, void *ptr)
{
/* FIXME: This function should return bool because it can fail. */
MODULE_FUNCTION_BEGIN ();
- check_main_thread ();
- if (module_non_local_exit_check (env) != emacs_funcall_exit_return)
- return;
Lisp_Object lisp = value_to_lisp (uptr);
- if (! USER_PTRP (lisp))
- module_wrong_type (env, Quser_ptr, lisp);
+ CHECK_USER_PTR (lisp);
XUSER_PTR (lisp)->p = ptr;
}
@@ -596,11 +572,7 @@ module_get_user_finalizer (emacs_env *env, emacs_value uptr)
{
MODULE_FUNCTION_BEGIN (NULL);
Lisp_Object lisp = value_to_lisp (uptr);
- if (! USER_PTRP (lisp))
- {
- module_wrong_type (env, Quser_ptr, lisp);
- return NULL;
- }
+ CHECK_USER_PTR (lisp);
return XUSER_PTR (lisp)->finalizer;
}
@@ -611,8 +583,7 @@ module_set_user_finalizer (emacs_env *env, emacs_value uptr,
/* FIXME: This function should return bool because it can fail. */
MODULE_FUNCTION_BEGIN ();
Lisp_Object lisp = value_to_lisp (uptr);
- if (! USER_PTRP (lisp))
- module_wrong_type (env, Quser_ptr, lisp);
+ CHECK_USER_PTR (lisp);
XUSER_PTR (lisp)->finalizer = fin;
}
@@ -622,19 +593,8 @@ module_vec_set (emacs_env *env, emacs_value vec, ptrdiff_t i, emacs_value val)
/* FIXME: This function should return bool because it can fail. */
MODULE_FUNCTION_BEGIN ();
Lisp_Object lvec = value_to_lisp (vec);
- if (! VECTORP (lvec))
- {
- module_wrong_type (env, Qvectorp, lvec);
- return;
- }
- if (! (0 <= i && i < ASIZE (lvec)))
- {
- if (MOST_NEGATIVE_FIXNUM <= i && i <= MOST_POSITIVE_FIXNUM)
- module_args_out_of_range (env, lvec, make_number (i));
- else
- module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil);
- return;
- }
+ CHECK_VECTOR (lvec);
+ CHECK_RANGED_INTEGER (make_number (i), 0, ASIZE (lvec) - 1);
ASET (lvec, i, value_to_lisp (val));
}
@@ -643,19 +603,8 @@ module_vec_get (emacs_env *env, emacs_value vec, ptrdiff_t i)
{
MODULE_FUNCTION_BEGIN (module_nil);
Lisp_Object lvec = value_to_lisp (vec);
- if (! VECTORP (lvec))
- {
- module_wrong_type (env, Qvectorp, lvec);
- return module_nil;
- }
- if (! (0 <= i && i < ASIZE (lvec)))
- {
- if (MOST_NEGATIVE_FIXNUM <= i && i <= MOST_POSITIVE_FIXNUM)
- module_args_out_of_range (env, lvec, make_number (i));
- else
- module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil);
- return module_nil;
- }
+ CHECK_VECTOR (lvec);
+ CHECK_RANGED_INTEGER (make_number (i), 0, ASIZE (lvec) - 1);
return lisp_to_value (AREF (lvec, i));
}
@@ -665,11 +614,7 @@ module_vec_size (emacs_env *env, emacs_value vec)
/* FIXME: Return a sentinel value (e.g., -1) on error. */
MODULE_FUNCTION_BEGIN (0);
Lisp_Object lvec = value_to_lisp (vec);
- if (! VECTORP (lvec))
- {
- module_wrong_type (env, Qvectorp, lvec);
- return 0;
- }
+ CHECK_VECTOR (lvec);
return ASIZE (lvec);
}
@@ -828,14 +773,6 @@ module_non_local_exit_throw_1 (emacs_env *env, Lisp_Object tag,
}
}
-/* Module version of `wrong_type_argument'. */
-static void
-module_wrong_type (emacs_env *env, Lisp_Object predicate, Lisp_Object value)
-{
- module_non_local_exit_signal_1 (env, Qwrong_type_argument,
- list2 (predicate, value));
-}
-
/* Signal an out-of-memory condition to the caller. */
static void
module_out_of_memory (emacs_env *env)
@@ -846,13 +783,6 @@ module_out_of_memory (emacs_env *env)
XCDR (Vmemory_signal_data));
}
-/* Signal arguments are out of range. */
-static void
-module_args_out_of_range (emacs_env *env, Lisp_Object a1, Lisp_Object a2)
-{
- module_non_local_exit_signal_1 (env, Qargs_out_of_range, list2 (a1, a2));
-}
-
/* Value conversion. */
diff --git a/src/emacs-module.h b/src/emacs-module.h
index b4ae5ea7433..ae7311b05a7 100644
--- a/src/emacs-module.h
+++ b/src/emacs-module.h
@@ -41,7 +41,7 @@ typedef struct emacs_env_25 emacs_env;
BEWARE: Do not assume NULL is a valid value! */
typedef struct emacs_value_tag *emacs_value;
-enum emacs_arity { emacs_variadic_function = -2 };
+enum { emacs_variadic_function = -2 };
/* Struct passed to a module init function (emacs_module_init). */
struct emacs_runtime
@@ -57,13 +57,6 @@ struct emacs_runtime
};
-/* Function prototype for the module init function. */
-typedef int (*emacs_init_function) (struct emacs_runtime *ert);
-
-/* Function prototype for the module Lisp functions. */
-typedef emacs_value (*emacs_subr) (emacs_env *env, ptrdiff_t nargs,
- emacs_value args[], void *data);
-
/* Possible Emacs function call outcomes. */
enum emacs_funcall_exit
{
diff --git a/src/emacs.c b/src/emacs.c
index d1d649dfcfd..95d1905ae22 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -79,6 +79,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "composite.h"
#include "dispextern.h"
#include "regex.h"
+#include "sheap.h"
#include "syntax.h"
#include "sysselect.h"
#include "systime.h"
@@ -127,14 +128,15 @@ Lisp_Object Vlibrary_cache;
bool initialized;
/* Set to true if this instance of Emacs might dump. */
+#ifndef DOUG_LEA_MALLOC
+static
+#endif
bool might_dump;
#ifdef DARWIN_OS
extern void unexec_init_emacs_zone (void);
#endif
-extern void malloc_enable_thread (void);
-
/* If true, Emacs should not attempt to use a window-specific code,
but instead should use the virtual terminal under which it was started. */
bool inhibit_window_system;
@@ -179,6 +181,9 @@ bool noninteractive;
/* True means remove site-lisp directories from load-path. */
bool no_site_lisp;
+/* True means put details like time stamps into builds. */
+bool build_details;
+
/* Name for the server started by the daemon.*/
static char *daemon_name;
@@ -220,6 +225,7 @@ Initialization options:\n\
--display, -d DISPLAY use X server DISPLAY\n\
",
"\
+--no-build-details do not add build details such as time stamps\n\
--no-desktop do not load a saved desktop\n\
--no-init-file, -q load neither ~/.emacs nor default.el\n\
--no-loadup, -nl do not load loadup.el into bare Emacs\n\
@@ -352,17 +358,20 @@ terminate_due_to_signal (int sig, int backtrace_limit)
{
signal (sig, SIG_DFL);
- /* If fatal error occurs in code below, avoid infinite recursion. */
- if (! fatal_error_in_progress)
+ if (attempt_orderly_shutdown_on_fatal_signal)
{
- fatal_error_in_progress = 1;
+ /* If fatal error occurs in code below, avoid infinite recursion. */
+ if (! fatal_error_in_progress)
+ {
+ fatal_error_in_progress = 1;
- totally_unblock_input ();
- if (sig == SIGTERM || sig == SIGHUP || sig == SIGINT)
- Fkill_emacs (make_number (sig));
+ totally_unblock_input ();
+ if (sig == SIGTERM || sig == SIGHUP || sig == SIGINT)
+ Fkill_emacs (make_number (sig));
- shut_down_emacs (sig, Qnil);
- emacs_backtrace (backtrace_limit);
+ shut_down_emacs (sig, Qnil);
+ emacs_backtrace (backtrace_limit);
+ }
}
/* Signal the same code; this time it will really be fatal.
@@ -771,7 +780,7 @@ main (int argc, char **argv)
filename_from_ansi (ch_to_dir, newdir);
ch_to_dir = newdir;
#endif
- original_pwd = get_current_dir_name ();
+ original_pwd = emacs_get_current_dir_name ();
if (chdir (ch_to_dir) != 0)
{
fprintf (stderr, "%s: Can't chdir to %s: %s\n",
@@ -1184,6 +1193,9 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
no_site_lisp
= argmatch (argv, argc, "-nsl", "--no-site-lisp", 11, NULL, &skip_args);
+ build_details = ! argmatch (argv, argc, "-no-build-details",
+ "--no-build-details", 7, NULL, &skip_args);
+
#ifdef HAVE_NS
ns_pool = ns_alloc_autorelease_pool ();
#ifdef NS_IMPL_GNUSTEP
@@ -1633,6 +1645,7 @@ static const struct standard_args standard_args[] =
{ "-help", "--help", 90, 0 },
{ "-nl", "--no-loadup", 70, 0 },
{ "-nsl", "--no-site-lisp", 65, 0 },
+ { "-no-build-details", "--no-build-details", 63, 0 },
/* -d must come last before the options handled in startup.el. */
{ "-d", "--display", 60, 1 },
{ "-display", 0, 60, 1 },
@@ -2075,6 +2088,17 @@ You must run Emacs in batch mode in order to dump it. */)
tem = Vpurify_flag;
Vpurify_flag = Qnil;
+#ifdef HYBRID_MALLOC
+ {
+ static char const fmt[] = "%d of %d static heap bytes used";
+ char buf[sizeof fmt + 2 * (INT_STRLEN_BOUND (int) - 2)];
+ int max_usage = max_bss_sbrk_ptr - bss_sbrk_buffer;
+ sprintf (buf, fmt, max_usage, STATIC_HEAP_SIZE);
+ /* Don't log messages, because at this point buffers cannot be created. */
+ message1_nolog (buf);
+ }
+#endif
+
fflush (stdout);
/* Tell malloc where start of impure now is. */
/* Also arrange for warnings when nearly out of space. */
@@ -2395,8 +2419,8 @@ Special values:
`ms-dos' compiled as an MS-DOS application.
`windows-nt' compiled as a native W32 application.
`cygwin' compiled using the Cygwin library.
-Anything else (in Emacs 24.1, the possibilities are: aix, berkeley-unix,
-hpux, irix, usg-unix-v) indicates some sort of Unix system. */);
+Anything else (in Emacs 26, the possibilities are: aix, berkeley-unix,
+hpux, usg-unix-v) indicates some sort of Unix system. */);
Vsystem_type = intern_c_string (SYSTEM_TYPE);
/* See configure.ac for the possible SYSTEM_TYPEs. */
diff --git a/src/eval.c b/src/eval.c
index fe6460d53bb..74b30e66bce 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1751,9 +1751,9 @@ find_handler_clause (Lisp_Object handlers, Lisp_Object conditions)
}
-/* Dump an error message; called like vprintf. */
-void
-verror (const char *m, va_list ap)
+/* Format and return a string; called like vprintf. */
+Lisp_Object
+vformat_string (const char *m, va_list ap)
{
char buf[4000];
ptrdiff_t size = sizeof buf;
@@ -1767,7 +1767,14 @@ verror (const char *m, va_list ap)
if (buffer != buf)
xfree (buffer);
- xsignal1 (Qerror, string);
+ return string;
+}
+
+/* Dump an error message; called like vprintf. */
+void
+verror (const char *m, va_list ap)
+{
+ xsignal1 (Qerror, vformat_string (m, ap));
}
diff --git a/src/filelock.c b/src/filelock.c
index bc3a6209a8d..4c5d72ddb95 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -253,14 +253,7 @@ get_boot_time_1 (const char *filename, bool newest)
struct utmp ut, *utp;
if (filename)
- {
- /* On some versions of IRIX, opening a nonexistent file name
- is likely to crash in the utmp routines. */
- if (faccessat (AT_FDCWD, filename, R_OK, AT_EACCESS) != 0)
- return;
-
- utmpname (filename);
- }
+ utmpname (filename);
setutent ();
diff --git a/src/fns.c b/src/fns.c
index 47ed2d82207..0e3fc2765b4 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -21,8 +21,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include <unistd.h>
+#include <filevercmp.h>
#include <intprops.h>
#include <vla.h>
+#include <errno.h>
#include "lisp.h"
#include "character.h"
@@ -331,6 +333,50 @@ Symbols are also allowed; their print names are used instead. */)
return i1 < SCHARS (string2) ? Qt : Qnil;
}
+DEFUN ("string-version-lessp", Fstring_version_lessp,
+ Sstring_version_lessp, 2, 2, 0,
+ doc: /* Return non-nil if S1 is less than S2, as version strings.
+
+This function compares version strings S1 and S2:
+ 1) By prefix lexicographically.
+ 2) Then by version (similarly to version comparison of Debian's dpkg).
+ Leading zeros in version numbers are ignored.
+ 3) If both prefix and version are equal, compare as ordinary strings.
+
+For example, \"foo2.png\" compares less than \"foo12.png\".
+Case is significant.
+Symbols are also allowed; their print names are used instead. */)
+ (Lisp_Object string1, Lisp_Object string2)
+{
+ if (SYMBOLP (string1))
+ string1 = SYMBOL_NAME (string1);
+ if (SYMBOLP (string2))
+ string2 = SYMBOL_NAME (string2);
+ CHECK_STRING (string1);
+ CHECK_STRING (string2);
+
+ char *p1 = SSDATA (string1);
+ char *p2 = SSDATA (string2);
+ char *lim1 = p1 + SBYTES (string1);
+ char *lim2 = p2 + SBYTES (string2);
+ int cmp;
+
+ while ((cmp = filevercmp (p1, p2)) == 0)
+ {
+ /* If the strings are identical through their first null bytes,
+ skip past identical prefixes and try again. */
+ ptrdiff_t size = strlen (p1) + 1;
+ p1 += size;
+ p2 += size;
+ if (lim1 < p1)
+ return lim2 < p2 ? Qnil : Qt;
+ if (lim2 < p2)
+ return Qnil;
+ }
+
+ return cmp < 0 ? Qt : Qnil;
+}
+
DEFUN ("string-collate-lessp", Fstring_collate_lessp, Sstring_collate_lessp, 2, 4, 0,
doc: /* Return t if first arg string is less than second in collation order.
Symbols are also allowed; their print names are used instead.
@@ -1349,7 +1395,7 @@ The value is actually the tail of LIST whose car is ELT. */)
(register Lisp_Object elt, Lisp_Object list)
{
register Lisp_Object tail;
- for (tail = list; CONSP (tail); tail = XCDR (tail))
+ for (tail = list; !NILP (tail); tail = XCDR (tail))
{
register Lisp_Object tem;
CHECK_LIST_CONS (tail, list);
@@ -1397,7 +1443,7 @@ The value is actually the tail of LIST whose car is ELT. */)
if (!FLOATP (elt))
return Fmemq (elt, list);
- for (tail = list; CONSP (tail); tail = XCDR (tail))
+ for (tail = list; !NILP (tail); tail = XCDR (tail))
{
register Lisp_Object tem;
CHECK_LIST_CONS (tail, list);
@@ -1710,7 +1756,7 @@ changing the value of a sequence `foo'. */)
{
Lisp_Object tail, prev;
- for (tail = seq, prev = Qnil; CONSP (tail); tail = XCDR (tail))
+ for (tail = seq, prev = Qnil; !NILP (tail); tail = XCDR (tail))
{
CHECK_LIST_CONS (tail, seq);
@@ -5049,6 +5095,7 @@ this variable. */);
defsubr (&Sstring_equal);
defsubr (&Scompare_strings);
defsubr (&Sstring_lessp);
+ defsubr (&Sstring_version_lessp);
defsubr (&Sstring_collate_lessp);
defsubr (&Sstring_collate_equalp);
defsubr (&Sappend);
diff --git a/src/fontset.c b/src/fontset.c
index dc037a807cd..4ab13674318 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -63,17 +63,26 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
An element of a base fontset is a vector of FONT-DEFs which themselves
are vectors of the form [ FONT-SPEC ENCODING REPERTORY ].
- An element of a realized fontset is nil, t, 0, or a vector of this
- form:
+ An element of a realized fontset is nil, t, 0, or a cons that has
+ this from:
- [ PREFERRED-RFONT-DEF RFONT-DEF0 RFONT-DEF1 ... ]
+ (CHARSET-ORDERED-LIST-TICK . FONT-GROUP)
+
+ CHARSET_ORDERED_LIST_TICK is the same as charset_ordered_list_tick or -1.
+
+ FONT-GROUP is a vector of elements that have this form:
+
+ [ RFONT-DEF0 RFONT-DEF1 ... ]
Each RFONT-DEFn (i.e. Realized FONT-DEF) has this form:
[ FACE-ID FONT-DEF FONT-OBJECT SORTING-SCORE ]
- RFONT-DEFn are automatically reordered by the current charset
- priority list.
+ RFONT-DEFn are automatically reordered considering the current
+ charset priority list, the current language environment, and
+ priorities determined by font-backends.
+
+ RFONT-DEFn may not be a vector in the following cases.
The value nil means that we have not yet generated the above vector
from the base of the fontset.
@@ -83,7 +92,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
The value 0 means that no font is available for the corresponding
range of characters in this fontset, but may be available in the
- default fontset.
+ fallback font-group or in the default fontset.
A fontset has 8 extra slots.
@@ -407,6 +416,9 @@ reorder_font_vector (Lisp_Object font_group, struct font *font)
if (! NILP (encoding))
{
+ /* This spec specifies an encoding by a charset set
+ name. Reflect the preference order of that charset
+ in the upper bits of SCORE. */
Lisp_Object tail;
for (tail = Vcharset_ordered_list;
@@ -419,6 +431,10 @@ reorder_font_vector (Lisp_Object font_group, struct font *font)
}
else
{
+ /* This spec does not specify an encoding. If the spec
+ specifies a language, and the language is not for the
+ current language environment, make the score
+ larger. */
Lisp_Object lang = Ffont_get (font_spec, QClang);
if (! NILP (lang)
@@ -442,11 +458,11 @@ reorder_font_vector (Lisp_Object font_group, struct font *font)
XSETCAR (font_group, make_number (low_tick_bits));
}
-/* Return a font-group (actually a cons (-1 . FONT-GROUP-VECTOR)) for
- character C in FONTSET. If C is -1, return a fallback font-group.
- If C is not -1, the value may be Qt (FONTSET doesn't have a font
- for C even in the fallback group), or 0 (a font for C may be found
- only in the fallback group). */
+/* Return a font-group (actually a cons (CHARSET_ORDERED_LIST_TICK
+ . FONT-GROUP)) for character C or a fallback font-group in the
+ realized fontset FONTSET. The elements of FONT-GROUP are
+ RFONT-DEFs. The value may not be a cons. See the comment at the
+ head of this file for the detail of the return value. */
static Lisp_Object
fontset_get_font_group (Lisp_Object fontset, int c)
@@ -461,23 +477,37 @@ fontset_get_font_group (Lisp_Object fontset, int c)
else
font_group = FONTSET_FALLBACK (fontset);
if (! NILP (font_group))
+ /* We have already realized FONT-DEFs of this font group for C or
+ for fallback (FONT_GROUP is a cons), or we have already found
+ that no appropriate font was found (FONT_GROUP is t or 0). */
return font_group;
base_fontset = FONTSET_BASE (fontset);
if (NILP (base_fontset))
+ /* Actually we never come here because FONTSET is a realized one,
+ and thus it should have a base. */
font_group = Qnil;
else if (c >= 0)
font_group = char_table_ref_and_range (base_fontset, c, &from, &to);
else
font_group = FONTSET_FALLBACK (base_fontset);
+
+ /* FONT_GROUP not being a vector means that no fonts are specified
+ for C, or the fontset does not have fallback fonts. */
if (NILP (font_group))
{
font_group = make_number (0);
if (c >= 0)
+ /* Record that FONTSET does not specify fonts for C. As
+ there's a possibility that a font is found in a fallback
+ font group, we set 0 at the moment. */
char_table_set_range (fontset, from, to, font_group);
return font_group;
}
if (!VECTORP (font_group))
return font_group;
+
+ /* Now realize FONT-DEFs of this font group, and update the realized
+ fontset FONTSET. */
font_group = Fcopy_sequence (font_group);
for (i = 0; i < ASIZE (font_group); i++)
if (! NILP (AREF (font_group, i)))
@@ -498,21 +528,21 @@ fontset_get_font_group (Lisp_Object fontset, int c)
}
/* Return RFONT-DEF (vector) in the realized fontset FONTSET for the
- character C. If no font is found, return Qnil if there's a
+ character C. If no font is found, return Qnil or 0 if there's a
possibility that the default fontset or the fallback font groups
have a proper font, and return Qt if not.
If a font is found but is not yet opened, open it (if FACE is not
NULL) or return Qnil (if FACE is NULL).
- ID is a charset-id that must be preferred, or -1 meaning no
+ CHARSET_ID is a charset-id that must be preferred, or -1 meaning no
preference.
If FALLBACK, search only fallback fonts. */
static Lisp_Object
-fontset_find_font (Lisp_Object fontset, int c, struct face *face, int id,
- bool fallback)
+fontset_find_font (Lisp_Object fontset, int c, struct face *face,
+ int charset_id, bool fallback)
{
Lisp_Object vec, font_group;
int i, charset_matched = 0, found_index;
@@ -534,8 +564,8 @@ fontset_find_font (Lisp_Object fontset, int c, struct face *face, int id,
/* We have just created the font-group,
or the charset priorities were changed. */
reorder_font_vector (font_group, face->ascii_face->font);
- if (id >= 0)
- /* Find a spec matching with the charset ID to try at
+ if (charset_id >= 0)
+ /* Find a spec matching with CHARSET_ID to try it at
first. */
for (i = 0; i < ASIZE (vec); i++)
{
@@ -546,7 +576,7 @@ fontset_find_font (Lisp_Object fontset, int c, struct face *face, int id,
break;
repertory = FONT_DEF_REPERTORY (RFONT_DEF_FONT_DEF (rfont_def));
- if (XINT (repertory) == id)
+ if (XINT (repertory) == charset_id)
{
charset_matched = i;
break;
@@ -554,7 +584,9 @@ fontset_find_font (Lisp_Object fontset, int c, struct face *face, int id,
}
}
- /* Find the first available font in the vector of RFONT-DEF. */
+ /* Find the first available font in the vector of RFONT-DEF. If
+ CHARSET_MATCHED > 0, try the corresponding RFONT-DEF first, then
+ try the rest. */
for (i = 0; i < ASIZE (vec); i++)
{
Lisp_Object font_def;
@@ -565,13 +597,13 @@ fontset_find_font (Lisp_Object fontset, int c, struct face *face, int id,
{
if (charset_matched > 0)
{
- /* Try the element matching with the charset ID at first. */
+ /* Try the element matching with CHARSET_ID at first. */
found_index = charset_matched;
/* Make this negative so that we don't come here in the
next loop. */
charset_matched = - charset_matched;
/* We must try the first element in the next loop. */
- i--;
+ i = -1;
}
}
else if (i == - charset_matched)
@@ -630,10 +662,10 @@ fontset_find_font (Lisp_Object fontset, int c, struct face *face, int id,
if (NILP (font_object))
{
/* Something strange happened, perhaps because of a
- Font-backend problem. Too avoid crashing, record
+ Font-backend problem. To avoid crashing, record
that this spec is unusable. It may be better to find
another font of the same spec, but currently we don't
- have such an API. */
+ have such an API in font-backend. */
RFONT_DEF_SET_FACE (rfont_def, -1);
continue;
}
@@ -693,6 +725,7 @@ fontset_find_font (Lisp_Object fontset, int c, struct face *face, int id,
i = found_index;
}
+ /* Record that no font in this font group supports C. */
FONTSET_SET (fontset, make_number (c), make_number (0));
return Qnil;
@@ -711,6 +744,9 @@ fontset_find_font (Lisp_Object fontset, int c, struct face *face, int id,
}
+/* Return RFONT-DEF (vector) corresponding to the font for character
+ C. The value is not a vector if no font is found for C. */
+
static Lisp_Object
fontset_font (Lisp_Object fontset, int c, struct face *face, int id)
{
diff --git a/src/frame.c b/src/frame.c
index 7511d5323ca..a0aff88cd38 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -591,8 +591,6 @@ adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
|| new_pixel_height != old_pixel_height);
unblock_input ();
-
- run_window_configuration_change_hook (f);
}
/* Allocate basically initialized frame. */
@@ -5264,6 +5262,21 @@ The function `frame--size-history' displays the value of this variable
in a more readable form. */);
frame_size_history = Qnil;
+ DEFVAR_BOOL ("tooltip-reuse-hidden-frame", tooltip_reuse_hidden_frame,
+ doc: /* Non-nil means reuse hidden tooltip frames.
+When this is nil, delete a tooltip frame when hiding the associated
+tooltip. When this is non-nil, make the tooltip frame invisible only,
+so it can be reused when the next tooltip is shown.
+
+Setting this to non-nil may drastically reduce the consing overhead
+incurred by creating new tooltip frames. However, a value of non-nil
+means also that intermittent changes of faces or `default-frame-alist'
+are not applied when showing a tooltip in a reused frame.
+
+This variable is effective only with the X toolkit (and there only when
+Gtk+ tooltips are not used) and on Windows. */);
+ tooltip_reuse_hidden_frame = false;
+
staticpro (&Vframe_list);
defsubr (&Sframep);
diff --git a/src/frame.h b/src/frame.h
index f0cdcd42096..9de672c8635 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -288,8 +288,9 @@ struct frame
cleared. */
bool_bf explicit_name : 1;
- /* True if size of some window on this frame has changed. */
- bool_bf window_sizes_changed : 1;
+ /* True if configuration of windows on this frame has changed since
+ last call of run_window_size_change_functions. */
+ bool_bf window_configuration_changed : 1;
/* True if the mouse has moved on this display device
since the last time we checked. */
@@ -828,10 +829,10 @@ default_pixels_per_inch_y (void)
are frozen on frame F. */
#define FRAME_WINDOWS_FROZEN(f) (f)->frozen_window_starts
-/* True if a size change has been requested for frame F
- but not yet really put into effect. This can be true temporarily
- when an X event comes in at a bad time. */
-#define FRAME_WINDOW_SIZES_CHANGED(f) (f)->window_sizes_changed
+/* True if the frame's window configuration has changed since last call
+ of run_window_size_change_functions. */
+#define FRAME_WINDOW_CONFIGURATION_CHANGED(f) \
+ (f)->window_configuration_changed
/* The minibuffer window of frame F, if it has one; otherwise nil. */
#define FRAME_MINIBUF_WINDOW(f) f->minibuffer_window
diff --git a/src/gmalloc.c b/src/gmalloc.c
index 00b83641319..d795c13f616 100644
--- a/src/gmalloc.c
+++ b/src/gmalloc.c
@@ -25,14 +25,10 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#define USE_PTHREAD
#endif
+#include <stddef.h>
#include <string.h>
#include <limits.h>
#include <stdint.h>
-
-#ifdef HYBRID_GET_CURRENT_DIR_NAME
-#undef get_current_dir_name
-#endif
-
#include <unistd.h>
#ifdef USE_PTHREAD
@@ -44,7 +40,22 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#endif
#ifdef emacs
-extern void emacs_abort (void);
+# include "lisp.h"
+#endif
+
+#ifdef HAVE_MALLOC_H
+# if 4 < __GNUC__ + (2 <= __GNUC_MINOR__)
+# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+# endif
+# include <malloc.h>
+#endif
+#ifndef __MALLOC_HOOK_VOLATILE
+# define __MALLOC_HOOK_VOLATILE volatile
+#endif
+#ifndef HAVE_MALLOC_H
+extern void (*__MALLOC_HOOK_VOLATILE __after_morecore_hook) (void);
+extern void (*__MALLOC_HOOK_VOLATILE __malloc_initialize_hook) (void);
+extern void *(*__morecore) (ptrdiff_t);
#endif
/* If HYBRID_MALLOC is defined, then temacs will use malloc,
@@ -53,31 +64,27 @@ extern void emacs_abort (void);
however, will use the system malloc, realloc.... In other source
files, malloc, realloc... are renamed hybrid_malloc,
hybrid_realloc... via macros in conf_post.h. hybrid_malloc and
- friends are wrapper functions defined later in this file.
- aligned_alloc is defined as a macro only in alloc.c.
-
- As of this writing (August 2014), Cygwin is the only platform on
- which HYBRID_MACRO is defined. Any other platform that wants to
- define it will have to define the macros DUMPED and
- ALLOCATED_BEFORE_DUMPING, defined below for Cygwin. */
+ friends are wrapper functions defined later in this file. */
#undef malloc
#undef realloc
#undef calloc
+#undef aligned_alloc
#undef free
#define malloc gmalloc
#define realloc grealloc
#define calloc gcalloc
#define aligned_alloc galigned_alloc
#define free gfree
+#define malloc_info gmalloc_info
-#ifdef CYGWIN
-extern void *bss_sbrk (ptrdiff_t size);
-extern int bss_sbrk_did_unexec;
-extern char bss_sbrk_buffer[];
-extern void *bss_sbrk_buffer_end;
-#define DUMPED bss_sbrk_did_unexec
-#define ALLOCATED_BEFORE_DUMPING(P) \
- ((P) < bss_sbrk_buffer_end && (P) >= (void *) bss_sbrk_buffer)
+#ifdef HYBRID_MALLOC
+# include "sheap.h"
+# define DUMPED bss_sbrk_did_unexec
+static bool
+ALLOCATED_BEFORE_DUMPING (char *p)
+{
+ return bss_sbrk_buffer <= p && p < bss_sbrk_buffer + STATIC_HEAP_SIZE;
+}
#endif
#ifdef __cplusplus
@@ -85,8 +92,9 @@ extern "C"
{
#endif
-#include <stddef.h>
-
+#ifdef HYBRID_MALLOC
+#define extern static
+#endif
/* Allocate SIZE bytes of memory. */
extern void *malloc (size_t size) ATTRIBUTE_MALLOC_SIZE ((1));
@@ -95,25 +103,16 @@ extern void *malloc (size_t size) ATTRIBUTE_MALLOC_SIZE ((1));
extern void *realloc (void *ptr, size_t size) ATTRIBUTE_ALLOC_SIZE ((2));
/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
extern void *calloc (size_t nmemb, size_t size) ATTRIBUTE_MALLOC_SIZE ((1,2));
-/* Free a block allocated by `malloc', `realloc' or `calloc'. */
+/* Free a block. */
extern void free (void *ptr);
/* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
-#ifdef MSDOS
extern void *aligned_alloc (size_t, size_t);
+#ifdef MSDOS
extern void *memalign (size_t, size_t);
extern int posix_memalign (void **, size_t, size_t);
#endif
-#ifdef USE_PTHREAD
-/* Set up mutexes and make malloc etc. thread-safe. */
-extern void malloc_enable_thread (void);
-#endif
-
-#ifdef emacs
-extern void emacs_abort (void);
-#endif
-
/* The allocator divides the heap into blocks of fixed size; large
requests receive one or more whole blocks, and small requests
receive a fragment of a block. Fragment sizes are powers of two,
@@ -245,36 +244,12 @@ extern int _malloc_thread_enabled_p;
#define UNLOCK_ALIGNED_BLOCKS()
#endif
-/* Given an address in the middle of a malloc'd object,
- return the address of the beginning of the object. */
-extern void *malloc_find_object_address (void *ptr);
-
-/* Underlying allocation function; successive calls should
- return contiguous pieces of memory. */
-extern void *(*__morecore) (ptrdiff_t size);
-
-/* Default value of `__morecore'. */
-extern void *__default_morecore (ptrdiff_t size);
-
-/* If not NULL, this function is called after each time
- `__morecore' is called to increase the data size. */
-extern void (*__after_morecore_hook) (void);
-
-/* Number of extra blocks to get each time we ask for more core.
- This reduces the frequency of calling `(*__morecore)'. */
-extern size_t __malloc_extra_blocks;
-
/* Nonzero if `malloc' has been called and done its initialization. */
extern int __malloc_initialized;
/* Function called to initialize malloc data structures. */
extern int __malloc_initialize (void);
-/* Hooks for debugging versions. */
-extern void (*__malloc_initialize_hook) (void);
-extern void (*__free_hook) (void *ptr);
-extern void *(*__malloc_hook) (size_t size);
-extern void *(*__realloc_hook) (void *ptr, size_t size);
-extern void *(*__memalign_hook) (size_t size, size_t alignment);
+#ifdef GC_MCHECK
/* Return values for `mprobe': these are the kinds of inconsistencies that
`mcheck' enables detection of. */
@@ -315,8 +290,9 @@ struct mstats
/* Pick up the current statistics. */
extern struct mstats mstats (void);
-/* Call WARNFUN with a warning message when memory usage is high. */
-extern void memory_warnings (void *start, void (*warnfun) (const char *));
+#endif
+
+#undef extern
#ifdef __cplusplus
}
@@ -344,10 +320,17 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include <errno.h>
-void *(*__morecore) (ptrdiff_t size) = __default_morecore;
+/* Debugging hook for 'malloc'. */
+static void *(*__MALLOC_HOOK_VOLATILE gmalloc_hook) (size_t);
-/* Debugging hook for `malloc'. */
-void *(*__malloc_hook) (size_t size);
+/* Replacements for traditional glibc malloc hooks, for platforms that
+ do not already have these hooks. Platforms with these hooks all
+ used relaxed ref/def, so it is OK to define them here too. */
+void (*__MALLOC_HOOK_VOLATILE __malloc_initialize_hook) (void);
+void (*__MALLOC_HOOK_VOLATILE __after_morecore_hook) (void);
+void *(*__morecore) (ptrdiff_t);
+
+#ifndef HYBRID_MALLOC
/* Pointer to the base of the first block. */
char *_heapbase;
@@ -355,9 +338,6 @@ char *_heapbase;
/* Block information table. Allocated with align/__free (not malloc/free). */
malloc_info *_heapinfo;
-/* Number of info entries. */
-static size_t heapsize;
-
/* Search index in the info table. */
size_t _heapindex;
@@ -376,10 +356,21 @@ size_t _bytes_free;
/* Are you experienced? */
int __malloc_initialized;
+#else
+
+static struct list _fraghead[BLOCKLOG];
+
+#endif /* HYBRID_MALLOC */
+
+/* Number of extra blocks to get each time we ask for more core.
+ This reduces the frequency of calling `(*__morecore)'. */
+#if defined DOUG_LEA_MALLOC || defined HYBRID_MALLOC || defined SYSTEM_MALLOC
+static
+#endif
size_t __malloc_extra_blocks;
-void (*__malloc_initialize_hook) (void);
-void (*__after_morecore_hook) (void);
+/* Number of info entries. */
+static size_t heapsize;
#if defined GC_MALLOC_CHECK && defined GC_PROTECT_MALLOC_STATE
@@ -934,19 +925,19 @@ malloc (size_t size)
if (!__malloc_initialized && !__malloc_initialize ())
return NULL;
- /* Copy the value of __malloc_hook to an automatic variable in case
- __malloc_hook is modified in another thread between its
+ /* Copy the value of gmalloc_hook to an automatic variable in case
+ gmalloc_hook is modified in another thread between its
NULL-check and the use.
Note: Strictly speaking, this is not a right solution. We should
use mutexes to access non-read-only variables that are shared
among multiple threads. We just leave it for compatibility with
- glibc malloc (i.e., assignments to __malloc_hook) for now. */
- hook = __malloc_hook;
+ glibc malloc (i.e., assignments to gmalloc_hook) for now. */
+ hook = gmalloc_hook;
return (hook != NULL ? *hook : _malloc_internal) (size);
}
-#ifndef _LIBC
+#if !(defined (_LIBC) || defined (HYBRID_MALLOC))
/* On some ANSI C systems, some libc functions call _malloc, _free
and _realloc. Make them use the GNU functions. */
@@ -994,12 +985,14 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
The author may be reached (Email) at the address mike@ai.mit.edu,
or (US mail) as Mike Haertel c/o Free Software Foundation. */
-
/* Debugging hook for free. */
-void (*__free_hook) (void *__ptr);
+static void (*__MALLOC_HOOK_VOLATILE gfree_hook) (void *);
+
+#ifndef HYBRID_MALLOC
/* List of blocks allocated by aligned_alloc. */
struct alignlist *_aligned_blocks = NULL;
+#endif
/* Return memory to the heap.
Like `_free_internal' but don't lock mutex. */
@@ -1248,7 +1241,7 @@ _free_internal_nolock (void *ptr)
}
/* Return memory to the heap.
- Like `free' but don't call a __free_hook if there is one. */
+ Like 'free' but don't call a hook if there is one. */
void
_free_internal (void *ptr)
{
@@ -1262,7 +1255,7 @@ _free_internal (void *ptr)
void
free (void *ptr)
{
- void (*hook) (void *) = __free_hook;
+ void (*hook) (void *) = gfree_hook;
if (hook != NULL)
(*hook) (ptr);
@@ -1270,6 +1263,7 @@ free (void *ptr)
_free_internal (ptr);
}
+#ifndef HYBRID_MALLOC
/* Define the `cfree' alias for `free'. */
#ifdef weak_alias
weak_alias (free, cfree)
@@ -1280,6 +1274,7 @@ cfree (void *ptr)
free (ptr);
}
#endif
+#endif
/* Change the size of a block allocated by `malloc'.
Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
Written May 1989 by Mike Haertel.
@@ -1305,7 +1300,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#endif
/* Debugging hook for realloc. */
-void *(*__realloc_hook) (void *ptr, size_t size);
+static void *(*grealloc_hook) (void *, size_t);
/* Resize the given region to the new size, returning a pointer
to the (possibly moved) region. This is optimized for speed;
@@ -1449,7 +1444,7 @@ realloc (void *ptr, size_t size)
if (!__malloc_initialized && !__malloc_initialize ())
return NULL;
- hook = __realloc_hook;
+ hook = grealloc_hook;
return (hook != NULL ? *hook : _realloc_internal) (ptr, size);
}
/* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc.
@@ -1519,11 +1514,11 @@ extern void *__sbrk (ptrdiff_t increment);
/* Allocate INCREMENT more bytes of data space,
and return the start of data space, or NULL on errors.
If INCREMENT is negative, shrink data space. */
-void *
-__default_morecore (ptrdiff_t increment)
+static void *
+gdefault_morecore (ptrdiff_t increment)
{
void *result;
-#if defined (CYGWIN)
+#ifdef HYBRID_MALLOC
if (!DUMPED)
{
return bss_sbrk (increment);
@@ -1534,6 +1529,9 @@ __default_morecore (ptrdiff_t increment)
return NULL;
return result;
}
+
+void *(*__morecore) (ptrdiff_t) = gdefault_morecore;
+
/* Copyright (C) 1991, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
@@ -1549,17 +1547,11 @@ General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>. */
-void *(*__memalign_hook) (size_t size, size_t alignment);
-
void *
aligned_alloc (size_t alignment, size_t size)
{
void *result;
size_t adj, lastadj;
- void *(*hook) (size_t, size_t) = __memalign_hook;
-
- if (hook)
- return (*hook) (alignment, size);
/* Allocate a block with enough extra space to pad the block with up to
(ALIGNMENT - 1) bytes if necessary. */
@@ -1638,6 +1630,8 @@ aligned_alloc (size_t alignment, size_t size)
return result;
}
+/* Note that memalign and posix_memalign are not used in Emacs. */
+#ifndef HYBRID_MALLOC
/* An obsolete alias for aligned_alloc, for any old libraries that use
this alias. */
@@ -1649,7 +1643,6 @@ memalign (size_t alignment, size_t size)
/* If HYBRID_MALLOC is defined, we may want to use the system
posix_memalign below. */
-#ifndef HYBRID_MALLOC
int
posix_memalign (void **memptr, size_t alignment, size_t size)
{
@@ -1689,14 +1682,18 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
The author may be reached (Email) at the address mike@ai.mit.edu,
or (US mail) as Mike Haertel c/o Free Software Foundation. */
+#ifndef HYBRID_MALLOC
+
+# ifndef HAVE_MALLOC_H
/* Allocate SIZE bytes on a page boundary. */
extern void *valloc (size_t);
+# endif
-#if defined _SC_PAGESIZE || !defined HAVE_GETPAGESIZE
-# include "getpagesize.h"
-#elif !defined getpagesize
+# if defined _SC_PAGESIZE || !defined HAVE_GETPAGESIZE
+# include "getpagesize.h"
+# elif !defined getpagesize
extern int getpagesize (void);
-#endif
+# endif
static size_t pagesize;
@@ -1708,6 +1705,7 @@ valloc (size_t size)
return aligned_alloc (pagesize, size);
}
+#endif /* HYBRID_MALLOC */
#undef malloc
#undef realloc
@@ -1773,7 +1771,7 @@ hybrid_aligned_alloc (size_t alignment, size_t size)
#endif
}
#endif
-
+
void *
hybrid_realloc (void *ptr, size_t size)
{
@@ -1801,19 +1799,6 @@ hybrid_realloc (void *ptr, size_t size)
return result;
}
-#ifdef HYBRID_GET_CURRENT_DIR_NAME
-/* Defined in sysdep.c. */
-char *gget_current_dir_name (void);
-
-char *
-hybrid_get_current_dir_name (void)
-{
- if (DUMPED)
- return get_current_dir_name ();
- return gget_current_dir_name ();
-}
-#endif
-
#else /* ! HYBRID_MALLOC */
void *
@@ -1948,9 +1933,9 @@ freehook (void *ptr)
else
hdr = NULL;
- __free_hook = old_free_hook;
+ gfree_hook = old_free_hook;
free (hdr);
- __free_hook = freehook;
+ gfree_hook = freehook;
}
static void *
@@ -1958,9 +1943,9 @@ mallochook (size_t size)
{
struct hdr *hdr;
- __malloc_hook = old_malloc_hook;
+ gmalloc_hook = old_malloc_hook;
hdr = malloc (sizeof *hdr + size + 1);
- __malloc_hook = mallochook;
+ gmalloc_hook = mallochook;
if (hdr == NULL)
return NULL;
@@ -1986,13 +1971,13 @@ reallochook (void *ptr, size_t size)
memset ((char *) ptr + size, FREEFLOOD, osize - size);
}
- __free_hook = old_free_hook;
- __malloc_hook = old_malloc_hook;
- __realloc_hook = old_realloc_hook;
+ gfree_hook = old_free_hook;
+ gmalloc_hook = old_malloc_hook;
+ grealloc_hook = old_realloc_hook;
hdr = realloc (hdr, sizeof *hdr + size + 1);
- __free_hook = freehook;
- __malloc_hook = mallochook;
- __realloc_hook = reallochook;
+ gfree_hook = freehook;
+ gmalloc_hook = mallochook;
+ grealloc_hook = reallochook;
if (hdr == NULL)
return NULL;
@@ -2049,12 +2034,12 @@ mcheck (void (*func) (enum mcheck_status))
/* These hooks may not be safely inserted if malloc is already in use. */
if (!__malloc_initialized && !mcheck_used)
{
- old_free_hook = __free_hook;
- __free_hook = freehook;
- old_malloc_hook = __malloc_hook;
- __malloc_hook = mallochook;
- old_realloc_hook = __realloc_hook;
- __realloc_hook = reallochook;
+ old_free_hook = gfree_hook;
+ gfree_hook = freehook;
+ old_malloc_hook = gmalloc_hook;
+ gmalloc_hook = mallochook;
+ old_realloc_hook = grealloc_hook;
+ grealloc_hook = reallochook;
mcheck_used = 1;
}
diff --git a/src/gnutls.c b/src/gnutls.c
index f0354d7fedf..63785fea07d 100644
--- a/src/gnutls.c
+++ b/src/gnutls.c
@@ -397,11 +397,47 @@ gnutls_log_function2i (int level, const char *string, int extra)
message ("gnutls.c: [%d] %s %d", level, string, extra);
}
+int
+gnutls_try_handshake (struct Lisp_Process *proc)
+{
+ gnutls_session_t state = proc->gnutls_state;
+ int ret;
+ bool non_blocking = proc->is_non_blocking_client;
+
+ if (proc->gnutls_complete_negotiation_p)
+ non_blocking = false;
+
+ if (non_blocking)
+ proc->gnutls_p = true;
+
+ do
+ {
+ ret = gnutls_handshake (state);
+ emacs_gnutls_handle_error (state, ret);
+ QUIT;
+ }
+ while (ret < 0
+ && gnutls_error_is_fatal (ret) == 0
+ && ! non_blocking);
+
+ proc->gnutls_initstage = GNUTLS_STAGE_HANDSHAKE_TRIED;
+
+ if (ret == GNUTLS_E_SUCCESS)
+ {
+ /* Here we're finally done. */
+ proc->gnutls_initstage = GNUTLS_STAGE_READY;
+ }
+ else
+ {
+ /* check_memory_full (gnutls_alert_send_appropriate (state, ret)); */
+ }
+ return ret;
+}
+
static int
emacs_gnutls_handshake (struct Lisp_Process *proc)
{
gnutls_session_t state = proc->gnutls_state;
- int ret;
if (proc->gnutls_initstage < GNUTLS_STAGE_HANDSHAKE_CANDO)
return -1;
@@ -443,26 +479,7 @@ emacs_gnutls_handshake (struct Lisp_Process *proc)
proc->gnutls_initstage = GNUTLS_STAGE_TRANSPORT_POINTERS_SET;
}
- do
- {
- ret = gnutls_handshake (state);
- emacs_gnutls_handle_error (state, ret);
- QUIT;
- }
- while (ret < 0 && gnutls_error_is_fatal (ret) == 0);
-
- proc->gnutls_initstage = GNUTLS_STAGE_HANDSHAKE_TRIED;
-
- if (ret == GNUTLS_E_SUCCESS)
- {
- /* Here we're finally done. */
- proc->gnutls_initstage = GNUTLS_STAGE_READY;
- }
- else
- {
- check_memory_full (gnutls_alert_send_appropriate (state, ret));
- }
- return ret;
+ return gnutls_try_handshake (proc);
}
ptrdiff_t
@@ -528,26 +545,12 @@ emacs_gnutls_read (struct Lisp_Process *proc, char *buf, ptrdiff_t nbyte)
ssize_t rtnval;
gnutls_session_t state = proc->gnutls_state;
- int log_level = proc->gnutls_log_level;
-
if (proc->gnutls_initstage != GNUTLS_STAGE_READY)
{
- /* If the handshake count is under the limit, try the handshake
- again and increment the handshake count. This count is kept
- per process (connection), not globally. */
- if (proc->gnutls_handshakes_tried < GNUTLS_EMACS_HANDSHAKES_LIMIT)
- {
- proc->gnutls_handshakes_tried++;
- emacs_gnutls_handshake (proc);
- GNUTLS_LOG2i (5, log_level, "Retried handshake",
- proc->gnutls_handshakes_tried);
- return -1;
- }
-
- GNUTLS_LOG (2, log_level, "Giving up on handshake; resetting retries");
- proc->gnutls_handshakes_tried = 0;
- return 0;
+ errno = EAGAIN;
+ return -1;
}
+
rtnval = gnutls_record_recv (state, buf, nbyte);
if (rtnval >= 0)
return rtnval;
@@ -655,7 +658,7 @@ emacs_gnutls_deinit (Lisp_Object proc)
CHECK_PROCESS (proc);
- if (XPROCESS (proc)->gnutls_p == 0)
+ if (! XPROCESS (proc)->gnutls_p)
return Qnil;
log_level = XPROCESS (proc)->gnutls_log_level;
@@ -682,10 +685,23 @@ emacs_gnutls_deinit (Lisp_Object proc)
GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_INIT - 1;
}
- XPROCESS (proc)->gnutls_p = 0;
+ XPROCESS (proc)->gnutls_p = false;
return Qt;
}
+DEFUN ("gnutls-asynchronous-parameters", Fgnutls_asynchronous_parameters,
+ Sgnutls_asynchronous_parameters, 2, 2, 0,
+ doc: /* Mark this process as being a pre-init GnuTLS process.
+The second parameter is the list of parameters to feed to gnutls-boot
+to finish setting up the connection. */)
+ (Lisp_Object proc, Lisp_Object params)
+{
+ CHECK_PROCESS (proc);
+
+ XPROCESS (proc)->gnutls_boot_parameters = params;
+ return Qnil;
+}
+
DEFUN ("gnutls-get-initstage", Fgnutls_get_initstage, Sgnutls_get_initstage, 1, 1, 0,
doc: /* Return the GnuTLS init stage of process PROC.
See also `gnutls-boot'. */)
@@ -703,7 +719,9 @@ usage: (gnutls-errorp ERROR) */
attributes: const)
(Lisp_Object err)
{
- if (EQ (err, Qt)) return Qnil;
+ if (EQ (err, Qt)
+ || EQ (err, Qgnutls_e_again))
+ return Qnil;
return Qt;
}
@@ -1022,7 +1040,7 @@ The return value is a property list with top-level keys :warnings and
CHECK_PROCESS (proc);
- if (GNUTLS_INITSTAGE (proc) < GNUTLS_STAGE_INIT)
+ if (GNUTLS_INITSTAGE (proc) != GNUTLS_STAGE_READY)
return Qnil;
/* Then collect any warnings already computed by the handshake. */
@@ -1154,6 +1172,159 @@ emacs_gnutls_global_deinit (void)
}
#endif
+static void ATTRIBUTE_FORMAT_PRINTF (2, 3)
+boot_error (struct Lisp_Process *p, const char *m, ...)
+{
+ va_list ap;
+ va_start (ap, m);
+ if (p->is_non_blocking_client)
+ pset_status (p, list2 (Qfailed, vformat_string (m, ap)));
+ else
+ verror (m, ap);
+}
+
+Lisp_Object
+gnutls_verify_boot (Lisp_Object proc, Lisp_Object proplist)
+{
+ int ret;
+ struct Lisp_Process *p = XPROCESS (proc);
+ gnutls_session_t state = p->gnutls_state;
+ unsigned int peer_verification;
+ Lisp_Object warnings;
+ int max_log_level = p->gnutls_log_level;
+ Lisp_Object hostname, verify_error;
+ bool verify_error_all = false;
+ char *c_hostname;
+
+ if (NILP (proplist))
+ proplist = Fcdr (Fplist_get (p->childp, QCtls_parameters));
+
+ verify_error = Fplist_get (proplist, QCgnutls_bootprop_verify_error);
+ hostname = Fplist_get (proplist, QCgnutls_bootprop_hostname);
+
+ if (EQ (verify_error, Qt))
+ verify_error_all = true;
+ else if (NILP (Flistp (verify_error)))
+ {
+ boot_error (p,
+ "gnutls-boot: invalid :verify_error parameter (not a list)");
+ return Qnil;
+ }
+
+ if (!STRINGP (hostname))
+ {
+ boot_error (p, "gnutls-boot: invalid :hostname parameter (not a string)");
+ return Qnil;
+ }
+ c_hostname = SSDATA (hostname);
+
+ /* Now verify the peer, following
+ http://www.gnu.org/software/gnutls/manual/html_node/Verifying-peer_0027s-certificate.html.
+ The peer should present at least one certificate in the chain; do a
+ check of the certificate's hostname with
+ gnutls_x509_crt_check_hostname against :hostname. */
+
+ ret = gnutls_certificate_verify_peers2 (state, &peer_verification);
+ if (ret < GNUTLS_E_SUCCESS)
+ return gnutls_make_error (ret);
+
+ XPROCESS (proc)->gnutls_peer_verification = peer_verification;
+
+ warnings = Fplist_get (Fgnutls_peer_status (proc), intern (":warnings"));
+ if (!NILP (warnings))
+ {
+ for (Lisp_Object tail = warnings; CONSP (tail); tail = XCDR (tail))
+ {
+ Lisp_Object warning = XCAR (tail);
+ Lisp_Object message = Fgnutls_peer_status_warning_describe (warning);
+ if (!NILP (message))
+ GNUTLS_LOG2 (1, max_log_level, "verification:", SSDATA (message));
+ }
+ }
+
+ if (peer_verification != 0)
+ {
+ if (verify_error_all
+ || !NILP (Fmember (QCgnutls_bootprop_trustfiles, verify_error)))
+ {
+ emacs_gnutls_deinit (proc);
+ boot_error (p,
+ "Certificate validation failed %s, verification code %x",
+ c_hostname, peer_verification);
+ return Qnil;
+ }
+ else
+ {
+ GNUTLS_LOG2 (1, max_log_level, "certificate validation failed:",
+ c_hostname);
+ }
+ }
+
+ /* Up to here the process is the same for X.509 certificates and
+ OpenPGP keys. From now on X.509 certificates are assumed. This
+ can be easily extended to work with openpgp keys as well. */
+ if (gnutls_certificate_type_get (state) == GNUTLS_CRT_X509)
+ {
+ gnutls_x509_crt_t gnutls_verify_cert;
+ const gnutls_datum_t *gnutls_verify_cert_list;
+ unsigned int gnutls_verify_cert_list_size;
+
+ ret = gnutls_x509_crt_init (&gnutls_verify_cert);
+ if (ret < GNUTLS_E_SUCCESS)
+ return gnutls_make_error (ret);
+
+ gnutls_verify_cert_list
+ = gnutls_certificate_get_peers (state, &gnutls_verify_cert_list_size);
+
+ if (gnutls_verify_cert_list == NULL)
+ {
+ gnutls_x509_crt_deinit (gnutls_verify_cert);
+ emacs_gnutls_deinit (proc);
+ boot_error (p, "No x509 certificate was found\n");
+ return Qnil;
+ }
+
+ /* Check only the first certificate in the given chain. */
+ ret = gnutls_x509_crt_import (gnutls_verify_cert,
+ &gnutls_verify_cert_list[0],
+ GNUTLS_X509_FMT_DER);
+
+ if (ret < GNUTLS_E_SUCCESS)
+ {
+ gnutls_x509_crt_deinit (gnutls_verify_cert);
+ return gnutls_make_error (ret);
+ }
+
+ XPROCESS (proc)->gnutls_certificate = gnutls_verify_cert;
+
+ int err = gnutls_x509_crt_check_hostname (gnutls_verify_cert,
+ c_hostname);
+ check_memory_full (err);
+ if (!err)
+ {
+ XPROCESS (proc)->gnutls_extra_peer_verification
+ |= CERTIFICATE_NOT_MATCHING;
+ if (verify_error_all
+ || !NILP (Fmember (QCgnutls_bootprop_hostname, verify_error)))
+ {
+ gnutls_x509_crt_deinit (gnutls_verify_cert);
+ emacs_gnutls_deinit (proc);
+ boot_error (p, "The x509 certificate does not match \"%s\"",
+ c_hostname);
+ return Qnil;
+ }
+ else
+ GNUTLS_LOG2 (1, max_log_level, "x509 certificate does not match:",
+ c_hostname);
+ }
+ }
+
+ /* Set this flag only if the whole initialization succeeded. */
+ XPROCESS (proc)->gnutls_p = true;
+
+ return gnutls_make_error (ret);
+}
+
DEFUN ("gnutls-boot", Fgnutls_boot, Sgnutls_boot, 3, 3, 0,
doc: /* Initialize GnuTLS client for process PROC with TYPE+PROPLIST.
Currently only client mode is supported. Return a success/failure
@@ -1190,6 +1361,9 @@ t to do all checks. Currently it can contain `:trustfiles' and
:min-prime-bits is the minimum accepted number of bits the client will
accept in Diffie-Hellman key exchange.
+:complete-negotiation, if non-nil, will make negotiation complete
+before returning even on non-blocking sockets.
+
The debug level will be set for this process AND globally for GnuTLS.
So if you set it higher or lower at any point, it affects global
debugging.
@@ -1212,14 +1386,12 @@ one trustfile (usually a CA bundle). */)
{
int ret = GNUTLS_E_SUCCESS;
int max_log_level = 0;
- bool verify_error_all = 0;
gnutls_session_t state;
gnutls_certificate_credentials_t x509_cred = NULL;
gnutls_anon_client_credentials_t anon_cred = NULL;
Lisp_Object global_init;
char const *priority_string_ptr = "NORMAL"; /* default priority string. */
- unsigned int peer_verification;
char *c_hostname;
/* Placeholders for the property list elements. */
@@ -1230,19 +1402,24 @@ one trustfile (usually a CA bundle). */)
/* Lisp_Object callbacks; */
Lisp_Object loglevel;
Lisp_Object hostname;
- Lisp_Object verify_error;
Lisp_Object prime_bits;
- Lisp_Object warnings;
+ struct Lisp_Process *p = XPROCESS (proc);
CHECK_PROCESS (proc);
CHECK_SYMBOL (type);
CHECK_LIST (proplist);
if (NILP (Fgnutls_available_p ()))
- error ("GnuTLS not available");
+ {
+ boot_error (p, "GnuTLS not available");
+ return Qnil;
+ }
if (!EQ (type, Qgnutls_x509pki) && !EQ (type, Qgnutls_anon))
- error ("Invalid GnuTLS credential type");
+ {
+ boot_error (p, "Invalid GnuTLS credential type");
+ return Qnil;
+ }
hostname = Fplist_get (proplist, QCgnutls_bootprop_hostname);
priority_string = Fplist_get (proplist, QCgnutls_bootprop_priority);
@@ -1250,20 +1427,13 @@ one trustfile (usually a CA bundle). */)
keylist = Fplist_get (proplist, QCgnutls_bootprop_keylist);
crlfiles = Fplist_get (proplist, QCgnutls_bootprop_crlfiles);
loglevel = Fplist_get (proplist, QCgnutls_bootprop_loglevel);
- verify_error = Fplist_get (proplist, QCgnutls_bootprop_verify_error);
prime_bits = Fplist_get (proplist, QCgnutls_bootprop_min_prime_bits);
- if (EQ (verify_error, Qt))
- {
- verify_error_all = 1;
- }
- else if (NILP (Flistp (verify_error)))
+ if (!STRINGP (hostname))
{
- error ("gnutls-boot: invalid :verify_error parameter (not a list)");
+ boot_error (p, "gnutls-boot: invalid :hostname parameter (not a string)");
+ return Qnil;
}
-
- if (!STRINGP (hostname))
- error ("gnutls-boot: invalid :hostname parameter (not a string)");
c_hostname = SSDATA (hostname);
state = XPROCESS (proc)->gnutls_state;
@@ -1371,7 +1541,8 @@ one trustfile (usually a CA bundle). */)
else
{
emacs_gnutls_deinit (proc);
- error ("Invalid trustfile");
+ boot_error (p, "Invalid trustfile");
+ return Qnil;
}
}
@@ -1395,7 +1566,8 @@ one trustfile (usually a CA bundle). */)
else
{
emacs_gnutls_deinit (proc);
- error ("Invalid CRL file");
+ boot_error (p, "Invalid CRL file");
+ return Qnil;
}
}
@@ -1424,8 +1596,9 @@ one trustfile (usually a CA bundle). */)
else
{
emacs_gnutls_deinit (proc);
- error (STRINGP (keyfile) ? "Invalid client cert file"
- : "Invalid client key file");
+ boot_error (p, STRINGP (keyfile) ? "Invalid client cert file"
+ : "Invalid client key file");
+ return Qnil;
}
}
}
@@ -1479,114 +1652,14 @@ one trustfile (usually a CA bundle). */)
return gnutls_make_error (ret);
}
+ XPROCESS (proc)->gnutls_complete_negotiation_p =
+ !NILP (Fplist_get (proplist, QCgnutls_complete_negotiation));
GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_CRED_SET;
ret = emacs_gnutls_handshake (XPROCESS (proc));
if (ret < GNUTLS_E_SUCCESS)
return gnutls_make_error (ret);
- /* Now verify the peer, following
- http://www.gnu.org/software/gnutls/manual/html_node/Verifying-peer_0027s-certificate.html.
- The peer should present at least one certificate in the chain; do a
- check of the certificate's hostname with
- gnutls_x509_crt_check_hostname against :hostname. */
-
- ret = gnutls_certificate_verify_peers2 (state, &peer_verification);
- if (ret < GNUTLS_E_SUCCESS)
- return gnutls_make_error (ret);
-
- XPROCESS (proc)->gnutls_peer_verification = peer_verification;
-
- warnings = Fplist_get (Fgnutls_peer_status (proc), intern (":warnings"));
- if (!NILP (warnings))
- {
- Lisp_Object tail;
- for (tail = warnings; CONSP (tail); tail = XCDR (tail))
- {
- Lisp_Object warning = XCAR (tail);
- Lisp_Object message = Fgnutls_peer_status_warning_describe (warning);
- if (!NILP (message))
- GNUTLS_LOG2 (1, max_log_level, "verification:", SSDATA (message));
- }
- }
-
- if (peer_verification != 0)
- {
- if (verify_error_all
- || !NILP (Fmember (QCgnutls_bootprop_trustfiles, verify_error)))
- {
- emacs_gnutls_deinit (proc);
- error ("Certificate validation failed %s, verification code %x",
- c_hostname, peer_verification);
- }
- else
- {
- GNUTLS_LOG2 (1, max_log_level, "certificate validation failed:",
- c_hostname);
- }
- }
-
- /* Up to here the process is the same for X.509 certificates and
- OpenPGP keys. From now on X.509 certificates are assumed. This
- can be easily extended to work with openpgp keys as well. */
- if (gnutls_certificate_type_get (state) == GNUTLS_CRT_X509)
- {
- gnutls_x509_crt_t gnutls_verify_cert;
- const gnutls_datum_t *gnutls_verify_cert_list;
- unsigned int gnutls_verify_cert_list_size;
-
- ret = gnutls_x509_crt_init (&gnutls_verify_cert);
- if (ret < GNUTLS_E_SUCCESS)
- return gnutls_make_error (ret);
-
- gnutls_verify_cert_list =
- gnutls_certificate_get_peers (state, &gnutls_verify_cert_list_size);
-
- if (gnutls_verify_cert_list == NULL)
- {
- gnutls_x509_crt_deinit (gnutls_verify_cert);
- emacs_gnutls_deinit (proc);
- error ("No x509 certificate was found\n");
- }
-
- /* We only check the first certificate in the given chain. */
- ret = gnutls_x509_crt_import (gnutls_verify_cert,
- &gnutls_verify_cert_list[0],
- GNUTLS_X509_FMT_DER);
-
- if (ret < GNUTLS_E_SUCCESS)
- {
- gnutls_x509_crt_deinit (gnutls_verify_cert);
- return gnutls_make_error (ret);
- }
-
- XPROCESS (proc)->gnutls_certificate = gnutls_verify_cert;
-
- int err = gnutls_x509_crt_check_hostname (gnutls_verify_cert,
- c_hostname);
- check_memory_full (err);
- if (!err)
- {
- XPROCESS (proc)->gnutls_extra_peer_verification |=
- CERTIFICATE_NOT_MATCHING;
- if (verify_error_all
- || !NILP (Fmember (QCgnutls_bootprop_hostname, verify_error)))
- {
- gnutls_x509_crt_deinit (gnutls_verify_cert);
- emacs_gnutls_deinit (proc);
- error ("The x509 certificate does not match \"%s\"", c_hostname);
- }
- else
- {
- GNUTLS_LOG2 (1, max_log_level, "x509 certificate does not match:",
- c_hostname);
- }
- }
- }
-
- /* Set this flag only if the whole initialization succeeded. */
- XPROCESS (proc)->gnutls_p = 1;
-
- return gnutls_make_error (ret);
+ return gnutls_verify_boot (proc, proplist);
}
DEFUN ("gnutls-bye", Fgnutls_bye,
@@ -1673,6 +1746,7 @@ syms_of_gnutls (void)
DEFSYM (QCgnutls_bootprop_crlfiles, ":crlfiles");
DEFSYM (QCgnutls_bootprop_min_prime_bits, ":min-prime-bits");
DEFSYM (QCgnutls_bootprop_loglevel, ":loglevel");
+ DEFSYM (QCgnutls_complete_negotiation, ":complete-negotiation");
DEFSYM (QCgnutls_bootprop_verify_flags, ":verify-flags");
DEFSYM (QCgnutls_bootprop_verify_error, ":verify-error");
@@ -1693,6 +1767,7 @@ syms_of_gnutls (void)
make_number (GNUTLS_E_APPLICATION_ERROR_MIN));
defsubr (&Sgnutls_get_initstage);
+ defsubr (&Sgnutls_asynchronous_parameters);
defsubr (&Sgnutls_errorp);
defsubr (&Sgnutls_error_fatalp);
defsubr (&Sgnutls_error_string);
diff --git a/src/gnutls.h b/src/gnutls.h
index e9348e7423e..47e11f2905f 100644
--- a/src/gnutls.h
+++ b/src/gnutls.h
@@ -25,8 +25,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "lisp.h"
-/* This limits the attempts to handshake per process (connection). */
-#define GNUTLS_EMACS_HANDSHAKES_LIMIT 100
+/* This limits the attempts to handshake per process (connection). It
+ should work out to about one minute in asynchronous cases. */
+#define GNUTLS_EMACS_HANDSHAKES_LIMIT 6000
typedef enum
{
@@ -84,6 +85,8 @@ extern void emacs_gnutls_transport_set_errno (gnutls_session_t state, int err);
#endif
extern Lisp_Object emacs_gnutls_deinit (Lisp_Object);
extern Lisp_Object emacs_gnutls_global_init (void);
+extern int gnutls_try_handshake (struct Lisp_Process *p);
+extern Lisp_Object gnutls_verify_boot (Lisp_Object proc, Lisp_Object proplist);
#endif
diff --git a/src/image.c b/src/image.c
index a44b90b78e7..bee066eb3fb 100644
--- a/src/image.c
+++ b/src/image.c
@@ -8073,15 +8073,25 @@ compute_image_size (size_t width, size_t height,
{
Lisp_Object value;
int desired_width, desired_height;
+ double scale = 1;
+
+ value = image_spec_value (spec, QCscale, NULL);
+ if (NUMBERP (value))
+ scale = extract_float (value);
/* If width and/or height is set in the display spec assume we want
to scale to those values. If either h or w is unspecified, the
unspecified should be calculated from the specified to preserve
aspect ratio. */
value = image_spec_value (spec, QCwidth, NULL);
- desired_width = NATNUMP (value) ? min (XFASTINT (value), INT_MAX) : -1;
+ desired_width = NATNUMP (value) ?
+ min (XFASTINT (value) * scale, INT_MAX) : -1;
value = image_spec_value (spec, QCheight, NULL);
- desired_height = NATNUMP (value) ? min (XFASTINT (value), INT_MAX) : -1;
+ desired_height = NATNUMP (value) ?
+ min (XFASTINT (value) * scale, INT_MAX) : -1;
+
+ width = width * scale;
+ height = height * scale;
if (desired_width == -1)
{
@@ -8132,6 +8142,13 @@ compute_image_size (size_t width, size_t height,
/* h known, calculate w. */
desired_width = scale_image_size (desired_height, height, width);
+ /* We have no width/height settings, so just apply the scale. */
+ if (desired_width == -1 && desired_height == -1)
+ {
+ desired_width = width;
+ desired_height = height;
+ }
+
*d_width = desired_width;
*d_height = desired_height;
}
@@ -8546,6 +8563,18 @@ imagemagick_load_image (struct frame *f, struct image *img,
return 0;
}
+#ifdef HAVE_MAGICKAUTOORIENTIMAGE
+ /* If no :rotation is explicitly specified, apply the automatic
+ rotation from EXIF. */
+ if (NILP (image_spec_value (img->spec, QCrotation, NULL)))
+ if (MagickAutoOrientImage (image_wand) == MagickFalse)
+ {
+ image_error ("Error applying automatic orientation in image `%s'", img->spec);
+ DestroyMagickWand (image_wand);
+ return 0;
+ }
+#endif
+
if (ino < 0 || ino >= MagickGetNumberImages (image_wand))
{
image_error ("Invalid image number `%s' in image `%s'", image, img->spec);
@@ -9228,8 +9257,8 @@ svg_load_image (struct frame *f, /* Pointer to emacs frame structure. *
eassert (gdk_pixbuf_get_has_alpha (pixbuf));
eassert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
-#ifdef USE_CAIRO
{
+#ifdef USE_CAIRO
unsigned char *data = (unsigned char *) xmalloc (width*height*4);
uint32_t bgcolor = get_spec_bg_or_alpha_as_argb (img, f);
@@ -9255,82 +9284,77 @@ svg_load_image (struct frame *f, /* Pointer to emacs frame structure. *
create_cairo_image_surface (img, data, width, height);
g_object_unref (pixbuf);
- }
#else
- /* Try to create a x pixmap to hold the svg pixmap. */
- XImagePtr ximg;
- if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0))
- {
- g_object_unref (pixbuf);
- return 0;
- }
+ /* Try to create a x pixmap to hold the svg pixmap. */
+ XImagePtr ximg;
+ if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0))
+ {
+ g_object_unref (pixbuf);
+ return 0;
+ }
- init_color_table ();
+ init_color_table ();
- /* Handle alpha channel by combining the image with a background
- color. */
- XColor background;
- Lisp_Object specified_bg = image_spec_value (img->spec, QCbackground, NULL);
- if (!STRINGP (specified_bg)
- || !x_defined_color (f, SSDATA (specified_bg), &background, 0))
- x_query_frame_background_color (f, &background);
-
- /* SVG pixmaps specify transparency in the last byte, so right
- shift 8 bits to get rid of it, since emacs doesn't support
- transparency. */
- background.red >>= 8;
- background.green >>= 8;
- background.blue >>= 8;
-
- /* This loop handles opacity values, since Emacs assumes
- non-transparent images. Each pixel must be "flattened" by
- calculating the resulting color, given the transparency of the
- pixel, and the image background color. */
- for (int y = 0; y < height; ++y)
- {
- for (int x = 0; x < width; ++x)
- {
- int red;
- int green;
- int blue;
- int opacity;
-
- red = *pixels++;
- green = *pixels++;
- blue = *pixels++;
- opacity = *pixels++;
-
- red = ((red * opacity)
- + (background.red * ((1 << 8) - opacity)));
- green = ((green * opacity)
- + (background.green * ((1 << 8) - opacity)));
- blue = ((blue * opacity)
- + (background.blue * ((1 << 8) - opacity)));
-
- XPutPixel (ximg, x, y, lookup_rgb_color (f, red, green, blue));
- }
+ /* Handle alpha channel by combining the image with a background
+ color. */
+ XColor background;
+ Lisp_Object specified_bg = image_spec_value (img->spec, QCbackground, NULL);
+ if (!STRINGP (specified_bg)
+ || !x_defined_color (f, SSDATA (specified_bg), &background, 0))
+ x_query_frame_background_color (f, &background);
+
+ /* SVG pixmaps specify transparency in the last byte, so right
+ shift 8 bits to get rid of it, since emacs doesn't support
+ transparency. */
+ background.red >>= 8;
+ background.green >>= 8;
+ background.blue >>= 8;
+
+ /* This loop handles opacity values, since Emacs assumes
+ non-transparent images. Each pixel must be "flattened" by
+ calculating the resulting color, given the transparency of the
+ pixel, and the image background color. */
+ for (int y = 0; y < height; ++y)
+ {
+ for (int x = 0; x < width; ++x)
+ {
+ int red = *pixels++;
+ int green = *pixels++;
+ int blue = *pixels++;
+ int opacity = *pixels++;
+
+ red = ((red * opacity)
+ + (background.red * ((1 << 8) - opacity)));
+ green = ((green * opacity)
+ + (background.green * ((1 << 8) - opacity)));
+ blue = ((blue * opacity)
+ + (background.blue * ((1 << 8) - opacity)));
+
+ XPutPixel (ximg, x, y, lookup_rgb_color (f, red, green, blue));
+ }
- pixels += rowstride - 4 * width;
- }
+ pixels += rowstride - 4 * width;
+ }
#ifdef COLOR_TABLE_SUPPORT
- /* Remember colors allocated for this image. */
- img->colors = colors_in_color_table (&img->ncolors);
- free_color_table ();
+ /* Remember colors allocated for this image. */
+ img->colors = colors_in_color_table (&img->ncolors);
+ free_color_table ();
#endif /* COLOR_TABLE_SUPPORT */
- g_object_unref (pixbuf);
+ g_object_unref (pixbuf);
- img->width = width;
- img->height = height;
+ img->width = width;
+ img->height = height;
- /* Maybe fill in the background field while we have ximg handy.
- Casting avoids a GCC warning. */
- IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg);
+ /* Maybe fill in the background field while we have ximg handy.
+ Casting avoids a GCC warning. */
+ IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg);
- /* Put ximg into the image. */
- image_put_x_image (f, img, ximg, 0);
+ /* Put ximg into the image. */
+ image_put_x_image (f, img, ximg, 0);
#endif /* ! USE_CAIRO */
+ }
return 1;
@@ -9795,6 +9819,7 @@ non-numeric, there is no explicit limit on the size of images. */);
DEFSYM (QCcrop, ":crop");
DEFSYM (QCrotation, ":rotation");
DEFSYM (QCmatrix, ":matrix");
+ DEFSYM (QCscale, ":scale");
DEFSYM (QCcolor_adjustment, ":color-adjustment");
DEFSYM (QCmask, ":mask");
diff --git a/src/keyboard.c b/src/keyboard.c
index 29d6d6778f4..b8e0a6d88ea 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -5972,7 +5972,6 @@ make_lispy_event (struct input_event *event)
}
#endif
-
#if defined HAVE_INOTIFY || defined HAVE_KQUEUE || defined HAVE_GFILENOTIFY
case FILE_NOTIFY_EVENT:
{
@@ -10308,6 +10307,9 @@ handle_interrupt (bool in_signal_handler)
is used. Note that [Enter] is not echoed by dos. */
cursor_to (SELECTED_FRAME (), 0, 0);
#endif
+
+ write_stdout ("Emacs is resuming after an emergency escape.\n");
+
/* It doesn't work to autosave while GC is in progress;
the code used for auto-saving doesn't cope with the mark bit. */
if (!gc_in_progress)
@@ -11712,6 +11714,25 @@ Currently, the only supported values for this
variable are `sigusr1' and `sigusr2'. */);
Vdebug_on_event = intern_c_string ("sigusr2");
+ DEFVAR_BOOL ("attempt-stack-overflow-recovery",
+ attempt_stack_overflow_recovery,
+ doc: /* If non-nil, attempt to recover from C stack
+overflow. This recovery is unsafe and may lead to deadlocks or data
+corruption, but it usually works and may preserve modified buffers
+that would otherwise be lost. If nil, treat stack overflow like any
+other kind of crash. */);
+ attempt_stack_overflow_recovery = true;
+
+ DEFVAR_BOOL ("attempt-orderly-shutdown-on-fatal-signal",
+ attempt_orderly_shutdown_on_fatal_signal,
+ doc: /* If non-nil, attempt to perform an orderly
+shutdown when Emacs receives a fatal signal (e.g., a crash).
+This cleanup is unsafe and may lead to deadlocks or data corruption,
+but it usually works and may preserve modified buffers that would
+otherwise be lost. If nil, crash immediately in response to fatal
+signals. */);
+ attempt_orderly_shutdown_on_fatal_signal = true;
+
/* Create the initial keyboard. Qt means 'unset'. */
initial_kboard = allocate_kboard (Qt);
}
diff --git a/src/kqueue.c b/src/kqueue.c
index c848b7ff1af..f45bd0c4c24 100644
--- a/src/kqueue.c
+++ b/src/kqueue.c
@@ -29,6 +29,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "keyboard.h"
#include "process.h"
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif /* HAVE_SYS_RESOURCE_H */
+
/* File handle for kqueue. */
static int kqueuefd = -1;
@@ -366,9 +370,12 @@ only when the upper directory of the renamed file is watched. */)
(Lisp_Object file, Lisp_Object flags, Lisp_Object callback)
{
Lisp_Object watch_object, dir_list;
- int fd, oflags;
+ int maxfd, fd, oflags;
u_short fflags = 0;
struct kevent kev;
+#ifdef HAVE_GETRLIMIT
+ struct rlimit rlim;
+#endif /* HAVE_GETRLIMIT */
/* Check parameters. */
CHECK_STRING (file);
@@ -381,6 +388,21 @@ only when the upper directory of the renamed file is watched. */)
if (! FUNCTIONP (callback))
wrong_type_argument (Qinvalid_function, callback);
+ /* Check available file descriptors. */
+#ifdef HAVE_GETRLIMIT
+ if (! getrlimit (RLIMIT_NOFILE, &rlim))
+ maxfd = rlim.rlim_cur;
+ else
+#endif /* HAVE_GETRLIMIT */
+ maxfd = 256;
+
+ /* We assume 50 file descriptors are sufficient for the rest of Emacs. */
+ if ((maxfd - 50) < XINT (Flength (watch_list)))
+ xsignal2
+ (Qfile_notify_error,
+ build_string ("File watching not possible, no file descriptor left"),
+ Flength (watch_list));
+
if (kqueuefd < 0)
{
/* Create kqueue descriptor. */
diff --git a/src/lastfile.c b/src/lastfile.c
index d516093b297..9d70b001d11 100644
--- a/src/lastfile.c
+++ b/src/lastfile.c
@@ -38,7 +38,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "lisp.h"
+#if ((!defined SYSTEM_MALLOC && !defined HYBRID_MALLOC) \
+ || defined WINDOWSNT || defined CYGWIN || defined DARWIN_OS)
char my_edata[] = "End of Emacs initialized data";
+#endif
/* Help unexec locate the end of the .bss area used by Emacs (which
isn't always a separate section in NT executables). */
diff --git a/src/lisp.h b/src/lisp.h
index 27588848c29..d0abb24b685 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -600,7 +600,9 @@ extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object);
extern _Noreturn void wrong_choice (Lisp_Object, Lisp_Object);
/* Defined in emacs.c. */
+#ifdef DOUG_LEA_MALLOC
extern bool might_dump;
+#endif
/* True means Emacs has already been initialized.
Used during startup to detect startup of dumped Emacs. */
extern bool initialized;
@@ -3583,13 +3585,8 @@ extern void mark_object (Lisp_Object);
#if defined REL_ALLOC && !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
extern void refill_memory_reserve (void);
#endif
-#ifdef DOUG_LEA_MALLOC
extern void alloc_unexec_pre (void);
extern void alloc_unexec_post (void);
-#else
-INLINE void alloc_unexec_pre (void) {}
-INLINE void alloc_unexec_post (void) {}
-#endif
extern const char *pending_malloc_warning;
extern Lisp_Object zero_vector;
extern Lisp_Object *stack_base;
@@ -3755,6 +3752,15 @@ extern void check_cons_list (void);
INLINE void (check_cons_list) (void) { lisp_h_check_cons_list (); }
#endif
+/* Defined in gmalloc.c. */
+#if !defined DOUG_LEA_MALLOC && !defined HYBRID_MALLOC && !defined SYSTEM_MALLOC
+extern size_t __malloc_extra_blocks;
+#endif
+#if !HAVE_DECL_ALIGNED_ALLOC
+extern void *aligned_alloc (size_t, size_t) ATTRIBUTE_MALLOC_SIZE ((2));
+#endif
+extern void malloc_enable_thread (void);
+
#ifdef REL_ALLOC
/* Defined in ralloc.c. */
extern void *r_alloc (void **, size_t) ATTRIBUTE_ALLOC_SIZE ((2));
@@ -3900,6 +3906,8 @@ extern Lisp_Object unbind_to (ptrdiff_t, Lisp_Object);
extern _Noreturn void error (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
extern _Noreturn void verror (const char *, va_list)
ATTRIBUTE_FORMAT_PRINTF (1, 0);
+extern Lisp_Object vformat_string (const char *, va_list)
+ ATTRIBUTE_FORMAT_PRINTF (1, 0);
extern void un_autoload (Lisp_Object);
extern Lisp_Object call_debugger (Lisp_Object arg);
extern void *near_C_stack_top (void);
@@ -4124,6 +4132,9 @@ extern bool noninteractive;
/* True means remove site-lisp directories from load-path. */
extern bool no_site_lisp;
+/* True means put details like time stamps into builds. */
+extern bool build_details;
+
/* Pipe used to send exit notification to the daemon parent at
startup. On Windows, we use a kernel event instead. */
#ifndef WINDOWSNT
@@ -4235,9 +4246,7 @@ struct tty_display_info;
struct terminal;
/* Defined in sysdep.c. */
-#ifndef HAVE_GET_CURRENT_DIR_NAME
-extern char *get_current_dir_name (void);
-#endif
+extern char *emacs_get_current_dir_name (void);
extern void stuff_char (char c);
extern void init_foreground_group (void);
extern void sys_subshell (void);
diff --git a/src/process.c b/src/process.c
index dd508836f79..a518c2bffb8 100644
--- a/src/process.c
+++ b/src/process.c
@@ -75,11 +75,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
# include <sys/stropts.h>
#endif
-#ifdef HAVE_RES_INIT
-#include <arpa/nameser.h>
-#include <resolv.h>
-#endif
-
#ifdef HAVE_UTIL_H
#include <util.h>
#endif
@@ -125,6 +120,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#endif
#endif
+#if defined HAVE_GETADDRINFO_A || defined HAVE_GNUTLS
+/* This is 0.1s in nanoseconds. */
+#define ASYNC_RETRY_NSEC 100000000
+#endif
+
#ifdef WINDOWSNT
extern int sys_select (int, fd_set *, fd_set *, fd_set *,
struct timespec *, void *);
@@ -281,6 +281,7 @@ static int max_input_desc;
/* Indexed by descriptor, gives the process (if any) for that descriptor. */
static Lisp_Object chan_process[FD_SETSIZE];
+static void wait_for_socket_fds (Lisp_Object, char const *);
/* Alist of elements (NAME . PROCESS). */
static Lisp_Object Vprocess_alist;
@@ -301,7 +302,7 @@ static struct coding_system *proc_encode_coding_system[FD_SETSIZE];
/* Table of `partner address' for datagram sockets. */
static struct sockaddr_and_len {
struct sockaddr *sa;
- int len;
+ ptrdiff_t len;
} datagram_address[FD_SETSIZE];
#define DATAGRAM_CHAN_P(chan) (datagram_address[chan].sa != 0)
#define DATAGRAM_CONN_P(proc) \
@@ -381,11 +382,6 @@ pset_sentinel (struct Lisp_Process *p, Lisp_Object val)
p->sentinel = NILP (val) ? Qinternal_default_process_sentinel : val;
}
static void
-pset_status (struct Lisp_Process *p, Lisp_Object val)
-{
- p->status = val;
-}
-static void
pset_tty_name (struct Lisp_Process *p, Lisp_Object val)
{
p->tty_name = val;
@@ -711,6 +707,7 @@ make_process (Lisp_Object name)
#ifdef HAVE_GNUTLS
p->gnutls_initstage = GNUTLS_STAGE_EMPTY;
+ p->gnutls_boot_parameters = Qnil;
#endif
/* If name is already in use, modify it until it is unused. */
@@ -742,6 +739,19 @@ remove_process (register Lisp_Object proc)
deactivate_process (proc);
}
+#ifdef HAVE_GETADDRINFO_A
+static void
+free_dns_request (Lisp_Object proc)
+{
+ struct Lisp_Process *p = XPROCESS (proc);
+
+ if (p->dns_request->ar_result)
+ freeaddrinfo (p->dns_request->ar_result);
+ xfree (p->dns_request);
+ p->dns_request = NULL;
+}
+#endif
+
DEFUN ("processp", Fprocessp, Sprocessp, 1, 1, 0,
doc: /* Return t if OBJECT is a process. */)
@@ -832,6 +842,25 @@ nil, indicating the current buffer's process. */)
process = get_process (process);
p = XPROCESS (process);
+#ifdef HAVE_GETADDRINFO_A
+ if (p->dns_request)
+ {
+ /* Cancel the request. Unless shutting down, wait until
+ completion. Free the request if completely canceled. */
+
+ bool canceled = gai_cancel (p->dns_request) != EAI_NOTCANCELED;
+ if (!canceled && !inhibit_sentinels)
+ {
+ struct gaicb const *req = p->dns_request;
+ while (gai_suspend (&req, 1, NULL) != 0)
+ continue;
+ canceled = true;
+ }
+ if (canceled)
+ free_dns_request (process);
+ }
+#endif
+
p->raw_status_new = 0;
if (NETCONN1_P (p) || SERIALCONN1_P (p) || PIPECONN1_P (p))
{
@@ -1008,6 +1037,23 @@ DEFUN ("process-mark", Fprocess_mark, Sprocess_mark,
return XPROCESS (process)->mark;
}
+static void
+set_process_filter_masks (struct Lisp_Process *p)
+{
+ if (EQ (p->filter, Qt) && !EQ (p->status, Qlisten))
+ {
+ FD_CLR (p->infd, &input_wait_mask);
+ FD_CLR (p->infd, &non_keyboard_wait_mask);
+ }
+ else if (EQ (p->filter, Qt)
+ /* Network or serial process not stopped: */
+ && !EQ (p->command, Qt))
+ {
+ FD_SET (p->infd, &input_wait_mask);
+ FD_SET (p->infd, &non_keyboard_wait_mask);
+ }
+}
+
DEFUN ("set-process-filter", Fset_process_filter, Sset_process_filter,
2, 2, 0,
doc: /* Give PROCESS the filter function FILTER; nil means default.
@@ -1024,12 +1070,10 @@ The string argument is normally a multibyte string, except:
- if `default-enable-multibyte-characters' is nil, it is a unibyte
string (the result of converting the decoded input multibyte
string to unibyte with `string-make-unibyte'). */)
- (register Lisp_Object process, Lisp_Object filter)
+ (Lisp_Object process, Lisp_Object filter)
{
- struct Lisp_Process *p;
-
CHECK_PROCESS (process);
- p = XPROCESS (process);
+ struct Lisp_Process *p = XPROCESS (process);
/* Don't signal an error if the process's input file descriptor
is closed. This could make debugging Lisp more difficult,
@@ -1042,23 +1086,11 @@ The string argument is normally a multibyte string, except:
if (NILP (filter))
filter = Qinternal_default_process_filter;
+ pset_filter (p, filter);
+
if (p->infd >= 0)
- {
- if (EQ (filter, Qt) && !EQ (p->status, Qlisten))
- {
- FD_CLR (p->infd, &input_wait_mask);
- FD_CLR (p->infd, &non_keyboard_wait_mask);
- }
- else if (EQ (p->filter, Qt)
- /* Network or serial process not stopped: */
- && !EQ (p->command, Qt))
- {
- FD_SET (p->infd, &input_wait_mask);
- FD_SET (p->infd, &non_keyboard_wait_mask);
- }
- }
+ set_process_filter_masks (p);
- pset_filter (p, filter);
if (NETCONN1_P (p) || SERIALCONN1_P (p) || PIPECONN1_P (p))
pset_childp (p, Fplist_put (p->childp, QCfilter, filter));
setup_process_coding_systems (process);
@@ -1117,7 +1149,8 @@ DEFUN ("set-process-window-size", Fset_process_window_size,
CHECK_RANGED_INTEGER (height, 0, USHRT_MAX);
CHECK_RANGED_INTEGER (width, 0, USHRT_MAX);
- if (XPROCESS (process)->infd < 0
+ if (NETCONN_P (process)
+ || XPROCESS (process)->infd < 0
|| (set_window_size (XPROCESS (process)->infd,
XINT (height), XINT (width))
< 0))
@@ -1185,8 +1218,10 @@ SERVICE) for a network connection or (PORT SPEED) for a serial
connection. If KEY is t, the complete contact information for the
connection is returned, else the specific value for the keyword KEY is
returned. See `make-network-process' or `make-serial-process' for a
-list of keywords. */)
- (register Lisp_Object process, Lisp_Object key)
+list of keywords.
+If PROCESS is a non-blocking network process that hasn't been fully
+set up yet, this function will block until socket setup has completed. */)
+ (Lisp_Object process, Lisp_Object key)
{
Lisp_Object contact;
@@ -1194,6 +1229,10 @@ list of keywords. */)
contact = XPROCESS (process)->childp;
#ifdef DATAGRAM_SOCKETS
+
+ if (NETCONN_P (process))
+ wait_for_socket_fds (process, "process-contact");
+
if (DATAGRAM_CONN_P (process)
&& (EQ (key, Qt) || EQ (key, QCremote)))
contact = Fplist_put (contact, QCremote,
@@ -1228,8 +1267,8 @@ DEFUN ("process-plist", Fprocess_plist, Sprocess_plist,
DEFUN ("set-process-plist", Fset_process_plist, Sset_process_plist,
2, 2, 0,
- doc: /* Replace the plist of PROCESS with PLIST. Returns PLIST. */)
- (register Lisp_Object process, Lisp_Object plist)
+ doc: /* Replace the plist of PROCESS with PLIST. Return PLIST. */)
+ (Lisp_Object process, Lisp_Object plist)
{
CHECK_PROCESS (process);
CHECK_LIST (plist);
@@ -1269,7 +1308,7 @@ A 4 or 5 element vector represents an IPv4 address (with port number).
An 8 or 9 element vector represents an IPv6 address (with port number).
If optional second argument OMIT-PORT is non-nil, don't include a port
number in the string, even when present in ADDRESS.
-Returns nil if format of ADDRESS is invalid. */)
+Return nil if format of ADDRESS is invalid. */)
(Lisp_Object address, Lisp_Object omit_port)
{
if (NILP (address))
@@ -2217,12 +2256,12 @@ usage: (make-pipe-process &rest ARGS) */)
The address family of sa is not included in the result. */
Lisp_Object
-conv_sockaddr_to_lisp (struct sockaddr *sa, int len)
+conv_sockaddr_to_lisp (struct sockaddr *sa, ptrdiff_t len)
{
Lisp_Object address;
- int i;
+ ptrdiff_t i;
unsigned char *cp;
- register struct Lisp_Vector *p;
+ struct Lisp_Vector *p;
/* Workaround for a bug in getsockname on BSD: Names bound to
sockets in the UNIX domain are inaccessible; getsockname returns
@@ -2297,10 +2336,10 @@ conv_sockaddr_to_lisp (struct sockaddr *sa, int len)
/* Get family and required size for sockaddr structure to hold ADDRESS. */
-static int
+static ptrdiff_t
get_lisp_to_sockaddr_size (Lisp_Object address, int *familyp)
{
- register struct Lisp_Vector *p;
+ struct Lisp_Vector *p;
if (VECTORP (address))
{
@@ -2416,13 +2455,18 @@ conv_lisp_to_sockaddr (int family, Lisp_Object address, struct sockaddr *sa, int
#ifdef DATAGRAM_SOCKETS
DEFUN ("process-datagram-address", Fprocess_datagram_address, Sprocess_datagram_address,
1, 1, 0,
- doc: /* Get the current datagram address associated with PROCESS. */)
+ doc: /* Get the current datagram address associated with PROCESS.
+If PROCESS is a non-blocking network process that hasn't been fully
+set up yet, this function will block until socket setup has completed. */)
(Lisp_Object process)
{
int channel;
CHECK_PROCESS (process);
+ if (NETCONN_P (process))
+ wait_for_socket_fds (process, "process-datagram-address");
+
if (!DATAGRAM_CONN_P (process))
return Qnil;
@@ -2434,14 +2478,21 @@ DEFUN ("process-datagram-address", Fprocess_datagram_address, Sprocess_datagram_
DEFUN ("set-process-datagram-address", Fset_process_datagram_address, Sset_process_datagram_address,
2, 2, 0,
doc: /* Set the datagram address for PROCESS to ADDRESS.
-Returns nil upon error setting address, ADDRESS otherwise. */)
+Return nil upon error setting address, ADDRESS otherwise.
+
+If PROCESS is a non-blocking network process that hasn't been fully
+set up yet, this function will block until socket setup has completed. */)
(Lisp_Object process, Lisp_Object address)
{
int channel;
- int family, len;
+ int family;
+ ptrdiff_t len;
CHECK_PROCESS (process);
+ if (NETCONN_P (process))
+ wait_for_socket_fds (process, "set-process-datagram-address");
+
if (!DATAGRAM_CONN_P (process))
return Qnil;
@@ -2497,7 +2548,7 @@ static const struct socket_options {
/* Set option OPT to value VAL on socket S.
- Returns (1<<socket_options[OPT].optbit) if option is known, 0 otherwise.
+ Return (1<<socket_options[OPT].optbit) if option is known, 0 otherwise.
Signals an error if setting a known option fails.
*/
@@ -2599,7 +2650,10 @@ DEFUN ("set-network-process-option",
doc: /* For network process PROCESS set option OPTION to value VALUE.
See `make-network-process' for a list of options and values.
If optional fourth arg NO-ERROR is non-nil, don't signal an error if
-OPTION is not a supported option, return nil instead; otherwise return t. */)
+OPTION is not a supported option, return nil instead; otherwise return t.
+
+If PROCESS is a non-blocking network process that hasn't been fully
+set up yet, this function will block until socket setup has completed. */)
(Lisp_Object process, Lisp_Object option, Lisp_Object value, Lisp_Object no_error)
{
int s;
@@ -2610,6 +2664,8 @@ OPTION is not a supported option, return nil instead; otherwise return t. */)
if (!NETCONN1_P (p))
error ("Process is not a network process");
+ wait_for_socket_fds (process, "set-network-process-option");
+
s = p->infd;
if (s < 0)
error ("Process is not running");
@@ -2904,6 +2960,471 @@ usage: (make-serial-process &rest ARGS) */)
return proc;
}
+static void
+set_network_socket_coding_system (Lisp_Object proc, Lisp_Object host,
+ Lisp_Object service, Lisp_Object name)
+{
+ Lisp_Object tem;
+ struct Lisp_Process *p = XPROCESS (proc);
+ Lisp_Object contact = p->childp;
+ Lisp_Object coding_systems = Qt;
+ Lisp_Object val;
+
+ tem = Fplist_member (contact, QCcoding);
+ if (!NILP (tem) && (!CONSP (tem) || !CONSP (XCDR (tem))))
+ tem = Qnil; /* No error message (too late!). */
+
+ /* Setup coding systems for communicating with the network stream. */
+ /* Qt denotes we have not yet called Ffind_operation_coding_system. */
+
+ if (!NILP (tem))
+ {
+ val = XCAR (XCDR (tem));
+ if (CONSP (val))
+ val = XCAR (val);
+ }
+ else if (!NILP (Vcoding_system_for_read))
+ val = Vcoding_system_for_read;
+ else if ((!NILP (p->buffer)
+ && NILP (BVAR (XBUFFER (p->buffer), enable_multibyte_characters)))
+ || (NILP (p->buffer)
+ && NILP (BVAR (&buffer_defaults, enable_multibyte_characters))))
+ /* We dare not decode end-of-line format by setting VAL to
+ Qraw_text, because the existing Emacs Lisp libraries
+ assume that they receive bare code including a sequence of
+ CR LF. */
+ val = Qnil;
+ else
+ {
+ if (NILP (host) || NILP (service))
+ coding_systems = Qnil;
+ else
+ coding_systems = CALLN (Ffind_operation_coding_system,
+ Qopen_network_stream, name, p->buffer,
+ host, service);
+ if (CONSP (coding_systems))
+ val = XCAR (coding_systems);
+ else if (CONSP (Vdefault_process_coding_system))
+ val = XCAR (Vdefault_process_coding_system);
+ else
+ val = Qnil;
+ }
+ pset_decode_coding_system (p, val);
+
+ if (!NILP (tem))
+ {
+ val = XCAR (XCDR (tem));
+ if (CONSP (val))
+ val = XCDR (val);
+ }
+ else if (!NILP (Vcoding_system_for_write))
+ val = Vcoding_system_for_write;
+ else if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
+ val = Qnil;
+ else
+ {
+ if (EQ (coding_systems, Qt))
+ {
+ if (NILP (host) || NILP (service))
+ coding_systems = Qnil;
+ else
+ coding_systems = CALLN (Ffind_operation_coding_system,
+ Qopen_network_stream, name, p->buffer,
+ host, service);
+ }
+ if (CONSP (coding_systems))
+ val = XCDR (coding_systems);
+ else if (CONSP (Vdefault_process_coding_system))
+ val = XCDR (Vdefault_process_coding_system);
+ else
+ val = Qnil;
+ }
+ pset_encode_coding_system (p, val);
+
+ pset_decoding_buf (p, empty_unibyte_string);
+ p->decoding_carryover = 0;
+ pset_encoding_buf (p, empty_unibyte_string);
+
+ p->inherit_coding_system_flag
+ = !(!NILP (tem) || NILP (p->buffer) || !inherit_process_coding_system);
+}
+
+#ifdef HAVE_GNUTLS
+static void
+finish_after_tls_connection (Lisp_Object proc)
+{
+ struct Lisp_Process *p = XPROCESS (proc);
+ Lisp_Object contact = p->childp;
+ Lisp_Object result = Qt;
+
+ if (!NILP (Ffboundp (Qnsm_verify_connection)))
+ result = call3 (Qnsm_verify_connection,
+ proc,
+ Fplist_get (contact, QChost),
+ Fplist_get (contact, QCservice));
+
+ if (NILP (result))
+ {
+ pset_status (p, list2 (Qfailed,
+ build_string ("The Network Security Manager stopped the connections")));
+ deactivate_process (proc);
+ }
+ else
+ {
+ /* If we cleared the connection wait mask before we did
+ the TLS setup, then we have to say that the process
+ is finally "open" here. */
+ if (! FD_ISSET (p->outfd, &connect_wait_mask))
+ {
+ pset_status (p, Qrun);
+ /* Execute the sentinel here. If we had relied on
+ status_notify to do it later, it will read input
+ from the process before calling the sentinel. */
+ exec_sentinel (proc, build_string ("open\n"));
+ }
+ }
+}
+#endif
+
+static void
+connect_network_socket (Lisp_Object proc, Lisp_Object ip_addresses)
+{
+ ptrdiff_t count = SPECPDL_INDEX ();
+ ptrdiff_t count1;
+ int s = -1, outch, inch;
+ int xerrno = 0;
+ Lisp_Object ip_address;
+ int family;
+ struct sockaddr *sa = NULL;
+ int ret;
+ ptrdiff_t addrlen;
+ struct Lisp_Process *p = XPROCESS (proc);
+ Lisp_Object contact = p->childp;
+ int optbits = 0;
+
+ /* Do this in case we never enter the while-loop below. */
+ count1 = SPECPDL_INDEX ();
+ s = -1;
+
+ while (!NILP (ip_addresses))
+ {
+ ip_address = XCAR (ip_addresses);
+ ip_addresses = XCDR (ip_addresses);
+
+#ifdef WINDOWSNT
+ retry_connect:
+#endif
+
+ addrlen = get_lisp_to_sockaddr_size (ip_address, &family);
+ if (sa)
+ free (sa);
+ sa = xmalloc (addrlen);
+ conv_lisp_to_sockaddr (family, ip_address, sa, addrlen);
+
+ s = socket (family, p->socktype | SOCK_CLOEXEC, p->ai_protocol);
+ if (s < 0)
+ {
+ xerrno = errno;
+ continue;
+ }
+
+#ifdef DATAGRAM_SOCKETS
+ if (!p->is_server && p->socktype == SOCK_DGRAM)
+ break;
+#endif /* DATAGRAM_SOCKETS */
+
+#ifdef NON_BLOCKING_CONNECT
+ if (p->is_non_blocking_client)
+ {
+ ret = fcntl (s, F_SETFL, O_NONBLOCK);
+ if (ret < 0)
+ {
+ xerrno = errno;
+ emacs_close (s);
+ s = -1;
+ continue;
+ }
+ }
+#endif
+
+ /* Make us close S if quit. */
+ record_unwind_protect_int (close_file_unwind, s);
+
+ /* Parse network options in the arg list. We simply ignore anything
+ which isn't a known option (including other keywords). An error
+ is signaled if setting a known option fails. */
+ {
+ Lisp_Object params = contact, key, val;
+
+ while (!NILP (params))
+ {
+ key = XCAR (params);
+ params = XCDR (params);
+ val = XCAR (params);
+ params = XCDR (params);
+ optbits |= set_socket_option (s, key, val);
+ }
+ }
+
+ if (p->is_server)
+ {
+ /* Configure as a server socket. */
+
+ /* SO_REUSEADDR = 1 is default for server sockets; must specify
+ explicit :reuseaddr key to override this. */
+#ifdef HAVE_LOCAL_SOCKETS
+ if (family != AF_LOCAL)
+#endif
+ if (!(optbits & (1 << OPIX_REUSEADDR)))
+ {
+ int optval = 1;
+ if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval))
+ report_file_error ("Cannot set reuse option on server socket", Qnil);
+ }
+
+ if (bind (s, sa, addrlen))
+ report_file_error ("Cannot bind server socket", Qnil);
+
+#ifdef HAVE_GETSOCKNAME
+ if (p->port == 0)
+ {
+ struct sockaddr_in sa1;
+ socklen_t len1 = sizeof (sa1);
+ if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
+ {
+ Lisp_Object service;
+ service = make_number (ntohs (sa1.sin_port));
+ contact = Fplist_put (contact, QCservice, service);
+ /* Save the port number so that we can stash it in
+ the process object later. */
+ ((struct sockaddr_in *)sa)->sin_port = sa1.sin_port;
+ }
+ }
+#endif
+
+ if (p->socktype != SOCK_DGRAM && listen (s, p->backlog))
+ report_file_error ("Cannot listen on server socket", Qnil);
+
+ break;
+ }
+
+ immediate_quit = 1;
+ QUIT;
+
+ ret = connect (s, sa, addrlen);
+ xerrno = errno;
+
+ if (ret == 0 || xerrno == EISCONN)
+ {
+ /* The unwind-protect will be discarded afterwards.
+ Likewise for immediate_quit. */
+ break;
+ }
+
+#ifdef NON_BLOCKING_CONNECT
+#ifdef EINPROGRESS
+ if (p->is_non_blocking_client && xerrno == EINPROGRESS)
+ break;
+#else
+#ifdef EWOULDBLOCK
+ if (p->is_non_blocking_client && xerrno == EWOULDBLOCK)
+ break;
+#endif
+#endif
+#endif
+
+#ifndef WINDOWSNT
+ if (xerrno == EINTR)
+ {
+ /* Unlike most other syscalls connect() cannot be called
+ again. (That would return EALREADY.) The proper way to
+ wait for completion is pselect(). */
+ int sc;
+ socklen_t len;
+ fd_set fdset;
+ retry_select:
+ FD_ZERO (&fdset);
+ FD_SET (s, &fdset);
+ QUIT;
+ sc = pselect (s + 1, NULL, &fdset, NULL, NULL, NULL);
+ if (sc == -1)
+ {
+ if (errno == EINTR)
+ goto retry_select;
+ else
+ report_file_error ("Failed select", Qnil);
+ }
+ eassert (sc > 0);
+
+ len = sizeof xerrno;
+ eassert (FD_ISSET (s, &fdset));
+ if (getsockopt (s, SOL_SOCKET, SO_ERROR, &xerrno, &len) < 0)
+ report_file_error ("Failed getsockopt", Qnil);
+ if (xerrno)
+ report_file_errno ("Failed connect", Qnil, xerrno);
+ break;
+ }
+#endif /* !WINDOWSNT */
+
+ immediate_quit = 0;
+
+ /* Discard the unwind protect closing S. */
+ specpdl_ptr = specpdl + count1;
+ emacs_close (s);
+ s = -1;
+
+#ifdef WINDOWSNT
+ if (xerrno == EINTR)
+ goto retry_connect;
+#endif
+ }
+
+ if (s >= 0)
+ {
+#ifdef DATAGRAM_SOCKETS
+ if (p->socktype == SOCK_DGRAM)
+ {
+ if (datagram_address[s].sa)
+ emacs_abort ();
+
+ datagram_address[s].sa = xmalloc (addrlen);
+ datagram_address[s].len = addrlen;
+ if (p->is_server)
+ {
+ Lisp_Object remote;
+ memset (datagram_address[s].sa, 0, addrlen);
+ if (remote = Fplist_get (contact, QCremote), !NILP (remote))
+ {
+ int rfamily;
+ ptrdiff_t rlen = get_lisp_to_sockaddr_size (remote, &rfamily);
+ if (rlen != 0 && rfamily == family
+ && rlen == addrlen)
+ conv_lisp_to_sockaddr (rfamily, remote,
+ datagram_address[s].sa, rlen);
+ }
+ }
+ else
+ memcpy (datagram_address[s].sa, sa, addrlen);
+ }
+#endif
+
+ contact = Fplist_put (contact, p->is_server? QClocal: QCremote,
+ conv_sockaddr_to_lisp (sa, addrlen));
+#ifdef HAVE_GETSOCKNAME
+ if (!p->is_server)
+ {
+ struct sockaddr_in sa1;
+ socklen_t len1 = sizeof (sa1);
+ if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
+ contact = Fplist_put (contact, QClocal,
+ conv_sockaddr_to_lisp ((struct sockaddr *)&sa1, len1));
+ }
+#endif
+ }
+
+ immediate_quit = 0;
+
+ if (s < 0)
+ {
+ /* If non-blocking got this far - and failed - assume non-blocking is
+ not supported after all. This is probably a wrong assumption, but
+ the normal blocking calls to open-network-stream handles this error
+ better. */
+ if (p->is_non_blocking_client)
+ return;
+
+ report_file_errno ((p->is_server
+ ? "make server process failed"
+ : "make client process failed"),
+ contact, xerrno);
+ }
+
+ inch = s;
+ outch = s;
+
+ chan_process[inch] = proc;
+
+ fcntl (inch, F_SETFL, O_NONBLOCK);
+
+ p = XPROCESS (proc);
+ p->open_fd[SUBPROCESS_STDIN] = inch;
+ p->infd = inch;
+ p->outfd = outch;
+
+ /* Discard the unwind protect for closing S, if any. */
+ specpdl_ptr = specpdl + count1;
+
+ /* Unwind bind_polling_period and request_sigio. */
+ unbind_to (count, Qnil);
+
+ if (p->is_server && p->socktype != SOCK_DGRAM)
+ pset_status (p, Qlisten);
+
+ /* Make the process marker point into the process buffer (if any). */
+ if (BUFFERP (p->buffer))
+ set_marker_both (p->mark, p->buffer,
+ BUF_ZV (XBUFFER (p->buffer)),
+ BUF_ZV_BYTE (XBUFFER (p->buffer)));
+
+#ifdef NON_BLOCKING_CONNECT
+ if (p->is_non_blocking_client)
+ {
+ /* We may get here if connect did succeed immediately. However,
+ in that case, we still need to signal this like a non-blocking
+ connection. */
+ pset_status (p, Qconnect);
+ if (!FD_ISSET (inch, &connect_wait_mask))
+ {
+ FD_SET (inch, &connect_wait_mask);
+ FD_SET (inch, &write_mask);
+ num_pending_connects++;
+ }
+ }
+ else
+#endif
+ /* A server may have a client filter setting of Qt, but it must
+ still listen for incoming connects unless it is stopped. */
+ if ((!EQ (p->filter, Qt) && !EQ (p->command, Qt))
+ || (EQ (p->status, Qlisten) && NILP (p->command)))
+ {
+ FD_SET (inch, &input_wait_mask);
+ FD_SET (inch, &non_keyboard_wait_mask);
+ }
+
+ if (inch > max_process_desc)
+ max_process_desc = inch;
+
+ /* Set up the masks based on the process filter. */
+ set_process_filter_masks (p);
+
+ setup_process_coding_systems (proc);
+
+#ifdef HAVE_GNUTLS
+ /* Continue the asynchronous connection. */
+ if (!NILP (p->gnutls_boot_parameters))
+ {
+ Lisp_Object boot, params = p->gnutls_boot_parameters;
+
+ boot = Fgnutls_boot (proc, XCAR (params), XCDR (params));
+ p->gnutls_boot_parameters = Qnil;
+
+ if (p->gnutls_initstage == GNUTLS_STAGE_READY)
+ /* Run sentinels, etc. */
+ finish_after_tls_connection (proc);
+ else if (p->gnutls_initstage != GNUTLS_STAGE_HANDSHAKE_TRIED)
+ {
+ deactivate_process (proc);
+ if (NILP (boot))
+ pset_status (p, list2 (Qfailed,
+ build_string ("TLS negotiation failed")));
+ else
+ pset_status (p, list2 (Qfailed, boot));
+ }
+ }
+#endif
+
+}
+
/* Create a network stream/datagram client/server process. Treated
exactly like a normal process when reading and writing. Primary
differences are in status display and process deletion. A network
@@ -2939,9 +3460,8 @@ host, and only clients connecting to that address will be accepted.
:service SERVICE -- SERVICE is name of the service desired, or an
integer specifying a port number to connect to. If SERVICE is t,
-a random port number is selected for the server. (If Emacs was
-compiled with getaddrinfo, a port number can also be specified as a
-string, e.g. "80", as well as an integer. This is not portable.)
+a random port number is selected for the server. A port number can
+be specified as an integer string, e.g., "80", as well as an integer.
:type TYPE -- TYPE is the type of connection. The default (nil) is a
stream type connection, `datagram' creates a datagram type connection,
@@ -2982,11 +3502,12 @@ system used for both reading and writing for this process. If CODING
is a cons (DECODING . ENCODING), DECODING is used for reading, and
ENCODING is used for writing.
-:nowait BOOL -- If BOOL is non-nil for a stream type client process,
-return without waiting for the connection to complete; instead, the
-sentinel function will be called with second arg matching "open" (if
-successful) or "failed" when the connect completes. Default is to use
-a blocking connect (i.e. wait) for stream type connections.
+:nowait BOOL -- If NOWAIT is non-nil for a stream type client
+process, return without waiting for the connection to complete;
+instead, the sentinel function will be called with second arg matching
+"open" (if successful) or "failed" when the connect completes.
+Default is to use a blocking connect (i.e. wait) for stream type
+connections.
:noquery BOOL -- Query the user unless BOOL is non-nil, and process is
running when Emacs is exited.
@@ -3014,6 +3535,12 @@ and MESSAGE is a string.
:plist PLIST -- Install PLIST as the new process's initial plist.
+:tls-parameters LIST -- is a list that should be supplied if you're
+opening a TLS connection. The first element is the TLS type (either
+`gnutls-x509pki' or `gnutls-anon'), and the remaining elements should
+be a keyword list accepted by gnutls-boot (as returned by
+`gnutls-boot-parameters').
+
:server QLEN -- if QLEN is non-nil, create a server process for the
specified FAMILY, SERVICE, and connection type (stream or datagram).
If QLEN is an integer, it is used as the max. length of the server's
@@ -3067,41 +3594,24 @@ usage: (make-network-process &rest ARGS) */)
Lisp_Object proc;
Lisp_Object contact;
struct Lisp_Process *p;
-#ifdef HAVE_GETADDRINFO
- struct addrinfo ai, *res, *lres;
- struct addrinfo hints;
const char *portstring;
- char portbuf[128];
-#else /* HAVE_GETADDRINFO */
- struct _emacs_addrinfo
- {
- int ai_family;
- int ai_socktype;
- int ai_protocol;
- int ai_addrlen;
- struct sockaddr *ai_addr;
- struct _emacs_addrinfo *ai_next;
- } ai, *res, *lres;
-#endif /* HAVE_GETADDRINFO */
- struct sockaddr_in address_in;
+ ptrdiff_t portstringlen ATTRIBUTE_UNUSED;
+ char portbuf[INT_BUFSIZE_BOUND (EMACS_INT)];
#ifdef HAVE_LOCAL_SOCKETS
struct sockaddr_un address_un;
#endif
- int port;
- int ret = 0;
- int xerrno = 0;
- int s = -1, outch, inch;
- ptrdiff_t count = SPECPDL_INDEX ();
- ptrdiff_t count1;
- Lisp_Object colon_address; /* Either QClocal or QCremote. */
+ EMACS_INT port = 0;
Lisp_Object tem;
Lisp_Object name, buffer, host, service, address;
Lisp_Object filter, sentinel;
- bool is_non_blocking_client = 0;
- bool is_server = 0;
- int backlog = 5;
+ Lisp_Object ip_addresses = Qnil;
int socktype;
int family = -1;
+ int ai_protocol = 0;
+#ifdef HAVE_GETADDRINFO_A
+ struct gaicb *dns_request = NULL;
+#endif
+ ptrdiff_t count = SPECPDL_INDEX ();
if (nargs == 0)
return Qnil;
@@ -3129,31 +3639,6 @@ usage: (make-network-process &rest ARGS) */)
else
error ("Unsupported connection type");
- /* :server BOOL */
- tem = Fplist_get (contact, QCserver);
- if (!NILP (tem))
- {
- /* Don't support network sockets when non-blocking mode is
- not available, since a blocked Emacs is not useful. */
- is_server = 1;
- if (TYPE_RANGED_INTEGERP (int, tem))
- backlog = XINT (tem);
- }
-
- /* Make colon_address an alias for :local (server) or :remote (client). */
- colon_address = is_server ? QClocal : QCremote;
-
- /* :nowait BOOL */
- if (!is_server && socktype != SOCK_DGRAM
- && (tem = Fplist_get (contact, QCnowait), !NILP (tem)))
- {
-#ifndef NON_BLOCKING_CONNECT
- error ("Non-blocking connect not supported");
-#else
- is_non_blocking_client = 1;
-#endif
- }
-
name = Fplist_get (contact, QCname);
buffer = Fplist_get (contact, QCbuffer);
filter = Fplist_get (contact, QCfilter);
@@ -3161,23 +3646,20 @@ usage: (make-network-process &rest ARGS) */)
CHECK_STRING (name);
- /* Initialize addrinfo structure in case we don't use getaddrinfo. */
- ai.ai_socktype = socktype;
- ai.ai_protocol = 0;
- ai.ai_next = NULL;
- res = &ai;
-
/* :local ADDRESS or :remote ADDRESS */
- address = Fplist_get (contact, colon_address);
+ tem = Fplist_get (contact, QCserver);
+ if (!NILP (tem))
+ address = Fplist_get (contact, QCremote);
+ else
+ address = Fplist_get (contact, QClocal);
if (!NILP (address))
{
host = service = Qnil;
- if (!(ai.ai_addrlen = get_lisp_to_sockaddr_size (address, &family)))
+ if (!get_lisp_to_sockaddr_size (address, &family))
error ("Malformed :address");
- ai.ai_family = family;
- ai.ai_addr = alloca (ai.ai_addrlen);
- conv_lisp_to_sockaddr (family, address, ai.ai_addr, ai.ai_addrlen);
+
+ ip_addresses = list1 (address);
goto open_socket;
}
@@ -3185,7 +3667,7 @@ usage: (make-network-process &rest ARGS) */)
tem = Fplist_get (contact, QCfamily);
if (NILP (tem))
{
-#if defined (HAVE_GETADDRINFO) && defined (AF_INET6)
+#ifdef AF_INET6
family = AF_UNSPEC;
#else
family = AF_INET;
@@ -3206,14 +3688,21 @@ usage: (make-network-process &rest ARGS) */)
else
error ("Unknown address family");
- ai.ai_family = family;
-
/* :service SERVICE -- string, integer (port number), or t (random port). */
service = Fplist_get (contact, QCservice);
/* :host HOST -- hostname, ip address, or 'local for localhost. */
host = Fplist_get (contact, QChost);
- if (!NILP (host))
+ if (NILP (host))
+ {
+ /* The "connection" function gets it bind info from the address we're
+ given, so use this dummy address if nothing is specified. */
+#ifdef HAVE_LOCAL_SOCKETS
+ if (family != AF_LOCAL)
+#endif
+ host = build_string ("127.0.0.1");
+ }
+ else
{
if (EQ (host, Qlocal))
/* Depending on setup, "localhost" may map to different IPv4 and/or
@@ -3232,13 +3721,9 @@ usage: (make-network-process &rest ARGS) */)
host = Qnil;
}
CHECK_STRING (service);
- memset (&address_un, 0, sizeof address_un);
- address_un.sun_family = AF_LOCAL;
if (sizeof address_un.sun_path <= SBYTES (service))
error ("Service name too long");
- lispstpcpy (address_un.sun_path, service);
- ai.ai_addr = (struct sockaddr *) &address_un;
- ai.ai_addrlen = sizeof address_un;
+ ip_addresses = list1 (service);
goto open_socket;
}
#endif
@@ -3254,359 +3739,147 @@ usage: (make-network-process &rest ARGS) */)
}
#endif
-#ifdef HAVE_GETADDRINFO
- /* If we have a host, use getaddrinfo to resolve both host and service.
- Otherwise, use getservbyname to lookup the service. */
if (!NILP (host))
{
-
/* SERVICE can either be a string or int.
Convert to a C string for later use by getaddrinfo. */
if (EQ (service, Qt))
- portstring = "0";
+ {
+ portstring = "0";
+ portstringlen = 1;
+ }
else if (INTEGERP (service))
{
- sprintf (portbuf, "%"pI"d", XINT (service));
portstring = portbuf;
+ portstringlen = sprintf (portbuf, "%"pI"d", XINT (service));
}
else
{
CHECK_STRING (service);
portstring = SSDATA (service);
+ portstringlen = SBYTES (service);
}
+ }
- immediate_quit = 1;
- QUIT;
- memset (&hints, 0, sizeof (hints));
- hints.ai_flags = 0;
- hints.ai_family = family;
- hints.ai_socktype = socktype;
- hints.ai_protocol = 0;
-
-#ifdef HAVE_RES_INIT
- res_init ();
-#endif
-
- ret = getaddrinfo (SSDATA (host), portstring, &hints, &res);
+#ifdef HAVE_GETADDRINFO_A
+ if (!NILP (host) && !NILP (Fplist_get (contact, QCnowait)))
+ {
+ ptrdiff_t hostlen = SBYTES (host);
+ struct req
+ {
+ struct gaicb gaicb;
+ struct addrinfo hints;
+ char str[FLEXIBLE_ARRAY_MEMBER];
+ } *req = xmalloc (offsetof (struct req, str)
+ + hostlen + 1 + portstringlen + 1);
+ dns_request = &req->gaicb;
+ dns_request->ar_name = req->str;
+ dns_request->ar_service = req->str + hostlen + 1;
+ dns_request->ar_request = &req->hints;
+ dns_request->ar_result = NULL;
+ memset (&req->hints, 0, sizeof req->hints);
+ req->hints.ai_family = family;
+ req->hints.ai_socktype = socktype;
+ strcpy (req->str, SSDATA (host));
+ strcpy (req->str + hostlen + 1, portstring);
+
+ int ret = getaddrinfo_a (GAI_NOWAIT, &dns_request, 1, NULL);
if (ret)
-#ifdef HAVE_GAI_STRERROR
- error ("%s/%s %s", SSDATA (host), portstring, gai_strerror (ret));
-#else
- error ("%s/%s getaddrinfo error %d", SSDATA (host), portstring, ret);
-#endif
- immediate_quit = 0;
+ error ("%s/%s getaddrinfo_a error %d", SSDATA (host), portstring, ret);
goto open_socket;
}
-#endif /* HAVE_GETADDRINFO */
-
- /* We end up here if getaddrinfo is not defined, or in case no hostname
- has been specified (e.g. for a local server process). */
+#endif /* HAVE_GETADDRINFO_A */
- if (EQ (service, Qt))
- port = 0;
- else if (INTEGERP (service))
- port = htons ((unsigned short) XINT (service));
- else
- {
- struct servent *svc_info;
- CHECK_STRING (service);
- svc_info = getservbyname (SSDATA (service),
- (socktype == SOCK_DGRAM ? "udp" : "tcp"));
- if (svc_info == 0)
- error ("Unknown service: %s", SDATA (service));
- port = svc_info->s_port;
- }
-
- memset (&address_in, 0, sizeof address_in);
- address_in.sin_family = family;
- address_in.sin_addr.s_addr = INADDR_ANY;
- address_in.sin_port = port;
+ /* If we have a host, use getaddrinfo to resolve both host and service.
+ Otherwise, use getservbyname to lookup the service. */
-#ifndef HAVE_GETADDRINFO
if (!NILP (host))
{
- struct hostent *host_info_ptr;
-
- /* gethostbyname may fail with TRY_AGAIN, but we don't honor that,
- as it may `hang' Emacs for a very long time. */
- immediate_quit = 1;
- QUIT;
-
-#ifdef HAVE_RES_INIT
- res_init ();
-#endif
-
- host_info_ptr = gethostbyname (SDATA (host));
- immediate_quit = 0;
-
- if (host_info_ptr)
- {
- memcpy (&address_in.sin_addr, host_info_ptr->h_addr,
- host_info_ptr->h_length);
- family = host_info_ptr->h_addrtype;
- address_in.sin_family = family;
- }
- else
- /* Attempt to interpret host as numeric inet address. */
- {
- unsigned long numeric_addr;
- numeric_addr = inet_addr (SSDATA (host));
- if (numeric_addr == -1)
- error ("Unknown host \"%s\"", SDATA (host));
-
- memcpy (&address_in.sin_addr, &numeric_addr,
- sizeof (address_in.sin_addr));
- }
-
- }
-#endif /* not HAVE_GETADDRINFO */
-
- ai.ai_family = family;
- ai.ai_addr = (struct sockaddr *) &address_in;
- ai.ai_addrlen = sizeof address_in;
-
- open_socket:
-
- /* Do this in case we never enter the for-loop below. */
- count1 = SPECPDL_INDEX ();
- s = -1;
-
- for (lres = res; lres; lres = lres->ai_next)
- {
- ptrdiff_t optn;
- int optbits;
-
-#ifdef WINDOWSNT
- retry_connect:
-#endif
-
- s = socket (lres->ai_family, lres->ai_socktype | SOCK_CLOEXEC,
- lres->ai_protocol);
- if (s < 0)
- {
- xerrno = errno;
- continue;
- }
-
-#ifdef DATAGRAM_SOCKETS
- if (!is_server && socktype == SOCK_DGRAM)
- break;
-#endif /* DATAGRAM_SOCKETS */
-
-#ifdef NON_BLOCKING_CONNECT
- if (is_non_blocking_client)
- {
- ret = fcntl (s, F_SETFL, O_NONBLOCK);
- if (ret < 0)
- {
- xerrno = errno;
- emacs_close (s);
- s = -1;
- continue;
- }
- }
-#endif
-
- /* Make us close S if quit. */
- record_unwind_protect_int (close_file_unwind, s);
-
- /* Parse network options in the arg list.
- We simply ignore anything which isn't a known option (including other keywords).
- An error is signaled if setting a known option fails. */
- for (optn = optbits = 0; optn < nargs - 1; optn += 2)
- optbits |= set_socket_option (s, args[optn], args[optn + 1]);
-
- if (is_server)
- {
- /* Configure as a server socket. */
-
- /* SO_REUSEADDR = 1 is default for server sockets; must specify
- explicit :reuseaddr key to override this. */
-#ifdef HAVE_LOCAL_SOCKETS
- if (family != AF_LOCAL)
-#endif
- if (!(optbits & (1 << OPIX_REUSEADDR)))
- {
- int optval = 1;
- if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval))
- report_file_error ("Cannot set reuse option on server socket", Qnil);
- }
-
- if (bind (s, lres->ai_addr, lres->ai_addrlen))
- report_file_error ("Cannot bind server socket", Qnil);
-
-#ifdef HAVE_GETSOCKNAME
- if (EQ (service, Qt))
- {
- struct sockaddr_in sa1;
- socklen_t len1 = sizeof (sa1);
- if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
- {
- ((struct sockaddr_in *)(lres->ai_addr))->sin_port = sa1.sin_port;
- service = make_number (ntohs (sa1.sin_port));
- contact = Fplist_put (contact, QCservice, service);
- }
- }
-#endif
-
- if (socktype != SOCK_DGRAM && listen (s, backlog))
- report_file_error ("Cannot listen on server socket", Qnil);
-
- break;
- }
+ struct addrinfo *res, *lres;
+ int ret;
immediate_quit = 1;
QUIT;
- ret = connect (s, lres->ai_addr, lres->ai_addrlen);
- xerrno = errno;
+ struct addrinfo hints;
+ memset (&hints, 0, sizeof hints);
+ hints.ai_family = family;
+ hints.ai_socktype = socktype;
- if (ret == 0 || xerrno == EISCONN)
+ ret = getaddrinfo (SSDATA (host), portstring, &hints, &res);
+ if (ret)
+#ifdef HAVE_GAI_STRERROR
{
- /* The unwind-protect will be discarded afterwards.
- Likewise for immediate_quit. */
- break;
+ synchronize_system_messages_locale ();
+ char const *str = gai_strerror (ret);
+ if (! NILP (Vlocale_coding_system))
+ str = SSDATA (code_convert_string_norecord
+ (build_string (str), Vlocale_coding_system, 0));
+ error ("%s/%s %s", SSDATA (host), portstring, str);
}
-
-#ifdef NON_BLOCKING_CONNECT
-#ifdef EINPROGRESS
- if (is_non_blocking_client && xerrno == EINPROGRESS)
- break;
#else
-#ifdef EWOULDBLOCK
- if (is_non_blocking_client && xerrno == EWOULDBLOCK)
- break;
-#endif
-#endif
+ error ("%s/%s getaddrinfo error %d", SSDATA (host), portstring, ret);
#endif
+ immediate_quit = 0;
-#ifndef WINDOWSNT
- if (xerrno == EINTR)
+ for (lres = res; lres; lres = lres->ai_next)
{
- /* Unlike most other syscalls connect() cannot be called
- again. (That would return EALREADY.) The proper way to
- wait for completion is pselect(). */
- int sc;
- socklen_t len;
- fd_set fdset;
- retry_select:
- FD_ZERO (&fdset);
- FD_SET (s, &fdset);
- QUIT;
- sc = pselect (s + 1, NULL, &fdset, NULL, NULL, NULL);
- if (sc == -1)
- {
- if (errno == EINTR)
- goto retry_select;
- else
- report_file_error ("Failed select", Qnil);
- }
- eassert (sc > 0);
-
- len = sizeof xerrno;
- eassert (FD_ISSET (s, &fdset));
- if (getsockopt (s, SOL_SOCKET, SO_ERROR, &xerrno, &len) < 0)
- report_file_error ("Failed getsockopt", Qnil);
- if (xerrno)
- report_file_errno ("Failed connect", Qnil, xerrno);
- break;
+ ip_addresses = Fcons (conv_sockaddr_to_lisp
+ (lres->ai_addr, lres->ai_addrlen),
+ ip_addresses);
+ ai_protocol = lres->ai_protocol;
}
-#endif /* !WINDOWSNT */
- immediate_quit = 0;
+ ip_addresses = Fnreverse (ip_addresses);
- /* Discard the unwind protect closing S. */
- specpdl_ptr = specpdl + count1;
- emacs_close (s);
- s = -1;
+ freeaddrinfo (res);
-#ifdef WINDOWSNT
- if (xerrno == EINTR)
- goto retry_connect;
-#endif
+ goto open_socket;
}
- if (s >= 0)
+ /* No hostname has been specified (e.g., a local server process). */
+
+ if (EQ (service, Qt))
+ port = 0;
+ else if (INTEGERP (service))
+ port = XINT (service);
+ else
{
-#ifdef DATAGRAM_SOCKETS
- if (socktype == SOCK_DGRAM)
+ CHECK_STRING (service);
+
+ port = -1;
+ if (SBYTES (service) != 0)
{
- if (datagram_address[s].sa)
- emacs_abort ();
- datagram_address[s].sa = xmalloc (lres->ai_addrlen);
- datagram_address[s].len = lres->ai_addrlen;
- if (is_server)
+ /* Allow the service to be a string containing the port number,
+ because that's allowed if you have getaddrbyname. */
+ char *service_end;
+ long int lport = strtol (SSDATA (service), &service_end, 10);
+ if (service_end == SSDATA (service) + SBYTES (service))
+ port = lport;
+ else
{
- Lisp_Object remote;
- memset (datagram_address[s].sa, 0, lres->ai_addrlen);
- if (remote = Fplist_get (contact, QCremote), !NILP (remote))
- {
- int rfamily, rlen;
- rlen = get_lisp_to_sockaddr_size (remote, &rfamily);
- if (rlen != 0 && rfamily == lres->ai_family
- && rlen == lres->ai_addrlen)
- conv_lisp_to_sockaddr (rfamily, remote,
- datagram_address[s].sa, rlen);
- }
+ struct servent *svc_info
+ = getservbyname (SSDATA (service),
+ socktype == SOCK_DGRAM ? "udp" : "tcp");
+ if (svc_info)
+ port = ntohs (svc_info->s_port);
}
- else
- memcpy (datagram_address[s].sa, lres->ai_addr, lres->ai_addrlen);
}
-#endif
- contact = Fplist_put (contact, colon_address,
- conv_sockaddr_to_lisp (lres->ai_addr, lres->ai_addrlen));
-#ifdef HAVE_GETSOCKNAME
- if (!is_server)
- {
- struct sockaddr_in sa1;
- socklen_t len1 = sizeof (sa1);
- if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
- contact = Fplist_put (contact, QClocal,
- conv_sockaddr_to_lisp ((struct sockaddr *)&sa1, len1));
- }
-#endif
}
- immediate_quit = 0;
-
-#ifdef HAVE_GETADDRINFO
- if (res != &ai)
+ if (! (0 <= port && port < 1 << 16))
{
- block_input ();
- freeaddrinfo (res);
- unblock_input ();
- }
-#endif
-
- if (s < 0)
- {
- /* If non-blocking got this far - and failed - assume non-blocking is
- not supported after all. This is probably a wrong assumption, but
- the normal blocking calls to open-network-stream handles this error
- better. */
- if (is_non_blocking_client)
- return Qnil;
-
- report_file_errno ((is_server
- ? "make server process failed"
- : "make client process failed"),
- contact, xerrno);
+ AUTO_STRING (unknown_service, "Unknown service: %s");
+ xsignal1 (Qerror, CALLN (Fformat, unknown_service, service));
}
- inch = s;
- outch = s;
+ open_socket:
if (!NILP (buffer))
buffer = Fget_buffer_create (buffer);
proc = make_process (name);
-
- chan_process[inch] = proc;
-
- fcntl (inch, F_SETFL, O_NONBLOCK);
-
p = XPROCESS (proc);
-
pset_childp (p, contact);
pset_plist (p, Fcopy_sequence (Fplist_get (contact, QCplist)));
pset_type (p, Qnetwork);
@@ -3620,135 +3893,59 @@ usage: (make-network-process &rest ARGS) */)
if ((tem = Fplist_get (contact, QCstop), !NILP (tem)))
pset_command (p, Qt);
p->pid = 0;
+ p->backlog = 5;
+ p->is_non_blocking_client = 0;
+ p->is_server = 0;
+ p->port = port;
+ p->socktype = socktype;
+ p->ai_protocol = ai_protocol;
+#ifdef HAVE_GETADDRINFO_A
+ p->dns_request = NULL;
+#endif
+#ifdef HAVE_GNUTLS
+ tem = Fplist_get (contact, QCtls_parameters);
+ CHECK_LIST (tem);
+ p->gnutls_boot_parameters = tem;
+#endif
- p->open_fd[SUBPROCESS_STDIN] = inch;
- p->infd = inch;
- p->outfd = outch;
-
- /* Discard the unwind protect for closing S, if any. */
- specpdl_ptr = specpdl + count1;
+ set_network_socket_coding_system (proc, service, host, name);
- /* Unwind bind_polling_period and request_sigio. */
unbind_to (count, Qnil);
- if (is_server && socktype != SOCK_DGRAM)
- pset_status (p, Qlisten);
+ /* :server BOOL */
+ tem = Fplist_get (contact, QCserver);
+ if (!NILP (tem))
+ {
+ /* Don't support network sockets when non-blocking mode is
+ not available, since a blocked Emacs is not useful. */
+ p->is_server = 1;
+ if (TYPE_RANGED_INTEGERP (int, tem))
+ p->backlog = XINT (tem);
+ }
- /* Make the process marker point into the process buffer (if any). */
- if (BUFFERP (buffer))
- set_marker_both (p->mark, buffer,
- BUF_ZV (XBUFFER (buffer)),
- BUF_ZV_BYTE (XBUFFER (buffer)));
+ /* :nowait BOOL */
+ if (!p->is_server && socktype != SOCK_DGRAM
+ && (tem = Fplist_get (contact, QCnowait), !NILP (tem)))
+ {
+#ifndef NON_BLOCKING_CONNECT
+ error ("Non-blocking connect not supported");
+#else
+ p->is_non_blocking_client = 1;
+#endif
+ }
-#ifdef NON_BLOCKING_CONNECT
- if (is_non_blocking_client)
+#ifdef HAVE_GETADDRINFO_A
+ /* With async address resolution, the list of addresses is empty, so
+ postpone connecting to the server. */
+ if (!p->is_server && NILP (ip_addresses))
{
- /* We may get here if connect did succeed immediately. However,
- in that case, we still need to signal this like a non-blocking
- connection. */
- pset_status (p, Qconnect);
- if (!FD_ISSET (inch, &connect_wait_mask))
- {
- FD_SET (inch, &connect_wait_mask);
- FD_SET (inch, &write_mask);
- num_pending_connects++;
- }
+ p->dns_request = dns_request;
+ p->status = Qconnect;
+ return proc;
}
- else
#endif
- /* A server may have a client filter setting of Qt, but it must
- still listen for incoming connects unless it is stopped. */
- if ((!EQ (p->filter, Qt) && !EQ (p->command, Qt))
- || (EQ (p->status, Qlisten) && NILP (p->command)))
- {
- FD_SET (inch, &input_wait_mask);
- FD_SET (inch, &non_keyboard_wait_mask);
- }
-
- if (inch > max_process_desc)
- max_process_desc = inch;
-
- tem = Fplist_member (contact, QCcoding);
- if (!NILP (tem) && (!CONSP (tem) || !CONSP (XCDR (tem))))
- tem = Qnil; /* No error message (too late!). */
-
- {
- /* Setup coding systems for communicating with the network stream. */
- /* Qt denotes we have not yet called Ffind_operation_coding_system. */
- Lisp_Object coding_systems = Qt;
- Lisp_Object val;
-
- if (!NILP (tem))
- {
- val = XCAR (XCDR (tem));
- if (CONSP (val))
- val = XCAR (val);
- }
- else if (!NILP (Vcoding_system_for_read))
- val = Vcoding_system_for_read;
- else if ((!NILP (buffer) && NILP (BVAR (XBUFFER (buffer), enable_multibyte_characters)))
- || (NILP (buffer) && NILP (BVAR (&buffer_defaults, enable_multibyte_characters))))
- /* We dare not decode end-of-line format by setting VAL to
- Qraw_text, because the existing Emacs Lisp libraries
- assume that they receive bare code including a sequence of
- CR LF. */
- val = Qnil;
- else
- {
- if (NILP (host) || NILP (service))
- coding_systems = Qnil;
- else
- coding_systems = CALLN (Ffind_operation_coding_system,
- Qopen_network_stream, name, buffer,
- host, service);
- if (CONSP (coding_systems))
- val = XCAR (coding_systems);
- else if (CONSP (Vdefault_process_coding_system))
- val = XCAR (Vdefault_process_coding_system);
- else
- val = Qnil;
- }
- pset_decode_coding_system (p, val);
-
- if (!NILP (tem))
- {
- val = XCAR (XCDR (tem));
- if (CONSP (val))
- val = XCDR (val);
- }
- else if (!NILP (Vcoding_system_for_write))
- val = Vcoding_system_for_write;
- else if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
- val = Qnil;
- else
- {
- if (EQ (coding_systems, Qt))
- {
- if (NILP (host) || NILP (service))
- coding_systems = Qnil;
- else
- coding_systems = CALLN (Ffind_operation_coding_system,
- Qopen_network_stream, name, buffer,
- host, service);
- }
- if (CONSP (coding_systems))
- val = XCDR (coding_systems);
- else if (CONSP (Vdefault_process_coding_system))
- val = XCDR (Vdefault_process_coding_system);
- else
- val = Qnil;
- }
- pset_encode_coding_system (p, val);
- }
- setup_process_coding_systems (proc);
-
- pset_decoding_buf (p, empty_unibyte_string);
- p->decoding_carryover = 0;
- pset_encoding_buf (p, empty_unibyte_string);
-
- p->inherit_coding_system_flag
- = !(!NILP (tem) || NILP (buffer) || !inherit_process_coding_system);
+ connect_network_socket (proc, ip_addresses);
return proc;
}
@@ -4453,6 +4650,91 @@ server_accept_connection (Lisp_Object server, int channel)
exec_sentinel (proc, concat3 (open_from, host_string, nl));
}
+#ifdef HAVE_GETADDRINFO_A
+static Lisp_Object
+check_for_dns (Lisp_Object proc)
+{
+ struct Lisp_Process *p = XPROCESS (proc);
+ Lisp_Object ip_addresses = Qnil;
+
+ /* Sanity check. */
+ if (! p->dns_request)
+ return Qnil;
+
+ int ret = gai_error (p->dns_request);
+ if (ret == EAI_INPROGRESS)
+ return Qt;
+
+ /* We got a response. */
+ if (ret == 0)
+ {
+ struct addrinfo *res;
+
+ for (res = p->dns_request->ar_result; res; res = res->ai_next)
+ {
+ ip_addresses = Fcons (conv_sockaddr_to_lisp
+ (res->ai_addr, res->ai_addrlen),
+ ip_addresses);
+ }
+
+ ip_addresses = Fnreverse (ip_addresses);
+ }
+ /* The DNS lookup failed. */
+ else if (EQ (p->status, Qconnect))
+ {
+ deactivate_process (proc);
+ pset_status (p, (list2
+ (Qfailed,
+ concat3 (build_string ("Name lookup of "),
+ build_string (p->dns_request->ar_name),
+ build_string (" failed")))));
+ }
+
+ free_dns_request (proc);
+
+ /* This process should not already be connected (or killed). */
+ if (!EQ (p->status, Qconnect))
+ return Qnil;
+
+ return ip_addresses;
+}
+
+#endif /* HAVE_GETADDRINFO_A */
+
+static void
+wait_for_socket_fds (Lisp_Object process, char const *name)
+{
+ while (XPROCESS (process)->infd < 0
+ && EQ (XPROCESS (process)->status, Qconnect))
+ {
+ add_to_log ("Waiting for socket from %s...", build_string (name));
+ wait_reading_process_output (0, 20 * 1000 * 1000, 0, 0, Qnil, NULL, 0);
+ }
+}
+
+static void
+wait_while_connecting (Lisp_Object process)
+{
+ while (EQ (XPROCESS (process)->status, Qconnect))
+ {
+ add_to_log ("Waiting for connection...");
+ wait_reading_process_output (0, 20 * 1000 * 1000, 0, 0, Qnil, NULL, 0);
+ }
+}
+
+static void
+wait_for_tls_negotiation (Lisp_Object process)
+{
+#ifdef HAVE_GNUTLS
+ while (XPROCESS (process)->gnutls_p
+ && XPROCESS (process)->gnutls_initstage != GNUTLS_STAGE_READY)
+ {
+ add_to_log ("Waiting for TLS...");
+ wait_reading_process_output (0, 20 * 1000 * 1000, 0, 0, Qnil, NULL, 0);
+ }
+#endif
+}
+
/* This variable is different from waiting_for_input in keyboard.c.
It is used to communicate to a lisp process-filter/sentinel (via the
function Fwaiting_for_user_input_p below) whether Emacs was waiting
@@ -4531,6 +4813,9 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
struct timespec got_output_end_time = invalid_timespec ();
enum { MINIMUM = -1, TIMEOUT, INFINITY } wait;
int got_some_output = -1;
+#if defined HAVE_GETADDRINFO_A || defined HAVE_GNUTLS
+ bool retry_for_async;
+#endif
ptrdiff_t count = SPECPDL_INDEX ();
/* Close to the current time if known, an invalid timespec otherwise. */
@@ -4578,6 +4863,60 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell)))
break;
+#if defined HAVE_GETADDRINFO_A || defined HAVE_GNUTLS
+ {
+ Lisp_Object process_list_head, aproc;
+ struct Lisp_Process *p;
+
+ retry_for_async = false;
+ FOR_EACH_PROCESS(process_list_head, aproc)
+ {
+ p = XPROCESS (aproc);
+
+ if (! wait_proc || p == wait_proc)
+ {
+#ifdef HAVE_GETADDRINFO_A
+ /* Check for pending DNS requests. */
+ if (p->dns_request)
+ {
+ Lisp_Object ip_addresses = check_for_dns (aproc);
+ if (!NILP (ip_addresses) && !EQ (ip_addresses, Qt))
+ connect_network_socket (aproc, ip_addresses);
+ else
+ retry_for_async = true;
+ }
+#endif
+#ifdef HAVE_GNUTLS
+ /* Continue TLS negotiation. */
+ if (p->gnutls_initstage == GNUTLS_STAGE_HANDSHAKE_TRIED
+ && p->is_non_blocking_client)
+ {
+ gnutls_try_handshake (p);
+ p->gnutls_handshakes_tried++;
+
+ if (p->gnutls_initstage == GNUTLS_STAGE_READY)
+ {
+ gnutls_verify_boot (aproc, Qnil);
+ finish_after_tls_connection (aproc);
+ }
+ else
+ {
+ retry_for_async = true;
+ if (p->gnutls_handshakes_tried
+ > GNUTLS_EMACS_HANDSHAKES_LIMIT)
+ {
+ deactivate_process (aproc);
+ pset_status (p, list2 (Qfailed,
+ build_string ("TLS negotiation failed")));
+ }
+ }
+ }
+#endif
+ }
+ }
+ }
+#endif /* GETADDRINFO_A or GNUTLS */
+
/* Compute time from now till when time limit is up. */
/* Exit if already run out. */
if (wait == TIMEOUT)
@@ -4836,6 +5175,15 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
if (timeout.tv_sec > 0 || timeout.tv_nsec > 0)
now = invalid_timespec ();
+#if defined HAVE_GETADDRINFO_A || defined HAVE_GNUTLS
+ if (retry_for_async
+ && (timeout.tv_sec > 0 || timeout.tv_nsec > ASYNC_RETRY_NSEC))
+ {
+ timeout.tv_sec = 0;
+ timeout.tv_nsec = ASYNC_RETRY_NSEC;
+ }
+#endif
+
#if defined (HAVE_NS)
nfds = ns_select
#elif defined (HAVE_GLIB)
@@ -5197,11 +5545,21 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
}
else
{
- pset_status (p, Qrun);
- /* Execute the sentinel here. If we had relied on
- status_notify to do it later, it will read input
- from the process before calling the sentinel. */
- exec_sentinel (proc, build_string ("open\n"));
+#ifdef HAVE_GNUTLS
+ /* If we have an incompletely set up TLS connection,
+ then defer the sentinel signalling until
+ later. */
+ if (NILP (p->gnutls_boot_parameters)
+ && !p->gnutls_p)
+#endif
+ {
+ pset_status (p, Qrun);
+ /* Execute the sentinel here. If we had relied on
+ status_notify to do it later, it will read input
+ from the process before calling the sentinel. */
+ exec_sentinel (proc, build_string ("open\n"));
+ }
+
if (0 <= p->infd && !EQ (p->filter, Qt)
&& !EQ (p->command, Qt))
{
@@ -5658,6 +6016,12 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len,
ssize_t rv;
struct coding_system *coding;
+ if (NETCONN_P (proc))
+ {
+ wait_while_connecting (proc);
+ wait_for_tls_negotiation (proc);
+ }
+
if (p->raw_status_new)
update_status (p);
if (! EQ (p->status, Qrun))
@@ -5875,7 +6239,10 @@ nil, indicating the current buffer's process.
Called from program, takes three arguments, PROCESS, START and END.
If the region is more than 500 characters long,
it is sent in several bunches. This may happen even for shorter regions.
-Output from processes can arrive in between bunches. */)
+Output from processes can arrive in between bunches.
+
+If PROCESS is a non-blocking network process that hasn't been fully
+set up yet, this function will block until socket setup has completed. */)
(Lisp_Object process, Lisp_Object start, Lisp_Object end)
{
Lisp_Object proc = get_process (process);
@@ -5889,6 +6256,9 @@ Output from processes can arrive in between bunches. */)
if (XINT (start) < GPT && XINT (end) > GPT)
move_gap_both (XINT (start), start_byte);
+ if (NETCONN_P (proc))
+ wait_while_connecting (proc);
+
send_process (proc, (char *) BYTE_POS_ADDR (start_byte),
end_byte - start_byte, Fcurrent_buffer ());
@@ -5902,12 +6272,14 @@ PROCESS may be a process, a buffer, the name of a process or buffer, or
nil, indicating the current buffer's process.
If STRING is more than 500 characters long,
it is sent in several bunches. This may happen even for shorter strings.
-Output from processes can arrive in between bunches. */)
+Output from processes can arrive in between bunches.
+
+If PROCESS is a non-blocking network process that hasn't been fully
+set up yet, this function will block until socket setup has completed. */)
(Lisp_Object process, Lisp_Object string)
{
- Lisp_Object proc;
CHECK_STRING (string);
- proc = get_process (process);
+ Lisp_Object proc = get_process (process);
send_process (proc, SSDATA (string),
SBYTES (string), string);
return Qnil;
@@ -5949,12 +6321,8 @@ process group. */)
{
/* Initialize in case ioctl doesn't exist or gives an error,
in a way that will cause returning t. */
- pid_t gid;
- Lisp_Object proc;
- struct Lisp_Process *p;
-
- proc = get_process (process);
- p = XPROCESS (proc);
+ Lisp_Object proc = get_process (process);
+ struct Lisp_Process *p = XPROCESS (proc);
if (!EQ (p->type, Qreal))
error ("Process %s is not a subprocess",
@@ -5963,7 +6331,7 @@ process group. */)
error ("Process %s is not active",
SDATA (p->name));
- gid = emacs_get_tty_pgrp (p);
+ pid_t gid = emacs_get_tty_pgrp (p);
if (gid == p->pid)
return Qnil;
@@ -6034,7 +6402,7 @@ process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group,
break;
case SIGTSTP:
-#if defined (VSWTCH) && !defined (PREFER_VSUSP)
+#ifdef VSWTCH
sig_char = &t.c_cc[VSWTCH];
#else
sig_char = &t.c_cc[VSUSP];
@@ -6322,10 +6690,15 @@ process has been transmitted to the serial port. */)
struct coding_system *coding = NULL;
int outfd;
- if (DATAGRAM_CONN_P (process))
+ proc = get_process (process);
+
+ if (NETCONN_P (proc))
+ wait_while_connecting (proc);
+
+ if (DATAGRAM_CONN_P (proc))
return process;
- proc = get_process (process);
+
outfd = XPROCESS (proc)->outfd;
if (outfd >= 0)
coding = proc_encode_coding_system[outfd];
@@ -6770,22 +7143,24 @@ DEFUN ("set-process-coding-system", Fset_process_coding_system,
Sset_process_coding_system, 1, 3, 0,
doc: /* Set coding systems of PROCESS to DECODING and ENCODING.
DECODING will be used to decode subprocess output and ENCODING to
-encode subprocess input. */)
- (register Lisp_Object process, Lisp_Object decoding, Lisp_Object encoding)
+encode subprocess input. */)
+ (Lisp_Object process, Lisp_Object decoding, Lisp_Object encoding)
{
- register struct Lisp_Process *p;
-
CHECK_PROCESS (process);
- p = XPROCESS (process);
- if (p->infd < 0)
- error ("Input file descriptor of %s closed", SDATA (p->name));
- if (p->outfd < 0)
- error ("Output file descriptor of %s closed", SDATA (p->name));
+
+ struct Lisp_Process *p = XPROCESS (process);
+
Fcheck_coding_system (decoding);
Fcheck_coding_system (encoding);
encoding = coding_inherit_eol_type (encoding, Qnil);
pset_decode_coding_system (p, decoding);
pset_encode_coding_system (p, encoding);
+
+ /* If the sockets haven't been set up yet, the final setup part of
+ this will be called asynchronously. */
+ if (p->infd < 0 || p->outfd < 0)
+ return Qnil;
+
setup_process_coding_systems (process);
return Qnil;
@@ -6810,13 +7185,18 @@ all character code conversion except for end-of-line conversion is
suppressed. */)
(Lisp_Object process, Lisp_Object flag)
{
- register struct Lisp_Process *p;
-
CHECK_PROCESS (process);
- p = XPROCESS (process);
+
+ struct Lisp_Process *p = XPROCESS (process);
if (NILP (flag))
pset_decode_coding_system
(p, raw_text_coding_system (p->decode_coding_system));
+
+ /* If the sockets haven't been set up yet, the final setup part of
+ this will be called asynchronously. */
+ if (p->infd < 0 || p->outfd < 0)
+ return Qnil;
+
setup_process_coding_systems (process);
return Qnil;
@@ -6827,14 +7207,11 @@ DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p,
doc: /* Return t if a multibyte string is given to PROCESS's filter.*/)
(Lisp_Object process)
{
- register struct Lisp_Process *p;
- struct coding_system *coding;
-
CHECK_PROCESS (process);
- p = XPROCESS (process);
+ struct Lisp_Process *p = XPROCESS (process);
if (p->infd < 0)
return Qnil;
- coding = proc_decode_coding_system[p->infd];
+ struct coding_system *coding = proc_decode_coding_system[p->infd];
return (CODING_FOR_UNIBYTE (coding) ? Qnil : Qt);
}
@@ -7501,6 +7878,8 @@ syms_of_process (void)
DEFSYM (QCserver, ":server");
DEFSYM (QCnowait, ":nowait");
DEFSYM (QCsentinel, ":sentinel");
+ DEFSYM (QCtls_parameters, ":tls-parameters");
+ DEFSYM (Qnsm_verify_connection, "nsm-verify-connection");
DEFSYM (QClog, ":log");
DEFSYM (QCnoquery, ":noquery");
DEFSYM (QCstop, ":stop");
diff --git a/src/process.h b/src/process.h
index 2e743a3dc38..20593f5e8fa 100644
--- a/src/process.h
+++ b/src/process.h
@@ -106,6 +106,7 @@ struct Lisp_Process
#ifdef HAVE_GNUTLS
Lisp_Object gnutls_cred_type;
+ Lisp_Object gnutls_boot_parameters;
#endif
/* Pipe process attached to the standard error of this process. */
@@ -161,7 +162,25 @@ struct Lisp_Process
flag indicates that `raw_status' contains a new status that still
needs to be synced to `status'. */
bool_bf raw_status_new : 1;
+ /* Whether this is a nonblocking socket. */
+ bool_bf is_non_blocking_client : 1;
+ /* Whether this is a server or a client socket. */
+ bool_bf is_server : 1;
int raw_status;
+ /* The length of the socket backlog. */
+ int backlog;
+ /* The port number. */
+ int port;
+ /* The socket type. */
+ int socktype;
+ /* The socket protocol. */
+ int ai_protocol;
+
+#ifdef HAVE_GETADDRINFO_A
+ /* Whether the socket is waiting for response from an asynchronous
+ DNS call. */
+ struct gaicb *dns_request;
+#endif
#ifdef HAVE_GNUTLS
gnutls_initstage_t gnutls_initstage;
@@ -174,6 +193,7 @@ struct Lisp_Process
int gnutls_log_level;
int gnutls_handshakes_tried;
bool_bf gnutls_p : 1;
+ bool_bf gnutls_complete_negotiation_p : 1;
#endif
};
@@ -191,6 +211,12 @@ pset_childp (struct Lisp_Process *p, Lisp_Object val)
p->childp = val;
}
+INLINE void
+pset_status (struct Lisp_Process *p, Lisp_Object val)
+{
+ p->status = val;
+}
+
#ifdef HAVE_GNUTLS
INLINE void
pset_gnutls_cred_type (struct Lisp_Process *p, Lisp_Object val)
@@ -225,7 +251,7 @@ extern Lisp_Object system_process_attributes (Lisp_Object);
extern void record_deleted_pid (pid_t, Lisp_Object);
struct sockaddr;
-extern Lisp_Object conv_sockaddr_to_lisp (struct sockaddr *, int);
+extern Lisp_Object conv_sockaddr_to_lisp (struct sockaddr *, ptrdiff_t);
extern void hold_keyboard_input (void);
extern void unhold_keyboard_input (void);
extern bool kbd_on_hold_p (void);
diff --git a/src/ralloc.c b/src/ralloc.c
index a94f81b5bfe..071cee777e9 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -22,31 +22,15 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
rather than all of them. This means allowing for a possible
hole between the first bloc and the end of malloc storage. */
-#ifdef emacs
-
#include <config.h>
-#include "lisp.h" /* Needed for VALBITS. */
-#include "blockinput.h"
-
-#include <unistd.h>
-
-#ifdef DOUG_LEA_MALLOC
-#define M_TOP_PAD -2
-extern int mallopt (int, int);
-#else /* not DOUG_LEA_MALLOC */
-#if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
-extern size_t __malloc_extra_blocks;
-#endif /* not SYSTEM_MALLOC and not HYBRID_MALLOC */
-#endif /* not DOUG_LEA_MALLOC */
-
-#else /* not emacs */
-
#include <stddef.h>
-#include <malloc.h>
-
-#endif /* not emacs */
+#ifdef emacs
+# include "lisp.h"
+# include "blockinput.h"
+# include <unistd.h>
+#endif
#include "getpagesize.h"
@@ -95,7 +79,9 @@ static int extra_bytes;
/* The hook `malloc' uses for the function which gets more space
from the system. */
-#if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
+#ifdef HAVE_MALLOC_H
+# include <malloc.h>
+#else
extern void *(*__morecore) (ptrdiff_t);
#endif
diff --git a/src/regex.c b/src/regex.c
index 164eb4612ae..d5c58aeaf8b 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -5140,8 +5140,6 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1,
if (p == pend)
{
- ptrdiff_t dcnt;
-
/* End of pattern means we might have succeeded. */
DEBUG_PRINT ("end of pattern ... ");
@@ -5149,19 +5147,22 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1,
longest match, try backtracking. */
if (d != end_match_2)
{
- /* 1 if this match ends in the same string (string1 or string2)
- as the best previous match. */
- boolean same_str_p = (FIRST_STRING_P (match_end)
- == FIRST_STRING_P (d));
- /* 1 if this match is the best seen so far. */
- boolean best_match_p;
-
- /* AIX compiler got confused when this was combined
- with the previous declaration. */
- if (same_str_p)
- best_match_p = d > match_end;
- else
- best_match_p = !FIRST_STRING_P (d);
+ /* True if this match is the best seen so far. */
+ bool best_match_p;
+
+ {
+ /* True if this match ends in the same string (string1
+ or string2) as the best previous match. */
+ bool same_str_p = (FIRST_STRING_P (match_end)
+ == FIRST_STRING_P (d));
+
+ /* AIX compiler got confused when this was combined
+ with the previous declaration. */
+ if (same_str_p)
+ best_match_p = d > match_end;
+ else
+ best_match_p = !FIRST_STRING_P (d);
+ }
DEBUG_PRINT ("backtracking.\n");
@@ -5290,7 +5291,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1,
nfailure_points_pushed - nfailure_points_popped);
DEBUG_PRINT ("%u registers pushed.\n", num_regs_pushed);
- dcnt = POINTER_TO_OFFSET (d) - pos;
+ ptrdiff_t dcnt = POINTER_TO_OFFSET (d) - pos;
DEBUG_PRINT ("Returning %td from re_match_2.\n", dcnt);
diff --git a/src/sheap.c b/src/sheap.c
index fc53c5822d7..72b74fa355f 100644
--- a/src/sheap.c
+++ b/src/sheap.c
@@ -19,87 +19,62 @@ You should have received a copy of the GNU General Public License
along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
+
+#include "sheap.h"
+
#include <stdio.h>
#include "lisp.h"
#include <unistd.h>
#include <stdlib.h> /* for exit */
-#ifdef ENABLE_CHECKING
-#define STATIC_HEAP_SIZE (28 * 1024 * 1024)
-#else
-#define STATIC_HEAP_SIZE (19 * 1024 * 1024)
-#endif
-
-int debug_sheap = 0;
-
-#define BLOCKSIZE 4096
+static int debug_sheap;
char bss_sbrk_buffer[STATIC_HEAP_SIZE];
-/* The following is needed in gmalloc.c */
-void *bss_sbrk_buffer_end = bss_sbrk_buffer + STATIC_HEAP_SIZE;
-char *bss_sbrk_ptr;
char *max_bss_sbrk_ptr;
-int bss_sbrk_did_unexec;
+bool bss_sbrk_did_unexec;
void *
bss_sbrk (ptrdiff_t request_size)
{
+ static char *bss_sbrk_ptr;
+
if (!bss_sbrk_ptr)
{
max_bss_sbrk_ptr = bss_sbrk_ptr = bss_sbrk_buffer;
#ifdef CYGWIN
- sbrk (BLOCKSIZE); /* force space for fork to work */
+ /* Force space for fork to work. */
+ sbrk (4096);
#endif
}
- if (!(int) request_size)
- {
- return (bss_sbrk_ptr);
- }
- else if (bss_sbrk_ptr + (int) request_size < bss_sbrk_buffer)
+ int used = bss_sbrk_ptr - bss_sbrk_buffer;
+
+ if (request_size < -used)
{
- printf
- ("attempt to free too much: avail %d used %d failed request %d\n",
- STATIC_HEAP_SIZE, bss_sbrk_ptr - bss_sbrk_buffer,
- (int) request_size);
+ printf (("attempt to free too much: "
+ "avail %d used %d failed request %"pD"d\n"),
+ STATIC_HEAP_SIZE, used, request_size);
exit (-1);
return 0;
}
- else if (bss_sbrk_ptr + (int) request_size >
- bss_sbrk_buffer + STATIC_HEAP_SIZE)
+ else if (STATIC_HEAP_SIZE - used < request_size)
{
- printf ("static heap exhausted: avail %d used %d failed request %d\n",
- STATIC_HEAP_SIZE,
- bss_sbrk_ptr - bss_sbrk_buffer, (int) request_size);
+ printf ("static heap exhausted: avail %d used %d failed request %"pD"d\n",
+ STATIC_HEAP_SIZE, used, request_size);
exit (-1);
return 0;
}
- else if ((int) request_size < 0)
- {
- bss_sbrk_ptr += (int) request_size;
- if (debug_sheap)
- printf ("freed size %d\n", request_size);
- return bss_sbrk_ptr;
- }
- else
+
+ void *ret = bss_sbrk_ptr;
+ bss_sbrk_ptr += request_size;
+ if (max_bss_sbrk_ptr < bss_sbrk_ptr)
+ max_bss_sbrk_ptr = bss_sbrk_ptr;
+ if (debug_sheap)
{
- char *ret = bss_sbrk_ptr;
- if (debug_sheap)
- printf ("allocated 0x%08x size %d\n", ret, request_size);
- bss_sbrk_ptr += (int) request_size;
- if (bss_sbrk_ptr > max_bss_sbrk_ptr)
- max_bss_sbrk_ptr = bss_sbrk_ptr;
- return ret;
+ if (request_size < 0)
+ printf ("freed size %"pD"d\n", request_size);
+ else
+ printf ("allocated %p size %"pD"d\n", ret, request_size);
}
-}
-
-void
-report_sheap_usage (int die_if_pure_storage_exceeded)
-{
- char buf[200];
- sprintf (buf, "Maximum static heap usage: %d of %d bytes",
- max_bss_sbrk_ptr - bss_sbrk_buffer, STATIC_HEAP_SIZE);
- /* Don't log messages, cause at this point, we're not allowed to create
- buffers. */
- message1_nolog (buf);
+ return ret;
}
diff --git a/src/sheap.h b/src/sheap.h
new file mode 100644
index 00000000000..c229a1b06ed
--- /dev/null
+++ b/src/sheap.h
@@ -0,0 +1,31 @@
+/* Static heap allocation for GNU Emacs.
+
+Copyright 2016 Free Software Foundation, Inc.
+
+This file is part of GNU Emacs.
+
+GNU Emacs is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+GNU Emacs is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stddef.h>
+#include "lisp.h"
+
+/* Size of the static heap. Guess a value that is probably too large,
+ by up to a factor of four or so. Typically the unused part is not
+ paged in and so does not cost much. */
+enum { STATIC_HEAP_SIZE = sizeof (Lisp_Object) << 22 };
+
+extern char bss_sbrk_buffer[STATIC_HEAP_SIZE];
+extern char *max_bss_sbrk_ptr;
+extern bool bss_sbrk_did_unexec;
+extern void *bss_sbrk (ptrdiff_t);
diff --git a/src/syntax.c b/src/syntax.c
index 8e14bf3fb1d..fdcfdfc62a9 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -3701,11 +3701,11 @@ Each function is called with two arguments; POS and LIMIT.
POS and LIMIT are character positions in the current buffer.
If POS is less than LIMIT, POS is at the first character of a word,
-and the return value of a function should be a position after the
-last character of that word.
+and the return value of a function is a position after the last
+character of that word.
If POS is not less than LIMIT, POS is at the last character of a word,
-and the return value of a function should be a position at the first
+and the return value of a function is a position at the first
character of that word.
In both cases, LIMIT bounds the search. */);
diff --git a/src/sysdep.c b/src/sysdep.c
index 460166d119e..6154c1325d8 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -19,14 +19,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
-/* If HYBRID_GET_CURRENT_DIR_NAME is defined in conf_post.h, then we
- need the following before including unistd.h, in order to pick up
- the right prototype for gget_current_dir_name. */
-#ifdef HYBRID_GET_CURRENT_DIR_NAME
-#undef get_current_dir_name
-#define get_current_dir_name gget_current_dir_name
-#endif
-
#include <execinfo.h>
#include "sysstdio.h"
#ifdef HAVE_PWD_H
@@ -40,6 +32,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <utimens.h>
#include "lisp.h"
+#include "sheap.h"
#include "sysselect.h"
#include "blockinput.h"
@@ -137,14 +130,21 @@ static const int baud_convert[] =
1800, 2400, 4800, 9600, 19200, 38400
};
-#if !defined HAVE_GET_CURRENT_DIR_NAME || defined BROKEN_GET_CURRENT_DIR_NAME \
- || (defined HYBRID_GET_CURRENT_DIR_NAME)
-/* Return the current working directory. Returns NULL on errors.
- Any other returned value must be freed with free. This is used
- only when get_current_dir_name is not defined on the system. */
+/* Return the current working directory. The result should be freed
+ with 'free'. Return NULL on errors. */
char *
-get_current_dir_name (void)
+emacs_get_current_dir_name (void)
{
+# if HAVE_GET_CURRENT_DIR_NAME && !BROKEN_GET_CURRENT_DIR_NAME
+# ifdef HYBRID_MALLOC
+ bool use_libc = bss_sbrk_did_unexec;
+# else
+ bool use_libc = true;
+# endif
+ if (use_libc)
+ return get_current_dir_name ();
+# endif
+
char *buf;
char *pwd = getenv ("PWD");
struct stat dotstat, pwdstat;
@@ -192,7 +192,6 @@ get_current_dir_name (void)
}
return buf;
}
-#endif
/* Discard pending input on all input descriptors. */
@@ -1409,6 +1408,12 @@ setup_pty (int fd)
void
init_system_name (void)
{
+ if (!build_details)
+ {
+ /* Set system-name to nil so that the build is deterministic. */
+ Vsystem_name = Qnil;
+ return;
+ }
char *hostname_alloc = NULL;
char *hostname;
#ifndef HAVE_GETHOSTNAME
@@ -1632,6 +1637,9 @@ static unsigned char sigsegv_stack[SIGSTKSZ];
static bool
stack_overflow (siginfo_t *siginfo)
{
+ if (!attempt_stack_overflow_recovery)
+ return false;
+
/* In theory, a more-accurate heuristic can be obtained by using
GNU/Linux pthread_getattr_np along with POSIX pthread_attr_getstack
and pthread_attr_getguardsize to find the location and size of the
diff --git a/src/unexcw.c b/src/unexcw.c
index afd5413c644..399e2c34dda 100644
--- a/src/unexcw.c
+++ b/src/unexcw.c
@@ -30,10 +30,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#define DOTEXE ".exe"
-extern void report_sheap_usage (int);
-
-extern int bss_sbrk_did_unexec;
-
/*
** header for Windows executable files
*/
@@ -276,8 +272,6 @@ unexec (const char *outfile, const char *infile)
int ret;
int ret2;
- report_sheap_usage (1);
-
infile = add_exe_suffix_if_necessary (infile, infile_buffer);
outfile = add_exe_suffix_if_necessary (outfile, outfile_buffer);
@@ -302,9 +296,7 @@ unexec (const char *outfile, const char *infile)
ret = emacs_close (fd_in);
assert (ret == 0);
- bss_sbrk_did_unexec = 1;
fixup_executable (fd_out);
- bss_sbrk_did_unexec = 0;
ret = emacs_close (fd_out);
assert (ret == 0);
diff --git a/src/unexelf.c b/src/unexelf.c
index 068d268808a..551915712fb 100644
--- a/src/unexelf.c
+++ b/src/unexelf.c
@@ -461,29 +461,6 @@ unexec (const char *new_name, const char *old_name)
|| !strcmp (old_section_names + new_shdr->sh_name, ".sdata")
|| !strcmp (old_section_names + new_shdr->sh_name, ".lit4")
|| !strcmp (old_section_names + new_shdr->sh_name, ".lit8")
- /* The conditional bit below was in Oliva's original code
- (1999-08-25) and seems to have been dropped by mistake
- subsequently. It prevents a crash at startup under X in
- `IRIX64 6.5 6.5.17m', whether compiled on that release or
- an earlier one. It causes no trouble on the other ELF
- platforms I could test (Irix 6.5.15m, Solaris 8, Debian
- Potato x86, Debian Woody SPARC); however, it's reported
- to cause crashes under some version of GNU/Linux. It's
- not yet clear what's changed in that Irix version to
- cause the problem, or why the fix sometimes fails under
- GNU/Linux. There's probably no good reason to have
- something Irix-specific here, but this will have to do
- for now. IRIX6_5 is the most specific macro we have to
- test. -- fx 2002-10-01
-
- The issue _looks_ as though it's gone away on 6.5.18m,
- but maybe it's still lurking, to be triggered by some
- change in the binary. It appears to concern the dynamic
- loader, but I never got anywhere with an SGI support call
- seeking clues. -- fx 2002-11-29. */
-#ifdef IRIX6_5
- || !strcmp (old_section_names + new_shdr->sh_name, ".got")
-#endif
|| !strcmp (old_section_names + new_shdr->sh_name, ".sdata1")
|| !strcmp (old_section_names + new_shdr->sh_name, ".data1"))
src = (caddr_t) old_shdr->sh_addr;
@@ -665,9 +642,6 @@ unexec (const char *new_name, const char *old_name)
|| !strcmp (old_section_names + shdr->sh_name, ".sdata")
|| !strcmp (old_section_names + shdr->sh_name, ".lit4")
|| !strcmp (old_section_names + shdr->sh_name, ".lit8")
-#ifdef IRIX6_5 /* see above */
- || !strcmp (old_section_names + shdr->sh_name, ".got")
-#endif
|| !strcmp (old_section_names + shdr->sh_name, ".sdata1")
|| !strcmp (old_section_names + shdr->sh_name, ".data1"))
{
diff --git a/src/vm-limit.c b/src/vm-limit.c
index d32050fd015..7eeca3c8250 100644
--- a/src/vm-limit.c
+++ b/src/vm-limit.c
@@ -51,9 +51,16 @@ char data_start[1] = { 1 };
# endif
#endif
-/* From gmalloc.c. */
-extern void (* __after_morecore_hook) (void);
+#ifdef HAVE_MALLOC_H
+# include <malloc.h>
+#endif
+#ifndef __MALLOC_HOOK_VOLATILE
+# define __MALLOC_HOOK_VOLATILE volatile
+#endif
+#ifndef HAVE_MALLOC_H
extern void *(*__morecore) (ptrdiff_t);
+extern void (*__MALLOC_HOOK_VOLATILE __after_morecore_hook) (void);
+#endif
/* From ralloc.c. */
#ifdef REL_ALLOC
diff --git a/src/w32.c b/src/w32.c
index c26f14593f1..3f4ac88520e 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -7202,6 +7202,10 @@ int (PASCAL *pfn_recvfrom) (SOCKET s, char * buf, int len, int flags,
int (PASCAL *pfn_sendto) (SOCKET s, const char * buf, int len, int flags,
const struct sockaddr * to, int tolen);
+int (PASCAL *pfn_getaddrinfo) (const char *, const char *,
+ const struct addrinfo *, struct addrinfo **);
+void (PASCAL *pfn_freeaddrinfo) (struct addrinfo *);
+
/* SetHandleInformation is only needed to make sockets non-inheritable. */
BOOL (WINAPI *pfn_SetHandleInformation) (HANDLE object, DWORD mask, DWORD flags);
#ifndef HANDLE_FLAG_INHERIT
@@ -7284,6 +7288,16 @@ init_winsock (int load_now)
LOAD_PROC (sendto);
#undef LOAD_PROC
+ /* Try loading functions not available before XP. */
+ pfn_getaddrinfo = (void *) GetProcAddress (winsock_lib, "getaddrinfo");
+ pfn_freeaddrinfo = (void *) GetProcAddress (winsock_lib, "freeaddrinfo");
+ /* Paranoia: these two functions should go together, so if one
+ is absent, we cannot use the other. */
+ if (pfn_getaddrinfo == NULL)
+ pfn_freeaddrinfo = NULL;
+ else if (pfn_freeaddrinfo == NULL)
+ pfn_getaddrinfo = NULL;
+
/* specify version 1.1 of winsock */
if (pfn_WSAStartup (0x101, &winsockData) == 0)
{
@@ -7734,6 +7748,117 @@ sys_getpeername (int s, struct sockaddr *addr, int * namelen)
}
int
+sys_getaddrinfo (const char *node, const char *service,
+ const struct addrinfo *hints, struct addrinfo **res)
+{
+ int rc;
+
+ if (winsock_lib == NULL)
+ {
+ errno = ENETDOWN;
+ return SOCKET_ERROR;
+ }
+
+ check_errno ();
+ if (pfn_getaddrinfo)
+ rc = pfn_getaddrinfo (node, service, hints, res);
+ else
+ {
+ int port = 0;
+ struct hostent *host_info;
+ struct gai_storage {
+ struct addrinfo addrinfo;
+ struct sockaddr_in sockaddr_in;
+ } *gai_storage;
+
+ /* We don't (yet) support any flags, as Emacs doesn't need that. */
+ if (hints && hints->ai_flags != 0)
+ return WSAEINVAL;
+ /* NODE cannot be NULL, since process.c has fallbacks for that. */
+ if (!node)
+ return WSAHOST_NOT_FOUND;
+
+ if (service)
+ {
+ const char *protocol =
+ (hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp";
+ struct servent *srv = sys_getservbyname (service, protocol);
+
+ if (srv)
+ port = srv->s_port;
+ else if (*service >= '0' && *service <= '9')
+ {
+ char *endp;
+
+ port = strtoul (service, &endp, 10);
+ if (*endp || port > 65536)
+ return WSAHOST_NOT_FOUND;
+ port = sys_htons ((unsigned short) port);
+ }
+ else
+ return WSAHOST_NOT_FOUND;
+ }
+
+ gai_storage = xzalloc (sizeof *gai_storage);
+ gai_storage->sockaddr_in.sin_port = port;
+ host_info = sys_gethostbyname (node);
+ if (host_info)
+ {
+ memcpy (&gai_storage->sockaddr_in.sin_addr,
+ host_info->h_addr, host_info->h_length);
+ gai_storage->sockaddr_in.sin_family = host_info->h_addrtype;
+ }
+ else
+ {
+ /* Attempt to interpret host as numeric inet address. */
+ unsigned long numeric_addr = sys_inet_addr (node);
+
+ if (numeric_addr == -1)
+ {
+ free (gai_storage);
+ return WSAHOST_NOT_FOUND;
+ }
+
+ memcpy (&gai_storage->sockaddr_in.sin_addr, &numeric_addr,
+ sizeof (gai_storage->sockaddr_in.sin_addr));
+ gai_storage->sockaddr_in.sin_family = (hints) ? hints->ai_family : 0;
+ }
+
+ gai_storage->addrinfo.ai_addr =
+ (struct sockaddr *)&gai_storage->sockaddr_in;
+ gai_storage->addrinfo.ai_addrlen = sizeof (gai_storage->sockaddr_in);
+ gai_storage->addrinfo.ai_protocol = (hints) ? hints->ai_protocol : 0;
+ gai_storage->addrinfo.ai_socktype = (hints) ? hints->ai_socktype : 0;
+ gai_storage->addrinfo.ai_family = gai_storage->sockaddr_in.sin_family;
+ gai_storage->addrinfo.ai_next = NULL;
+
+ *res = &gai_storage->addrinfo;
+ rc = 0;
+ }
+
+ return rc;
+}
+
+void
+sys_freeaddrinfo (struct addrinfo *ai)
+{
+ if (winsock_lib == NULL)
+ {
+ errno = ENETDOWN;
+ return;
+ }
+
+ check_errno ();
+ if (pfn_freeaddrinfo)
+ pfn_freeaddrinfo (ai);
+ else
+ {
+ eassert (ai->ai_next == NULL);
+ xfree (ai);
+ }
+}
+
+int
sys_shutdown (int s, int how)
{
if (winsock_lib == NULL)
@@ -8647,6 +8772,30 @@ sys_write (int fd, const void * buffer, unsigned int count)
unsigned long nblock = 0;
if (winsock_lib == NULL) emacs_abort ();
+ child_process *cp = fd_info[fd].cp;
+
+ /* If this is a non-blocking socket whose connection is in
+ progress or terminated with an error already, return the
+ proper error code to the caller. */
+ if (cp != NULL && (fd_info[fd].flags & FILE_CONNECT) != 0)
+ {
+ /* In case connection is in progress, ENOTCONN that would
+ result from calling pfn_send is not what callers expect. */
+ if (cp->status != STATUS_CONNECT_FAILED)
+ {
+ errno = EWOULDBLOCK;
+ return -1;
+ }
+ /* In case connection failed, use the actual error code
+ stashed by '_sys_wait_connect' in cp->errcode. */
+ else if (cp->errcode != 0)
+ {
+ pfn_WSASetLastError (cp->errcode);
+ set_errno ();
+ return -1;
+ }
+ }
+
/* TODO: implement select() properly so non-blocking I/O works. */
/* For now, make sure the write blocks. */
if (fd_info[fd].flags & FILE_NDELAY)
@@ -8654,6 +8803,13 @@ sys_write (int fd, const void * buffer, unsigned int count)
nchars = pfn_send (SOCK_HANDLE (fd), buffer, count, 0);
+ if (nchars == SOCKET_ERROR)
+ {
+ set_errno ();
+ DebPrint (("sys_write.send failed with error %d on socket %ld\n",
+ pfn_WSAGetLastError (), SOCK_HANDLE (fd)));
+ }
+
/* Set the socket back to non-blocking if it was before,
for other operations that support it. */
if (fd_info[fd].flags & FILE_NDELAY)
@@ -8661,13 +8817,6 @@ sys_write (int fd, const void * buffer, unsigned int count)
nblock = 1;
pfn_ioctlsocket (SOCK_HANDLE (fd), FIONBIO, &nblock);
}
-
- if (nchars == SOCKET_ERROR)
- {
- DebPrint (("sys_write.send failed with error %d on socket %ld\n",
- pfn_WSAGetLastError (), SOCK_HANDLE (fd)));
- set_errno ();
- }
}
else
{
@@ -8740,7 +8889,7 @@ sys_write (int fd, const void * buffer, unsigned int count)
/* Emulation of SIOCGIFCONF and getifaddrs, see process.c. */
-extern Lisp_Object conv_sockaddr_to_lisp (struct sockaddr *, int);
+extern Lisp_Object conv_sockaddr_to_lisp (struct sockaddr *, ptrdiff_t);
/* Return information about network interface IFNAME, or about all
interfaces (if IFNAME is nil). */
diff --git a/src/w32console.c b/src/w32console.c
index 512d20dd242..82ba4b1cf9c 100644
--- a/src/w32console.c
+++ b/src/w32console.c
@@ -759,6 +759,9 @@ initialize_w32_display (struct terminal *term, int *width, int *height)
/* Setup w32_display_info structure for this frame. */
w32_initialize_display_info (build_string ("Console"));
+
+ /* Set up the keyboard hook. */
+ setup_w32_kbdhook ();
}
diff --git a/src/w32fns.c b/src/w32fns.c
index b9002bae770..a08474fa9c3 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -20,6 +20,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
/* Added by Kevin Gallo */
#include <config.h>
+/* Override API version to get the latest functionality. */
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x0600
#include <signal.h>
#include <stdio.h>
@@ -41,6 +44,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "coding.h"
#include "w32common.h"
+#include "w32inevt.h"
#ifdef WINDOWSNT
#include <mbstring.h>
@@ -52,6 +56,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "w32.h"
#endif
+#include <basetyps.h>
+#include <unknwn.h>
#include <commctrl.h>
#include <commdlg.h>
#include <shellapi.h>
@@ -251,6 +257,38 @@ HINSTANCE hinst = NULL;
static unsigned int sound_type = 0xFFFFFFFF;
#define MB_EMACS_SILENT (0xFFFFFFFF - 1)
+/* Special virtual key code for indicating "any" key. */
+#define VK_ANY 0xFF
+
+#ifndef WM_WTSSESSION_CHANGE
+/* 32-bit MinGW does not define these constants. */
+# define WM_WTSSESSION_CHANGE 0x02B1
+# define WTS_SESSION_LOCK 0x7
+#endif
+
+/* Keyboard hook state data. */
+static struct
+{
+ int hook_count; /* counter, if several windows are created */
+ HHOOK hook; /* hook handle */
+ HWND console; /* console window handle */
+
+ int lwindown; /* Left Windows key currently pressed (and hooked) */
+ int rwindown; /* Right Windows key currently pressed (and hooked) */
+ int winsdown; /* Number of handled keys currently pressed */
+ int send_win_up; /* Pass through the keyup for this Windows key press? */
+ int suppress_lone; /* Suppress simulated Windows keydown-keyup for this press? */
+ int winseen; /* Windows keys seen during this press? */
+
+ char alt_hooked[256]; /* hook Alt+[this key]? */
+ char lwin_hooked[256]; /* hook left Win+[this key]? */
+ char rwin_hooked[256]; /* hook right Win+[this key]? */
+} kbdhook;
+typedef HWND (WINAPI *GetConsoleWindow_Proc) (void);
+
+/* stdin, from w32console.c */
+extern HANDLE keyboard_handle;
+
/* Let the user specify a display with a frame.
nil stands for the selected frame--or, if that is not a w32 frame,
the first display on the list. */
@@ -2074,6 +2112,350 @@ my_post_msg (W32Msg * wmsg, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
post_msg (wmsg);
}
+#ifdef WINDOWSNT
+/* The Windows keyboard hook callback. */
+static LRESULT CALLBACK
+funhook (int code, WPARAM w, LPARAM l)
+{
+ INPUT inputs[2];
+ HWND focus = GetFocus ();
+ int console = 0;
+ KBDLLHOOKSTRUCT const *hs = (KBDLLHOOKSTRUCT*)l;
+
+ if (code < 0 || (hs->flags & LLKHF_INJECTED))
+ return CallNextHookEx (0, code, w, l);
+
+ /* The keyboard hook sees keyboard input on all processes (except
+ elevated ones, when Emacs itself is not elevated). As such,
+ care must be taken to only filter out keyboard input when Emacs
+ itself is on the foreground.
+
+ GetFocus returns a non-NULL window if another application is active,
+ and always for a console Emacs process. For a console Emacs, determine
+ focus by checking if the current foreground window is the process's
+ console window. */
+ if (focus == NULL && kbdhook.console != NULL)
+ {
+ if (GetForegroundWindow () == kbdhook.console)
+ {
+ focus = kbdhook.console;
+ console = 1;
+ }
+ }
+
+ /* First, check hooks for the left and right Windows keys. */
+ if (hs->vkCode == VK_LWIN || hs->vkCode == VK_RWIN)
+ {
+ if (focus != NULL && (w == WM_KEYDOWN || w == WM_SYSKEYDOWN))
+ {
+ /* The key is being pressed in an Emacs window. */
+ if (hs->vkCode == VK_LWIN && !kbdhook.lwindown)
+ {
+ kbdhook.lwindown = 1;
+ kbdhook.winseen = 1;
+ kbdhook.winsdown++;
+ }
+ else if (hs->vkCode == VK_RWIN && !kbdhook.rwindown)
+ {
+ kbdhook.rwindown = 1;
+ kbdhook.winseen = 1;
+ kbdhook.winsdown++;
+ }
+ /* Returning 1 here drops the keypress without further processing.
+ If the keypress was allowed to go through, the normal Windows
+ hotkeys would take over. */
+ return 1;
+ }
+ else if (kbdhook.winsdown > 0 && (w == WM_KEYUP || w == WM_SYSKEYUP))
+ {
+ /* A key that has been captured earlier is being released now. */
+ if (hs->vkCode == VK_LWIN && kbdhook.lwindown)
+ {
+ kbdhook.lwindown = 0;
+ kbdhook.winsdown--;
+ }
+ else if (hs->vkCode == VK_RWIN && kbdhook.rwindown)
+ {
+ kbdhook.rwindown = 0;
+ kbdhook.winsdown--;
+ }
+ if (kbdhook.winsdown == 0 && kbdhook.winseen)
+ {
+ if (!kbdhook.suppress_lone)
+ {
+ /* The Windows key was pressed, then released,
+ without any other key pressed simultaneously.
+ Normally, this opens the Start menu, but the user
+ can prevent this by setting the
+ w32-pass-[lr]window-to-system variable to
+ NIL. */
+ if (hs->vkCode == VK_LWIN && !NILP (Vw32_pass_lwindow_to_system) ||
+ hs->vkCode == VK_RWIN && !NILP (Vw32_pass_rwindow_to_system))
+ {
+ /* Not prevented - Simulate the keypress to the system. */
+ memset (inputs, 0, sizeof (inputs));
+ inputs[0].type = INPUT_KEYBOARD;
+ inputs[0].ki.wVk = hs->vkCode;
+ inputs[0].ki.wScan = hs->vkCode;
+ inputs[0].ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
+ inputs[0].ki.time = 0;
+ inputs[1].type = INPUT_KEYBOARD;
+ inputs[1].ki.wVk = hs->vkCode;
+ inputs[1].ki.wScan = hs->vkCode;
+ inputs[1].ki.dwFlags
+ = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP;
+ inputs[1].ki.time = 0;
+ SendInput (2, inputs, sizeof (INPUT));
+ }
+ else if (focus != NULL)
+ {
+ /* When not passed to system, must simulate privately to Emacs. */
+ PostMessage (focus, WM_SYSKEYDOWN, hs->vkCode, 0);
+ PostMessage (focus, WM_SYSKEYUP, hs->vkCode, 0);
+ }
+ }
+ }
+ if (kbdhook.winsdown == 0)
+ {
+ /* No Windows keys pressed anymore - clear the state flags. */
+ kbdhook.suppress_lone = 0;
+ kbdhook.winseen = 0;
+ }
+ if (!kbdhook.send_win_up)
+ {
+ /* Swallow this release message, as not to confuse
+ applications who did not get to see the original
+ WM_KEYDOWN message either. */
+ return 1;
+ }
+ kbdhook.send_win_up = 0;
+ }
+ }
+ else if (kbdhook.winsdown > 0)
+ {
+ /* Some other key was pressed while a captured Win key is down.
+ This is either an Emacs registered hotkey combination, or a
+ system hotkey. */
+ if (kbdhook.lwindown && kbdhook.lwin_hooked[hs->vkCode] ||
+ kbdhook.rwindown && kbdhook.rwin_hooked[hs->vkCode])
+ {
+ /* Hooked Win-x combination, do not pass the keypress to Windows. */
+ kbdhook.suppress_lone = 1;
+ }
+ else if (!kbdhook.suppress_lone)
+ {
+ /* Unhooked S-x combination; simulate the combination now
+ (will be seen by the system). */
+ memset (inputs, 0, sizeof (inputs));
+ inputs[0].type = INPUT_KEYBOARD;
+ inputs[0].ki.wVk = kbdhook.lwindown ? VK_LWIN : VK_RWIN;
+ inputs[0].ki.wScan = kbdhook.lwindown ? VK_LWIN : VK_RWIN;
+ inputs[0].ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
+ inputs[0].ki.time = 0;
+ inputs[1].type = INPUT_KEYBOARD;
+ inputs[1].ki.wVk = hs->vkCode;
+ inputs[1].ki.wScan = hs->scanCode;
+ inputs[1].ki.dwFlags =
+ (hs->flags & LLKHF_EXTENDED) ? KEYEVENTF_EXTENDEDKEY : 0;
+ inputs[1].ki.time = 0;
+ SendInput (2, inputs, sizeof (INPUT));
+ /* Stop processing of this Win sequence here; the
+ corresponding keyup messages will come through the normal
+ channel when the keys are released. */
+ kbdhook.suppress_lone = 1;
+ kbdhook.send_win_up = 1;
+ /* Swallow the original keypress (as we want the Win key
+ down message simulated above to precede this real message). */
+ return 1;
+ }
+ }
+
+ /* Next, handle the registered Alt-* combinations. */
+ if ((w == WM_SYSKEYDOWN || w == WM_KEYDOWN)
+ && kbdhook.alt_hooked[hs->vkCode]
+ && focus != NULL
+ && (GetAsyncKeyState (VK_MENU) & 0x8000))
+ {
+ /* Prevent the system from getting this Alt-* key - suppress the
+ message and post as a normal keypress to Emacs. */
+ if (console)
+ {
+ INPUT_RECORD rec;
+ DWORD n;
+ rec.EventType = KEY_EVENT;
+ rec.Event.KeyEvent.bKeyDown = TRUE;
+ rec.Event.KeyEvent.wVirtualKeyCode = hs->vkCode;
+ rec.Event.KeyEvent.wVirtualScanCode = hs->scanCode;
+ rec.Event.KeyEvent.uChar.UnicodeChar = 0;
+ rec.Event.KeyEvent.dwControlKeyState =
+ ((GetAsyncKeyState (VK_LMENU) & 0x8000) ? LEFT_ALT_PRESSED : 0)
+ | ((GetAsyncKeyState (VK_RMENU) & 0x8000) ? RIGHT_ALT_PRESSED : 0)
+ | ((GetAsyncKeyState (VK_LCONTROL) & 0x8000) ? LEFT_CTRL_PRESSED : 0)
+ | ((GetAsyncKeyState (VK_RCONTROL) & 0x8000) ? RIGHT_CTRL_PRESSED : 0)
+ | ((GetAsyncKeyState (VK_SHIFT) & 0x8000) ? SHIFT_PRESSED : 0)
+ | ((hs->flags & LLKHF_EXTENDED) ? ENHANCED_KEY : 0);
+ if (w32_console_unicode_input)
+ WriteConsoleInputW (keyboard_handle, &rec, 1, &n);
+ else
+ WriteConsoleInputA (keyboard_handle, &rec, 1, &n);
+ }
+ else
+ PostMessage (focus, w, hs->vkCode, 1 | (1<<29));
+ return 1;
+ }
+
+ /* The normal case - pass the message through. */
+ return CallNextHookEx (0, code, w, l);
+}
+
+/* Set up the hook; can be called several times, with matching
+ remove_w32_kbdhook calls. */
+void
+setup_w32_kbdhook (void)
+{
+ kbdhook.hook_count++;
+
+ /* Hooking is only available on NT architecture systems, as
+ indicated by the w32_kbdhook_active variable. */
+ if (kbdhook.hook_count == 1 && w32_kbdhook_active)
+ {
+ /* Get the handle of the Emacs console window. As the
+ GetConsoleWindow function is only available on Win2000+, a
+ hackish workaround described in Microsoft KB article 124103
+ (https://support.microsoft.com/en-us/kb/124103) is used for
+ NT 4 systems. */
+ GetConsoleWindow_Proc get_console = (GetConsoleWindow_Proc)
+ GetProcAddress (GetModuleHandle ("kernel32.dll"), "GetConsoleWindow");
+
+ if (get_console != NULL)
+ kbdhook.console = get_console ();
+ else
+ {
+ GUID guid;
+ wchar_t *oldTitle = malloc (1024 * sizeof(wchar_t));
+ wchar_t newTitle[64];
+ int i;
+
+ CoCreateGuid (&guid);
+ StringFromGUID2 (&guid, newTitle, 64);
+ if (newTitle != NULL)
+ {
+ GetConsoleTitleW (oldTitle, 1024);
+ SetConsoleTitleW (newTitle);
+ for (i = 0; i < 25; i++)
+ {
+ Sleep (40);
+ kbdhook.console = FindWindowW (NULL, newTitle);
+ if (kbdhook.console != NULL)
+ break;
+ }
+ SetConsoleTitleW (oldTitle);
+ }
+ free (oldTitle);
+ }
+
+ /* Set the hook. */
+ kbdhook.hook = SetWindowsHookEx (WH_KEYBOARD_LL, funhook,
+ GetModuleHandle (NULL), 0);
+ }
+}
+
+/* Remove the hook. */
+void
+remove_w32_kbdhook (void)
+{
+ kbdhook.hook_count--;
+ if (kbdhook.hook_count == 0 && w32_kbdhook_active)
+ {
+ UnhookWindowsHookEx (kbdhook.hook);
+ kbdhook.hook = NULL;
+ }
+}
+#endif /* WINDOWSNT */
+
+/* Mark a specific key combination as hooked, preventing it to be
+ handled by the system. */
+void
+hook_w32_key (int hook, int modifier, int vkey)
+{
+ char *tbl = NULL;
+
+ switch (modifier)
+ {
+ case VK_MENU:
+ tbl = kbdhook.alt_hooked;
+ break;
+ case VK_LWIN:
+ tbl = kbdhook.lwin_hooked;
+ break;
+ case VK_RWIN:
+ tbl = kbdhook.rwin_hooked;
+ break;
+ }
+
+ if (tbl != NULL && vkey >= 0 && vkey <= 255)
+ {
+ /* VK_ANY hooks all keys for this modifier */
+ if (vkey == VK_ANY)
+ memset (tbl, (char)hook, 256);
+ else
+ tbl[vkey] = (char)hook;
+ /* Alt-<modifier>s should go through */
+ kbdhook.alt_hooked[VK_MENU] = 0;
+ kbdhook.alt_hooked[VK_LMENU] = 0;
+ kbdhook.alt_hooked[VK_RMENU] = 0;
+ kbdhook.alt_hooked[VK_CONTROL] = 0;
+ kbdhook.alt_hooked[VK_LCONTROL] = 0;
+ kbdhook.alt_hooked[VK_RCONTROL] = 0;
+ kbdhook.alt_hooked[VK_SHIFT] = 0;
+ kbdhook.alt_hooked[VK_LSHIFT] = 0;
+ kbdhook.alt_hooked[VK_RSHIFT] = 0;
+ }
+}
+
+/* Check the current Win key pressed state. */
+int
+check_w32_winkey_state (int vkey)
+{
+ /* The hook code handles grabbing of the Windows keys and Alt-* key
+ combinations reserved by the system. Handling Alt is a bit
+ easier, as Windows intends Alt-* shortcuts for application use in
+ Windows; hotkeys such as Alt-tab and Alt-escape are special
+ cases. Win-* hotkeys, on the other hand, are primarily meant for
+ system use.
+
+ As a result, when we want Emacs to be able to grab the Win-*
+ keys, we must swallow all Win key presses in a low-level keyboard
+ hook. Unfortunately, this means that the Emacs window procedure
+ (and console input handler) never see the keypresses either.
+ Thus, to check the modifier states properly, Emacs code must use
+ the check_w32_winkey_state function that uses the flags directly
+ updated by the hook callback. */
+ switch (vkey)
+ {
+ case VK_LWIN:
+ return kbdhook.lwindown;
+ case VK_RWIN:
+ return kbdhook.rwindown;
+ }
+ return 0;
+}
+
+/* Reset the keyboard hook state. Locking the workstation with Win-L
+ leaves the Win key(s) "down" from the hook's point of view - the
+ keyup event is never seen. Thus, this function must be called when
+ the system is locked. */
+void
+reset_w32_kbdhook_state (void)
+{
+ kbdhook.lwindown = 0;
+ kbdhook.rwindown = 0;
+ kbdhook.winsdown = 0;
+ kbdhook.send_win_up = 0;
+ kbdhook.suppress_lone = 0;
+ kbdhook.winseen = 0;
+}
+
/* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
between left and right keys as advertised. We test for this
support dynamically, and set a flag when the support is absent. If
@@ -2248,6 +2630,8 @@ modifier_set (int vkey)
else
return (GetKeyState (vkey) & 0x1);
}
+ if (w32_kbdhook_active && (vkey == VK_LWIN || vkey == VK_RWIN))
+ return check_w32_winkey_state (vkey);
if (!modifiers_recorded)
return (GetKeyState (vkey) & 0x8000);
@@ -2390,7 +2774,9 @@ map_keypad_keys (unsigned int virt_key, unsigned int extended)
/* List of special key combinations which w32 would normally capture,
but Emacs should grab instead. Not directly visible to lisp, to
simplify synchronization. Each item is an integer encoding a virtual
- key code and modifier combination to capture. */
+ key code and modifier combination to capture.
+ Note: This code is not used if keyboard hooks are active
+ (Windows 2000 and later). */
static Lisp_Object w32_grabbed_keys;
#define HOTKEY(vk, mods) make_number (((vk) & 255) | ((mods) << 8))
@@ -3440,7 +3826,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
switch (wParam)
{
case VK_LWIN:
- if (NILP (Vw32_pass_lwindow_to_system))
+ if (!w32_kbdhook_active && NILP (Vw32_pass_lwindow_to_system))
{
/* Prevent system from acting on keyup (which opens the
Start menu if no other key was pressed) by simulating a
@@ -3459,7 +3845,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
return 0;
break;
case VK_RWIN:
- if (NILP (Vw32_pass_rwindow_to_system))
+ if (!w32_kbdhook_active && NILP (Vw32_pass_rwindow_to_system))
{
if (GetAsyncKeyState (wParam) & 1)
{
@@ -4316,10 +4702,12 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_SETFOCUS:
dpyinfo->faked_key = 0;
reset_modifiers ();
- register_hot_keys (hwnd);
+ if (!w32_kbdhook_active)
+ register_hot_keys (hwnd);
goto command;
case WM_KILLFOCUS:
- unregister_hot_keys (hwnd);
+ if (!w32_kbdhook_active)
+ unregister_hot_keys (hwnd);
button_state = 0;
ReleaseCapture ();
/* Relinquish the system caret. */
@@ -4348,10 +4736,24 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
my_post_msg (&wmsg, hwnd, msg, wParam, lParam);
goto dflt;
+#ifdef WINDOWSNT
+ case WM_CREATE:
+ setup_w32_kbdhook ();
+ goto dflt;
+#endif
+
case WM_DESTROY:
+#ifdef WINDOWSNT
+ remove_w32_kbdhook ();
+#endif
CoUninitialize ();
return 0;
+ case WM_WTSSESSION_CHANGE:
+ if (wParam == WTS_SESSION_LOCK)
+ reset_w32_kbdhook_state ();
+ goto dflt;
+
case WM_CLOSE:
wmsg.dwModifiers = w32_get_modifiers ();
my_post_msg (&wmsg, hwnd, msg, wParam, lParam);
@@ -6020,8 +6422,6 @@ no value of TYPE (always string in the MS Windows case). */)
Tool tips
***********************************************************************/
-static Lisp_Object x_create_tip_frame (struct w32_display_info *,
- Lisp_Object, Lisp_Object);
static void compute_tip_xy (struct frame *, Lisp_Object, Lisp_Object,
Lisp_Object, int, int, int *, int *);
@@ -6056,8 +6456,7 @@ unwind_create_tip_frame (Lisp_Object frame)
/* Create a frame for a tooltip on the display described by DPYINFO.
- PARMS is a list of frame parameters. TEXT is the string to
- display in the tip frame. Value is the frame.
+ PARMS is a list of frame parameters. Value is the frame.
Note that functions called here, esp. x_default_parameter can
signal errors, for instance when a specified color name is
@@ -6065,8 +6464,7 @@ unwind_create_tip_frame (Lisp_Object frame)
when this happens. */
static Lisp_Object
-x_create_tip_frame (struct w32_display_info *dpyinfo,
- Lisp_Object parms, Lisp_Object text)
+x_create_tip_frame (struct w32_display_info *dpyinfo, Lisp_Object parms)
{
struct frame *f;
Lisp_Object frame;
@@ -6075,8 +6473,6 @@ x_create_tip_frame (struct w32_display_info *dpyinfo,
ptrdiff_t count = SPECPDL_INDEX ();
struct kboard *kb;
bool face_change_before = face_change;
- Lisp_Object buffer;
- struct buffer *old_buffer;
int x_width = 0, x_height = 0;
/* Use this general default value to start with until we know if
@@ -6100,23 +6496,9 @@ x_create_tip_frame (struct w32_display_info *dpyinfo,
frame = Qnil;
/* Make a frame without minibuffer nor mode-line. */
f = make_frame (false);
- f->wants_modeline = 0;
+ f->wants_modeline = false;
XSETFRAME (frame, f);
- AUTO_STRING (tip, " *tip*");
- buffer = Fget_buffer_create (tip);
- /* Use set_window_buffer instead of Fset_window_buffer (see
- discussion of bug#11984, bug#12025, bug#12026). */
- set_window_buffer (FRAME_ROOT_WINDOW (f), buffer, false, false);
- old_buffer = current_buffer;
- set_buffer_internal_1 (XBUFFER (buffer));
- bset_truncate_lines (current_buffer, Qnil);
- specbind (Qinhibit_read_only, Qt);
- specbind (Qinhibit_modification_hooks, Qt);
- Ferase_buffer ();
- Finsert (1, &text);
- set_buffer_internal_1 (old_buffer);
-
record_unwind_protect (unwind_create_tip_frame, frame);
/* By setting the output method, we're essentially saying that
@@ -6150,7 +6532,7 @@ x_create_tip_frame (struct w32_display_info *dpyinfo,
{
fset_name (f, name);
f->explicit_name = true;
- /* use the frame's title when getting resources for this frame. */
+ /* Use the frame's title when getting resources for this frame. */
specbind (Qx_resource_name, name);
}
@@ -6180,14 +6562,10 @@ x_create_tip_frame (struct w32_display_info *dpyinfo,
parms = Fcons (Fcons (Qinternal_border_width, value),
parms);
}
+
x_default_parameter (f, parms, Qinternal_border_width, make_number (1),
"internalBorderWidth", "internalBorderWidth",
RES_TYPE_NUMBER);
- x_default_parameter (f, parms, Qright_divider_width, make_number (0),
- NULL, NULL, RES_TYPE_NUMBER);
- x_default_parameter (f, parms, Qbottom_divider_width, make_number (0),
- NULL, NULL, RES_TYPE_NUMBER);
-
/* Also do the stuff which must be set before the window exists. */
x_default_parameter (f, parms, Qforeground_color, build_string ("black"),
"foreground", "Foreground", RES_TYPE_STRING);
@@ -6214,6 +6592,9 @@ x_create_tip_frame (struct w32_display_info *dpyinfo,
f->fringe_cols = 0;
f->left_fringe_width = 0;
f->right_fringe_width = 0;
+ /* No dividers on tip frame. */
+ f->right_divider_width = 0;
+ f->bottom_divider_width = 0;
block_input ();
my_create_tip_window (f);
@@ -6240,7 +6621,6 @@ x_create_tip_frame (struct w32_display_info *dpyinfo,
SET_FRAME_LINES (f, 0);
adjust_frame_size (f, width * FRAME_COLUMN_WIDTH (f),
height * FRAME_LINE_HEIGHT (f), 0, true, Qtip_frame);
-
/* Add `tooltip' frame parameter's default value. */
if (NILP (Fframe_parameter (frame, Qtooltip)))
Fmodify_frame_parameters (frame, Fcons (Fcons (Qtooltip, Qt), Qnil));
@@ -6258,8 +6638,6 @@ x_create_tip_frame (struct w32_display_info *dpyinfo,
Lisp_Object fg = Fframe_parameter (frame, Qforeground_color);
Lisp_Object colors = Qnil;
- /* Set tip_frame here, so that */
- tip_frame = frame;
call2 (Qface_set_after_frame_default, frame, Qnil);
if (!EQ (bg, Fframe_parameter (frame, Qbackground_color)))
@@ -6391,6 +6769,48 @@ compute_tip_xy (struct frame *f,
*root_x = min_x;
}
+/* Hide tooltip. Delete its frame if DELETE is true. */
+static Lisp_Object
+x_hide_tip (bool delete)
+{
+ if (!NILP (tip_timer))
+ {
+ call1 (Qcancel_timer, tip_timer);
+ tip_timer = Qnil;
+ }
+
+ if (NILP (tip_frame)
+ || (!delete && FRAMEP (tip_frame)
+ && !FRAME_VISIBLE_P (XFRAME (tip_frame))))
+ return Qnil;
+ else
+ {
+ ptrdiff_t count;
+ Lisp_Object was_open = Qnil;
+
+ count = SPECPDL_INDEX ();
+ specbind (Qinhibit_redisplay, Qt);
+ specbind (Qinhibit_quit, Qt);
+
+ if (FRAMEP (tip_frame))
+ {
+ if (delete)
+ {
+ delete_frame (tip_frame, Qnil);
+ tip_frame = Qnil;
+ }
+ else
+ x_make_frame_invisible (XFRAME (tip_frame));
+
+ was_open = Qt;
+ }
+ else
+ tip_frame = Qnil;
+
+ return unbind_to (count, was_open);
+ }
+}
+
DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
doc: /* Show STRING in a \"tooltip\" window on frame FRAME.
@@ -6424,15 +6844,16 @@ A tooltip's maximum size is specified by `x-max-tooltip-size'.
Text larger than the specified size is clipped. */)
(Lisp_Object string, Lisp_Object frame, Lisp_Object parms, Lisp_Object timeout, Lisp_Object dx, Lisp_Object dy)
{
- struct frame *f;
+ struct frame *f, *tip_f;
struct window *w;
int root_x, root_y;
struct buffer *old_buffer;
struct text_pos pos;
int i, width, height;
- bool seen_reversed_p;
int old_windows_or_buffers_changed = windows_or_buffers_changed;
ptrdiff_t count = SPECPDL_INDEX ();
+ ptrdiff_t count_1;
+ Lisp_Object window, size;
specbind (Qinhibit_redisplay, Qt);
@@ -6456,91 +6877,155 @@ Text larger than the specified size is clipped. */)
if (NILP (last_show_tip_args))
last_show_tip_args = Fmake_vector (make_number (3), Qnil);
- if (!NILP (tip_frame))
+ if (FRAMEP (tip_frame) && FRAME_LIVE_P (XFRAME (tip_frame)))
{
Lisp_Object last_string = AREF (last_show_tip_args, 0);
Lisp_Object last_frame = AREF (last_show_tip_args, 1);
Lisp_Object last_parms = AREF (last_show_tip_args, 2);
- if (EQ (frame, last_frame)
- && !NILP (Fequal (last_string, string))
+ if (FRAME_VISIBLE_P (XFRAME (tip_frame))
+ && EQ (frame, last_frame)
+ && !NILP (Fequal_including_properties (last_string, string))
&& !NILP (Fequal (last_parms, parms)))
{
- struct frame *f = XFRAME (tip_frame);
-
/* Only DX and DY have changed. */
+ tip_f = XFRAME (tip_frame);
if (!NILP (tip_timer))
{
Lisp_Object timer = tip_timer;
+
tip_timer = Qnil;
call1 (Qcancel_timer, timer);
}
block_input ();
- compute_tip_xy (f, parms, dx, dy, FRAME_PIXEL_WIDTH (f),
- FRAME_PIXEL_HEIGHT (f), &root_x, &root_y);
+ compute_tip_xy (tip_f, parms, dx, dy, FRAME_PIXEL_WIDTH (tip_f),
+ FRAME_PIXEL_HEIGHT (tip_f), &root_x, &root_y);
/* Put tooltip in topmost group and in position. */
- SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOPMOST,
+ SetWindowPos (FRAME_W32_WINDOW (tip_f), HWND_TOPMOST,
root_x, root_y, 0, 0,
SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
/* Ensure tooltip is on top of other topmost windows (eg menus). */
- SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOP,
+ SetWindowPos (FRAME_W32_WINDOW (tip_f), HWND_TOP,
0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE
| SWP_NOACTIVATE | SWP_NOOWNERZORDER);
+ /* Let redisplay know that we have made the frame visible already. */
+ SET_FRAME_VISIBLE (tip_f, 1);
+ ShowWindow (FRAME_W32_WINDOW (tip_f), SW_SHOWNOACTIVATE);
unblock_input ();
+
goto start_timer;
}
- }
+ else if (tooltip_reuse_hidden_frame && EQ (frame, last_frame))
+ {
+ bool delete = false;
+ Lisp_Object tail, elt, parm, last;
+
+ /* Check if every parameter in PARMS has the same value in
+ last_parms. This may destruct last_parms which, however,
+ will be recreated below. */
+ for (tail = parms; CONSP (tail); tail = XCDR (tail))
+ {
+ elt = XCAR (tail);
+ parm = Fcar (elt);
+ /* The left, top, right and bottom parameters are handled
+ by compute_tip_xy so they can be ignored here. */
+ if (!EQ (parm, Qleft) && !EQ (parm, Qtop)
+ && !EQ (parm, Qright) && !EQ (parm, Qbottom))
+ {
+ last = Fassq (parm, last_parms);
+ if (NILP (Fequal (Fcdr (elt), Fcdr (last))))
+ {
+ /* We lost, delete the old tooltip. */
+ delete = true;
+ break;
+ }
+ else
+ last_parms = call2 (Qassq_delete_all, parm, last_parms);
+ }
+ else
+ last_parms = call2 (Qassq_delete_all, parm, last_parms);
+ }
- /* Hide a previous tip, if any. */
- Fx_hide_tip ();
+ /* Now check if there's a parameter left in last_parms with a
+ non-nil value. */
+ for (tail = last_parms; CONSP (tail); tail = XCDR (tail))
+ {
+ elt = XCAR (tail);
+ parm = Fcar (elt);
+ if (!EQ (parm, Qleft) && !EQ (parm, Qtop) && !EQ (parm, Qright)
+ && !EQ (parm, Qbottom) && !NILP (Fcdr (elt)))
+ {
+ /* We lost, delete the old tooltip. */
+ delete = true;
+ break;
+ }
+ }
+
+ x_hide_tip (delete);
+ }
+ else
+ x_hide_tip (true);
+ }
+ else
+ x_hide_tip (true);
ASET (last_show_tip_args, 0, string);
ASET (last_show_tip_args, 1, frame);
ASET (last_show_tip_args, 2, parms);
- /* Add default values to frame parameters. */
- if (NILP (Fassq (Qname, parms)))
- parms = Fcons (Fcons (Qname, build_string ("tooltip")), parms);
- if (NILP (Fassq (Qinternal_border_width, parms)))
- parms = Fcons (Fcons (Qinternal_border_width, make_number (3)), parms);
- if (NILP (Fassq (Qright_divider_width, parms)))
- parms = Fcons (Fcons (Qright_divider_width, make_number (0)), parms);
- if (NILP (Fassq (Qbottom_divider_width, parms)))
- parms = Fcons (Fcons (Qbottom_divider_width, make_number (0)), parms);
- if (NILP (Fassq (Qborder_width, parms)))
- parms = Fcons (Fcons (Qborder_width, make_number (1)), parms);
- if (NILP (Fassq (Qborder_color, parms)))
- parms = Fcons (Fcons (Qborder_color, build_string ("lightyellow")), parms);
- if (NILP (Fassq (Qbackground_color, parms)))
- parms = Fcons (Fcons (Qbackground_color, build_string ("lightyellow")),
- parms);
-
/* Block input until the tip has been fully drawn, to avoid crashes
when drawing tips in menus. */
block_input ();
- /* Create a frame for the tooltip, and record it in the global
- variable tip_frame. */
- frame = x_create_tip_frame (FRAME_DISPLAY_INFO (f), parms, string);
- f = XFRAME (frame);
+ if (!FRAMEP (tip_frame) || !FRAME_LIVE_P (XFRAME (tip_frame)))
+ {
+ /* Add default values to frame parameters. */
+ if (NILP (Fassq (Qname, parms)))
+ parms = Fcons (Fcons (Qname, build_string ("tooltip")), parms);
+ if (NILP (Fassq (Qinternal_border_width, parms)))
+ parms = Fcons (Fcons (Qinternal_border_width, make_number (3)), parms);
+ if (NILP (Fassq (Qborder_width, parms)))
+ parms = Fcons (Fcons (Qborder_width, make_number (1)), parms);
+ if (NILP (Fassq (Qborder_color, parms)))
+ parms = Fcons (Fcons (Qborder_color, build_string ("lightyellow")), parms);
+ if (NILP (Fassq (Qbackground_color, parms)))
+ parms = Fcons (Fcons (Qbackground_color, build_string ("lightyellow")),
+ parms);
+
+ /* Create a frame for the tooltip, and record it in the global
+ variable tip_frame. */
+ if (NILP (tip_frame = x_create_tip_frame (FRAME_DISPLAY_INFO (f), parms)))
+ {
+ /* Creating the tip frame failed. */
+ unblock_input ();
+ return unbind_to (count, Qnil);
+ }
+ }
+
+ tip_f = XFRAME (tip_frame);
+ window = FRAME_ROOT_WINDOW (tip_f);
+ AUTO_STRING (tip, " *tip*");
+ set_window_buffer (window, Fget_buffer_create (tip), false, false);
+ w = XWINDOW (window);
+ w->pseudo_window_p = true;
- /* Set up the frame's root window. */
- w = XWINDOW (FRAME_ROOT_WINDOW (f));
+ /* Set up the frame's root window. Note: The following code does not
+ try to size the window or its frame correctly. Its only purpose is
+ to make the subsequent text size calculations work. The right
+ sizes should get installed when the toolkit gets back to us. */
w->left_col = 0;
w->top_line = 0;
w->pixel_left = 0;
w->pixel_top = 0;
if (CONSP (Vx_max_tooltip_size)
- && INTEGERP (XCAR (Vx_max_tooltip_size))
- && XINT (XCAR (Vx_max_tooltip_size)) > 0
- && INTEGERP (XCDR (Vx_max_tooltip_size))
- && XINT (XCDR (Vx_max_tooltip_size)) > 0)
+ && RANGED_INTEGERP (1, XCAR (Vx_max_tooltip_size), INT_MAX)
+ && RANGED_INTEGERP (1, XCDR (Vx_max_tooltip_size), INT_MAX))
{
w->total_cols = XFASTINT (XCAR (Vx_max_tooltip_size));
w->total_lines = XFASTINT (XCDR (Vx_max_tooltip_size));
@@ -6551,164 +7036,71 @@ Text larger than the specified size is clipped. */)
w->total_lines = 40;
}
- w->pixel_width = w->total_cols * FRAME_COLUMN_WIDTH (f);
- w->pixel_height = w->total_lines * FRAME_LINE_HEIGHT (f);
-
- FRAME_TOTAL_COLS (f) = WINDOW_TOTAL_COLS (w);
- adjust_frame_glyphs (f);
- w->pseudo_window_p = true;
+ w->pixel_width = w->total_cols * FRAME_COLUMN_WIDTH (tip_f);
+ w->pixel_height = w->total_lines * FRAME_LINE_HEIGHT (tip_f);
+ FRAME_TOTAL_COLS (tip_f) = WINDOW_TOTAL_COLS (w);
+ adjust_frame_glyphs (tip_f);
- /* Display the tooltip text in a temporary buffer. */
+ /* Insert STRING into the root window's buffer and fit the frame to
+ the buffer. */
+ count_1 = SPECPDL_INDEX ();
old_buffer = current_buffer;
- set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f))->contents));
+ set_buffer_internal_1 (XBUFFER (w->contents));
bset_truncate_lines (current_buffer, Qnil);
+ specbind (Qinhibit_read_only, Qt);
+ specbind (Qinhibit_modification_hooks, Qt);
+ specbind (Qinhibit_point_motion_hooks, Qt);
+ Ferase_buffer ();
+ Finsert (1, &string);
clear_glyph_matrix (w->desired_matrix);
clear_glyph_matrix (w->current_matrix);
SET_TEXT_POS (pos, BEGV, BEGV_BYTE);
- try_window (FRAME_ROOT_WINDOW (f), pos, TRY_WINDOW_IGNORE_FONTS_CHANGE);
-
- /* Compute width and height of the tooltip. */
- width = height = 0;
- seen_reversed_p = false;
- for (i = 0; i < w->desired_matrix->nrows; ++i)
- {
- struct glyph_row *row = &w->desired_matrix->rows[i];
- struct glyph *last;
- int row_width;
-
- /* Stop at the first empty row at the end. */
- if (!row->enabled_p || !MATRIX_ROW_DISPLAYS_TEXT_P (row))
- break;
-
- /* Let the row go over the full width of the frame. */
- row->full_width_p = true;
-
- row_width = row->pixel_width;
- if (row->used[TEXT_AREA])
- {
- if (!row->reversed_p)
- {
- /* There's a glyph at the end of rows that is used to
- place the cursor there. Don't include the width of
- this glyph. */
- last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1];
- if (NILP (last->object))
- row_width -= last->pixel_width;
- }
- else
- {
- /* There could be a stretch glyph at the beginning of R2L
- rows that is produced by extend_face_to_end_of_line.
- Don't count that glyph. */
- struct glyph *g = row->glyphs[TEXT_AREA];
-
- if (g->type == STRETCH_GLYPH && NILP (g->object))
- {
- row_width -= g->pixel_width;
- seen_reversed_p = true;
- }
- }
- }
-
- height += row->height;
- width = max (width, row_width);
- }
-
- /* If we've seen partial-length R2L rows, we need to re-adjust the
- tool-tip frame width and redisplay it again, to avoid over-wide
- tips due to the stretch glyph that extends R2L lines to full
- width of the frame. */
- if (seen_reversed_p)
- {
- /* PXW: Why do we do the pixel-to-cols conversion only if
- seen_reversed_p holds? Don't we have to set other fields of
- the window/frame structure?
-
- w->total_cols and FRAME_TOTAL_COLS want the width in columns,
- not in pixels. */
- w->pixel_width = width;
- width /= WINDOW_FRAME_COLUMN_WIDTH (w);
- w->total_cols = width;
- FRAME_TOTAL_COLS (f) = width;
- SET_FRAME_WIDTH (f, width);
- adjust_frame_glyphs (f);
- w->pseudo_window_p = 1;
- clear_glyph_matrix (w->desired_matrix);
- clear_glyph_matrix (w->current_matrix);
- try_window (FRAME_ROOT_WINDOW (f), pos, TRY_WINDOW_IGNORE_FONTS_CHANGE);
- width = height = 0;
- /* Recompute width and height of the tooltip. */
- for (i = 0; i < w->desired_matrix->nrows; ++i)
- {
- struct glyph_row *row = &w->desired_matrix->rows[i];
- struct glyph *last;
- int row_width;
-
- if (!row->enabled_p || !MATRIX_ROW_DISPLAYS_TEXT_P (row))
- break;
- row->full_width_p = true;
- row_width = row->pixel_width;
- if (row->used[TEXT_AREA] && !row->reversed_p)
- {
- last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1];
- if (NILP (last->object))
- row_width -= last->pixel_width;
- }
-
- height += row->height;
- width = max (width, row_width);
- }
- }
-
- /* Add the frame's internal border to the width and height the w32
- window should have. */
- height += 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
- width += 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
-
- /* Move the tooltip window where the mouse pointer is. Resize and
- show it.
-
- PXW: This should use the frame's pixel coordinates. */
- compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y);
-
+ try_window (window, pos, TRY_WINDOW_IGNORE_FONTS_CHANGE);
+ /* Calculate size of tooltip window. */
+ size = Fwindow_text_pixel_size (window, Qnil, Qnil, Qnil,
+ make_number (w->pixel_height), Qnil);
+ /* Add the frame's internal border to calculated size. */
+ width = XINT (Fcar (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f);
+ height = XINT (Fcdr (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f);
+ /* Calculate position of tooltip frame. */
+ compute_tip_xy (tip_f, parms, dx, dy, width, height, &root_x, &root_y);
+
+ /* Show tooltip frame. */
{
- /* Adjust Window size to take border into account. */
RECT rect;
+ int pad = (NUMBERP (Vw32_tooltip_extra_pixels)
+ ? max (0, XINT (Vw32_tooltip_extra_pixels))
+ : FRAME_COLUMN_WIDTH (tip_f));
+
rect.left = rect.top = 0;
rect.right = width;
rect.bottom = height;
- AdjustWindowRect (&rect, f->output_data.w32->dwStyle, false);
-
- /* Position and size tooltip, and put it in the topmost group.
- The add-on of FRAME_COLUMN_WIDTH to the 5th argument is a
- peculiarity of w32 display: without it, some fonts cause the
- last character of the tip to be truncated or wrapped around to
- the next line. */
- SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOPMOST,
+ AdjustWindowRect (&rect, tip_f->output_data.w32->dwStyle,
+ FRAME_EXTERNAL_MENU_BAR (tip_f));
+
+ /* Position and size tooltip and put it in the topmost group. */
+ SetWindowPos (FRAME_W32_WINDOW (tip_f), HWND_TOPMOST,
root_x, root_y,
- rect.right - rect.left + FRAME_COLUMN_WIDTH (f),
+ rect.right - rect.left + pad,
rect.bottom - rect.top, SWP_NOACTIVATE | SWP_NOOWNERZORDER);
/* Ensure tooltip is on top of other topmost windows (eg menus). */
- SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOP,
+ SetWindowPos (FRAME_W32_WINDOW (tip_f), HWND_TOP,
0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE
| SWP_NOACTIVATE | SWP_NOOWNERZORDER);
/* Let redisplay know that we have made the frame visible already. */
- SET_FRAME_VISIBLE (f, 1);
+ SET_FRAME_VISIBLE (tip_f, 1);
- ShowWindow (FRAME_W32_WINDOW (f), SW_SHOWNOACTIVATE);
+ ShowWindow (FRAME_W32_WINDOW (tip_f), SW_SHOWNOACTIVATE);
}
- /* Draw into the window. */
w->must_be_updated_p = true;
update_single_window (w);
-
- unblock_input ();
-
- /* Restore original current buffer. */
set_buffer_internal_1 (old_buffer);
+ unbind_to (count_1, Qnil);
+ unblock_input ();
windows_or_buffers_changed = old_windows_or_buffers_changed;
start_timer:
@@ -6725,31 +7117,7 @@ DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
Value is t if tooltip was open, nil otherwise. */)
(void)
{
- ptrdiff_t count;
- Lisp_Object deleted, frame, timer;
-
- /* Return quickly if nothing to do. */
- if (NILP (tip_timer) && NILP (tip_frame))
- return Qnil;
-
- frame = tip_frame;
- timer = tip_timer;
- tip_frame = tip_timer = deleted = Qnil;
-
- count = SPECPDL_INDEX ();
- specbind (Qinhibit_redisplay, Qt);
- specbind (Qinhibit_quit, Qt);
-
- if (!NILP (timer))
- call1 (Qcancel_timer, timer);
-
- if (FRAMEP (frame))
- {
- delete_frame (frame, Qnil);
- deleted = Qt;
- }
-
- return unbind_to (count, deleted);
+ return x_hide_tip (!tooltip_reuse_hidden_frame);
}
/***********************************************************************
@@ -7617,19 +7985,34 @@ lookup_vk_code (char *key)
&& strcmp (lispy_function_keys[i], key) == 0)
return i;
+ if (w32_kbdhook_active)
+ {
+ /* Alphanumerics map to themselves. */
+ if (key[1] == 0)
+ {
+ if (key[0] >= 'A' && key[0] <= 'Z' ||
+ key[0] >= '0' && key[0] <= '9')
+ return key[0];
+ if (key[0] >= 'a' && key[0] <= 'z')
+ return toupper(key[0]);
+ }
+ }
+
return -1;
}
/* Convert a one-element vector style key sequence to a hot key
definition. */
static Lisp_Object
-w32_parse_hot_key (Lisp_Object key)
+w32_parse_and_hook_hot_key (Lisp_Object key, int hook)
{
/* Copied from Fdefine_key and store_in_keymap. */
register Lisp_Object c;
int vk_code;
int lisp_modifiers;
int w32_modifiers;
+ Lisp_Object res = Qnil;
+ char* vkname;
CHECK_VECTOR (key);
@@ -7652,7 +8035,12 @@ w32_parse_hot_key (Lisp_Object key)
c = Fcar (c);
if (!SYMBOLP (c))
emacs_abort ();
- vk_code = lookup_vk_code (SSDATA (SYMBOL_NAME (c)));
+ vkname = SSDATA (SYMBOL_NAME (c));
+ /* [s-], [M-], [h-]: Register all keys for this modifier */
+ if (w32_kbdhook_active && vkname[0] == 0)
+ vk_code = VK_ANY;
+ else
+ vk_code = lookup_vk_code (vkname);
}
else if (INTEGERP (c))
{
@@ -7676,34 +8064,75 @@ w32_parse_hot_key (Lisp_Object key)
#define MOD_WIN 0x0008
#endif
- /* Convert lisp modifiers to Windows hot-key form. */
- w32_modifiers = (lisp_modifiers & hyper_modifier) ? MOD_WIN : 0;
- w32_modifiers |= (lisp_modifiers & alt_modifier) ? MOD_ALT : 0;
- w32_modifiers |= (lisp_modifiers & ctrl_modifier) ? MOD_CONTROL : 0;
- w32_modifiers |= (lisp_modifiers & shift_modifier) ? MOD_SHIFT : 0;
+ if (w32_kbdhook_active)
+ {
+ /* Register Alt-x combinations. */
+ if (lisp_modifiers & alt_modifier)
+ {
+ hook_w32_key (hook, VK_MENU, vk_code);
+ res = Qt;
+ }
+ /* Register Win-x combinations based on modifier mappings. */
+ if (((lisp_modifiers & hyper_modifier)
+ && EQ (Vw32_lwindow_modifier, Qhyper))
+ || ((lisp_modifiers & super_modifier)
+ && EQ (Vw32_lwindow_modifier, Qsuper)))
+ {
+ hook_w32_key (hook, VK_LWIN, vk_code);
+ res = Qt;
+ }
+ if (((lisp_modifiers & hyper_modifier)
+ && EQ (Vw32_rwindow_modifier, Qhyper))
+ || ((lisp_modifiers & super_modifier)
+ && EQ (Vw32_rwindow_modifier, Qsuper)))
+ {
+ hook_w32_key (hook, VK_RWIN, vk_code);
+ res = Qt;
+ }
+ return res;
+ }
+ else
+ {
+ /* Convert lisp modifiers to Windows hot-key form. */
+ w32_modifiers = (lisp_modifiers & hyper_modifier) ? MOD_WIN : 0;
+ w32_modifiers |= (lisp_modifiers & alt_modifier) ? MOD_ALT : 0;
+ w32_modifiers |= (lisp_modifiers & ctrl_modifier) ? MOD_CONTROL : 0;
+ w32_modifiers |= (lisp_modifiers & shift_modifier) ? MOD_SHIFT : 0;
- return HOTKEY (vk_code, w32_modifiers);
+ return HOTKEY (vk_code, w32_modifiers);
+ }
}
DEFUN ("w32-register-hot-key", Fw32_register_hot_key,
Sw32_register_hot_key, 1, 1, 0,
doc: /* Register KEY as a hot-key combination.
-Certain key combinations like Alt-Tab are reserved for system use on
-Windows, and therefore are normally intercepted by the system. However,
-most of these key combinations can be received by registering them as
-hot-keys, overriding their special meaning.
-
-KEY must be a one element key definition in vector form that would be
-acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
-modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
-is always interpreted as the Windows modifier keys.
-
-The return value is the hotkey-id if registered, otherwise nil. */)
+Certain key combinations like Alt-Tab and Win-R are reserved for
+system use on Windows, and therefore are normally intercepted by the
+system. These key combinations can be received by registering them
+as hot-keys, except for Win-L which always locks the computer.
+
+On Windows 98 and ME, KEY must be a one element key definition in
+vector form that would be acceptable to `define-key' (e.g. [A-tab] for
+Alt-Tab). The meta modifier is interpreted as Alt if
+`w32-alt-is-meta' is t, and hyper is always interpreted as the Windows
+modifier keys. The return value is the hotkey-id if registered, otherwise nil.
+
+On Windows versions since NT, KEY can also be specified as [M-], [s-] or
+[h-] to indicate that all combinations of that key should be processed
+by Emacs instead of the operating system. The super and hyper
+modifiers are interpreted according to the current values of
+`w32-lwindow-modifier' and `w32-rwindow-modifier'. For instance,
+setting `w32-lwindow-modifier' to `super' and then calling
+`(register-hot-key [s-])' grabs all combinations of the left Windows
+key to Emacs, but leaves the right Windows key free for the operating
+system keyboard shortcuts. The return value is t if the call affected
+any key combinations, otherwise nil. */)
(Lisp_Object key)
{
- key = w32_parse_hot_key (key);
+ key = w32_parse_and_hook_hot_key (key, 1);
- if (!NILP (key) && NILP (Fmemq (key, w32_grabbed_keys)))
+ if (!w32_kbdhook_active
+ && !NILP (key) && NILP (Fmemq (key, w32_grabbed_keys)))
{
/* Reuse an empty slot if possible. */
Lisp_Object item = Fmemq (Qnil, w32_grabbed_keys);
@@ -7731,7 +8160,10 @@ DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key,
Lisp_Object item;
if (!INTEGERP (key))
- key = w32_parse_hot_key (key);
+ key = w32_parse_and_hook_hot_key (key, 0);
+
+ if (w32_kbdhook_active)
+ return key;
item = Fmemq (key, w32_grabbed_keys);
@@ -9285,6 +9717,7 @@ syms_of_w32fns (void)
DEFSYM (Qmm_size, "mm-size");
DEFSYM (Qframes, "frames");
DEFSYM (Qtip_frame, "tip-frame");
+ DEFSYM (Qassq_delete_all, "assq-delete-all");
DEFSYM (Qunicode_sip, "unicode-sip");
#if defined WINDOWSNT && !defined HAVE_DBUS
DEFSYM (QCicon, ":icon");
@@ -9338,11 +9771,15 @@ When non-nil, the Start menu is opened by tapping the key.
If you set this to nil, the left \"Windows\" key is processed by Emacs
according to the value of `w32-lwindow-modifier', which see.
-Note that some combinations of the left \"Windows\" key with other keys are
-caught by Windows at low level, and so binding them in Emacs will have no
-effect. For example, <lwindow>-r always pops up the Windows Run dialog,
-<lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
-the doc string of `w32-phantom-key-code'. */);
+Note that some combinations of the left \"Windows\" key with other
+keys are caught by Windows at low level. For example, <lwindow>-r
+pops up the Windows Run dialog, <lwindow>-<Pause> pops up the "System
+Properties" dialog, etc. On Windows 10, no \"Windows\" key
+combinations are normally handed to applications. To enable Emacs to
+process \"Windows\" key combinations, use the function
+`w32-register-hot-key`.
+
+For Windows 98/ME, see the doc string of `w32-phantom-key-code'. */);
Vw32_pass_lwindow_to_system = Qt;
DEFVAR_LISP ("w32-pass-rwindow-to-system",
@@ -9353,11 +9790,15 @@ When non-nil, the Start menu is opened by tapping the key.
If you set this to nil, the right \"Windows\" key is processed by Emacs
according to the value of `w32-rwindow-modifier', which see.
-Note that some combinations of the right \"Windows\" key with other keys are
-caught by Windows at low level, and so binding them in Emacs will have no
-effect. For example, <rwindow>-r always pops up the Windows Run dialog,
-<rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see
-the doc string of `w32-phantom-key-code'. */);
+Note that some combinations of the right \"Windows\" key with other
+keys are caught by Windows at low level. For example, <rwindow>-r
+pops up the Windows Run dialog, <rwindow>-<Pause> pops up the "System
+Properties" dialog, etc. On Windows 10, no \"Windows\" key
+combinations are normally handed to applications. To enable Emacs to
+process \"Windows\" key combinations, use the function
+`w32-register-hot-key`.
+
+For Windows 98/ME, see the doc string of `w32-phantom-key-code'. */);
Vw32_pass_rwindow_to_system = Qt;
DEFVAR_LISP ("w32-phantom-key-code",
@@ -9367,7 +9808,11 @@ Value is a number between 0 and 255.
Phantom key presses are generated in order to stop the system from
acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
-`w32-pass-rwindow-to-system' is nil. */);
+`w32-pass-rwindow-to-system' is nil.
+
+This variable is only used on Windows 98 and ME. For other Windows
+versions, see the documentation of the `w32-register-hot-key`
+function. */);
/* Although 255 is technically not a valid key code, it works and
means that this hack won't interfere with any real key code. */
XSETINT (Vw32_phantom_key_code, 255);
@@ -9397,7 +9842,9 @@ Any other value will cause the Scroll Lock key to be ignored. */);
doc: /* Modifier to use for the left \"Windows\" key.
The value can be hyper, super, meta, alt, control or shift for the
respective modifier, or nil to appear as the `lwindow' key.
-Any other value will cause the key to be ignored. */);
+Any other value will cause the key to be ignored.
+
+Also see the documentation of the `w32-register-hot-key` function. */);
Vw32_lwindow_modifier = Qnil;
DEFVAR_LISP ("w32-rwindow-modifier",
@@ -9405,7 +9852,9 @@ Any other value will cause the key to be ignored. */);
doc: /* Modifier to use for the right \"Windows\" key.
The value can be hyper, super, meta, alt, control or shift for the
respective modifier, or nil to appear as the `rwindow' key.
-Any other value will cause the key to be ignored. */);
+Any other value will cause the key to be ignored.
+
+Also see the documentation of the `w32-register-hot-key` function. */);
Vw32_rwindow_modifier = Qnil;
DEFVAR_LISP ("w32-apps-modifier",
@@ -9581,6 +10030,18 @@ Default is nil.
This variable has effect only on Windows Vista and later. */);
w32_disable_new_uniscribe_apis = 0;
+ DEFVAR_LISP ("w32-tooltip-extra-pixels",
+ Vw32_tooltip_extra_pixels,
+ doc: /* Number of pixels added after tooltip text.
+On Windows some fonts may cause the last character of a tooltip be
+truncated or wrapped around to the next line. Adding some extra space
+at the end of the toooltip works around this problem.
+
+This variable specifies the number of pixels that shall be added. The
+default value t means to add the width of one canonical character of the
+tip frame. */);
+ Vw32_tooltip_extra_pixels = Qt;
+
#if 0 /* TODO: Port to W32 */
defsubr (&Sx_change_window_property);
defsubr (&Sx_delete_window_property);
diff --git a/src/w32inevt.c b/src/w32inevt.c
index 867425f0bf2..a33f82dc7db 100644
--- a/src/w32inevt.c
+++ b/src/w32inevt.c
@@ -41,6 +41,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "termchar.h" /* for Mouse_HLInfo, tty_display_info */
#include "w32term.h"
#include "w32inevt.h"
+#include "w32common.h"
/* stdin, from w32console.c */
extern HANDLE keyboard_handle;
@@ -148,10 +149,12 @@ key_event (KEY_EVENT_RECORD *event, struct input_event *emacs_ev, int *isdead)
switch (event->wVirtualKeyCode)
{
case VK_LWIN:
- mod_key_state &= ~LEFT_WIN_PRESSED;
+ if (!w32_kbdhook_active)
+ mod_key_state &= ~LEFT_WIN_PRESSED;
break;
case VK_RWIN:
- mod_key_state &= ~RIGHT_WIN_PRESSED;
+ if (!w32_kbdhook_active)
+ mod_key_state &= ~RIGHT_WIN_PRESSED;
break;
case VK_APPS:
mod_key_state &= ~APPS_PRESSED;
@@ -185,7 +188,8 @@ key_event (KEY_EVENT_RECORD *event, struct input_event *emacs_ev, int *isdead)
keybd_event (faked_key, (BYTE) MapVirtualKey (faked_key, 0), 0, 0);
}
}
- mod_key_state |= LEFT_WIN_PRESSED;
+ if (!w32_kbdhook_active)
+ mod_key_state |= LEFT_WIN_PRESSED;
if (!NILP (Vw32_lwindow_modifier))
return 0;
break;
@@ -201,7 +205,8 @@ key_event (KEY_EVENT_RECORD *event, struct input_event *emacs_ev, int *isdead)
keybd_event (faked_key, (BYTE) MapVirtualKey (faked_key, 0), 0, 0);
}
}
- mod_key_state |= RIGHT_WIN_PRESSED;
+ if (!w32_kbdhook_active)
+ mod_key_state |= RIGHT_WIN_PRESSED;
if (!NILP (Vw32_rwindow_modifier))
return 0;
break;
@@ -267,6 +272,13 @@ key_event (KEY_EVENT_RECORD *event, struct input_event *emacs_ev, int *isdead)
/* Recognize state of Windows and Apps keys. */
event->dwControlKeyState |= mod_key_state;
+ if (w32_kbdhook_active)
+ {
+ if (check_w32_winkey_state (VK_LWIN))
+ event->dwControlKeyState |= LEFT_WIN_PRESSED;
+ if (check_w32_winkey_state (VK_RWIN))
+ event->dwControlKeyState |= RIGHT_WIN_PRESSED;
+ }
/* Distinguish numeric keypad keys from extended keys. */
event->wVirtualKeyCode =
diff --git a/src/w32term.h b/src/w32term.h
index 2fed56ed797..d809be3c03d 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -738,6 +738,16 @@ extern int handle_file_notifications (struct input_event *);
extern void w32_initialize_display_info (Lisp_Object);
extern void initialize_w32_display (struct terminal *, int *, int *);
+#ifdef WINDOWSNT
+/* Keyboard hooks. */
+extern void setup_w32_kbdhook (void);
+extern void remove_w32_kbdhook (void);
+extern int check_w32_winkey_state (int);
+#define w32_kbdhook_active (os_subtype != OS_9X)
+#else
+#define w32_kbdhook_active 0
+#endif
+
/* Keypad command key support. W32 doesn't have virtual keys defined
for the function keys on the keypad (they are mapped to the standard
function keys), so we define our own. */
diff --git a/src/window.c b/src/window.c
index 733cf75d132..3cfb6fce239 100644
--- a/src/window.c
+++ b/src/window.c
@@ -57,6 +57,7 @@ static bool foreach_window_1 (struct window *,
static bool window_resize_check (struct window *, bool);
static void window_resize_apply (struct window *, bool);
static void select_window_1 (Lisp_Object, bool);
+static void run_window_configuration_change_hook (struct frame *);
static struct window *set_window_fringes (struct window *, Lisp_Object,
Lisp_Object, Lisp_Object);
@@ -720,6 +721,36 @@ the height of the screen areas spanned by its children. */)
return make_number (decode_valid_window (window)->pixel_height);
}
+DEFUN ("window-pixel-width-before-size-change",
+ Fwindow_pixel_width_before_size_change,
+ Swindow_pixel_width_before_size_change, 0, 1, 0,
+ doc: /* Return pixel width of window WINDOW before last size changes.
+WINDOW must be a valid window and defaults to the selected one.
+
+The return value is the pixel width of WINDOW at the last time
+`window-size-change-functions' was run. It's zero if WINDOW was made
+after that. */)
+ (Lisp_Object window)
+{
+ return (make_number
+ (decode_valid_window (window)->pixel_width_before_size_change));
+}
+
+DEFUN ("window-pixel-height-before-size-change",
+ Fwindow_pixel_height_before_size_change,
+ Swindow_pixel_height_before_size_change, 0, 1, 0,
+ doc: /* Return pixel height of window WINDOW before last size changes.
+WINDOW must be a valid window and defaults to the selected one.
+
+The return value is the pixel height of WINDOW at the last time
+`window-size-change-functions' was run. It's zero if WINDOW was made
+after that. */)
+ (Lisp_Object window)
+{
+ return (make_number
+ (decode_valid_window (window)->pixel_height_before_size_change));
+}
+
DEFUN ("window-total-height", Fwindow_total_height, Swindow_total_height, 0, 2, 0,
doc: /* Return the height of window WINDOW in lines.
WINDOW must be a valid window and defaults to the selected one.
@@ -2879,6 +2910,7 @@ window-start value is reasonable when this function is called. */)
Lisp_Object sibling, pwindow, swindow IF_LINT (= Qnil), delta;
ptrdiff_t startpos IF_LINT (= 0), startbyte IF_LINT (= 0);
int top IF_LINT (= 0), new_top;
+ bool resize_failed = false;
w = decode_valid_window (window);
XSETWINDOW (window, w);
@@ -2978,8 +3010,6 @@ window-start value is reasonable when this function is called. */)
fset_redisplay (f);
Vwindow_list = Qnil;
- FRAME_WINDOW_SIZES_CHANGED (f) = true;
- bool resize_failed = false;
if (!WINDOW_LEAF_P (w))
{
@@ -3157,7 +3187,7 @@ select_frame_norecord (Lisp_Object frame)
Fselect_frame (frame, Qt);
}
-void
+static void
run_window_configuration_change_hook (struct frame *f)
{
ptrdiff_t count = SPECPDL_INDEX ();
@@ -3229,6 +3259,76 @@ If WINDOW is omitted or nil, it defaults to the selected window. */)
return Qnil;
}
+
+/* Compare old and present pixel sizes of windows in tree rooted at W.
+ Return true iff any of these windows differs in size. */
+
+static bool
+window_size_changed (struct window *w)
+{
+ if (w->pixel_width != w->pixel_width_before_size_change
+ || w->pixel_height != w->pixel_height_before_size_change)
+ return true;
+
+ if (WINDOW_INTERNAL_P (w))
+ {
+ w = XWINDOW (w->contents);
+ while (w)
+ {
+ if (window_size_changed (w))
+ return true;
+
+ w = NILP (w->next) ? 0 : XWINDOW (w->next);
+ }
+ }
+
+ return false;
+}
+
+/* Set before size change pixel sizes of windows in tree rooted at W to
+ their present pixel sizes. */
+
+static void
+window_set_before_size_change_sizes (struct window *w)
+{
+ w->pixel_width_before_size_change = w->pixel_width;
+ w->pixel_height_before_size_change = w->pixel_height;
+
+ if (WINDOW_INTERNAL_P (w))
+ {
+ w = XWINDOW (w->contents);
+ while (w)
+ {
+ window_set_before_size_change_sizes (w);
+ w = NILP (w->next) ? 0 : XWINDOW (w->next);
+ }
+ }
+}
+
+
+void
+run_window_size_change_functions (Lisp_Object frame)
+{
+ struct frame *f = XFRAME (frame);
+ struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
+ Lisp_Object functions = Vwindow_size_change_functions;
+
+ if (FRAME_WINDOW_CONFIGURATION_CHANGED (f)
+ || window_size_changed (r))
+ {
+ while (CONSP (functions))
+ {
+ if (!EQ (XCAR (functions), Qt))
+ call1 (XCAR (functions), frame);
+ functions = XCDR (functions);
+ }
+
+ window_set_before_size_change_sizes (r);
+ FRAME_WINDOW_CONFIGURATION_CHANGED (f) = false;
+ }
+}
+
+
/* Make WINDOW display BUFFER. RUN_HOOKS_P means it's allowed
to run hooks. See make_frame for a case where it's not allowed.
KEEP_MARGINS_P means that the current margins, fringes, and
@@ -3263,15 +3363,9 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer,
if (!(keep_margins_p && samebuf))
{ /* If we're not actually changing the buffer, don't reset hscroll
- and vscroll. This case happens for example when called from
- change_frame_size_1, where we use a dummy call to
- Fset_window_buffer on the frame's selected window (and no
- other) just in order to run window-configuration-change-hook
- (no longer true since change_frame_size_1 directly calls
- run_window_configuration_change_hook). Resetting hscroll and
- vscroll here is problematic for things like image-mode and
- doc-view-mode since it resets the image's position whenever we
- resize the frame. */
+ and vscroll. Resetting hscroll and vscroll here is problematic
+ for things like image-mode and doc-view-mode since it resets
+ the image's position whenever we resize the frame. */
w->hscroll = w->min_hscroll = w->hscroll_whole = 0;
w->suspend_auto_hscroll = false;
w->vscroll = 0;
@@ -3283,10 +3377,8 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer,
w->start_at_line_beg = false;
w->force_start = false;
}
- /* Maybe we could move this into the `if' but it's not obviously safe and
- I doubt it's worth the trouble. */
- wset_redisplay (w);
+ wset_redisplay (w);
wset_update_mode_line (w);
/* We must select BUFFER to run the window-scroll-functions and to look up
@@ -3314,7 +3406,7 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer,
if (run_hooks_p)
{
- if (! NILP (Vwindow_scroll_functions))
+ if (!NILP (Vwindow_scroll_functions))
run_hook_with_args_2 (Qwindow_scroll_functions, window,
Fmarker_position (w->start));
if (!samebuf)
@@ -3559,6 +3651,8 @@ make_window (void)
w->phys_cursor_width = -1;
#endif
w->sequence_number = ++sequence_number;
+ w->pixel_width_before_size_change = 0;
+ w->pixel_height_before_size_change = 0;
w->scroll_bar_width = -1;
w->scroll_bar_height = -1;
w->column_number_displayed = -1;
@@ -3922,7 +4016,6 @@ be applied on the Elisp level. */)
window_resize_apply (r, horflag);
fset_redisplay (f);
- FRAME_WINDOW_SIZES_CHANGED (f) = true;
adjust_frame_glyphs (f);
unblock_input ();
@@ -3971,11 +4064,9 @@ values. */)
}
-/* Resize frame F's windows when F's width or height is set to SIZE.
- If HORFLAG is zero, F's width was set to SIZE, otherwise its height
- was set. SIZE is interpreted in F's canonical character units
- (a.k.a. "columns" or "lines"), unless PIXELWISE is non-zero, which
- means to interpret SIZE in pixel units. */
+/* Resize frame F's windows when number of lines of F is set to SIZE.
+ HORFLAG means resize windows when number of columns of F is set to
+ SIZE. PIXELWISE means to interpret SIZE as pixels. */
void
resize_frame_windows (struct frame *f, int size, bool horflag, bool pixelwise)
{
@@ -4076,7 +4167,7 @@ resize_frame_windows (struct frame *f, int size, bool horflag, bool pixelwise)
m = XWINDOW (mini);
if (horflag)
{
- m->total_cols = new_size;
+ m->total_cols = size;
m->pixel_width = new_pixel_size;
}
else
@@ -4089,7 +4180,6 @@ resize_frame_windows (struct frame *f, int size, bool horflag, bool pixelwise)
}
}
- FRAME_WINDOW_SIZES_CHANGED (f) = true;
fset_redisplay (f);
}
@@ -4216,7 +4306,6 @@ set correctly. See the code of `split-window' for how this is done. */)
p = XWINDOW (o->parent);
fset_redisplay (f);
- FRAME_WINDOW_SIZES_CHANGED (f) = true;
new = make_window ();
n = XWINDOW (new);
wset_frame (n, frame);
@@ -4385,7 +4474,6 @@ Signal an error when WINDOW is the only window on its frame. */)
fset_redisplay (f);
Vwindow_list = Qnil;
- FRAME_WINDOW_SIZES_CHANGED (f) = true;
wset_next (w, Qnil); /* Don't delete w->next too. */
free_window_matrices (w);
@@ -4453,9 +4541,6 @@ Signal an error when WINDOW is the only window on its frame. */)
}
else
unblock_input ();
-
- /* Must be run by the caller:
- run_window_configuration_change_hook (f); */
}
else
/* We failed: Relink WINDOW into window tree. */
@@ -4529,7 +4614,6 @@ grow_mini_window (struct window *w, int delta, bool pixelwise)
/* Enforce full redisplay of the frame. */
/* FIXME: Shouldn't window--resize-root-window-vertically do it? */
fset_redisplay (f);
- FRAME_WINDOW_SIZES_CHANGED (f) = true;
adjust_frame_glyphs (f);
unblock_input ();
}
@@ -4569,7 +4653,6 @@ shrink_mini_window (struct window *w, bool pixelwise)
/* Enforce full redisplay of the frame. */
/* FIXME: Shouldn't window--resize-root-window-vertically do it? */
fset_redisplay (f);
- FRAME_WINDOW_SIZES_CHANGED (f) = true;
adjust_frame_glyphs (f);
unblock_input ();
}
@@ -4612,7 +4695,6 @@ DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal, Sresize_mini
w->top_line = r->top_line + r->total_lines;
fset_redisplay (f);
- FRAME_WINDOW_SIZES_CHANGED (f) = true;
adjust_frame_glyphs (f);
unblock_input ();
return Qt;
@@ -5950,6 +6032,7 @@ struct saved_window
Lisp_Object window, buffer, start, pointm, old_pointm;
Lisp_Object pixel_left, pixel_top, pixel_height, pixel_width;
+ Lisp_Object pixel_height_before_size_change, pixel_width_before_size_change;
Lisp_Object left_col, top_line, total_cols, total_lines;
Lisp_Object normal_cols, normal_lines;
Lisp_Object hscroll, min_hscroll, hscroll_whole, suspend_auto_hscroll;
@@ -6065,6 +6148,12 @@ the return value is nil. Otherwise the value is t. */)
struct window *root_window;
struct window **leaf_windows;
ptrdiff_t i, k, n_leaf_windows;
+ /* Records whether a window has been added or removed wrt the
+ original configuration. */
+ bool window_changed = false;
+ /* Records whether a window has changed its buffer wrt the
+ original configuration. */
+ bool buffer_changed = false;
/* Don't do this within the main loop below: This may call Lisp
code and is thus potentially unsafe while input is blocked. */
@@ -6073,6 +6162,12 @@ the return value is nil. Otherwise the value is t. */)
p = SAVED_WINDOW_N (saved_windows, k);
window = p->window;
w = XWINDOW (window);
+
+ if (NILP (w->contents))
+ /* A dead window that will be resurrected, the window
+ configuration will change. */
+ window_changed = true;
+
if (BUFFERP (w->contents)
&& !EQ (w->contents, p->buffer)
&& BUFFER_LIVE_P (XBUFFER (p->buffer)))
@@ -6102,7 +6197,6 @@ the return value is nil. Otherwise the value is t. */)
}
fset_redisplay (f);
- FRAME_WINDOW_SIZES_CHANGED (f) = true;
/* Problem: Freeing all matrices and later allocating them again
is a serious redisplay flickering problem. What we would
@@ -6158,6 +6252,10 @@ the return value is nil. Otherwise the value is t. */)
w->pixel_top = XFASTINT (p->pixel_top);
w->pixel_width = XFASTINT (p->pixel_width);
w->pixel_height = XFASTINT (p->pixel_height);
+ w->pixel_width_before_size_change
+ = XFASTINT (p->pixel_width_before_size_change);
+ w->pixel_height_before_size_change
+ = XFASTINT (p->pixel_height_before_size_change);
w->left_col = XFASTINT (p->left_col);
w->top_line = XFASTINT (p->top_line);
w->total_cols = XFASTINT (p->total_cols);
@@ -6205,6 +6303,9 @@ the return value is nil. Otherwise the value is t. */)
if (BUFFERP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer)))
/* If saved buffer is alive, install it. */
{
+ if (!EQ (w->contents, p->buffer))
+ /* Record buffer configuration change. */
+ buffer_changed = true;
wset_buffer (w, p->buffer);
w->start_at_line_beg = !NILP (p->start_at_line_beg);
set_marker_restricted (w->start, p->start, w->contents);
@@ -6238,6 +6339,8 @@ the return value is nil. Otherwise the value is t. */)
else if (!NILP (w->start))
/* Leaf window has no live buffer, get one. */
{
+ /* Record buffer configuration change. */
+ buffer_changed = true;
/* Get the buffer via other_buffer_safely in order to
avoid showing an unimportant buffer and, if necessary, to
recreate *scratch* in the course (part of Juanma's bs-show
@@ -6285,7 +6388,10 @@ the return value is nil. Otherwise the value is t. */)
/* Now, free glyph matrices in windows that were not reused. */
for (i = 0; i < n_leaf_windows; i++)
if (NILP (leaf_windows[i]->contents))
- free_window_matrices (leaf_windows[i]);
+ {
+ free_window_matrices (leaf_windows[i]);
+ window_changed = true;
+ }
/* Allow x_set_window_size again and apply frame size changes if
needed. */
@@ -6305,7 +6411,8 @@ the return value is nil. Otherwise the value is t. */)
/* Record the selected window's buffer here. The window should
already be the selected one from the call above. */
- select_window (data->current_window, Qnil, false);
+ if (WINDOW_LIVE_P (data->current_window))
+ select_window (data->current_window, Qnil, false);
/* Fselect_window will have made f the selected frame, so we
reselect the proper frame here. Fhandle_switch_frame will change the
@@ -6315,7 +6422,32 @@ the return value is nil. Otherwise the value is t. */)
if (FRAME_LIVE_P (XFRAME (data->selected_frame)))
do_switch_frame (data->selected_frame, 0, 0, Qnil);
- run_window_configuration_change_hook (f);
+ if (window_changed)
+ /* At least one window has been added or removed. Run
+ `window-configuration-change-hook' and make sure
+ `window-size-change-functions' get run later.
+
+ We have to do this in order to capture the following
+ scenario: Suppose our frame contains two live windows W1 and
+ W2 and ‘set-window-configuration’ replaces them by two
+ windows W3 and W4 that were dead the last time
+ run_window_size_change_functions was run. If W3 and W4 have
+ the same values for their old and new pixel sizes but these
+ values differ from those of W1 and W2, the sizes of our
+ frame's two live windows changed but window_size_changed has
+ no means to detect that fact.
+
+ Obviously, this will get us false positives, for example,
+ when we restore the original configuration with W1 and W2
+ before run_window_size_change_functions gets called. */
+ {
+ run_window_configuration_change_hook (f);
+ FRAME_WINDOW_CONFIGURATION_CHANGED (f) = true;
+ }
+ else if (buffer_changed)
+ /* At least one window has changed its buffer. Run
+ `window-configuration-change-hook' only. */
+ run_window_configuration_change_hook (f);
}
if (!NILP (new_current_buffer))
@@ -6466,6 +6598,10 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, ptrdiff_t i)
p->pixel_top = make_number (w->pixel_top);
p->pixel_width = make_number (w->pixel_width);
p->pixel_height = make_number (w->pixel_height);
+ p->pixel_width_before_size_change
+ = make_number (w->pixel_width_before_size_change);
+ p->pixel_height_before_size_change
+ = make_number (w->pixel_height_before_size_change);
p->left_col = make_number (w->left_col);
p->top_line = make_number (w->top_line);
p->total_cols = make_number (w->total_cols);
@@ -7248,6 +7384,16 @@ selected; while the global part is run only once for the modified frame,
with the relevant frame selected. */);
Vwindow_configuration_change_hook = Qnil;
+ DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions,
+ doc: /* Functions called during redisplay, if window sizes have changed.
+The value should be a list of functions that take one argument.
+During the first part of redisplay, for each frame, if any of its windows
+have changed size since the last redisplay, or have been split or deleted,
+all the functions in the list are called, with the frame as argument.
+If redisplay decides to resize the minibuffer window, it calls these
+functions on behalf of that as well. */);
+ Vwindow_size_change_functions = Qnil;
+
DEFVAR_LISP ("recenter-redisplay", Vrecenter_redisplay,
doc: /* Non-nil means `recenter' redraws entire frame.
If this option is non-nil, then the `recenter' command with a nil
@@ -7376,6 +7522,8 @@ displayed after a scrolling operation to be somewhat inaccurate. */);
defsubr (&Swindow_use_time);
defsubr (&Swindow_pixel_width);
defsubr (&Swindow_pixel_height);
+ defsubr (&Swindow_pixel_width_before_size_change);
+ defsubr (&Swindow_pixel_height_before_size_change);
defsubr (&Swindow_total_width);
defsubr (&Swindow_total_height);
defsubr (&Swindow_normal_size);
diff --git a/src/window.h b/src/window.h
index 0cfff88be51..84180c96a7d 100644
--- a/src/window.h
+++ b/src/window.h
@@ -214,6 +214,11 @@ struct window
int pixel_width;
int pixel_height;
+ /* The pixel sizes of the window at the last time
+ `window-size-change-functions' was run. */
+ int pixel_width_before_size_change;
+ int pixel_height_before_size_change;
+
/* The size of the window. */
int total_cols;
int total_lines;
@@ -499,15 +504,17 @@ wset_next_buffers (struct window *w, Lisp_Object val)
#define WINDOW_LEAF_P(W) \
(BUFFERP ((W)->contents))
-/* True if W is a member of horizontal combination. */
+/* Non-nil if W is internal. */
+#define WINDOW_INTERNAL_P(W) \
+ (WINDOWP ((W)->contents))
+/* True if W is a member of horizontal combination. */
#define WINDOW_HORIZONTAL_COMBINATION_P(W) \
- (WINDOWP ((W)->contents) && (W)->horizontal)
+ (WINDOW_INTERNAL_P (W) && (W)->horizontal)
/* True if W is a member of vertical combination. */
-
#define WINDOW_VERTICAL_COMBINATION_P(W) \
- (WINDOWP ((W)->contents) && !(W)->horizontal)
+ (WINDOW_INTERNAL_P (W) && !(W)->horizontal)
/* WINDOW's XFRAME. */
#define WINDOW_XFRAME(W) (XFRAME (WINDOW_FRAME ((W))))
@@ -1013,7 +1020,7 @@ extern void grow_mini_window (struct window *, int, bool);
extern void shrink_mini_window (struct window *, bool);
extern int window_relative_x_coord (struct window *, enum window_part, int);
-void run_window_configuration_change_hook (struct frame *f);
+void run_window_size_change_functions (Lisp_Object);
/* Make WINDOW display BUFFER. RUN_HOOKS_P means it's allowed
to run hooks. See make_frame for a case where it's not allowed. */
diff --git a/src/xdisp.c b/src/xdisp.c
index e5ac6504067..123303ef8d8 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -9794,26 +9794,28 @@ the maximum pixel-height of all text lines.
The optional argument FROM, if non-nil, specifies the first text
position and defaults to the minimum accessible position of the buffer.
-If FROM is t, use the minimum accessible position that is not a newline
-character. TO, if non-nil, specifies the last text position and
+If FROM is t, use the minimum accessible position that starts a
+non-empty line. TO, if non-nil, specifies the last text position and
defaults to the maximum accessible position of the buffer. If TO is t,
-use the maximum accessible position that is not a newline character.
+use the maximum accessible position that ends a non-empty line.
The optional argument X-LIMIT, if non-nil, specifies the maximum text
width that can be returned. X-LIMIT nil or omitted, means to use the
-pixel-width of WINDOW's body; use this if you do not intend to change
-the width of WINDOW. Use the maximum width WINDOW may assume if you
-intend to change WINDOW's width. In any case, text whose x-coordinate
-is beyond X-LIMIT is ignored. Since calculating the width of long lines
-can take some time, it's always a good idea to make this argument as
-small as possible; in particular, if the buffer contains long lines that
-shall be truncated anyway.
+pixel-width of WINDOW's body; use this if you want to know how high
+WINDOW should be become in order to fit all of its buffer's text with
+the width of WINDOW unaltered. Use the maximum width WINDOW may assume
+if you intend to change WINDOW's width. In any case, text whose
+x-coordinate is beyond X-LIMIT is ignored. Since calculating the width
+of long lines can take some time, it's always a good idea to make this
+argument as small as possible; in particular, if the buffer contains
+long lines that shall be truncated anyway.
The optional argument Y-LIMIT, if non-nil, specifies the maximum text
-height that can be returned. Text lines whose y-coordinate is beyond
-Y-LIMIT are ignored. Since calculating the text height of a large
-buffer can take some time, it makes sense to specify this argument if
-the size of the buffer is unknown.
+height (exluding the height of the mode- or header-line, if any) that
+can be returned. Text lines whose y-coordinate is beyond Y-LIMIT are
+ignored. Since calculating the text height of a large buffer can take
+some time, it makes sense to specify this argument if the size of the
+buffer is large or unknown.
Optional argument MODE-AND-HEADER-LINE nil or omitted means do not
include the height of the mode- or header-line of WINDOW in the return
@@ -9831,7 +9833,7 @@ include the height of both, if present, in the return value. */)
ptrdiff_t start, end, pos;
struct text_pos startp;
void *itdata = NULL;
- int c, max_y = -1, x = 0, y = 0;
+ int c, max_x = 0, max_y = 0, x = 0, y = 0;
CHECK_BUFFER (buffer);
b = XBUFFER (buffer);
@@ -9876,11 +9878,13 @@ include the height of both, if present, in the return value. */)
end = max (start, min (XINT (to), ZV));
}
- if (!NILP (y_limit))
- {
- CHECK_NUMBER (y_limit);
- max_y = min (XINT (y_limit), INT_MAX);
- }
+ if (!NILP (x_limit) && RANGED_INTEGERP (0, x_limit, INT_MAX))
+ max_x = XINT (x_limit);
+
+ if (NILP (y_limit))
+ max_y = INT_MAX;
+ else if (RANGED_INTEGERP (0, y_limit, INT_MAX))
+ max_y = XINT (y_limit);
itdata = bidi_shelve_cache ();
SET_TEXT_POS (startp, start, CHAR_TO_BYTE (start));
@@ -9890,27 +9894,30 @@ include the height of both, if present, in the return value. */)
x = move_it_to (&it, end, -1, max_y, -1, MOVE_TO_POS | MOVE_TO_Y);
else
{
- CHECK_NUMBER (x_limit);
- it.last_visible_x = min (XINT (x_limit), INFINITY);
+ it.last_visible_x = max_x;
/* Actually, we never want move_it_to stop at to_x. But to make
sure that move_it_in_display_line_to always moves far enough,
- we set it to INT_MAX and specify MOVE_TO_X. */
- x = move_it_to (&it, end, INT_MAX, max_y, -1,
- MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y);
+ we set it to INT_MAX and specify MOVE_TO_X. Also bound width
+ value by X-LIMIT. */
+ x = min (move_it_to (&it, end, INT_MAX, max_y, -1,
+ MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y),
+ max_x);
}
- y = it.current_y + it.max_ascent + it.max_descent;
+ /* Subtract height of header-line which was counted automatically by
+ start_display. */
+ y = min (it.current_y + it.max_ascent + it.max_descent
+ - WINDOW_HEADER_LINE_HEIGHT (w),
+ max_y);
- if (!EQ (mode_and_header_line, Qheader_line)
- && !EQ (mode_and_header_line, Qt))
- /* Do not count the header-line which was counted automatically by
- start_display. */
- y = y - WINDOW_HEADER_LINE_HEIGHT (w);
+ if (EQ (mode_and_header_line, Qheader_line)
+ || EQ (mode_and_header_line, Qt))
+ /* Re-add height of header-line as requested. */
+ y = y + WINDOW_HEADER_LINE_HEIGHT (w);
if (EQ (mode_and_header_line, Qmode_line)
|| EQ (mode_and_header_line, Qt))
- /* Do count the mode-line which is not included automatically by
- start_display. */
+ /* Add height of mode-line as requested. */
y = y + WINDOW_MODE_LINE_HEIGHT (w);
bidi_unshelve_cache (itdata, false);
@@ -11793,24 +11800,7 @@ prepare_menu_bars (void)
&& !XBUFFER (w->contents)->text->redisplay)
continue;
- /* If a window on this frame changed size, report that to
- the user and clear the size-change flag. */
- if (FRAME_WINDOW_SIZES_CHANGED (f))
- {
- Lisp_Object functions;
-
- /* Clear flag first in case we get an error below. */
- FRAME_WINDOW_SIZES_CHANGED (f) = false;
- functions = Vwindow_size_change_functions;
-
- while (CONSP (functions))
- {
- if (!EQ (XCAR (functions), Qt))
- call1 (XCAR (functions), frame);
- functions = XCDR (functions);
- }
- }
-
+ run_window_size_change_functions (frame);
menu_bar_hooks_run = update_menu_bar (f, false, menu_bar_hooks_run);
#ifdef HAVE_WINDOW_SYSTEM
update_tool_bar (f, false);
@@ -13606,24 +13596,12 @@ redisplay_internal (void)
it's too late for the hooks in window-size-change-functions,
which have been examined already in prepare_menu_bars. So in
that case we call the hooks here only for the selected frame. */
- if (sf->redisplay && FRAME_WINDOW_SIZES_CHANGED (sf))
+ if (sf->redisplay)
{
- Lisp_Object functions;
ptrdiff_t count1 = SPECPDL_INDEX ();
record_unwind_save_match_data ();
-
- /* Clear flag first in case we get an error below. */
- FRAME_WINDOW_SIZES_CHANGED (sf) = false;
- functions = Vwindow_size_change_functions;
-
- while (CONSP (functions))
- {
- if (!EQ (XCAR (functions), Qt))
- call1 (XCAR (functions), selected_frame);
- functions = XCDR (functions);
- }
-
+ run_window_size_change_functions (selected_frame);
unbind_to (count1, Qnil);
}
@@ -13645,22 +13623,10 @@ redisplay_internal (void)
{
if (sf->redisplay)
{
- Lisp_Object functions;
ptrdiff_t count1 = SPECPDL_INDEX ();
record_unwind_save_match_data ();
-
- /* Clear flag first in case we get an error below. */
- FRAME_WINDOW_SIZES_CHANGED (sf) = false;
- functions = Vwindow_size_change_functions;
-
- while (CONSP (functions))
- {
- if (!EQ (XCAR (functions), Qt))
- call1 (XCAR (functions), selected_frame);
- functions = XCDR (functions);
- }
-
+ run_window_size_change_functions (selected_frame);
unbind_to (count1, Qnil);
}
@@ -14037,9 +14003,6 @@ redisplay_internal (void)
}
else if (FRAME_VISIBLE_P (sf) && !FRAME_OBSCURED_P (sf))
{
- Lisp_Object mini_window = FRAME_MINIBUF_WINDOW (sf);
- struct frame *mini_frame;
-
displayed_buffer = XBUFFER (XWINDOW (selected_window)->contents);
/* Use list_of_error, not Qerror, so that
we catch only errors and don't run the debugger. */
@@ -14047,8 +14010,8 @@ redisplay_internal (void)
list_of_error,
redisplay_window_error);
if (update_miniwindow_p)
- internal_condition_case_1 (redisplay_window_1, mini_window,
- list_of_error,
+ internal_condition_case_1 (redisplay_window_1,
+ FRAME_MINIBUF_WINDOW (sf), list_of_error,
redisplay_window_error);
/* Compare desired and current matrices, perform output. */
@@ -14098,8 +14061,8 @@ redisplay_internal (void)
have put text on a frame other than the selected one, so the
above call to update_frame would not have caught it. Catch
it here. */
- mini_window = FRAME_MINIBUF_WINDOW (sf);
- mini_frame = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
+ Lisp_Object mini_window = FRAME_MINIBUF_WINDOW (sf);
+ struct frame *mini_frame = XFRAME (WINDOW_FRAME (XWINDOW (mini_window)));
if (mini_frame != sf && FRAME_WINDOW_P (mini_frame))
{
@@ -16089,6 +16052,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p)
bool last_line_misfit = false;
ptrdiff_t beg_unchanged, end_unchanged;
int frame_line_height;
+ bool use_desired_matrix;
SET_TEXT_POS (lpoint, PT, PT_BYTE);
opoint = lpoint;
@@ -16811,7 +16775,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p)
startp = run_window_scroll_functions (window, it.current.pos);
/* Redisplay the window. */
- bool use_desired_matrix = false;
+ use_desired_matrix = false;
if (!current_matrix_up_to_date_p
|| windows_or_buffers_changed
|| f->cursor_type_changed
@@ -31454,16 +31418,6 @@ If nil, disable message logging. If t, log messages but don't truncate
the buffer when it becomes large. */);
Vmessage_log_max = make_number (1000);
- DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions,
- doc: /* Functions called during redisplay, if window sizes have changed.
-The value should be a list of functions that take one argument.
-During the first part of redisplay, for each frame, if any of its windows
-have changed size since the last redisplay, or have been split or deleted,
-all the functions in the list are called, with the frame as argument.
-If redisplay decides to resize the minibuffer window, it calls these
-functions on behalf of that as well. */);
- Vwindow_size_change_functions = Qnil;
-
DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions,
doc: /* List of functions to call before redisplaying a window with scrolling.
Each function is called with two arguments, the window and its new
diff --git a/src/xfns.c b/src/xfns.c
index 0a4a09ef285..74c559a5a0b 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1313,7 +1313,6 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
}
#endif /* not USE_X_TOOLKIT && not USE_GTK */
adjust_frame_glyphs (f);
- run_window_configuration_change_hook (f);
}
@@ -5318,8 +5317,6 @@ no value of TYPE (always string in the MS Windows case). */)
Tool tips
***********************************************************************/
-static Lisp_Object x_create_tip_frame (struct x_display_info *,
- Lisp_Object, Lisp_Object);
static void compute_tip_xy (struct frame *, Lisp_Object, Lisp_Object,
Lisp_Object, int, int, int *, int *);
@@ -5363,9 +5360,7 @@ unwind_create_tip_frame (Lisp_Object frame)
when this happens. */
static Lisp_Object
-x_create_tip_frame (struct x_display_info *dpyinfo,
- Lisp_Object parms,
- Lisp_Object text)
+x_create_tip_frame (struct x_display_info *dpyinfo, Lisp_Object parms)
{
struct frame *f;
Lisp_Object frame;
@@ -5373,8 +5368,6 @@ x_create_tip_frame (struct x_display_info *dpyinfo,
int width, height;
ptrdiff_t count = SPECPDL_INDEX ();
bool face_change_before = face_change;
- Lisp_Object buffer;
- struct buffer *old_buffer;
int x_width = 0, x_height = 0;
if (!dpyinfo->terminal->name)
@@ -5390,23 +5383,9 @@ x_create_tip_frame (struct x_display_info *dpyinfo,
error ("Invalid frame name--not a string or nil");
frame = Qnil;
- f = make_frame (true);
+ f = make_frame (false);
+ f->wants_modeline = false;
XSETFRAME (frame, f);
-
- AUTO_STRING (tip, " *tip*");
- buffer = Fget_buffer_create (tip);
- /* Use set_window_buffer instead of Fset_window_buffer (see
- discussion of bug#11984, bug#12025, bug#12026). */
- set_window_buffer (FRAME_ROOT_WINDOW (f), buffer, false, false);
- old_buffer = current_buffer;
- set_buffer_internal_1 (XBUFFER (buffer));
- bset_truncate_lines (current_buffer, Qnil);
- specbind (Qinhibit_read_only, Qt);
- specbind (Qinhibit_modification_hooks, Qt);
- Ferase_buffer ();
- Finsert (1, &text);
- set_buffer_internal_1 (old_buffer);
-
record_unwind_protect (unwind_create_tip_frame, frame);
f->terminal = dpyinfo->terminal;
@@ -5648,8 +5627,6 @@ x_create_tip_frame (struct x_display_info *dpyinfo,
{
Lisp_Object bg = Fframe_parameter (frame, Qbackground_color);
- /* Set tip_frame here, so that */
- tip_frame = frame;
call2 (Qface_set_after_frame_default, frame, Qnil);
if (!EQ (bg, Fframe_parameter (frame, Qbackground_color)))
@@ -5788,6 +5765,85 @@ compute_tip_xy (struct frame *f, Lisp_Object parms, Lisp_Object dx, Lisp_Object
}
+/* Hide tooltip. Delete its frame if DELETE is true. */
+static Lisp_Object
+x_hide_tip (bool delete)
+{
+ if (!NILP (tip_timer))
+ {
+ call1 (Qcancel_timer, tip_timer);
+ tip_timer = Qnil;
+ }
+
+
+ if (NILP (tip_frame)
+ || (!delete && FRAMEP (tip_frame)
+ && !FRAME_VISIBLE_P (XFRAME (tip_frame))))
+ return Qnil;
+ else
+ {
+ ptrdiff_t count;
+ Lisp_Object was_open = Qnil;
+
+ count = SPECPDL_INDEX ();
+ specbind (Qinhibit_redisplay, Qt);
+ specbind (Qinhibit_quit, Qt);
+
+#ifdef USE_GTK
+ {
+ /* When using system tooltip, tip_frame is the Emacs frame on
+ which the tip is shown. */
+ struct frame *f = XFRAME (tip_frame);
+
+ if (FRAME_LIVE_P (f) && xg_hide_tooltip (f))
+ {
+ tip_frame = Qnil;
+ was_open = Qt;
+ }
+ }
+#endif
+
+ if (FRAMEP (tip_frame))
+ {
+ if (delete)
+ {
+ delete_frame (tip_frame, Qnil);
+ tip_frame = Qnil;
+ }
+ else
+ x_make_frame_invisible (XFRAME (tip_frame));
+
+ was_open = Qt;
+
+#ifdef USE_LUCID
+ /* Bloodcurdling hack alert: The Lucid menu bar widget's
+ redisplay procedure is not called when a tip frame over
+ menu items is unmapped. Redisplay the menu manually... */
+ {
+ Widget w;
+ struct frame *f = SELECTED_FRAME ();
+ if (FRAME_X_P (f) && FRAME_LIVE_P (f))
+ {
+ w = f->output_data.x->menubar_widget;
+
+ if (!DoesSaveUnders (FRAME_DISPLAY_INFO (f)->screen)
+ && w != NULL)
+ {
+ block_input ();
+ xlwmenu_redisplay (w);
+ unblock_input ();
+ }
+ }
+ }
+#endif /* USE_LUCID */
+ }
+ else
+ tip_frame = Qnil;
+
+ return unbind_to (count, was_open);
+ }
+}
+
DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
doc: /* Show STRING in a "tooltip" window on frame FRAME.
A tooltip window is a small X window displaying a string.
@@ -5820,15 +5876,17 @@ A tooltip's maximum size is specified by `x-max-tooltip-size'.
Text larger than the specified size is clipped. */)
(Lisp_Object string, Lisp_Object frame, Lisp_Object parms, Lisp_Object timeout, Lisp_Object dx, Lisp_Object dy)
{
- struct frame *f;
+ struct frame *f, *tip_f;
struct window *w;
int root_x, root_y;
struct buffer *old_buffer;
struct text_pos pos;
- int i, width, height;
- bool seen_reversed_p;
+ int width, height;
int old_windows_or_buffers_changed = windows_or_buffers_changed;
ptrdiff_t count = SPECPDL_INDEX ();
+ ptrdiff_t count_1;
+ Lisp_Object window, size;
+ AUTO_STRING (tip, " *tip*");
specbind (Qinhibit_redisplay, Qt);
@@ -5877,22 +5935,23 @@ Text larger than the specified size is clipped. */)
if (NILP (last_show_tip_args))
last_show_tip_args = Fmake_vector (make_number (3), Qnil);
- if (!NILP (tip_frame))
+ if (FRAMEP (tip_frame) && FRAME_LIVE_P (XFRAME (tip_frame)))
{
Lisp_Object last_string = AREF (last_show_tip_args, 0);
Lisp_Object last_frame = AREF (last_show_tip_args, 1);
Lisp_Object last_parms = AREF (last_show_tip_args, 2);
- if (EQ (frame, last_frame)
- && !NILP (Fequal (last_string, string))
+ if (FRAME_VISIBLE_P (XFRAME (tip_frame))
+ && EQ (frame, last_frame)
+ && !NILP (Fequal_including_properties (last_string, string))
&& !NILP (Fequal (last_parms, parms)))
{
- struct frame *tip_f = XFRAME (tip_frame);
-
/* Only DX and DY have changed. */
+ tip_f = XFRAME (tip_frame);
if (!NILP (tip_timer))
{
Lisp_Object timer = tip_timer;
+
tip_timer = Qnil;
call1 (Qcancel_timer, timer);
}
@@ -5903,41 +5962,102 @@ Text larger than the specified size is clipped. */)
XMoveWindow (FRAME_X_DISPLAY (tip_f), FRAME_X_WINDOW (tip_f),
root_x, root_y);
unblock_input ();
+
goto start_timer;
}
- }
+ else if (tooltip_reuse_hidden_frame && EQ (frame, last_frame))
+ {
+ bool delete = false;
+ Lisp_Object tail, elt, parm, last;
+
+ /* Check if every parameter in PARMS has the same value in
+ last_parms unless it should be ignored by means of
+ Vtooltip_reuse_hidden_frame_parameters. This may destruct
+ last_parms which, however, will be recreated below. */
+ for (tail = parms; CONSP (tail); tail = XCDR (tail))
+ {
+ elt = XCAR (tail);
+ parm = Fcar (elt);
+ /* The left, top, right and bottom parameters are handled
+ by compute_tip_xy so they can be ignored here. */
+ if (!EQ (parm, Qleft) && !EQ (parm, Qtop)
+ && !EQ (parm, Qright) && !EQ (parm, Qbottom))
+ {
+ last = Fassq (parm, last_parms);
+ if (NILP (Fequal (Fcdr (elt), Fcdr (last))))
+ {
+ /* We lost, delete the old tooltip. */
+ delete = true;
+ break;
+ }
+ else
+ last_parms = call2 (Qassq_delete_all, parm, last_parms);
+ }
+ else
+ last_parms = call2 (Qassq_delete_all, parm, last_parms);
+ }
- /* Hide a previous tip, if any. */
- Fx_hide_tip ();
+ /* Now check if every parameter in what is left of last_parms
+ with a non-nil value has an association in PARMS unless it
+ should be ignored by means of
+ Vtooltip_reuse_hidden_frame_parameters. */
+ for (tail = last_parms; CONSP (tail); tail = XCDR (tail))
+ {
+ elt = XCAR (tail);
+ parm = Fcar (elt);
+ if (!EQ (parm, Qleft) && !EQ (parm, Qtop) && !EQ (parm, Qright)
+ && !EQ (parm, Qbottom) && !NILP (Fcdr (elt)))
+ {
+ /* We lost, delete the old tooltip. */
+ delete = true;
+ break;
+ }
+ }
+
+ x_hide_tip (delete);
+ }
+ else
+ x_hide_tip (true);
+ }
+ else
+ x_hide_tip (true);
ASET (last_show_tip_args, 0, string);
ASET (last_show_tip_args, 1, frame);
ASET (last_show_tip_args, 2, parms);
- /* Add default values to frame parameters. */
- if (NILP (Fassq (Qname, parms)))
- parms = Fcons (Fcons (Qname, build_string ("tooltip")), parms);
- if (NILP (Fassq (Qinternal_border_width, parms)))
- parms = Fcons (Fcons (Qinternal_border_width, make_number (3)), parms);
- if (NILP (Fassq (Qborder_width, parms)))
- parms = Fcons (Fcons (Qborder_width, make_number (1)), parms);
- if (NILP (Fassq (Qbottom_divider_width, parms)))
- parms = Fcons (Fcons (Qbottom_divider_width, make_number (0)), parms);
- if (NILP (Fassq (Qright_divider_width, parms)))
- parms = Fcons (Fcons (Qright_divider_width, make_number (0)), parms);
- if (NILP (Fassq (Qborder_color, parms)))
- parms = Fcons (Fcons (Qborder_color, build_string ("lightyellow")), parms);
- if (NILP (Fassq (Qbackground_color, parms)))
- parms = Fcons (Fcons (Qbackground_color, build_string ("lightyellow")),
- parms);
-
- /* Create a frame for the tooltip, and record it in the global
- variable tip_frame. */
- frame = x_create_tip_frame (FRAME_DISPLAY_INFO (f), parms, string);
- f = XFRAME (frame);
-
- /* Set up the frame's root window. */
- w = XWINDOW (FRAME_ROOT_WINDOW (f));
+ if (!FRAMEP (tip_frame) || !FRAME_LIVE_P (XFRAME (tip_frame)))
+ {
+ /* Add default values to frame parameters. */
+ if (NILP (Fassq (Qname, parms)))
+ parms = Fcons (Fcons (Qname, build_string ("tooltip")), parms);
+ if (NILP (Fassq (Qinternal_border_width, parms)))
+ parms = Fcons (Fcons (Qinternal_border_width, make_number (3)), parms);
+ if (NILP (Fassq (Qborder_width, parms)))
+ parms = Fcons (Fcons (Qborder_width, make_number (1)), parms);
+ if (NILP (Fassq (Qborder_color, parms)))
+ parms = Fcons (Fcons (Qborder_color, build_string ("lightyellow")), parms);
+ if (NILP (Fassq (Qbackground_color, parms)))
+ parms = Fcons (Fcons (Qbackground_color, build_string ("lightyellow")),
+ parms);
+
+ /* Create a frame for the tooltip, and record it in the global
+ variable tip_frame. */
+ if (NILP (tip_frame = x_create_tip_frame (FRAME_DISPLAY_INFO (f), parms)))
+ /* Creating the tip frame failed. */
+ return unbind_to (count, Qnil);
+ }
+
+ tip_f = XFRAME (tip_frame);
+ window = FRAME_ROOT_WINDOW (tip_f);
+ set_window_buffer (window, Fget_buffer_create (tip), false, false);
+ w = XWINDOW (window);
+ w->pseudo_window_p = true;
+
+ /* Set up the frame's root window. Note: The following code does not
+ try to size the window or its frame correctly. Its only purpose is
+ to make the subsequent text size calculations work. The right
+ sizes should get installed when the toolkit gets back to us. */
w->left_col = 0;
w->top_line = 0;
w->pixel_left = 0;
@@ -5956,130 +6076,47 @@ Text larger than the specified size is clipped. */)
w->total_lines = 40;
}
- w->pixel_width = w->total_cols * FRAME_COLUMN_WIDTH (f);
- w->pixel_height = w->total_lines * FRAME_LINE_HEIGHT (f);
-
- FRAME_TOTAL_COLS (f) = w->total_cols;
- adjust_frame_glyphs (f);
- w->pseudo_window_p = true;
+ w->pixel_width = w->total_cols * FRAME_COLUMN_WIDTH (tip_f);
+ w->pixel_height = w->total_lines * FRAME_LINE_HEIGHT (tip_f);
+ FRAME_TOTAL_COLS (tip_f) = w->total_cols;
+ adjust_frame_glyphs (tip_f);
- /* Display the tooltip text in a temporary buffer. */
+ /* Insert STRING into root window's buffer and fit the frame to the
+ buffer. */
+ count_1 = SPECPDL_INDEX ();
old_buffer = current_buffer;
- set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f))->contents));
+ set_buffer_internal_1 (XBUFFER (w->contents));
bset_truncate_lines (current_buffer, Qnil);
+ specbind (Qinhibit_read_only, Qt);
+ specbind (Qinhibit_modification_hooks, Qt);
+ specbind (Qinhibit_point_motion_hooks, Qt);
+ Ferase_buffer ();
+ Finsert (1, &string);
clear_glyph_matrix (w->desired_matrix);
clear_glyph_matrix (w->current_matrix);
SET_TEXT_POS (pos, BEGV, BEGV_BYTE);
- try_window (FRAME_ROOT_WINDOW (f), pos, TRY_WINDOW_IGNORE_FONTS_CHANGE);
-
- /* Compute width and height of the tooltip. */
- width = height = 0;
- seen_reversed_p = false;
- for (i = 0; i < w->desired_matrix->nrows; ++i)
- {
- struct glyph_row *row = &w->desired_matrix->rows[i];
- struct glyph *last;
- int row_width;
-
- /* Stop at the first empty row at the end. */
- if (!row->enabled_p || !MATRIX_ROW_DISPLAYS_TEXT_P (row))
- break;
-
- /* Let the row go over the full width of the frame. */
- row->full_width_p = true;
-
- row_width = row->pixel_width;
- if (row->used[TEXT_AREA])
- {
- /* There's a glyph at the end of rows that is used to place
- the cursor there. Don't include the width of this glyph. */
- if (!row->reversed_p)
- {
- last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1];
- if (NILP (last->object))
- row_width -= last->pixel_width;
- }
- else
- {
- /* There could be a stretch glyph at the beginning of R2L
- rows that is produced by extend_face_to_end_of_line.
- Don't count that glyph. */
- struct glyph *g = row->glyphs[TEXT_AREA];
-
- if (g->type == STRETCH_GLYPH && NILP (g->object))
- {
- row_width -= g->pixel_width;
- seen_reversed_p = true;
- }
- }
- }
-
- height += row->height;
- width = max (width, row_width);
- }
-
- /* If we've seen partial-length R2L rows, we need to re-adjust the
- tool-tip frame width and redisplay it again, to avoid over-wide
- tips due to the stretch glyph that extends R2L lines to full
- width of the frame. */
- if (seen_reversed_p)
- {
- /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
- not in pixels. */
- w->pixel_width = width;
- width /= WINDOW_FRAME_COLUMN_WIDTH (w);
- w->total_cols = width;
- FRAME_TOTAL_COLS (f) = width;
- SET_FRAME_WIDTH (f, width);
- adjust_frame_glyphs (f);
- clear_glyph_matrix (w->desired_matrix);
- clear_glyph_matrix (w->current_matrix);
- try_window (FRAME_ROOT_WINDOW (f), pos, 0);
- width = height = 0;
- /* Recompute width and height of the tooltip. */
- for (i = 0; i < w->desired_matrix->nrows; ++i)
- {
- struct glyph_row *row = &w->desired_matrix->rows[i];
- struct glyph *last;
- int row_width;
-
- if (!row->enabled_p || !MATRIX_ROW_DISPLAYS_TEXT_P (row))
- break;
- row->full_width_p = true;
- row_width = row->pixel_width;
- if (row->used[TEXT_AREA] && !row->reversed_p)
- {
- last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1];
- if (NILP (last->object))
- row_width -= last->pixel_width;
- }
-
- height += row->height;
- width = max (width, row_width);
- }
- }
-
- /* Add the frame's internal border to the width and height the X
- window should have. */
- height += 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
- width += 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
-
- /* Move the tooltip window where the mouse pointer is. Resize and
- show it. */
- compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y);
-
+ try_window (window, pos, TRY_WINDOW_IGNORE_FONTS_CHANGE);
+ /* Calculate size of tooltip window. */
+ size = Fwindow_text_pixel_size (window, Qnil, Qnil, Qnil,
+ make_number (w->pixel_height), Qnil);
+ /* Add the frame's internal border to calculated size. */
+ width = XINT (Fcar (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f);
+ height = XINT (Fcdr (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f);
+
+ /* Calculate position of tooltip frame. */
+ compute_tip_xy (tip_f, parms, dx, dy, width, height, &root_x, &root_y);
+
+ /* Show tooltip frame. */
block_input ();
- XMoveResizeWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
+ XMoveResizeWindow (FRAME_X_DISPLAY (tip_f), FRAME_X_WINDOW (tip_f),
root_x, root_y, width, height);
- XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
+ XMapRaised (FRAME_X_DISPLAY (tip_f), FRAME_X_WINDOW (tip_f));
unblock_input ();
- /* Draw into the window. */
w->must_be_updated_p = true;
update_single_window (w);
-
- /* Restore original current buffer. */
set_buffer_internal_1 (old_buffer);
+ unbind_to (count_1, Qnil);
windows_or_buffers_changed = old_windows_or_buffers_changed;
start_timer:
@@ -6096,66 +6133,9 @@ DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
Value is t if tooltip was open, nil otherwise. */)
(void)
{
- ptrdiff_t count;
- Lisp_Object deleted, frame, timer;
-
- /* Return quickly if nothing to do. */
- if (NILP (tip_timer) && NILP (tip_frame))
- return Qnil;
-
- frame = tip_frame;
- timer = tip_timer;
- tip_frame = tip_timer = deleted = Qnil;
-
- count = SPECPDL_INDEX ();
- specbind (Qinhibit_redisplay, Qt);
- specbind (Qinhibit_quit, Qt);
-
- if (!NILP (timer))
- call1 (Qcancel_timer, timer);
-
-#ifdef USE_GTK
- {
- /* When using system tooltip, tip_frame is the Emacs frame on which
- the tip is shown. */
- struct frame *f = XFRAME (frame);
- if (FRAME_LIVE_P (f) && xg_hide_tooltip (f))
- frame = Qnil;
- }
-#endif
-
- if (FRAMEP (frame))
- {
- delete_frame (frame, Qnil);
- deleted = Qt;
-
-#ifdef USE_LUCID
- /* Bloodcurdling hack alert: The Lucid menu bar widget's
- redisplay procedure is not called when a tip frame over menu
- items is unmapped. Redisplay the menu manually... */
- {
- Widget w;
- struct frame *f = SELECTED_FRAME ();
- if (FRAME_X_P (f) && FRAME_LIVE_P (f))
- {
- w = f->output_data.x->menubar_widget;
-
- if (!DoesSaveUnders (FRAME_DISPLAY_INFO (f)->screen)
- && w != NULL)
- {
- block_input ();
- xlwmenu_redisplay (w);
- unblock_input ();
- }
- }
- }
-#endif /* USE_LUCID */
- }
-
- return unbind_to (count, deleted);
+ return x_hide_tip (!tooltip_reuse_hidden_frame);
}
-
/***********************************************************************
File selection dialog
@@ -6817,6 +6797,7 @@ syms_of_xfns (void)
DEFSYM (Qcancel_timer, "cancel-timer");
DEFSYM (Qfont_param, "font-parameter");
DEFSYM (Qmono, "mono");
+ DEFSYM (Qassq_delete_all, "assq-delete-all");
#ifdef USE_CAIRO
DEFSYM (Qpdf, "pdf");
diff --git a/src/xsmfns.c b/src/xsmfns.c
index 0819e877780..296b1cc3603 100644
--- a/src/xsmfns.c
+++ b/src/xsmfns.c
@@ -204,7 +204,7 @@ smc_save_yourself_CB (SmcConn smcConn,
props[props_idx]->vals[0].value = SDATA (user_login_name);
++props_idx;
- char *cwd = get_current_dir_name ();
+ char *cwd = emacs_get_current_dir_name ();
if (cwd)
{
props[props_idx] = &prop_ptr[props_idx];
@@ -401,7 +401,7 @@ x_session_initialize (struct x_display_info *dpyinfo)
ptrdiff_t name_len = 0;
/* libSM seems to crash if pwd is missing - see bug#18851. */
- if (! get_current_dir_name ())
+ if (! emacs_get_current_dir_name ())
{
fprintf (stderr, "Disabling session management due to pwd error: %s\n",
emacs_strerror (errno));