diff options
author | John Wiegley <johnw@newartisans.com> | 2015-12-29 21:39:08 -0800 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2015-12-29 21:39:08 -0800 |
commit | ec0a80cc283badc7f7fd5ef78512dde6d34b1355 (patch) | |
tree | 7190e0fb3d4aa06018d8cf997f06b806fb09a9c8 /src | |
parent | d259328fb87db8cc67d52771efcfa653e52c5b71 (diff) | |
parent | e823c34072bf045800d91e12c7ddb61fa23c6e30 (diff) | |
download | emacs-25-merge.tar.gz |
Merge emacs-25 into master (using imerge)emacs-25-merge
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog.13 | 4 | ||||
-rw-r--r-- | src/Makefile.in | 14 | ||||
-rw-r--r-- | src/alloc.c | 93 | ||||
-rw-r--r-- | src/bytecode.c | 14 | ||||
-rw-r--r-- | src/cmds.c | 6 | ||||
-rw-r--r-- | src/conf_post.h | 1 | ||||
-rw-r--r-- | src/data.c | 24 | ||||
-rw-r--r-- | src/dired.c | 48 | ||||
-rw-r--r-- | src/dispnew.c | 16 | ||||
-rw-r--r-- | src/doc.c | 3 | ||||
-rw-r--r-- | src/doprnt.c | 2 | ||||
-rw-r--r-- | src/dynlib.c | 330 | ||||
-rw-r--r-- | src/dynlib.h | 34 | ||||
-rw-r--r-- | src/emacs-module.c | 1134 | ||||
-rw-r--r-- | src/emacs-module.h | 215 | ||||
-rw-r--r-- | src/emacs.c | 12 | ||||
-rw-r--r-- | src/eval.c | 219 | ||||
-rw-r--r-- | src/fileio.c | 11 | ||||
-rw-r--r-- | src/fns.c | 24 | ||||
-rw-r--r-- | src/font.h | 42 | ||||
-rw-r--r-- | src/frame.c | 27 | ||||
-rw-r--r-- | src/gmalloc.c | 36 | ||||
-rw-r--r-- | src/indent.c | 11 | ||||
-rw-r--r-- | src/insdel.c | 23 | ||||
-rw-r--r-- | src/keyboard.c | 22 | ||||
-rw-r--r-- | src/keyboard.h | 12 | ||||
-rw-r--r-- | src/lisp.h | 152 | ||||
-rw-r--r-- | src/lread.c | 87 | ||||
-rw-r--r-- | src/macfont.m | 19 | ||||
-rw-r--r-- | src/nsfns.m | 74 | ||||
-rw-r--r-- | src/nsimage.m | 2 | ||||
-rw-r--r-- | src/nsmenu.m | 8 | ||||
-rw-r--r-- | src/nsterm.h | 176 | ||||
-rw-r--r-- | src/nsterm.m | 522 | ||||
-rw-r--r-- | src/print.c | 13 | ||||
-rw-r--r-- | src/puresize.h | 20 | ||||
-rw-r--r-- | src/regex.c | 18 | ||||
-rw-r--r-- | src/syntax.c | 18 | ||||
-rw-r--r-- | src/syntax.h | 14 | ||||
-rw-r--r-- | src/undo.c | 69 | ||||
-rw-r--r-- | src/unexelf.c | 11 | ||||
-rw-r--r-- | src/w32.c | 13 | ||||
-rw-r--r-- | src/w32.h | 6 | ||||
-rw-r--r-- | src/w32console.c | 5 | ||||
-rw-r--r-- | src/w32fns.c | 28 | ||||
-rw-r--r-- | src/w32menu.c | 5 | ||||
-rw-r--r-- | src/w32term.c | 46 | ||||
-rw-r--r-- | src/w32term.h | 2 | ||||
-rw-r--r-- | src/window.c | 34 | ||||
-rw-r--r-- | src/xdisp.c | 110 | ||||
-rw-r--r-- | src/xfns.c | 4 |
51 files changed, 3121 insertions, 712 deletions
diff --git a/src/ChangeLog.13 b/src/ChangeLog.13 index ac2162830c4..fd68f5370ad 100644 --- a/src/ChangeLog.13 +++ b/src/ChangeLog.13 @@ -8339,7 +8339,7 @@ * emacs.c (main): Initialize daemon_pipe[1] here ... (syms_of_emacs): ... instead of here. -2014-02-16 Anders Lindgern <andlind@gmail.com> +2014-02-16 Anders Lindgren <andlind@gmail.com> * nsterm.m (keyDown:): Check for normal key even if NSNumericPadKeyMask is set (Bug#16505). @@ -16566,7 +16566,7 @@ (ns_draw_fringe_bitmap): Remove unused rowY. Change #if to COCOA && >= 10_6. (ns_draw_window_cursor): Remove unused overspill. - (ns_draw_underwave): width and x are EamcsCGFloat. + (ns_draw_underwave): width and x are EmacsCGFloat. (ns_draw_box): thickness is CGFloat. (ns_dumpglyphs_image): Change #if to COCOA && >= 10_6. (ns_send_appdefined): When NS_IMPL_GNUSTEP, redirect to main thread diff --git a/src/Makefile.in b/src/Makefile.in index d7ad3954579..f96ebb2aeeb 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -231,6 +231,11 @@ LIBXML2_CFLAGS = @LIBXML2_CFLAGS@ LIBZ = @LIBZ@ +## system-specific libs for dynamic modules, else empty +LIBMODULES = @LIBMODULES@ +## dynlib.o emacs-module.o if modules enabled, else empty +MODULES_OBJ = @MODULES_OBJ@ + XRANDR_LIBS = @XRANDR_LIBS@ XRANDR_CFLAGS = @XRANDR_CFLAGS@ @@ -378,7 +383,7 @@ base_obj = dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \ minibuf.o fileio.o dired.o \ cmds.o casetab.o casefiddle.o indent.o search.o regex.o undo.o \ alloc.o data.o doc.o editfns.o callint.o \ - eval.o floatfns.o fns.o font.o print.o lread.o \ + eval.o floatfns.o fns.o font.o print.o lread.o $(MODULES_OBJ) \ syntax.o $(UNEXEC_OBJ) bytecode.o \ process.o gnutls.o callproc.o \ region-cache.o sound.o atimer.o \ @@ -469,7 +474,7 @@ LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \ $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \ $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \ $(LIBGNUTLS_LIBS) $(LIB_PTHREAD) \ - $(NOTIFY_LIBS) $(LIB_MATH) $(LIBZ) + $(NOTIFY_LIBS) $(LIB_MATH) $(LIBZ) $(LIBMODULES) $(leimdir)/leim-list.el: bootstrap-emacs$(EXEEXT) $(MAKE) -C ../leim leim-list.el EMACS="$(bootstrap_exe)" @@ -482,6 +487,11 @@ $(srcdir)/macuvs.h $(lispsource)/international/charprop.el: \ bootstrap-emacs$(EXEEXT) FORCE $(MAKE) -C ../admin/unidata all EMACS="../$(bootstrap_exe)" +## We require charprop.el to exist before ucs-normalize.el is +## byte-compiled, because ucs-normalize.el needs to load 2 uni-*.el files. +$(lispsource)/international/ucs-normalize.elc: | \ + $(lispsource)/international/charprop.el + lispintdir = ${lispsource}/international ${lispintdir}/cp51932.el ${lispintdir}/eucjp-ms.el: FORCE ${MAKE} -C ../admin/charsets $(notdir $@) diff --git a/src/alloc.c b/src/alloc.c index bee7cd1758d..fe55cde49c9 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -406,24 +406,37 @@ ALIGN (void *ptr, int alignment) If A is a symbol, extract the hidden pointer's offset from lispsym, converted to void *. */ -static void * -XPNTR_OR_SYMBOL_OFFSET (Lisp_Object a) -{ - intptr_t i = USE_LSB_TAG ? XLI (a) - XTYPE (a) : XLI (a) & VALMASK; - return (void *) i; -} +#define macro_XPNTR_OR_SYMBOL_OFFSET(a) \ + ((void *) (intptr_t) (USE_LSB_TAG ? XLI (a) - XTYPE (a) : XLI (a) & VALMASK)) /* Extract the pointer hidden within A. */ -static void * +#define macro_XPNTR(a) \ + ((void *) ((intptr_t) XPNTR_OR_SYMBOL_OFFSET (a) \ + + (SYMBOLP (a) ? (char *) lispsym : NULL))) + +/* For pointer access, define XPNTR and XPNTR_OR_SYMBOL_OFFSET as + functions, as functions are cleaner and can be used in debuggers. + Also, define them as macros if being compiled with GCC without + optimization, for performance in that case. The macro_* names are + private to this section of code. */ + +static ATTRIBUTE_UNUSED void * +XPNTR_OR_SYMBOL_OFFSET (Lisp_Object a) +{ + return macro_XPNTR_OR_SYMBOL_OFFSET (a); +} +static ATTRIBUTE_UNUSED void * XPNTR (Lisp_Object a) { - void *p = XPNTR_OR_SYMBOL_OFFSET (a); - if (SYMBOLP (a)) - p = (intptr_t) p + (char *) lispsym; - return p; + return macro_XPNTR (a); } +#if DEFINE_KEY_OPS_AS_MACROS +# define XPNTR_OR_SYMBOL_OFFSET(a) macro_XPNTR_OR_SYMBOL_OFFSET (a) +# define XPNTR(a) macro_XPNTR (a) +#endif + static void XFLOAT_INIT (Lisp_Object f, double n) { @@ -3711,6 +3724,23 @@ make_event_array (ptrdiff_t nargs, Lisp_Object *args) } } +#ifdef HAVE_MODULES +/* Create a new module user ptr object. */ +Lisp_Object +make_user_ptr (void (*finalizer) (void*), void *p) +{ + Lisp_Object obj; + struct Lisp_User_Ptr *uptr; + + obj = allocate_misc (Lisp_Misc_User_Ptr); + uptr = XUSER_PTR (obj); + uptr->finalizer = finalizer; + uptr->p = p; + return obj; +} + +#endif + static void init_finalizer_list (struct Lisp_Finalizer *head) { @@ -5300,10 +5330,6 @@ total_bytes_of_live_objects (void) #ifdef HAVE_WINDOW_SYSTEM -/* This code has a few issues on MS-Windows, see Bug#15876 and Bug#16140. */ - -#if !defined (HAVE_NTGUI) - /* Remove unmarked font-spec and font-entity objects from ENTRY, which is (DRIVER-TYPE NUM-FRAMES FONT-CACHE-DATA ...), and return changed entry. */ @@ -5318,11 +5344,15 @@ compact_font_cache_entry (Lisp_Object entry) Lisp_Object obj = XCAR (tail); /* Consider OBJ if it is (font-spec . [font-entity font-entity ...]). */ - if (CONSP (obj) && FONT_SPEC_P (XCAR (obj)) - && !VECTOR_MARKED_P (XFONT_SPEC (XCAR (obj))) - && VECTORP (XCDR (obj))) + if (CONSP (obj) && GC_FONT_SPEC_P (XCAR (obj)) + && !VECTOR_MARKED_P (GC_XFONT_SPEC (XCAR (obj))) + /* Don't use VECTORP here, as that calls ASIZE, which could + hit assertion violation during GC. */ + && (VECTORLIKEP (XCDR (obj)) + && ! (gc_asize (XCDR (obj)) & PSEUDOVECTOR_FLAG))) { - ptrdiff_t i, size = ASIZE (XCDR (obj)) & ~ARRAY_MARK_FLAG; + ptrdiff_t i, size = gc_asize (XCDR (obj)); + Lisp_Object obj_cdr = XCDR (obj); /* If font-spec is not marked, most likely all font-entities are not marked too. But we must be sure that nothing is @@ -5331,14 +5361,14 @@ compact_font_cache_entry (Lisp_Object entry) { Lisp_Object objlist; - if (VECTOR_MARKED_P (XFONT_ENTITY (AREF (XCDR (obj), i)))) + if (VECTOR_MARKED_P (GC_XFONT_ENTITY (AREF (obj_cdr, i)))) break; - objlist = AREF (AREF (XCDR (obj), i), FONT_OBJLIST_INDEX); + objlist = AREF (AREF (obj_cdr, i), FONT_OBJLIST_INDEX); for (; CONSP (objlist); objlist = XCDR (objlist)) { Lisp_Object val = XCAR (objlist); - struct font *font = XFONT_OBJECT (val); + struct font *font = GC_XFONT_OBJECT (val); if (!NILP (AREF (val, FONT_TYPE_INDEX)) && VECTOR_MARKED_P(font)) @@ -5366,8 +5396,6 @@ compact_font_cache_entry (Lisp_Object entry) return entry; } -#endif /* not HAVE_NTGUI */ - /* Compact font caches on all terminals and mark everything which is still here after compaction. */ @@ -5379,7 +5407,6 @@ compact_font_caches (void) for (t = terminal_list; t; t = t->next_terminal) { Lisp_Object cache = TERMINAL_FONT_CACHE (t); -#if !defined (HAVE_NTGUI) if (CONSP (cache)) { Lisp_Object entry; @@ -5387,7 +5414,6 @@ compact_font_caches (void) for (entry = XCDR (cache); CONSP (entry); entry = XCDR (entry)) XSETCAR (entry, compact_font_cache_entry (XCAR (entry))); } -#endif /* not HAVE_NTGUI */ mark_object (cache); } } @@ -6301,6 +6327,12 @@ mark_object (Lisp_Object arg) mark_object (XFINALIZER (obj)->function); break; +#ifdef HAVE_MODULES + case Lisp_Misc_User_Ptr: + XMISCANY (obj)->gcmarkbit = true; + break; +#endif + default: emacs_abort (); } @@ -6677,8 +6709,15 @@ sweep_misc (void) { if (mblk->markers[i].m.u_any.type == Lisp_Misc_Marker) unchain_marker (&mblk->markers[i].m.u_marker); - if (mblk->markers[i].m.u_any.type == Lisp_Misc_Finalizer) + else if (mblk->markers[i].m.u_any.type == Lisp_Misc_Finalizer) unchain_finalizer (&mblk->markers[i].m.u_finalizer); +#ifdef HAVE_MODULES + else if (mblk->markers[i].m.u_any.type == Lisp_Misc_User_Ptr) + { + struct Lisp_User_Ptr *uptr = &mblk->markers[i].m.u_user_ptr; + uptr->finalizer (uptr->p); + } +#endif /* Set the type of the freed object to Lisp_Misc_Free. We could leave the type alone, since nobody checks it, but this might catch bugs faster. */ diff --git a/src/bytecode.c b/src/bytecode.c index 864db1a0bed..464adc633a8 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -1067,17 +1067,13 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, type = CATCHER; goto pushhandler; CASE (Bpushconditioncase): /* New in 24.4. */ + type = CONDITION_CASE; + pushhandler: { - struct handler *c; - Lisp_Object tag; - int dest; + Lisp_Object tag = POP; + int dest = FETCH2; - type = CONDITION_CASE; - pushhandler: - tag = POP; - dest = FETCH2; - - PUSH_HANDLER (c, tag, type); + struct handler *c = push_handler (tag, type); c->bytecode_dest = dest; c->bytecode_top = top; diff --git a/src/cmds.c b/src/cmds.c index 167ebb74302..650b4628c32 100644 --- a/src/cmds.c +++ b/src/cmds.c @@ -233,7 +233,7 @@ because it respects values of `delete-active-region' and `overwrite-mode'. */) CHECK_NUMBER (n); if (eabs (XINT (n)) < 2) - call0 (Qundo_auto__amalgamate); + call0 (Qundo_auto_amalgamate); pos = PT + XINT (n); if (NILP (killflag)) @@ -279,7 +279,7 @@ At the end, it runs `post-self-insert-hook'. */) error ("Negative repetition argument %"pI"d", XINT (n)); if (XFASTINT (n) < 2) - call0 (Qundo_auto__amalgamate); + call0 (Qundo_auto_amalgamate); /* Barf if the key that invoked this was not a character. */ if (!CHARACTERP (last_command_event)) @@ -494,7 +494,7 @@ internal_self_insert (int c, EMACS_INT n) void syms_of_cmds (void) { - DEFSYM (Qundo_auto__amalgamate, "undo-auto--amalgamate"); + DEFSYM (Qundo_auto_amalgamate, "undo-auto-amalgamate"); DEFSYM (Qundo_auto__this_command_amalgamating, "undo-auto--this-command-amalgamating"); diff --git a/src/conf_post.h b/src/conf_post.h index 2c3eee59b77..b629e8d3df7 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -245,6 +245,7 @@ extern int emacs_setenv_TZ (char const *); #endif #define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST +#define ATTRIBUTE_UNUSED _GL_UNUSED #if 3 <= __GNUC__ # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) diff --git a/src/data.c b/src/data.c index 51546044c68..1e9cc814f00 100644 --- a/src/data.c +++ b/src/data.c @@ -223,6 +223,10 @@ for example, (type-of 1) returns `integer'. */) return Qfloat; case Lisp_Misc_Finalizer: return Qfinalizer; +#ifdef HAVE_MODULES + case Lisp_Misc_User_Ptr: + return Quser_ptr; +#endif default: emacs_abort (); } @@ -424,6 +428,17 @@ DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0, return Qnil; } +#ifdef HAVE_MODULES +DEFUN ("user-ptrp", Fuser_ptrp, Suser_ptrp, 1, 1, 0, + doc: /* Return t if OBJECT is a module user pointer. */) + (Lisp_Object object) +{ + if (USER_PTRP (object)) + return Qt; + return Qnil; +} +#endif + DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0, doc: /* Return t if OBJECT is a built-in function. */) (Lisp_Object object) @@ -3478,6 +3493,9 @@ syms_of_data (void) DEFSYM (Qbool_vector_p, "bool-vector-p"); DEFSYM (Qchar_or_string_p, "char-or-string-p"); DEFSYM (Qmarkerp, "markerp"); +#ifdef HAVE_MODULES + DEFSYM (Quser_ptrp, "user-ptrp"); +#endif DEFSYM (Qbuffer_or_string_p, "buffer-or-string-p"); DEFSYM (Qinteger_or_marker_p, "integer-or-marker-p"); DEFSYM (Qfboundp, "fboundp"); @@ -3569,6 +3587,9 @@ syms_of_data (void) DEFSYM (Qmarker, "marker"); DEFSYM (Qoverlay, "overlay"); DEFSYM (Qfinalizer, "finalizer"); +#ifdef HAVE_MODULES + DEFSYM (Quser_ptr, "user-ptr"); +#endif DEFSYM (Qfloat, "float"); DEFSYM (Qwindow_configuration, "window-configuration"); DEFSYM (Qprocess, "process"); @@ -3683,6 +3704,9 @@ syms_of_data (void) defsubr (&Sbyteorder); defsubr (&Ssubr_arity); defsubr (&Ssubr_name); +#ifdef HAVE_MODULES + defsubr (&Suser_ptrp); +#endif defsubr (&Sbool_vector_exclusive_or); defsubr (&Sbool_vector_union); diff --git a/src/dired.c b/src/dired.c index 84bf2472262..6c34dfdfcb0 100644 --- a/src/dired.c +++ b/src/dired.c @@ -467,6 +467,7 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag, well as "." and "..". Until shown otherwise, assume we can't exclude anything. */ bool includeall = 1; + bool check_decoded = false; ptrdiff_t count = SPECPDL_INDEX (); elt = Qnil; @@ -485,6 +486,28 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag, on the encoded file name. */ encoded_file = ENCODE_FILE (file); encoded_dir = ENCODE_FILE (Fdirectory_file_name (dirname)); + + Lisp_Object file_encoding = Vfile_name_coding_system; + if (NILP (Vfile_name_coding_system)) + file_encoding = Vdefault_file_name_coding_system; + /* If the file-name encoding decomposes characters, as we do for + HFS+ filesystems, we need to make an additional comparison of + decoded names in order to filter false positives, such as "a" + falsely matching "a-ring". */ + if (!NILP (file_encoding) + && !NILP (Fplist_get (Fcoding_system_plist (file_encoding), + Qdecomposed_characters))) + { + check_decoded = true; + if (STRING_MULTIBYTE (file)) + { + /* Recompute FILE to make sure any decomposed characters in + it are re-composed by the post-read-conversion. + Otherwise, any decomposed characters will be rejected by + the additional check below. */ + file = DECODE_FILE (encoded_file); + } + } int fd; DIR *d = open_directory (encoded_dir, &fd); record_unwind_protect_ptr (directory_files_internal_unwind, d); @@ -637,6 +660,23 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag, if (!NILP (predicate) && NILP (call1 (predicate, name))) continue; + /* Reject entries where the encoded strings match, but the + decoded don't. For example, "a" should not match "a-ring" on + file systems that store decomposed characters. */ + Lisp_Object zero = make_number (0); + + if (check_decoded && SCHARS (file) <= SCHARS (name)) + { + /* FIXME: This is a copy of the code below. */ + ptrdiff_t compare = SCHARS (file); + Lisp_Object cmp + = Fcompare_strings (name, zero, make_number (compare), + file, zero, make_number (compare), + completion_ignore_case ? Qt : Qnil); + if (!EQ (cmp, Qt)) + continue; + } + /* Suitably record this match. */ matchcount += matchcount <= 1; @@ -650,14 +690,11 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag, } else { - Lisp_Object zero = make_number (0); /* FIXME: This is a copy of the code in Ftry_completion. */ ptrdiff_t compare = min (bestmatchsize, SCHARS (name)); Lisp_Object cmp - = Fcompare_strings (bestmatch, zero, - make_number (compare), - name, zero, - make_number (compare), + = Fcompare_strings (bestmatch, zero, make_number (compare), + name, zero, make_number (compare), completion_ignore_case ? Qt : Qnil); ptrdiff_t matchsize = EQ (cmp, Qt) ? compare : eabs (XINT (cmp)) - 1; @@ -1007,6 +1044,7 @@ syms_of_dired (void) DEFSYM (Qfile_attributes, "file-attributes"); DEFSYM (Qfile_attributes_lessp, "file-attributes-lessp"); DEFSYM (Qdefault_directory, "default-directory"); + DEFSYM (Qdecomposed_characters, "decomposed-characters"); defsubr (&Sdirectory_files); defsubr (&Sdirectory_files_and_attributes); diff --git a/src/dispnew.c b/src/dispnew.c index 64c84aec6f9..1d30eee2082 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -6206,10 +6206,10 @@ It is up to you to set this variable if your terminal can do that. */); doc: /* Name of the window system that Emacs uses for the first frame. The value is a symbol: nil for a termcap frame (a character-only terminal), - 'x' for an Emacs frame that is really an X window, - 'w32' for an Emacs frame that is a window on MS-Windows display, - 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display, - 'pc' for a direct-write MS-DOS frame. + `x' for an Emacs frame that is really an X window, + `w32' for an Emacs frame that is a window on MS-Windows display, + `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display, + `pc' for a direct-write MS-DOS frame. Use of this variable as a boolean is deprecated. Instead, use `display-graphic-p' or any of the other `display-*-p' @@ -6219,10 +6219,10 @@ predicates which report frame's specific UI-related capabilities. */); doc: /* Name of window system through which the selected frame is displayed. The value is a symbol: nil for a termcap frame (a character-only terminal), - 'x' for an Emacs frame that is really an X window, - 'w32' for an Emacs frame that is a window on MS-Windows display, - 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display, - 'pc' for a direct-write MS-DOS frame. + `x' for an Emacs frame that is really an X window, + `w32' for an Emacs frame that is a window on MS-Windows display, + `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display, + `pc' for a direct-write MS-DOS frame. Use of this variable as a boolean is deprecated. Instead, use `display-graphic-p' or any of the other `display-*-p' diff --git a/src/doc.c b/src/doc.c index 694c159fc09..6c2a3e52a2e 100644 --- a/src/doc.c +++ b/src/doc.c @@ -1023,7 +1023,8 @@ syms_of_doc (void) Vbuild_files = Qnil; DEFVAR_LISP ("text-quoting-style", Vtext_quoting_style, - doc: /* Style to use for single quotes when generating text. + doc: /* Style to use for single quotes in help and messages. +Its value should be a symbol. `curve' means quote with curved single quotes \\=‘like this\\=’. `straight' means quote with straight apostrophes \\='like this\\='. `grave' means quote with grave accent and apostrophe \\=`like this\\='. diff --git a/src/doprnt.c b/src/doprnt.c index 51f8fd72ba0..55f249f5d72 100644 --- a/src/doprnt.c +++ b/src/doprnt.c @@ -500,7 +500,7 @@ esprintf (char *buf, char const *format, ...) return nbytes; } -#if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT +#if HAVE_MODULES || (defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT) /* Format to buffer *BUF of positive size *BUFSIZE, reallocating *BUF and updating *BUFSIZE if the buffer is too small, and otherwise diff --git a/src/dynlib.c b/src/dynlib.c new file mode 100644 index 00000000000..190f183fa61 --- /dev/null +++ b/src/dynlib.c @@ -0,0 +1,330 @@ +/* Portable API for dynamic loading. + +Copyright 2015 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/>. */ + + +/* Assume modules are enabled on modern systems... *Yes*, the + preprocessor macro checks could be more precise. I don't care. + + If you think the abstraction is too leaky use libltdl (libtool), + don't reinvent the wheel by fixing this one. */ + +#include <config.h> + +#include "dynlib.h" + +#ifdef WINDOWSNT + +/* MS-Windows systems. */ + +#include <errno.h> +#include "lisp.h" +#include "w32common.h" /* for os_subtype */ +#include "w32.h" + +static BOOL g_b_init_get_module_handle_ex; +static DWORD dynlib_last_err; + +/* Some versions of w32api headers only expose the following when + _WIN32_WINNT is set to higher values that we use. */ +typedef BOOL (WINAPI *GetModuleHandleExA_Proc) (DWORD,LPCSTR,HMODULE*); +#ifndef GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS +# define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 4 +#endif +#ifndef GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT +# define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT 2 +#endif + +/* This needs to be called at startup to countermand any non-zero + values recorded by temacs. */ +void +dynlib_reset_last_error (void) +{ + g_b_init_get_module_handle_ex = 0; + dynlib_last_err = 0; +} + +dynlib_handle_ptr +dynlib_open (const char *dll_fname) +{ + HMODULE hdll; + char dll_fname_local[MAX_UTF8_PATH]; + + if (!dll_fname) + { + errno = ENOTSUP; + return NULL; + } + + if (!dll_fname) + hdll = GetModuleHandle (NULL); + else + { + /* LoadLibrary wants backslashes. */ + strcpy (dll_fname_local, dll_fname); + unixtodos_filename (dll_fname_local); + + if (w32_unicode_filenames) + { + wchar_t dll_fname_w[MAX_PATH]; + + filename_to_utf16 (dll_fname_local, dll_fname_w); + hdll = LoadLibraryW (dll_fname_w); + } + else + { + char dll_fname_a[MAX_PATH]; + + filename_to_ansi (dll_fname_local, dll_fname_a); + hdll = LoadLibraryA (dll_fname_a); + } + } + + if (!hdll) + dynlib_last_err = GetLastError (); + + return (dynlib_handle_ptr) hdll; +} + +void * +dynlib_sym (dynlib_handle_ptr h, const char *sym) +{ + FARPROC sym_addr = NULL; + + if (!h || h == INVALID_HANDLE_VALUE || !sym) + { + dynlib_last_err = ERROR_INVALID_PARAMETER; + return NULL; + } + + sym_addr = GetProcAddress ((HMODULE) h, sym); + if (!sym_addr) + dynlib_last_err = GetLastError (); + + return (void *)sym_addr; +} + +bool +dynlib_addr (void *addr, const char **fname, const char **symname) +{ + static char dll_filename[MAX_UTF8_PATH]; + static char addr_str[22]; + static GetModuleHandleExA_Proc s_pfn_Get_Module_HandleExA = NULL; + char *dll_fn = NULL; + HMODULE hm_kernel32 = NULL; + bool result = false; + HMODULE hm_dll = NULL; + wchar_t mfn_w[MAX_PATH]; + char mfn_a[MAX_PATH]; + + /* Step 1: Find the handle of the module where ADDR lives. */ + if (os_subtype == OS_9X + /* Windows NT family version before XP (v5.1). */ + || ((w32_major_version + (w32_minor_version > 0)) < 6)) + { + MEMORY_BASIC_INFORMATION mbi; + + /* According to Matt Pietrek, the module handle is just the base + address where it's loaded in memory. */ + if (VirtualQuery (addr, &mbi, sizeof(mbi))) + hm_dll = (HMODULE)mbi.AllocationBase; + } + else + { + /* Use the documented API when available (XP and later). */ + if (g_b_init_get_module_handle_ex == 0) + { + g_b_init_get_module_handle_ex = 1; + hm_kernel32 = LoadLibrary ("kernel32.dll"); + /* We load the ANSI version of the function because the + address we pass to it is not an address of a string, but + an address of a function. So we don't care about the + Unicode version. */ + s_pfn_Get_Module_HandleExA = + (GetModuleHandleExA_Proc) GetProcAddress (hm_kernel32, + "GetModuleHandleExA"); + } + if (s_pfn_Get_Module_HandleExA) + { + DWORD flags = (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS + /* We don't want to call FreeLibrary at the + end, because then we'd need to remember + whether we obtained the handle by this + method or the above one. */ + | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT); + + if (!s_pfn_Get_Module_HandleExA (flags, addr, &hm_dll)) + { + dynlib_last_err = GetLastError (); + hm_dll = NULL; + } + } + } + + /* Step 2: Find the absolute file name of the module corresponding + to the hm_dll handle. */ + if (hm_dll) + { + DWORD retval; + + if (w32_unicode_filenames) + { + retval = GetModuleFileNameW (hm_dll, mfn_w, MAX_PATH); + if (retval > 0 && retval < MAX_PATH + && filename_from_utf16 (mfn_w, dll_filename) == 0) + dll_fn = dll_filename; + else if (retval == MAX_PATH) + dynlib_last_err = ERROR_INSUFFICIENT_BUFFER; + else + dynlib_last_err = GetLastError (); + } + else + { + retval = GetModuleFileNameA (hm_dll, mfn_a, MAX_PATH); + if (retval > 0 && retval < MAX_PATH + && filename_from_ansi (mfn_a, dll_filename) == 0) + dll_fn = dll_filename; + else if (retval == MAX_PATH) + dynlib_last_err = ERROR_INSUFFICIENT_BUFFER; + else + dynlib_last_err = GetLastError (); + } + if (dll_fn) + { + dostounix_filename (dll_fn); + /* We cannot easily produce the function name, since + typically all of the module functions will be unexported, + and probably even static, which means the symbols can be + obtained only if we link against libbfd (and the DLL can + be stripped anyway). So we just show the address and the + file name; they can use that with addr2line or GDB to + recover the symbolic name. */ + sprintf (addr_str, "at 0x%x", (DWORD_PTR)addr); + *symname = addr_str; + result = true; + } + } + + *fname = dll_fn; + return result; +} + +const char * +dynlib_error (void) +{ + char *error_string = NULL; + + if (dynlib_last_err) + { + error_string = w32_strerror (dynlib_last_err); + dynlib_last_err = 0; + } + + return error_string; +} + +int +dynlib_close (dynlib_handle_ptr h) +{ + if (!h || h == INVALID_HANDLE_VALUE) + { + dynlib_last_err = ERROR_INVALID_PARAMETER; + return -1; + } + /* If the handle is for the main module (the .exe file), it + shouldn't be passed to FreeLibrary, because GetModuleHandle + doesn't increment the refcount, but FreeLibrary does decrement + it. I don't think this should matter for the main module, but + just in case, we avoid the call here, relying on another call to + GetModuleHandle to return the same value. */ + if (h == GetModuleHandle (NULL)) + return 0; + + if (!FreeLibrary ((HMODULE) h)) + { + dynlib_last_err = GetLastError (); + return -1; + } + + return 0; +} + +#elif defined HAVE_UNISTD_H + +/* POSIX systems. */ + +#include <dlfcn.h> + +dynlib_handle_ptr +dynlib_open (const char *path) +{ + return dlopen (path, RTLD_LAZY); +} + +void * +dynlib_sym (dynlib_handle_ptr h, const char *sym) +{ + return dlsym (h, sym); +} + +bool +dynlib_addr (void *ptr, const char **path, const char **sym) +{ +#ifdef HAVE_DLADDR + Dl_info info; + if (dladdr (ptr, &info) && info.dli_fname && info.dli_sname) + { + *path = info.dli_fname; + *sym = info.dli_sname; + return true; + } +#endif + return false; +} + +const char * +dynlib_error (void) +{ + return dlerror (); +} + +/* FIXME: Currently there is no way to unload a module, so this + function is never used. */ +#if false +int +dynlib_close (dynlib_handle_ptr h) +{ + return dlclose (h) == 0; +} +#endif + +#else + +#error "No dynamic loading for this system" + +#endif + +#if !HAVE_DLFUNC +# define dlfunc dynlib_sym +#endif + +dynlib_function_ptr +dynlib_func (dynlib_handle_ptr h, const char *sym) +{ + return (dynlib_function_ptr) dlfunc (h, sym); +} diff --git a/src/dynlib.h b/src/dynlib.h new file mode 100644 index 00000000000..1c19b5db8ac --- /dev/null +++ b/src/dynlib.h @@ -0,0 +1,34 @@ +/* Portable API for dynamic loading. + +Copyright 2015 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/>. */ + +#ifndef DYNLIB_H +#define DYNLIB_H + +#include <stdbool.h> + +typedef void *dynlib_handle_ptr; +dynlib_handle_ptr dynlib_open (const char *path); +void *dynlib_sym (dynlib_handle_ptr h, const char *sym); +typedef struct dynlib_function_ptr_nonce *(*dynlib_function_ptr) (void); +dynlib_function_ptr dynlib_func (dynlib_handle_ptr h, const char *sym); +bool dynlib_addr (void *ptr, const char **path, const char **sym); +const char *dynlib_error (void); +int dynlib_close (dynlib_handle_ptr h); + +#endif /* DYNLIB_H */ diff --git a/src/emacs-module.c b/src/emacs-module.c new file mode 100644 index 00000000000..881ee3119de --- /dev/null +++ b/src/emacs-module.c @@ -0,0 +1,1134 @@ +/* emacs-module.c - Module loading and runtime implementation + +Copyright (C) 2015 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 <config.h> + +#include "emacs-module.h" + +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> +#include <stdio.h> +#include <string.h> + +#include "lisp.h" +#include "dynlib.h" +#include "coding.h" +#include "verify.h" + + +/* Feature tests. */ + +/* True if __attribute__ ((cleanup (...))) works, false otherwise. */ +#ifdef HAVE_VAR_ATTRIBUTE_CLEANUP +enum { module_has_cleanup = true }; +#else +enum { module_has_cleanup = false }; +#endif + +/* Handle to the main thread. Used to verify that modules call us in + the right thread. */ +#ifdef HAVE_PTHREAD +# include <pthread.h> +static pthread_t main_thread; +#elif defined WINDOWSNT +#include <windows.h> +#include "w32term.h" +static DWORD main_thread; +#endif + +/* True if Lisp_Object and emacs_value have the same representation. + This is typically true unless WIDE_EMACS_INT. In practice, having + the same sizes and alignments and maximums should be a good enough + proxy for equality of representation. */ +enum + { + plain_values + = (sizeof (Lisp_Object) == sizeof (emacs_value) + && alignof (Lisp_Object) == alignof (emacs_value) + && INTPTR_MAX == EMACS_INT_MAX) + }; + + +/* Private runtime and environment members. */ + +/* The private part of an environment stores the current non local exit state + and holds the `emacs_value' objects allocated during the lifetime + of the environment. */ +struct emacs_env_private +{ + enum emacs_funcall_exit pending_non_local_exit; + + /* Dedicated storage for non-local exit symbol and data so that + storage is always available for them, even in an out-of-memory + situation. */ + Lisp_Object non_local_exit_symbol, non_local_exit_data; +}; + +/* The private parts of an `emacs_runtime' object contain the initial + environment. */ +struct emacs_runtime_private +{ + /* FIXME: Ideally, we would just define "struct emacs_runtime_private" + as a synonym of "emacs_env", but I don't know how to do that in C. */ + emacs_env pub; +}; + + +/* Forward declarations. */ + +struct module_fun_env; + +static Lisp_Object module_format_fun_env (const struct module_fun_env *); +static Lisp_Object value_to_lisp (emacs_value); +static emacs_value lisp_to_value (Lisp_Object); +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 + happen to be the same thing in the current implementation, module + code should not assume this. */ +verify (NIL_IS_ZERO); +static emacs_value const module_nil = 0; + +/* Convenience macros for non-local exit handling. */ + +/* FIXME: The following implementation for non-local exit handling + does not support recovery from stack overflow, see sysdep.c. */ + +/* Emacs uses setjmp and longjmp for non-local exits, but + module frames cannot be skipped because they are in general + not prepared for long jumps (e.g., the behavior in C++ is undefined + if objects with nontrivial destructors would be skipped). + Therefore, catch all non-local exits. There are two kinds of + non-local exits: `signal' and `throw'. The macros in this section + can be used to catch both. Use macros to avoid additional variants + of `internal_condition_case' etc., and to avoid worrying about + passing information to the handler functions. */ + +/* Place this macro at the beginning of a function returning a number + or a pointer to handle non-local exits. The function must have an + ENV parameter. The function will return the specified value if a + signal or throw is caught. */ +// TODO: Have Fsignal check for CATCHER_ALL so we only have to install +// one handler. +#define MODULE_HANDLE_NONLOCAL_EXIT(retval) \ + MODULE_SETJMP (CONDITION_CASE, module_handle_signal, retval); \ + MODULE_SETJMP (CATCHER_ALL, module_handle_throw, retval) + +#define MODULE_SETJMP(handlertype, handlerfunc, retval) \ + MODULE_SETJMP_1 (handlertype, handlerfunc, retval, \ + internal_handler_##handlertype, \ + internal_cleanup_##handlertype) + +/* It is very important that pushing the handler doesn't itself raise + a signal. Install the cleanup only after the handler has been + pushed. Use __attribute__ ((cleanup)) to avoid + non-local-exit-prone manual cleanup. + + The do-while forces uses of the macro to be followed by a semicolon. + This macro cannot enclose its entire body inside a do-while, as the + code after the macro may longjmp back into the macro, which means + its local variable C must stay live in later code. */ + +// TODO: Make backtraces work if this macros is used. + +#define MODULE_SETJMP_1(handlertype, handlerfunc, retval, c, dummy) \ + if (module_non_local_exit_check (env) != emacs_funcall_exit_return) \ + return retval; \ + struct handler *c = push_handler_nosignal (Qt, handlertype); \ + if (!c) \ + { \ + module_out_of_memory (env); \ + return retval; \ + } \ + verify (module_has_cleanup); \ + int dummy __attribute__ ((cleanup (module_reset_handlerlist))); \ + if (sys_setjmp (c->jmp)) \ + { \ + (handlerfunc) (env, c->val); \ + return retval; \ + } \ + do { } while (false) + + +/* Function environments. */ + +/* A function environment is an auxiliary structure used by + `module_make_function' to store information about a module + function. It is stored in a save pointer and retrieved by + `internal--module-call'. Its members correspond to the arguments + given to `module_make_function'. */ + +struct module_fun_env +{ + ptrdiff_t min_arity, max_arity; + emacs_subr subr; + void *data; +}; + + +/* Implementation of runtime and environment functions. + + These should abide by the following rules: + + 1. The first argument should always be a pointer to emacs_env. + + 2. Each function should first call check_main_thread. Note that + this function is a no-op unless Emacs was built with + --enable-checking. + + 3. The very next thing each function should do is check that the + emacs_env object does not have a non-local exit indication set, + by calling module_non_local_exit_check. If that returns + anything but emacs_funcall_exit_return, the function should do + nothing and return immediately with an error indication, without + clobbering the existing error indication in emacs_env. This is + needed for correct reporting of Lisp errors to the Emacs Lisp + interpreter. + + 4. Any function that needs to call Emacs facilities, such as + encoding or decoding functions, or 'intern', or 'make_string', + should protect itself from signals and 'throw' in the called + Emacs functions, by placing the macro + MODULE_HANDLE_NONLOCAL_EXIT right after the above 2 tests. + + 5. Do NOT use 'eassert' for checking validity of user code in the + module. Instead, make those checks part of the code, and if the + check fails, call 'module_non_local_exit_signal_1' or + 'module_non_local_exit_throw_1' to report the error. This is + because using 'eassert' in these situations will abort Emacs + instead of reporting the error back to Lisp, and also because + 'eassert' is compiled to nothing in the release version. */ + +/* Use MODULE_FUNCTION_BEGIN to implement steps 2 through 4 for most + environment functions. On error it will return its argument, which + should be a sentinel value. */ + +#define MODULE_FUNCTION_BEGIN(error_retval) \ + check_main_thread (); \ + if (module_non_local_exit_check (env) != emacs_funcall_exit_return) \ + return error_retval; \ + MODULE_HANDLE_NONLOCAL_EXIT (error_retval) + +/* 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. */ + +static emacs_env * +module_get_environment (struct emacs_runtime *ert) +{ + check_main_thread (); + return &ert->private_members->pub; +} + +/* To make global refs (GC-protected global values) keep a hash that + maps global Lisp objects to reference counts. */ + +static emacs_value +module_make_global_ref (emacs_env *env, emacs_value ref) +{ + MODULE_FUNCTION_BEGIN (module_nil); + struct Lisp_Hash_Table *h = XHASH_TABLE (Vmodule_refs_hash); + Lisp_Object new_obj = value_to_lisp (ref); + EMACS_UINT hashcode; + ptrdiff_t i = hash_lookup (h, new_obj, &hashcode); + + if (i >= 0) + { + 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; + } + value = make_natnum (refcount); + set_hash_value_slot (h, i, value); + } + else + { + hash_put (h, new_obj, make_natnum (1), hashcode); + } + + return lisp_to_value (new_obj); +} + +static void +module_free_global_ref (emacs_env *env, emacs_value ref) +{ + /* TODO: This probably never signals. */ + /* FIXME: Wait a minute. Shouldn't this function report an error if + the hash lookup fails? */ + MODULE_FUNCTION_BEGIN (); + struct Lisp_Hash_Table *h = XHASH_TABLE (Vmodule_refs_hash); + Lisp_Object obj = value_to_lisp (ref); + EMACS_UINT hashcode; + ptrdiff_t i = hash_lookup (h, obj, &hashcode); + + if (i >= 0) + { + Lisp_Object value = HASH_VALUE (h, i); + EMACS_INT refcount = XFASTINT (value) - 1; + if (refcount > 0) + { + value = make_natnum (refcount); + set_hash_value_slot (h, i, value); + } + else + hash_remove_from_table (h, value); + } +} + +static enum emacs_funcall_exit +module_non_local_exit_check (emacs_env *env) +{ + check_main_thread (); + return env->private_members->pending_non_local_exit; +} + +static void +module_non_local_exit_clear (emacs_env *env) +{ + check_main_thread (); + env->private_members->pending_non_local_exit = emacs_funcall_exit_return; +} + +static enum emacs_funcall_exit +module_non_local_exit_get (emacs_env *env, emacs_value *sym, emacs_value *data) +{ + check_main_thread (); + struct emacs_env_private *p = env->private_members; + if (p->pending_non_local_exit != emacs_funcall_exit_return) + { + /* FIXME: lisp_to_value can exit non-locally. */ + *sym = lisp_to_value (p->non_local_exit_symbol); + *data = lisp_to_value (p->non_local_exit_data); + } + return p->pending_non_local_exit; +} + +/* Like for `signal', DATA must be a list. */ +static void +module_non_local_exit_signal (emacs_env *env, emacs_value sym, emacs_value data) +{ + check_main_thread (); + if (module_non_local_exit_check (env) == emacs_funcall_exit_return) + module_non_local_exit_signal_1 (env, value_to_lisp (sym), + value_to_lisp (data)); +} + +static void +module_non_local_exit_throw (emacs_env *env, emacs_value tag, emacs_value value) +{ + check_main_thread (); + if (module_non_local_exit_check (env) == emacs_funcall_exit_return) + module_non_local_exit_throw_1 (env, value_to_lisp (tag), + value_to_lisp (value)); +} + +/* A module function is lambda function that calls + `internal--module-call', passing the function pointer of the module + function along with the module emacs_env pointer as arguments. + + (function (lambda (&rest arglist) + (internal--module-call envobj arglist))) */ + +static emacs_value +module_make_function (emacs_env *env, ptrdiff_t min_arity, ptrdiff_t max_arity, + emacs_subr subr, const char *documentation, + void *data) +{ + MODULE_FUNCTION_BEGIN (module_nil); + + if (! (0 <= min_arity + && (max_arity < 0 + ? max_arity == emacs_variadic_function + : min_arity <= max_arity))) + xsignal2 (Qinvalid_arity, make_number (min_arity), make_number (max_arity)); + + /* FIXME: This should be freed when envobj is GC'd. */ + struct module_fun_env *envptr = xmalloc (sizeof *envptr); + envptr->min_arity = min_arity; + envptr->max_arity = max_arity; + envptr->subr = subr; + envptr->data = data; + + Lisp_Object envobj = make_save_ptr (envptr); + Lisp_Object doc + = (documentation + ? code_convert_string_norecord (build_unibyte_string (documentation), + Qutf_8, false) + : Qnil); + /* FIXME: Use a bytecompiled object, or even better a subr. */ + Lisp_Object ret = list4 (Qlambda, + list2 (Qand_rest, Qargs), + doc, + list4 (Qapply, + list2 (Qfunction, Qinternal_module_call), + envobj, + Qargs)); + + return lisp_to_value (ret); +} + +static emacs_value +module_funcall (emacs_env *env, emacs_value fun, ptrdiff_t nargs, + emacs_value args[]) +{ + MODULE_FUNCTION_BEGIN (module_nil); + + /* Make a new Lisp_Object array starting with the function as the + first arg, because that's what Ffuncall takes. */ + Lisp_Object *newargs; + USE_SAFE_ALLOCA; + SAFE_ALLOCA_LISP (newargs, nargs + 1); + newargs[0] = value_to_lisp (fun); + for (ptrdiff_t i = 0; i < nargs; i++) + newargs[1 + i] = value_to_lisp (args[i]); + emacs_value result = lisp_to_value (Ffuncall (nargs + 1, newargs)); + SAFE_FREE (); + return result; +} + +static emacs_value +module_intern (emacs_env *env, const char *name) +{ + MODULE_FUNCTION_BEGIN (module_nil); + return lisp_to_value (intern (name)); +} + +static emacs_value +module_type_of (emacs_env *env, emacs_value value) +{ + MODULE_FUNCTION_BEGIN (module_nil); + return lisp_to_value (Ftype_of (value_to_lisp (value))); +} + +static bool +module_is_not_nil (emacs_env *env, emacs_value value) +{ + check_main_thread (); + if (module_non_local_exit_check (env) != emacs_funcall_exit_return) + return false; + return ! NILP (value_to_lisp (value)); +} + +static bool +module_eq (emacs_env *env, emacs_value a, emacs_value b) +{ + check_main_thread (); + if (module_non_local_exit_check (env) != emacs_funcall_exit_return) + return false; + return EQ (value_to_lisp (a), value_to_lisp (b)); +} + +static intmax_t +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; + } + return XINT (l); +} + +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; + } + return lisp_to_value (make_number (n)); +} + +static double +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; + } + return XFLOAT_DATA (lisp); +} + +static emacs_value +module_make_float (emacs_env *env, double d) +{ + MODULE_FUNCTION_BEGIN (module_nil); + return lisp_to_value (make_float (d)); +} + +static bool +module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer, + ptrdiff_t *length) +{ + 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; + } + + 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); + + if (buffer == NULL) + { + *length = required_buf_size; + return true; + } + + eassert (*length >= 0); + + if (*length < required_buf_size) + { + *length = required_buf_size; + module_non_local_exit_signal_1 (env, Qargs_out_of_range, Qnil); + return false; + } + + *length = required_buf_size; + memcpy (buffer, SDATA (lisp_str_utf8), raw_size + 1); + + return true; +} + +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)); +} + +static emacs_value +module_make_user_ptr (emacs_env *env, emacs_finalizer_function fin, void *ptr) +{ + MODULE_FUNCTION_BEGIN (module_nil); + return lisp_to_value (make_user_ptr (fin, ptr)); +} + +static void * +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; + } + return XUSER_PTR (lisp)->p; +} + +static void +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); + XUSER_PTR (lisp)->p = ptr; +} + +static emacs_finalizer_function +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; + } + return XUSER_PTR (lisp)->finalizer; +} + +static void +module_set_user_finalizer (emacs_env *env, emacs_value uptr, + emacs_finalizer_function fin) +{ + /* 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); + XUSER_PTR (lisp)->finalizer = fin; +} + +static void +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; + } + ASET (lvec, i, value_to_lisp (val)); +} + +static emacs_value +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; + } + return lisp_to_value (AREF (lvec, i)); +} + +static ptrdiff_t +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; + } + return ASIZE (lvec); +} + + +/* Subroutines. */ + +DEFUN ("module-load", Fmodule_load, Smodule_load, 1, 1, 0, + doc: /* Load module FILE. */) + (Lisp_Object file) +{ + dynlib_handle_ptr handle; + emacs_init_function module_init; + void *gpl_sym; + + CHECK_STRING (file); + handle = dynlib_open (SSDATA (file)); + if (!handle) + error ("Cannot load file %s: %s", SDATA (file), dynlib_error ()); + + gpl_sym = dynlib_sym (handle, "plugin_is_GPL_compatible"); + if (!gpl_sym) + error ("Module %s is not GPL compatible", SDATA (file)); + + module_init = (emacs_init_function) dynlib_func (handle, "emacs_module_init"); + if (!module_init) + error ("Module %s does not have an init function.", SDATA (file)); + + struct emacs_runtime_private rt; /* Includes the public emacs_env. */ + struct emacs_env_private priv; + initialize_environment (&rt.pub, &priv); + struct emacs_runtime pub = + { + .size = sizeof pub, + .private_members = &rt, + .get_environment = module_get_environment + }; + int r = module_init (&pub); + finalize_environment (&priv); + + if (r != 0) + { + if (! (MOST_NEGATIVE_FIXNUM <= r && r <= MOST_POSITIVE_FIXNUM)) + xsignal0 (Qoverflow_error); + xsignal2 (Qmodule_load_failed, file, make_number (r)); + } + + return Qt; +} + +DEFUN ("internal--module-call", Finternal_module_call, Sinternal_module_call, 1, MANY, 0, + doc: /* Internal function to call a module function. +ENVOBJ is a save pointer to a module_fun_env structure. +ARGLIST is a list of arguments passed to SUBRPTR. +usage: (module-call ENVOBJ &rest ARGLIST) */) + (ptrdiff_t nargs, Lisp_Object *arglist) +{ + Lisp_Object envobj = arglist[0]; + /* FIXME: Rather than use a save_value, we should create a new object type. + Making save_value visible to Lisp is wrong. */ + CHECK_TYPE (SAVE_VALUEP (envobj), Qsave_value_p, envobj); + struct Lisp_Save_Value *save_value = XSAVE_VALUE (envobj); + CHECK_TYPE (save_type (save_value, 0) == SAVE_POINTER, Qsave_pointer_p, envobj); + /* FIXME: We have no reason to believe that XSAVE_POINTER (envobj, 0) + is a module_fun_env pointer. If some other part of Emacs also + exports save_value objects to Elisp, than we may be getting here this + other kind of save_value which will likely hold something completely + different in this field. */ + struct module_fun_env *envptr = XSAVE_POINTER (envobj, 0); + EMACS_INT len = nargs - 1; + eassume (0 <= envptr->min_arity); + if (! (envptr->min_arity <= len + && len <= (envptr->max_arity < 0 ? PTRDIFF_MAX : envptr->max_arity))) + xsignal2 (Qwrong_number_of_arguments, module_format_fun_env (envptr), + make_number (len)); + + emacs_env pub; + struct emacs_env_private priv; + initialize_environment (&pub, &priv); + + USE_SAFE_ALLOCA; + emacs_value *args; + if (plain_values) + args = (emacs_value *) arglist + 1; + else + { + args = SAFE_ALLOCA (len * sizeof *args); + for (ptrdiff_t i = 0; i < len; i++) + args[i] = lisp_to_value (arglist[i + 1]); + } + + emacs_value ret = envptr->subr (&pub, len, args, envptr->data); + SAFE_FREE (); + + eassert (&priv == pub.private_members); + + switch (priv.pending_non_local_exit) + { + case emacs_funcall_exit_return: + finalize_environment (&priv); + return value_to_lisp (ret); + case emacs_funcall_exit_signal: + { + Lisp_Object symbol = priv.non_local_exit_symbol; + Lisp_Object data = priv.non_local_exit_data; + finalize_environment (&priv); + xsignal (symbol, data); + } + case emacs_funcall_exit_throw: + { + Lisp_Object tag = priv.non_local_exit_symbol; + Lisp_Object value = priv.non_local_exit_data; + finalize_environment (&priv); + Fthrow (tag, value); + } + default: + eassume (false); + } +} + + +/* Helper functions. */ + +static void +check_main_thread (void) +{ +#ifdef HAVE_PTHREAD + eassert (pthread_equal (pthread_self (), main_thread)); +#elif defined WINDOWSNT + eassert (GetCurrentThreadId () == main_thread); +#endif +} + +static void +module_non_local_exit_signal_1 (emacs_env *env, Lisp_Object sym, + Lisp_Object data) +{ + struct emacs_env_private *p = env->private_members; + if (p->pending_non_local_exit == emacs_funcall_exit_return) + { + p->pending_non_local_exit = emacs_funcall_exit_signal; + p->non_local_exit_symbol = sym; + p->non_local_exit_data = data; + } +} + +static void +module_non_local_exit_throw_1 (emacs_env *env, Lisp_Object tag, + Lisp_Object value) +{ + struct emacs_env_private *p = env->private_members; + if (p->pending_non_local_exit == emacs_funcall_exit_return) + { + p->pending_non_local_exit = emacs_funcall_exit_throw; + p->non_local_exit_symbol = tag; + p->non_local_exit_data = value; + } +} + +/* 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) +{ + /* TODO: Reimplement this so it works even if memory-signal-data has + been modified. */ + module_non_local_exit_signal_1 (env, XCAR (Vmemory_signal_data), + 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. */ + +/* Unique Lisp_Object used to mark those emacs_values which are really + just containers holding a Lisp_Object that does not fit as an emacs_value, + either because it is an integer out of range, or is not properly aligned. + Used only if !plain_values. */ +static Lisp_Object ltv_mark; + +/* Convert V to the corresponding internal object O, such that + V == lisp_to_value_bits (O). Never fails. */ +static Lisp_Object +value_to_lisp_bits (emacs_value v) +{ + intptr_t i = (intptr_t) v; + if (plain_values || USE_LSB_TAG) + return XIL (i); + + /* With wide EMACS_INT and when tag bits are the most significant, + reassembling integers differs from reassembling pointers in two + ways. First, save and restore the least-significant bits of the + integer, not the most-significant bits. Second, sign-extend the + integer when restoring, but zero-extend pointers because that + makes TAG_PTR faster. */ + + EMACS_UINT tag = i & (GCALIGNMENT - 1); + EMACS_UINT untagged = i - tag; + switch (tag) + { + case_Lisp_Int: + { + bool negative = tag & 1; + EMACS_UINT sign_extension + = negative ? VALMASK & ~(INTPTR_MAX >> INTTYPEBITS): 0; + uintptr_t u = i; + intptr_t all_but_sign = u >> GCTYPEBITS; + untagged = sign_extension + all_but_sign; + break; + } + } + + return XIL ((tag << VALBITS) + untagged); +} + +/* If V was computed from lisp_to_value (O), then return O. + Exits non-locally only if the stack overflows. */ +static Lisp_Object +value_to_lisp (emacs_value v) +{ + Lisp_Object o = value_to_lisp_bits (v); + if (! plain_values && CONSP (o) && EQ (XCDR (o), ltv_mark)) + o = XCAR (o); + return o; +} + +/* Attempt to convert O to an emacs_value. Do not do any checking or + or allocate any storage; the caller should prevent or detect + any resulting bit pattern that is not a valid emacs_value. */ +static emacs_value +lisp_to_value_bits (Lisp_Object o) +{ + EMACS_UINT u = XLI (o); + + /* Compress U into the space of a pointer, possibly losing information. */ + uintptr_t p = (plain_values || USE_LSB_TAG + ? u + : (INTEGERP (o) ? u << VALBITS : u & VALMASK) + XTYPE (o)); + return (emacs_value) p; +} + +#ifndef HAVE_STRUCT_ATTRIBUTE_ALIGNED +enum { HAVE_STRUCT_ATTRIBUTE_ALIGNED = 0 }; +#endif + +/* Convert O to an emacs_value. Allocate storage if needed; this can + signal if memory is exhausted. Must be an injective function. */ +static emacs_value +lisp_to_value (Lisp_Object o) +{ + emacs_value v = lisp_to_value_bits (o); + + if (! EQ (o, value_to_lisp_bits (v))) + { + /* Package the incompressible object pointer inside a pair + that is compressible. */ + Lisp_Object pair = Fcons (o, ltv_mark); + + if (! HAVE_STRUCT_ATTRIBUTE_ALIGNED) + { + /* Keep calling Fcons until it returns a compressible pair. + This shouldn't take long. */ + while ((intptr_t) XCONS (pair) & (GCALIGNMENT - 1)) + pair = Fcons (o, pair); + + /* Plant the mark. The garbage collector will eventually + reclaim any just-allocated incompressible pairs. */ + XSETCDR (pair, ltv_mark); + } + + v = (emacs_value) ((intptr_t) XCONS (pair) + Lisp_Cons); + } + + eassert (EQ (o, value_to_lisp (v))); + return v; +} + + +/* Environment lifetime management. */ + +/* Must be called before the environment can be used. */ +static void +initialize_environment (emacs_env *env, struct emacs_env_private *priv) +{ + priv->pending_non_local_exit = emacs_funcall_exit_return; + env->size = sizeof *env; + env->private_members = priv; + env->make_global_ref = module_make_global_ref; + env->free_global_ref = module_free_global_ref; + env->non_local_exit_check = module_non_local_exit_check; + env->non_local_exit_clear = module_non_local_exit_clear; + env->non_local_exit_get = module_non_local_exit_get; + env->non_local_exit_signal = module_non_local_exit_signal; + env->non_local_exit_throw = module_non_local_exit_throw; + env->make_function = module_make_function; + env->funcall = module_funcall; + env->intern = module_intern; + env->type_of = module_type_of; + env->is_not_nil = module_is_not_nil; + env->eq = module_eq; + env->extract_integer = module_extract_integer; + env->make_integer = module_make_integer; + env->extract_float = module_extract_float; + env->make_float = module_make_float; + env->copy_string_contents = module_copy_string_contents; + env->make_string = module_make_string; + env->make_user_ptr = module_make_user_ptr; + env->get_user_ptr = module_get_user_ptr; + env->set_user_ptr = module_set_user_ptr; + env->get_user_finalizer = module_get_user_finalizer; + env->set_user_finalizer = module_set_user_finalizer; + env->vec_set = module_vec_set; + env->vec_get = module_vec_get; + env->vec_size = module_vec_size; + Vmodule_environments = Fcons (make_save_ptr (env), Vmodule_environments); +} + +/* Must be called before the lifetime of the environment object + ends. */ +static void +finalize_environment (struct emacs_env_private *env) +{ + Vmodule_environments = XCDR (Vmodule_environments); +} + + +/* Non-local exit handling. */ + +/* Must be called after setting up a handler immediately before + returning from the function. See the comments in lisp.h and the + code in eval.c for details. The macros below arrange for this + function to be called automatically. DUMMY is ignored. */ +static void +module_reset_handlerlist (const int *dummy) +{ + handlerlist = handlerlist->next; +} + +/* Called on `signal'. ERR is a pair (SYMBOL . DATA), which gets + stored in the environment. Set the pending non-local exit flag. */ +static void +module_handle_signal (emacs_env *env, Lisp_Object err) +{ + module_non_local_exit_signal_1 (env, XCAR (err), XCDR (err)); +} + +/* Called on `throw'. TAG_VAL is a pair (TAG . VALUE), which gets + stored in the environment. Set the pending non-local exit flag. */ +static void +module_handle_throw (emacs_env *env, Lisp_Object tag_val) +{ + module_non_local_exit_throw_1 (env, XCAR (tag_val), XCDR (tag_val)); +} + + +/* Function environments. */ + +/* Return a string object that contains a user-friendly + representation of the function environment. */ +static Lisp_Object +module_format_fun_env (const struct module_fun_env *env) +{ + /* Try to print a function name if possible. */ + const char *path, *sym; + static char const noaddr_format[] = "#<module function at %p>"; + char buffer[sizeof noaddr_format + INT_STRLEN_BOUND (intptr_t) + 256]; + char *buf = buffer; + ptrdiff_t bufsize = sizeof buffer; + ptrdiff_t size + = (dynlib_addr (env->subr, &path, &sym) + ? exprintf (&buf, &bufsize, buffer, -1, + "#<module function %s from %s>", sym, path) + : sprintf (buffer, noaddr_format, env->subr)); + Lisp_Object unibyte_result = make_unibyte_string (buffer, size); + if (buf != buffer) + xfree (buf); + return code_convert_string_norecord (unibyte_result, Qutf_8, false); +} + + +/* Segment initializer. */ + +void +syms_of_module (void) +{ + if (!plain_values) + ltv_mark = Fcons (Qnil, Qnil); + eassert (NILP (value_to_lisp (module_nil))); + + DEFSYM (Qmodule_refs_hash, "module-refs-hash"); + DEFVAR_LISP ("module-refs-hash", Vmodule_refs_hash, + doc: /* Module global reference table. */); + + Vmodule_refs_hash + = make_hash_table (hashtest_eq, make_number (DEFAULT_HASH_SIZE), + make_float (DEFAULT_REHASH_SIZE), + make_float (DEFAULT_REHASH_THRESHOLD), + Qnil); + Funintern (Qmodule_refs_hash, Qnil); + + DEFSYM (Qmodule_environments, "module-environments"); + DEFVAR_LISP ("module-environments", Vmodule_environments, + doc: /* List of active module environments. */); + Vmodule_environments = Qnil; + /* Unintern `module-environments' because it is only used + internally. */ + Funintern (Qmodule_environments, Qnil); + + DEFSYM (Qmodule_load_failed, "module-load-failed"); + Fput (Qmodule_load_failed, Qerror_conditions, + listn (CONSTYPE_PURE, 2, Qmodule_load_failed, Qerror)); + Fput (Qmodule_load_failed, Qerror_message, + build_pure_c_string ("Module load failed")); + + DEFSYM (Qinvalid_module_call, "invalid-module-call"); + Fput (Qinvalid_module_call, Qerror_conditions, + listn (CONSTYPE_PURE, 2, Qinvalid_module_call, Qerror)); + Fput (Qinvalid_module_call, Qerror_message, + build_pure_c_string ("Invalid module call")); + + DEFSYM (Qinvalid_arity, "invalid-arity"); + Fput (Qinvalid_arity, Qerror_conditions, + listn (CONSTYPE_PURE, 2, Qinvalid_arity, Qerror)); + Fput (Qinvalid_arity, Qerror_message, + build_pure_c_string ("Invalid function arity")); + + /* Unintern `module-refs-hash' because it is internal-only and Lisp + code or modules should not access it. */ + Funintern (Qmodule_refs_hash, Qnil); + + DEFSYM (Qsave_value_p, "save-value-p"); + DEFSYM (Qsave_pointer_p, "save-pointer-p"); + + defsubr (&Smodule_load); + + DEFSYM (Qinternal_module_call, "internal--module-call"); + defsubr (&Sinternal_module_call); +} + +/* Unlike syms_of_module, this initializer is called even from an + initialized (dumped) Emacs. */ + +void +module_init (void) +{ + /* It is not guaranteed that dynamic initializers run in the main thread, + therefore detect the main thread here. */ +#ifdef HAVE_PTHREAD + main_thread = pthread_self (); +#elif defined WINDOWSNT + /* The 'main' function already recorded the main thread's thread ID, + so we need just to use it . */ + main_thread = dwMainThreadId; +#endif +} diff --git a/src/emacs-module.h b/src/emacs-module.h new file mode 100644 index 00000000000..a3aa5017a4e --- /dev/null +++ b/src/emacs-module.h @@ -0,0 +1,215 @@ +/* emacs-module.h - GNU Emacs module API. + +Copyright (C) 2015 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/>. */ + +#ifndef EMACS_MODULE_H +#define EMACS_MODULE_H + +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> + +#if defined __cplusplus && __cplusplus >= 201103L +# define EMACS_NOEXCEPT noexcept + +/* Function prototype for module user-pointer finalizers. + + NOTE: C++11 15.4: An exception-specification shall not appear in a + typedef declaration or alias-declaration. + +*/ +void emacs_dummy_finalizer_function (void *) noexcept; +typedef decltype(emacs_dummy_finalizer_function) *emacs_finalizer_function; + +#else +# define EMACS_NOEXCEPT +typedef void (*emacs_finalizer_function) (void *); +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Current environment. */ +typedef struct emacs_env_25 emacs_env; + +/* Opaque pointer representing an Emacs Lisp value. + BEWARE: Do not assume NULL is a valid value! */ +typedef struct emacs_value_tag *emacs_value; + +enum emacs_arity { emacs_variadic_function = -2 }; + +/* Struct passed to a module init function (emacs_module_init). */ +struct emacs_runtime +{ + /* Structure size (for version checking). */ + ptrdiff_t size; + + /* Private data; users should not touch this. */ + struct emacs_runtime_private *private_members; + + /* Return an environment pointer. */ + emacs_env *(*get_environment) (struct emacs_runtime *ert); +}; + + +/* 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 +{ + /* Function has returned normally. */ + emacs_funcall_exit_return = 0, + + /* Function has signaled an error using `signal'. */ + emacs_funcall_exit_signal = 1, + + /* Function has exit using `throw'. */ + emacs_funcall_exit_throw = 2, +}; + +struct emacs_env_25 +{ + /* Structure size (for version checking). */ + ptrdiff_t size; + + /* Private data; users should not touch this. */ + struct emacs_env_private *private_members; + + /* Memory management. */ + + emacs_value (*make_global_ref) (emacs_env *env, + emacs_value any_reference); + + void (*free_global_ref) (emacs_env *env, + emacs_value global_reference); + + /* Non-local exit handling. */ + + enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env); + + void (*non_local_exit_clear) (emacs_env *env); + + enum emacs_funcall_exit (*non_local_exit_get) + (emacs_env *env, + emacs_value *non_local_exit_symbol_out, + emacs_value *non_local_exit_data_out); + + void (*non_local_exit_signal) (emacs_env *env, + emacs_value non_local_exit_symbol, + emacs_value non_local_exit_data); + + void (*non_local_exit_throw) (emacs_env *env, + emacs_value tag, + emacs_value value); + + /* Function registration. */ + + emacs_value (*make_function) (emacs_env *env, + ptrdiff_t min_arity, + ptrdiff_t max_arity, + emacs_value (*function) (emacs_env *env, + ptrdiff_t nargs, + emacs_value args[], + void *) + EMACS_NOEXCEPT, + const char *documentation, + void *data); + + emacs_value (*funcall) (emacs_env *env, + emacs_value function, + ptrdiff_t nargs, + emacs_value args[]); + + emacs_value (*intern) (emacs_env *env, + const char *symbol_name); + + /* Type conversion. */ + + emacs_value (*type_of) (emacs_env *env, + emacs_value value); + + bool (*is_not_nil) (emacs_env *env, emacs_value value); + + bool (*eq) (emacs_env *env, emacs_value a, emacs_value b); + + intmax_t (*extract_integer) (emacs_env *env, emacs_value value); + + emacs_value (*make_integer) (emacs_env *env, intmax_t value); + + double (*extract_float) (emacs_env *env, emacs_value value); + + emacs_value (*make_float) (emacs_env *env, double value); + + /* Copy the content of the Lisp string VALUE to BUFFER as an utf8 + null-terminated string. + + SIZE must point to the total size of the buffer. If BUFFER is + NULL or if SIZE is not big enough, write the required buffer size + to SIZE and return false. + + Note that SIZE must include the last null byte (e.g. "abc" needs + a buffer of size 4). + + Return true if the string was successfully copied. */ + + bool (*copy_string_contents) (emacs_env *env, + emacs_value value, + char *buffer, + ptrdiff_t *size_inout); + + /* Create a Lisp string from a utf8 encoded string. */ + emacs_value (*make_string) (emacs_env *env, + const char *contents, ptrdiff_t length); + + /* Embedded pointer type. */ + emacs_value (*make_user_ptr) (emacs_env *env, + emacs_finalizer_function fin, + void *ptr); + + void *(*get_user_ptr) (emacs_env *env, emacs_value uptr); + void (*set_user_ptr) (emacs_env *env, emacs_value uptr, void *ptr); + + emacs_finalizer_function (*get_user_finalizer) (emacs_env *env, + emacs_value uptr); + void (*set_user_finalizer) (emacs_env *env, + emacs_value uptr, + emacs_finalizer_function fin); + + /* Vector functions. */ + emacs_value (*vec_get) (emacs_env *env, emacs_value vec, ptrdiff_t i); + + void (*vec_set) (emacs_env *env, emacs_value vec, ptrdiff_t i, + emacs_value val); + + ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vec); +}; + +/* Every module should define a function as follows. */ +extern int emacs_module_init (struct emacs_runtime *ert); + +#ifdef __cplusplus +} +#endif + +#endif /* EMACS_MODULE_H */ diff --git a/src/emacs.c b/src/emacs.c index 2e9f950851a..926aa989e6a 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -761,6 +761,9 @@ main (int argc, char **argv) names between UTF-8 and the system's ANSI codepage. */ maybe_load_unicows_dll (); #endif + /* This has to be done before module_init is called below, so that + the latter could use the thread ID of the main thread. */ + w32_init_main_thread (); #endif #ifdef RUN_TIME_REMAP @@ -776,6 +779,10 @@ main (int argc, char **argv) atexit (close_output_streams); +#ifdef HAVE_MODULES + module_init (); +#endif + sort_args (argc, argv); argc = 0; while (argv[argc]) argc++; @@ -1454,6 +1461,11 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem syms_of_terminal (); syms_of_term (); syms_of_undo (); + +#ifdef HAVE_MODULES + syms_of_module (); +#endif + #ifdef HAVE_SOUND syms_of_sound (); #endif diff --git a/src/eval.c b/src/eval.c index ac98ca11bd4..bd0cf68369c 100644 --- a/src/eval.c +++ b/src/eval.c @@ -61,7 +61,7 @@ union specbinding *specpdl_ptr; /* Depth in Lisp evaluations and function calls. */ -EMACS_INT lisp_eval_depth; +static EMACS_INT lisp_eval_depth; /* The value of num_nonmacro_input_events as of the last time we started to enter the debugger. If we decide to enter the debugger @@ -226,9 +226,8 @@ init_eval (void) { /* Put a dummy catcher at top-level so that handlerlist is never NULL. This is important since handlerlist->nextfree holds the freelist which would otherwise leak every time we unwind back to top-level. */ - struct handler *c; handlerlist = handlerlist_sentinel.nextfree = &handlerlist_sentinel; - PUSH_HANDLER (c, Qunbound, CATCHER); + struct handler *c = push_handler (Qunbound, CATCHER); eassert (c == &handlerlist_sentinel); handlerlist_sentinel.nextfree = NULL; handlerlist_sentinel.next = NULL; @@ -488,6 +487,10 @@ usage: (setq [SYM VAL]...) */) if (CONSP (args)) { Lisp_Object args_left = args; + Lisp_Object numargs = Flength (args); + + if (XINT (numargs) & 1) + xsignal2 (Qwrong_number_of_arguments, Qsetq, numargs); do { @@ -1059,18 +1062,16 @@ usage: (catch TAG BODY...) */) This is how catches are done from within C code. */ Lisp_Object -internal_catch (Lisp_Object tag, Lisp_Object (*func) (Lisp_Object), Lisp_Object arg) +internal_catch (Lisp_Object tag, + Lisp_Object (*func) (Lisp_Object), Lisp_Object arg) { /* This structure is made part of the chain `catchlist'. */ - struct handler *c; - - /* Fill in the components of c, and put it on the list. */ - PUSH_HANDLER (c, tag, CATCHER); + struct handler *c = push_handler (tag, CATCHER); /* Call FUNC. */ if (! sys_setjmp (c->jmp)) { - Lisp_Object val = (*func) (arg); + Lisp_Object val = func (arg); clobbered_eassert (handlerlist == c); handlerlist = handlerlist->next; return val; @@ -1145,6 +1146,8 @@ Both TAG and VALUE are evalled. */ if (!NILP (tag)) for (c = handlerlist; c; c = c->next) { + if (c->type == CATCHER_ALL) + unwind_to_catch (c, Fcons (tag, value)); if (c->type == CATCHER && EQ (c->tag_or_ch, tag)) unwind_to_catch (c, value); } @@ -1211,7 +1214,6 @@ internal_lisp_condition_case (volatile Lisp_Object var, Lisp_Object bodyform, Lisp_Object handlers) { Lisp_Object val; - struct handler *c; struct handler *oldhandlerlist = handlerlist; int clausenb = 0; @@ -1246,7 +1248,7 @@ internal_lisp_condition_case (volatile Lisp_Object var, Lisp_Object bodyform, Lisp_Object condition = XCAR (clause); if (!CONSP (condition)) condition = Fcons (condition, Qnil); - PUSH_HANDLER (c, condition, CONDITION_CASE); + struct handler *c = push_handler (condition, CONDITION_CASE); if (sys_setjmp (c->jmp)) { ptrdiff_t count = SPECPDL_INDEX (); @@ -1294,46 +1296,45 @@ Lisp_Object internal_condition_case (Lisp_Object (*bfun) (void), Lisp_Object handlers, Lisp_Object (*hfun) (Lisp_Object)) { - Lisp_Object val; - struct handler *c; - - PUSH_HANDLER (c, handlers, CONDITION_CASE); + struct handler *c = push_handler (handlers, CONDITION_CASE); if (sys_setjmp (c->jmp)) { Lisp_Object val = handlerlist->val; clobbered_eassert (handlerlist == c); handlerlist = handlerlist->next; - return (*hfun) (val); + return hfun (val); + } + else + { + Lisp_Object val = bfun (); + clobbered_eassert (handlerlist == c); + handlerlist = handlerlist->next; + return val; } - - val = (*bfun) (); - clobbered_eassert (handlerlist == c); - handlerlist = handlerlist->next; - return val; } /* Like internal_condition_case but call BFUN with ARG as its argument. */ Lisp_Object internal_condition_case_1 (Lisp_Object (*bfun) (Lisp_Object), Lisp_Object arg, - Lisp_Object handlers, Lisp_Object (*hfun) (Lisp_Object)) + Lisp_Object handlers, + Lisp_Object (*hfun) (Lisp_Object)) { - Lisp_Object val; - struct handler *c; - - PUSH_HANDLER (c, handlers, CONDITION_CASE); + struct handler *c = push_handler (handlers, CONDITION_CASE); if (sys_setjmp (c->jmp)) { Lisp_Object val = handlerlist->val; clobbered_eassert (handlerlist == c); handlerlist = handlerlist->next; - return (*hfun) (val); + return hfun (val); + } + else + { + Lisp_Object val = bfun (arg); + clobbered_eassert (handlerlist == c); + handlerlist = handlerlist->next; + return val; } - - val = (*bfun) (arg); - clobbered_eassert (handlerlist == c); - handlerlist = handlerlist->next; - return val; } /* Like internal_condition_case_1 but call BFUN with ARG1 and ARG2 as @@ -1346,22 +1347,21 @@ internal_condition_case_2 (Lisp_Object (*bfun) (Lisp_Object, Lisp_Object), Lisp_Object handlers, Lisp_Object (*hfun) (Lisp_Object)) { - Lisp_Object val; - struct handler *c; - - PUSH_HANDLER (c, handlers, CONDITION_CASE); + struct handler *c = push_handler (handlers, CONDITION_CASE); if (sys_setjmp (c->jmp)) { Lisp_Object val = handlerlist->val; clobbered_eassert (handlerlist == c); handlerlist = handlerlist->next; - return (*hfun) (val); + return hfun (val); + } + else + { + Lisp_Object val = bfun (arg1, arg2); + clobbered_eassert (handlerlist == c); + handlerlist = handlerlist->next; + return val; } - - val = (*bfun) (arg1, arg2); - clobbered_eassert (handlerlist == c); - handlerlist = handlerlist->next; - return val; } /* Like internal_condition_case but call BFUN with NARGS as first, @@ -1376,22 +1376,57 @@ internal_condition_case_n (Lisp_Object (*bfun) (ptrdiff_t, Lisp_Object *), ptrdiff_t nargs, Lisp_Object *args)) { - Lisp_Object val; - struct handler *c; - - PUSH_HANDLER (c, handlers, CONDITION_CASE); + struct handler *c = push_handler (handlers, CONDITION_CASE); if (sys_setjmp (c->jmp)) { Lisp_Object val = handlerlist->val; clobbered_eassert (handlerlist == c); handlerlist = handlerlist->next; - return (*hfun) (val, nargs, args); + return hfun (val, nargs, args); + } + else + { + Lisp_Object val = bfun (nargs, args); + clobbered_eassert (handlerlist == c); + handlerlist = handlerlist->next; + return val; } +} - val = (*bfun) (nargs, args); - clobbered_eassert (handlerlist == c); - handlerlist = handlerlist->next; - return val; +struct handler * +push_handler (Lisp_Object tag_ch_val, enum handlertype handlertype) +{ + struct handler *c = push_handler_nosignal (tag_ch_val, handlertype); + if (!c) + memory_full (sizeof *c); + return c; +} + +struct handler * +push_handler_nosignal (Lisp_Object tag_ch_val, enum handlertype handlertype) +{ + struct handler *c = handlerlist->nextfree; + if (!c) + { + c = malloc (sizeof *c); + if (!c) + return c; + if (profiler_memory_running) + malloc_probe (sizeof *c); + c->nextfree = NULL; + handlerlist->nextfree = c; + } + c->type = handlertype; + c->tag_or_ch = tag_ch_val; + c->val = Qnil; + c->next = handlerlist; + c->lisp_eval_depth = lisp_eval_depth; + c->pdlcount = SPECPDL_INDEX (); + c->poll_suppress_count = poll_suppress_count; + c->interrupt_input_blocked = interrupt_input_blocked; + c->byte_stack = byte_stack_list; + handlerlist = c; + return c; } @@ -2014,6 +2049,10 @@ eval_sub (Lisp_Object form) Lisp_Object funcar; ptrdiff_t count; + /* Declare here, as this array may be accessed by call_debugger near + the end of this function. See Bug#21245. */ + Lisp_Object argvals[8]; + if (SYMBOLP (form)) { /* Look up its binding in the lexical environment. @@ -2066,13 +2105,8 @@ eval_sub (Lisp_Object form) if (SUBRP (fun)) { - Lisp_Object numargs; - Lisp_Object argvals[8]; - Lisp_Object args_left; - register int i, maxargs; - - args_left = original_args; - numargs = Flength (args_left); + Lisp_Object args_left = original_args; + Lisp_Object numargs = Flength (args_left); check_cons_list (); @@ -2101,11 +2135,20 @@ eval_sub (Lisp_Object form) set_backtrace_args (specpdl + count, vals, XINT (numargs)); val = (XSUBR (fun)->function.aMANY) (XINT (numargs), vals); + + check_cons_list (); + lisp_eval_depth--; + /* Do the debug-on-exit now, while VALS still exists. */ + if (backtrace_debug_on_exit (specpdl + count)) + val = call_debugger (list2 (Qexit, val)); SAFE_FREE (); + specpdl_ptr--; + return val; } else { - maxargs = XSUBR (fun)->max_args; + int i, maxargs = XSUBR (fun)->max_args; + for (i = 0; i < maxargs; i++) { argvals[i] = eval_sub (Fcar (args_left)); @@ -2165,7 +2208,7 @@ eval_sub (Lisp_Object form) } } else if (COMPILEDP (fun)) - val = apply_lambda (fun, original_args, count); + return apply_lambda (fun, original_args, count); else { if (NILP (fun)) @@ -2195,7 +2238,7 @@ eval_sub (Lisp_Object form) } else if (EQ (funcar, Qlambda) || EQ (funcar, Qclosure)) - val = apply_lambda (fun, original_args, count); + return apply_lambda (fun, original_args, count); else xsignal1 (Qinvalid_function, original_fun); } @@ -2750,14 +2793,13 @@ apply_lambda (Lisp_Object fun, Lisp_Object args, ptrdiff_t count) set_backtrace_args (specpdl + count, arg_vector, i); tem = funcall_lambda (fun, numargs, arg_vector); + check_cons_list (); + lisp_eval_depth--; /* Do the debug-on-exit now, while arg_vector still exists. */ if (backtrace_debug_on_exit (specpdl + count)) - { - /* Don't do it again when we return to eval. */ - set_backtrace_debug_on_exit (specpdl + count, false); - tem = call_debugger (list2 (Qexit, tem)); - } + tem = call_debugger (list2 (Qexit, tem)); SAFE_FREE (); + specpdl_ptr--; return tem; } @@ -2792,6 +2834,9 @@ funcall_lambda (Lisp_Object fun, ptrdiff_t nargs, } else if (COMPILEDP (fun)) { + ptrdiff_t size = ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK; + if (size <= COMPILED_STACK_DEPTH) + xsignal1 (Qinvalid_function, fun); syms_left = AREF (fun, COMPILED_ARGLIST); if (INTEGERP (syms_left)) /* A byte-code object with a non-nil `push args' slot means we @@ -2889,19 +2934,25 @@ DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode, { Lisp_Object tem; - if (COMPILEDP (object) && CONSP (AREF (object, COMPILED_BYTECODE))) + if (COMPILEDP (object)) { - tem = read_doc_string (AREF (object, COMPILED_BYTECODE)); - if (!CONSP (tem)) + ptrdiff_t size = ASIZE (object) & PSEUDOVECTOR_SIZE_MASK; + if (size <= COMPILED_STACK_DEPTH) + xsignal1 (Qinvalid_function, object); + if (CONSP (AREF (object, COMPILED_BYTECODE))) { - tem = AREF (object, COMPILED_BYTECODE); - if (CONSP (tem) && STRINGP (XCAR (tem))) - error ("Invalid byte code in %s", SDATA (XCAR (tem))); - else - error ("Invalid byte code"); + tem = read_doc_string (AREF (object, COMPILED_BYTECODE)); + if (!CONSP (tem)) + { + tem = AREF (object, COMPILED_BYTECODE); + if (CONSP (tem) && STRINGP (XCAR (tem))) + error ("Invalid byte code in %s", SDATA (XCAR (tem))); + else + error ("Invalid byte code"); + } + ASET (object, COMPILED_BYTECODE, XCAR (tem)); + ASET (object, COMPILED_CONSTANTS, XCDR (tem)); } - ASET (object, COMPILED_BYTECODE, XCAR (tem)); - ASET (object, COMPILED_CONSTANTS, XCDR (tem)); } return object; } @@ -3145,10 +3196,11 @@ unbind_to (ptrdiff_t count, Lisp_Object value) { /* If variable has a trivial value (no forwarding), we can just set it. No need to check for constant symbols here, since that was already done by specbind. */ - struct Lisp_Symbol *sym = XSYMBOL (specpdl_symbol (specpdl_ptr)); - if (sym->redirect == SYMBOL_PLAINVAL) + Lisp_Object sym = specpdl_symbol (specpdl_ptr); + if (SYMBOLP (sym) && XSYMBOL (sym)->redirect == SYMBOL_PLAINVAL) { - SET_SYMBOL_VAL (sym, specpdl_old_value (specpdl_ptr)); + SET_SYMBOL_VAL (XSYMBOL (sym), + specpdl_old_value (specpdl_ptr)); break; } else @@ -3357,12 +3409,12 @@ backtrace_eval_unrewind (int distance) { /* If variable has a trivial value (no forwarding), we can just set it. No need to check for constant symbols here, since that was already done by specbind. */ - struct Lisp_Symbol *sym = XSYMBOL (specpdl_symbol (tmp)); - if (sym->redirect == SYMBOL_PLAINVAL) + Lisp_Object sym = specpdl_symbol (tmp); + if (SYMBOLP (sym) && XSYMBOL (sym)->redirect == SYMBOL_PLAINVAL) { Lisp_Object old_value = specpdl_old_value (tmp); - set_specpdl_old_value (tmp, SYMBOL_VAL (sym)); - SET_SYMBOL_VAL (sym, old_value); + set_specpdl_old_value (tmp, SYMBOL_VAL (XSYMBOL (sym))); + SET_SYMBOL_VAL (XSYMBOL (sym), old_value); break; } else @@ -3607,6 +3659,7 @@ To prevent this happening, set `quit-flag' to nil before making `inhibit-quit' nil. */); Vinhibit_quit = Qnil; + DEFSYM (Qsetq, "setq"); DEFSYM (Qinhibit_quit, "inhibit-quit"); DEFSYM (Qautoload, "autoload"); DEFSYM (Qinhibit_debugger, "inhibit-debugger"); diff --git a/src/fileio.c b/src/fileio.c index 6cda1e39eed..e18ddb1a7aa 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -4263,9 +4263,14 @@ by calling `format-decode', which see. */) if (CODING_FOR_UNIBYTE (&coding) /* Can't do this if part of the buffer might be preserved. */ && NILP (replace)) - /* Visiting a file with these coding system makes the buffer - unibyte. */ - bset_enable_multibyte_characters (current_buffer, Qnil); + { + /* Visiting a file with these coding system makes the buffer + unibyte. */ + if (inserted > 0) + bset_enable_multibyte_characters (current_buffer, Qnil); + else + Fset_buffer_multibyte (Qnil); + } } coding.dst_multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); diff --git a/src/fns.c b/src/fns.c index 46956668777..4c13290158a 100644 --- a/src/fns.c +++ b/src/fns.c @@ -338,7 +338,7 @@ This function obeys the conventions for collation order in your locale settings. For example, punctuation and whitespace characters might be considered less significant for sorting: -(sort '("11" "12" "1 1" "1 2" "1.1" "1.2") \\='string-collate-lessp) +(sort \\='("11" "12" "1 1" "1 2" "1.1" "1.2") \\='string-collate-lessp) => ("11" "1 1" "1.1" "12" "1 2" "1.2") The optional argument LOCALE, a string, overrides the setting of your @@ -1580,7 +1580,8 @@ sublist by modifying its list structure, then returns the resulting list. Write `(setq foo (delq element foo))' to be sure of correctly changing -the value of a list `foo'. */) +the value of a list `foo'. See also `remq', which does not modify the +argument. */) (register Lisp_Object elt, Lisp_Object list) { Lisp_Object tail, tortoise, prev = Qnil; @@ -2763,8 +2764,9 @@ DEFUN ("require", Frequire, Srequire, 1, 3, 0, If FEATURE is not a member of the list `features', then the feature is not loaded; so load the file FILENAME. If FILENAME is omitted, the printname of FEATURE is used as the file name, -and `load' will try to load this name appended with the suffix `.elc' or -`.el', in that order. The name without appended suffix will not be used. +and `load' will try to load this name appended with the suffix `.elc', +`.el', or the system-dependent suffix for dynamic module files, in that +order. The name without appended suffix will not be used. See `get-load-suffixes' for the complete list of suffixes. If the optional third argument NOERROR is non-nil, then return nil if the file is not found instead of signaling an error. @@ -3619,8 +3621,7 @@ larger_vector (Lisp_Object vec, ptrdiff_t incr_min, ptrdiff_t nitems_max) Low-level Functions ***********************************************************************/ -static struct hash_table_test hashtest_eq; -struct hash_table_test hashtest_eql, hashtest_equal; +struct hash_table_test hashtest_eq, hashtest_eql, hashtest_equal; /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code HASH2 in hash table H using `eql'. Value is true if KEY1 and @@ -3991,7 +3992,7 @@ hash_put (struct Lisp_Hash_Table *h, Lisp_Object key, Lisp_Object value, /* Remove the entry matching KEY from hash table H, if there is one. */ -static void +void hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key) { EMACS_UINT hash_code; @@ -4078,13 +4079,10 @@ hash_clear (struct Lisp_Hash_Table *h) static bool sweep_weak_table (struct Lisp_Hash_Table *h, bool remove_entries_p) { - ptrdiff_t bucket, n; - bool marked; - - n = ASIZE (h->index) & ~ARRAY_MARK_FLAG; - marked = 0; + ptrdiff_t n = gc_asize (h->index); + bool marked = false; - for (bucket = 0; bucket < n; ++bucket) + for (ptrdiff_t bucket = 0; bucket < n; ++bucket) { Lisp_Object idx, next, prev; diff --git a/src/font.h b/src/font.h index 1d13e1cb6b0..24c058dd88b 100644 --- a/src/font.h +++ b/src/font.h @@ -427,6 +427,13 @@ FONT_SPEC_P (Lisp_Object x) return FONTP (x) && (ASIZE (x) & PSEUDOVECTOR_SIZE_MASK) == FONT_SPEC_MAX; } +/* Like FONT_SPEC_P, but can be used in the garbage collector. */ +INLINE bool +GC_FONT_SPEC_P (Lisp_Object x) +{ + return FONTP (x) && (gc_asize (x) & PSEUDOVECTOR_SIZE_MASK) == FONT_SPEC_MAX; +} + /* True iff X is font-entity. */ INLINE bool FONT_ENTITY_P (Lisp_Object x) @@ -434,6 +441,13 @@ FONT_ENTITY_P (Lisp_Object x) return FONTP (x) && (ASIZE (x) & PSEUDOVECTOR_SIZE_MASK) == FONT_ENTITY_MAX; } +/* Like FONT_ENTITY_P, but can be used in the garbage collector. */ +INLINE bool +GC_FONT_ENTITY_P (Lisp_Object x) +{ + return FONTP (x) && (gc_asize (x) & PSEUDOVECTOR_SIZE_MASK) == FONT_ENTITY_MAX; +} + /* True iff X is font-object. */ INLINE bool FONT_OBJECT_P (Lisp_Object x) @@ -441,6 +455,13 @@ FONT_OBJECT_P (Lisp_Object x) return FONTP (x) && (ASIZE (x) & PSEUDOVECTOR_SIZE_MASK) == FONT_OBJECT_MAX; } +/* Like FONT_OBJECT_P, but can be used in the garbage collector. */ +INLINE bool +GC_FONT_OBJECT_P (Lisp_Object x) +{ + return FONTP (x) && (gc_asize (x) & PSEUDOVECTOR_SIZE_MASK) == FONT_OBJECT_MAX; +} + /* Type checking functions for various font-related objects. */ INLINE void @@ -476,6 +497,13 @@ XFONT_SPEC (Lisp_Object p) return XUNTAG (p, Lisp_Vectorlike); } +INLINE struct font_spec * +GC_XFONT_SPEC (Lisp_Object p) +{ + eassert (GC_FONT_SPEC_P (p)); + return XUNTAG (p, Lisp_Vectorlike); +} + INLINE struct font_entity * XFONT_ENTITY (Lisp_Object p) { @@ -483,6 +511,13 @@ XFONT_ENTITY (Lisp_Object p) return XUNTAG (p, Lisp_Vectorlike); } +INLINE struct font_entity * +GC_XFONT_ENTITY (Lisp_Object p) +{ + eassert (GC_FONT_ENTITY_P (p)); + return XUNTAG (p, Lisp_Vectorlike); +} + INLINE struct font * XFONT_OBJECT (Lisp_Object p) { @@ -490,6 +525,13 @@ XFONT_OBJECT (Lisp_Object p) return XUNTAG (p, Lisp_Vectorlike); } +INLINE struct font * +GC_XFONT_OBJECT (Lisp_Object p) +{ + eassert (GC_FONT_OBJECT_P (p)); + return XUNTAG (p, Lisp_Vectorlike); +} + #define XSETFONT(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_FONT)) INLINE struct font * diff --git a/src/frame.c b/src/frame.c index 78f8ff71be3..4897052e1f9 100644 --- a/src/frame.c +++ b/src/frame.c @@ -239,10 +239,10 @@ DEFUN ("framep", Fframep, Sframep, 1, 1, 0, doc: /* Return non-nil if OBJECT is a frame. Value is: t for a termcap frame (a character-only terminal), - 'x' for an Emacs frame that is really an X window, - 'w32' for an Emacs frame that is a window on MS-Windows display, - 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display, - 'pc' for a direct-write MS-DOS frame. + `x' for an Emacs frame that is really an X window, + `w32' for an Emacs frame that is a window on MS-Windows display, + `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display, + `pc' for a direct-write MS-DOS frame. See also `frame-live-p'. */) (Lisp_Object object) { @@ -284,10 +284,10 @@ DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0, doc: /* The name of the window system that FRAME is displaying through. The value is a symbol: nil for a termcap frame (a character-only terminal), - 'x' for an Emacs frame that is really an X window, - 'w32' for an Emacs frame that is a window on MS-Windows display, - 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display, - 'pc' for a direct-write MS-DOS frame. + `x' for an Emacs frame that is really an X window, + `w32' for an Emacs frame that is a window on MS-Windows display, + `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display, + `pc' for a direct-write MS-DOS frame. FRAME defaults to the currently selected frame. @@ -2641,13 +2641,16 @@ If FRAME is nil, describe the currently selected frame. */) DEFUN ("modify-frame-parameters", Fmodify_frame_parameters, Smodify_frame_parameters, 2, 2, 0, - doc: /* Modify the parameters of frame FRAME according to ALIST. + doc: /* Modify FRAME according to new values of its parameters in ALIST. If FRAME is nil, it defaults to the selected frame. ALIST is an alist of parameters to change and their new values. Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol. -The meaningful PARMs depend on the kind of frame. -Undefined PARMs are ignored, but stored in the frame's parameter list -so that `frame-parameters' will return them. +Which PARMs are meaningful depends on the kind of frame. +The meaningful parameters are acted upon, i.e. the frame is changed +according to their new values, and are also stored in the frame's +parameter list so that `frame-parameters' will return them. +PARMs that are not meaningful are still stored in the frame's parameter +list, but are otherwise ignored. The value of frame parameter FOO can also be accessed as a frame-local binding for the variable FOO, if you have diff --git a/src/gmalloc.c b/src/gmalloc.c index a88f4ab75e0..90a52a1c728 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c @@ -60,7 +60,6 @@ extern void emacs_abort (void); 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. */ -#ifdef HYBRID_MALLOC #undef malloc #undef realloc #undef calloc @@ -70,7 +69,6 @@ extern void emacs_abort (void); #define calloc gcalloc #define aligned_alloc galigned_alloc #define free gfree -#endif /* HYBRID_MALLOC */ #ifdef CYGWIN extern void *bss_sbrk (ptrdiff_t size); @@ -1711,13 +1709,13 @@ valloc (size_t size) return aligned_alloc (pagesize, size); } -#ifdef HYBRID_MALLOC #undef malloc #undef realloc #undef calloc #undef aligned_alloc #undef free +#ifdef HYBRID_MALLOC /* Declare system malloc and friends. */ extern void *malloc (size_t size); extern void *realloc (void *ptr, size_t size); @@ -1816,6 +1814,38 @@ hybrid_get_current_dir_name (void) } #endif +#else /* ! HYBRID_MALLOC */ + +void * +malloc (size_t size) +{ + return gmalloc (size); +} + +void * +calloc (size_t nmemb, size_t size) +{ + return gcalloc (nmemb, size); +} + +void +free (void *ptr) +{ + gfree (ptr); +} + +void * +aligned_alloc (size_t alignment, size_t size) +{ + return galigned_alloc (alignment, size); +} + +void * +realloc (void *ptr, size_t size) +{ + return grealloc (ptr, size); +} + #endif /* HYBRID_MALLOC */ #ifdef GC_MCHECK diff --git a/src/indent.c b/src/indent.c index 04837f8f513..33bf424b344 100644 --- a/src/indent.c +++ b/src/indent.c @@ -2080,11 +2080,7 @@ whether or not it is currently displayed in some window. */) } else it_overshoot_count = - (!(it.method == GET_FROM_IMAGE - || it.method == GET_FROM_STRETCH) - /* We will overshoot if lines are truncated and PT lies - beyond the right margin of the window. */ - || it.line_wrap == TRUNCATE); + !(it.method == GET_FROM_IMAGE || it.method == GET_FROM_STRETCH); if (start_x_given) { @@ -2142,6 +2138,11 @@ whether or not it is currently displayed in some window. */) screen lines we need to backtrack. */ it_overshoot_count = it.vpos; } + /* We will overshoot if lines are truncated and point lies + beyond the right margin of the window. */ + if (it.line_wrap == TRUNCATE && it.current_x >= it.last_visible_x + && it_overshoot_count == 0) + it_overshoot_count = 1; if (it_overshoot_count > 0) move_it_by_lines (&it, -it_overshoot_count); diff --git a/src/insdel.c b/src/insdel.c index 24807b1e8f4..bb3171b14ce 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -1765,6 +1765,18 @@ modify_text (ptrdiff_t start, ptrdiff_t end) bset_point_before_scroll (current_buffer, Qnil); } +/* Signal that we are about to make a change that may result in new + undo information. + */ +static void +run_undoable_change (void) +{ + if (EQ (BVAR (current_buffer, undo_list), Qt)) + return; + + call0 (Qundo_auto__undoable_change); +} + /* Check that it is okay to modify the buffer between START and END, which are char positions. @@ -1773,7 +1785,12 @@ modify_text (ptrdiff_t start, ptrdiff_t end) any modification properties the text may have. If PRESERVE_PTR is nonzero, we relocate *PRESERVE_PTR - by holding its value temporarily in a marker. */ + by holding its value temporarily in a marker. + + This function runs Lisp, which means it can GC, which means it can + compact buffers, including the current buffer being worked on here. + So don't you dare calling this function while manipulating the gap, + or during some other similar "critical section". */ void prepare_to_modify_buffer_1 (ptrdiff_t start, ptrdiff_t end, @@ -1786,6 +1803,8 @@ prepare_to_modify_buffer_1 (ptrdiff_t start, ptrdiff_t end, if (!NILP (BVAR (current_buffer, read_only))) Fbarf_if_buffer_read_only (temp); + run_undoable_change(); + bset_redisplay (current_buffer); if (buffer_intervals (current_buffer)) @@ -2187,6 +2206,8 @@ syms_of_insdel (void) combine_after_change_list = Qnil; combine_after_change_buffer = Qnil; + DEFSYM (Qundo_auto__undoable_change, "undo-auto--undoable-change"); + DEFVAR_LISP ("combine-after-change-calls", Vcombine_after_change_calls, doc: /* Used internally by the function `combine-after-change-calls' macro. */); Vcombine_after_change_calls = Qnil; diff --git a/src/keyboard.c b/src/keyboard.c index ab7cb34a030..6fa38aa1328 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -195,14 +195,15 @@ Lisp_Object unread_switch_frame; /* Last size recorded for a current buffer which is not a minibuffer. */ static ptrdiff_t last_non_minibuf_size; -/* Total number of times read_char has returned, modulo UINTMAX_MAX + 1. */ uintmax_t num_input_events; +ptrdiff_t point_before_last_command_or_undo; +struct buffer *buffer_before_last_command_or_undo; /* Value of num_nonmacro_input_events as of last auto save. */ static EMACS_INT last_auto_save; -/* The value of point when the last command was started. */ +/* The value of point when the last command was started. */ static ptrdiff_t last_point_position; /* The frame in which the last input event occurred, or Qmacro if the @@ -1449,6 +1450,11 @@ command_loop_1 (void) result of changes from the last command. */ call0 (Qundo_auto__add_boundary); + /* Record point and buffer, so we can put point into the undo + information if necessary. */ + point_before_last_command_or_undo = PT; + buffer_before_last_command_or_undo = current_buffer; + call1 (Qcommand_execute, Vthis_command); #ifdef HAVE_WINDOW_SYSTEM @@ -3313,14 +3319,12 @@ readable_events (int flags) #endif )) { - union buffered_input_event *event; - - event = ((kbd_fetch_ptr < kbd_buffer + KBD_BUFFER_SIZE) - ? kbd_fetch_ptr - : kbd_buffer); + union buffered_input_event *event = kbd_fetch_ptr; do { + if (event == kbd_buffer + KBD_BUFFER_SIZE) + event = kbd_buffer; if (!( #ifdef USE_TOOLKIT_SCROLL_BARS (flags & READABLE_EVENTS_FILTER_EVENTS) && @@ -3337,8 +3341,6 @@ readable_events (int flags) && event->kind == BUFFER_SWITCH_EVENT)) return 1; event++; - if (event == kbd_buffer + KBD_BUFFER_SIZE) - event = kbd_buffer; } while (event != kbd_store_ptr); } @@ -11372,7 +11374,7 @@ If an unhandled error happens in running this hook, the function in which the error occurred is unconditionally removed, since otherwise the error might happen repeatedly and make Emacs nonfunctional. -See also `pre-command-hook'. */); +See also `post-command-hook'. */); Vpre_command_hook = Qnil; DEFVAR_LISP ("post-command-hook", Vpost_command_hook, diff --git a/src/keyboard.h b/src/keyboard.h index 98bc86b58ed..890d24eb2d9 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -245,6 +245,18 @@ extern KBOARD *current_kboard; /* Total number of times read_char has returned, modulo UINTMAX_MAX + 1. */ extern uintmax_t num_input_events; +/* The location of point immediately before the last command was + executed, or the last time the undo-boundary command added a + boundary.*/ +extern ptrdiff_t point_before_last_command_or_undo; + +/* The value of current_buffer immediately before the last command was + executed, or the last time the undo-boundary command added a + boundary.*/ +extern struct buffer *buffer_before_last_command_or_undo; + +extern struct buffer *prev_buffer; + /* Nonzero means polling for input is temporarily suppressed. */ extern int poll_suppress_count; diff --git a/src/lisp.h b/src/lisp.h index 426b6c949e9..ff88605fc9f 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -357,7 +357,7 @@ error !; # define lisp_h_XINT(a) (XLI (a) >> INTTYPEBITS) # define lisp_h_XSYMBOL(a) \ (eassert (SYMBOLP (a)), \ - (struct Lisp_Symbol *) ((uintptr_t) XLI (a) - Lisp_Symbol \ + (struct Lisp_Symbol *) ((intptr_t) XLI (a) - Lisp_Symbol \ + (char *) lispsym)) # define lisp_h_XTYPE(a) ((enum Lisp_Type) (XLI (a) & ~VALMASK)) # define lisp_h_XUNTAG(a, type) ((void *) (intptr_t) (XLI (a) - (type))) @@ -369,6 +369,12 @@ error !; #if (defined __NO_INLINE__ \ && ! defined __OPTIMIZE__ && ! defined __OPTIMIZE_SIZE__ \ && ! (defined INLINING && ! INLINING)) +# define DEFINE_KEY_OPS_AS_MACROS true +#else +# define DEFINE_KEY_OPS_AS_MACROS false +#endif + +#if DEFINE_KEY_OPS_AS_MACROS # define XLI(o) lisp_h_XLI (o) # define XIL(i) lisp_h_XIL (i) # define CHECK_LIST_CONS(x, y) lisp_h_CHECK_LIST_CONS (x, y) @@ -468,6 +474,9 @@ enum Lisp_Misc_Type Lisp_Misc_Overlay, Lisp_Misc_Save_Value, Lisp_Misc_Finalizer, +#ifdef HAVE_MODULES + Lisp_Misc_User_Ptr, +#endif /* Currently floats are not a misc type, but let's define this in case we want to change that. */ Lisp_Misc_Float, @@ -581,6 +590,12 @@ INLINE bool PROCESSP (Lisp_Object); INLINE bool PSEUDOVECTORP (Lisp_Object, int); INLINE bool SAVE_VALUEP (Lisp_Object); INLINE bool FINALIZERP (Lisp_Object); + +#ifdef HAVE_MODULES +INLINE bool USER_PTRP (Lisp_Object); +INLINE struct Lisp_User_Ptr *(XUSER_PTR) (Lisp_Object); +#endif + INLINE void set_sub_char_table_contents (Lisp_Object, ptrdiff_t, Lisp_Object); INLINE bool STRINGP (Lisp_Object); @@ -704,9 +719,15 @@ struct Lisp_Symbol #define DEFUN_ARGS_8 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \ Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object) -/* Yield an integer that contains TAG along with PTR. */ +/* Yield a signed integer that contains TAG along with PTR. + + Sign-extend pointers when USE_LSB_TAG (this simplifies emacs-module.c), + and zero-extend otherwise (that’s a bit faster here). + Sign extension matters only when EMACS_INT is wider than a pointer. */ #define TAG_PTR(tag, ptr) \ - ((USE_LSB_TAG ? (tag) : (EMACS_UINT) (tag) << VALBITS) + (uintptr_t) (ptr)) + (USE_LSB_TAG \ + ? (intptr_t) (ptr) + (tag) \ + : (EMACS_INT) (((EMACS_UINT) (tag) << VALBITS) + (uintptr_t) (ptr))) /* Yield an integer that contains a symbol tag along with OFFSET. OFFSET should be the offset in bytes from 'lispsym' to the symbol. */ @@ -838,7 +859,9 @@ INLINE EMACS_INT INLINE EMACS_INT (XFASTINT) (Lisp_Object a) { - return lisp_h_XFASTINT (a); + EMACS_INT n = lisp_h_XFASTINT (a); + eassume (0 <= n); + return n; } INLINE struct Lisp_Symbol * @@ -906,19 +929,10 @@ XFASTINT (Lisp_Object a) { EMACS_INT int0 = Lisp_Int0; EMACS_INT n = USE_LSB_TAG ? XINT (a) : XLI (a) - (int0 << VALBITS); - eassert (0 <= n); + eassume (0 <= n); return n; } -/* Extract A's value as a symbol. */ -INLINE struct Lisp_Symbol * -XSYMBOL (Lisp_Object a) -{ - uintptr_t i = (uintptr_t) XUNTAG (a, Lisp_Symbol); - void *p = (char *) lispsym + i; - return p; -} - /* Extract A's type. */ INLINE enum Lisp_Type XTYPE (Lisp_Object a) @@ -927,6 +941,16 @@ XTYPE (Lisp_Object a) return USE_LSB_TAG ? i & ~VALMASK : i >> VALBITS; } +/* Extract A's value as a symbol. */ +INLINE struct Lisp_Symbol * +XSYMBOL (Lisp_Object a) +{ + eassert (SYMBOLP (a)); + intptr_t i = (intptr_t) XUNTAG (a, Lisp_Symbol); + void *p = (char *) lispsym + i; + return p; +} + /* Extract A's pointer value, assuming A's type is TYPE. */ INLINE void * XUNTAG (Lisp_Object a, int type) @@ -1527,7 +1551,16 @@ aref_addr (Lisp_Object array, ptrdiff_t idx) INLINE ptrdiff_t ASIZE (Lisp_Object array) { - return XVECTOR (array)->header.size; + ptrdiff_t size = XVECTOR (array)->header.size; + eassume (0 <= size); + return size; +} + +INLINE ptrdiff_t +gc_asize (Lisp_Object array) +{ + /* Like ASIZE, but also can be used in the garbage collector. */ + return XVECTOR (array)->header.size & ~ARRAY_MARK_FLAG; } INLINE void @@ -1542,7 +1575,7 @@ gc_aset (Lisp_Object array, ptrdiff_t idx, Lisp_Object val) { /* Like ASET, but also can be used in the garbage collector: sweep_weak_table calls set_hash_key etc. while the table is marked. */ - eassert (0 <= idx && idx < (ASIZE (array) & ~ARRAY_MARK_FLAG)); + eassert (0 <= idx && idx < gc_asize (array)); XVECTOR (array)->contents[idx] = val; } @@ -1924,21 +1957,22 @@ struct Lisp_Hash_Table }; +INLINE bool +HASH_TABLE_P (Lisp_Object a) +{ + return PSEUDOVECTORP (a, PVEC_HASH_TABLE); +} + INLINE struct Lisp_Hash_Table * XHASH_TABLE (Lisp_Object a) { + eassert (HASH_TABLE_P (a)); return XUNTAG (a, Lisp_Vectorlike); } #define XSET_HASH_TABLE(VAR, PTR) \ (XSETPSEUDOVECTOR (VAR, PTR, PVEC_HASH_TABLE)) -INLINE bool -HASH_TABLE_P (Lisp_Object a) -{ - return PSEUDOVECTORP (a, PVEC_HASH_TABLE); -} - /* Value is the key part of entry IDX in hash table H. */ INLINE Lisp_Object HASH_KEY (struct Lisp_Hash_Table *h, ptrdiff_t idx) @@ -2230,6 +2264,18 @@ XSAVE_OBJECT (Lisp_Object obj, int n) return XSAVE_VALUE (obj)->data[n].object; } +#ifdef HAVE_MODULES +struct Lisp_User_Ptr +{ + ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_User_Ptr */ + bool_bf gcmarkbit : 1; + unsigned spacer : 15; + + void (*finalizer) (void *); + void *p; +}; +#endif + /* A finalizer sentinel. */ struct Lisp_Finalizer { @@ -2265,6 +2311,9 @@ union Lisp_Misc struct Lisp_Overlay u_overlay; struct Lisp_Save_Value u_save_value; struct Lisp_Finalizer u_finalizer; +#ifdef HAVE_MODULES + struct Lisp_User_Ptr u_user_ptr; +#endif }; INLINE union Lisp_Misc * @@ -2314,6 +2363,15 @@ XFINALIZER (Lisp_Object a) return & XMISC (a)->u_finalizer; } +#ifdef HAVE_MODULES +INLINE struct Lisp_User_Ptr * +XUSER_PTR (Lisp_Object a) +{ + eassert (USER_PTRP (a)); + return & XMISC (a)->u_user_ptr; +} +#endif + /* Forwarding pointer to an int variable. This is allowed only in the value cell of a symbol, @@ -2598,6 +2656,14 @@ FINALIZERP (Lisp_Object x) return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Finalizer; } +#ifdef HAVE_MODULES +INLINE bool +USER_PTRP (Lisp_Object x) +{ + return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_User_Ptr; +} +#endif + INLINE bool AUTOLOADP (Lisp_Object x) { @@ -3104,7 +3170,9 @@ SPECPDL_INDEX (void) A call like (throw TAG VAL) searches for a catchtag whose `tag_or_ch' member is TAG, and then unbinds to it. The `val' member is used to hold VAL while the stack is unwound; `val' is returned as the value - of the catch form. + of the catch form. If there is a handler of type CATCHER_ALL, it will + be treated as a handler for all invocations of `throw'; in this case + `val' will be set to (TAG . VAL). All the other members are concerned with restoring the interpreter state. @@ -3112,7 +3180,7 @@ SPECPDL_INDEX (void) Members are volatile if their values need to survive _longjmp when a 'struct handler' is a local variable. */ -enum handlertype { CATCHER, CONDITION_CASE }; +enum handlertype { CATCHER, CONDITION_CASE, CATCHER_ALL }; struct handler { @@ -3140,28 +3208,6 @@ struct handler struct byte_stack *byte_stack; }; -/* Fill in the components of c, and put it on the list. */ -#define PUSH_HANDLER(c, tag_ch_val, handlertype) \ - if (handlerlist->nextfree) \ - (c) = handlerlist->nextfree; \ - else \ - { \ - (c) = xmalloc (sizeof (struct handler)); \ - (c)->nextfree = NULL; \ - handlerlist->nextfree = (c); \ - } \ - (c)->type = (handlertype); \ - (c)->tag_or_ch = (tag_ch_val); \ - (c)->val = Qnil; \ - (c)->next = handlerlist; \ - (c)->lisp_eval_depth = lisp_eval_depth; \ - (c)->pdlcount = SPECPDL_INDEX (); \ - (c)->poll_suppress_count = poll_suppress_count; \ - (c)->interrupt_input_blocked = interrupt_input_blocked;\ - (c)->byte_stack = byte_stack_list; \ - handlerlist = (c); - - extern Lisp_Object memory_signal_data; /* An address near the bottom of the stack. @@ -3407,7 +3453,8 @@ Lisp_Object make_hash_table (struct hash_table_test, Lisp_Object, Lisp_Object, ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *); ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object, EMACS_UINT); -extern struct hash_table_test hashtest_eql, hashtest_equal; +void hash_remove_from_table (struct Lisp_Hash_Table *, Lisp_Object); +extern struct hash_table_test hashtest_eq, hashtest_eql, hashtest_equal; extern void validate_subarray (Lisp_Object, Lisp_Object, Lisp_Object, ptrdiff_t, ptrdiff_t *, ptrdiff_t *); extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t, @@ -3803,7 +3850,6 @@ intern_c_string (const char *str) } /* Defined in eval.c. */ -extern EMACS_INT lisp_eval_depth; extern Lisp_Object Vautoload_queue; extern Lisp_Object Vrun_hooks; extern Lisp_Object Vsignaling_function; @@ -3847,6 +3893,8 @@ extern Lisp_Object internal_condition_case_2 (Lisp_Object (*) (Lisp_Object, Lisp extern Lisp_Object internal_condition_case_n (Lisp_Object (*) (ptrdiff_t, Lisp_Object *), ptrdiff_t, Lisp_Object *, Lisp_Object, Lisp_Object (*) (Lisp_Object, ptrdiff_t, Lisp_Object *)); +extern struct handler *push_handler (Lisp_Object, enum handlertype); +extern struct handler *push_handler_nosignal (Lisp_Object, enum handlertype); extern void specbind (Lisp_Object, Lisp_Object); extern void record_unwind_protect (void (*) (Lisp_Object), Lisp_Object); extern void record_unwind_protect_ptr (void (*) (void *), void *); @@ -3877,6 +3925,14 @@ Lisp_Object backtrace_top_function (void); extern bool let_shadows_buffer_binding_p (struct Lisp_Symbol *symbol); extern bool let_shadows_global_binding_p (Lisp_Object symbol); +#ifdef HAVE_MODULES +/* Defined in alloc.c. */ +extern Lisp_Object make_user_ptr (void (*finalizer) (void*), void *p); + +/* Defined in emacs-module.c. */ +extern void module_init (void); +extern void syms_of_module (void); +#endif /* Defined in editfns.c. */ extern void insert1 (Lisp_Object); diff --git a/src/lread.c b/src/lread.c index c4456f37f6d..74a5fdfe67b 100644 --- a/src/lread.c +++ b/src/lread.c @@ -975,9 +975,20 @@ This uses the variables `load-suffixes' and `load-file-rep-suffixes'. */) return Fnreverse (lst); } +/* Returns true if STRING ends with SUFFIX */ +static bool +suffix_p (Lisp_Object string, const char *suffix) +{ + ptrdiff_t suffix_len = strlen (suffix); + ptrdiff_t string_len = SBYTES (string); + + return string_len >= suffix_len && !strcmp (SSDATA (string) + string_len - suffix_len, suffix); +} + DEFUN ("load", Fload, Sload, 1, 5, 0, doc: /* Execute a file of Lisp code named FILE. -First try FILE with `.elc' appended, then try with `.el', +First try FILE with `.elc' appended, then try with `.el', then try +with a system-dependent suffix of dynamic modules (see `load-suffixes'), then try FILE unmodified (the exact suffixes in the exact order are determined by `load-suffixes'). Environment variable references in FILE are replaced with their values by calling `substitute-in-file-name'. @@ -989,10 +1000,10 @@ Print messages at start and end of loading unless optional third arg NOMESSAGE is non-nil (but `force-load-messages' overrides that). If optional fourth arg NOSUFFIX is non-nil, don't try adding -suffixes `.elc' or `.el' to the specified name FILE. +suffixes to the specified name FILE. If optional fifth arg MUST-SUFFIX is non-nil, insist on -the suffix `.elc' or `.el'; don't accept just FILE unless -it ends in one of those suffixes or includes a directory name. +the suffix `.elc' or `.el' or the module suffix; don't accept just +FILE unless it ends in one of those suffixes or includes a directory name. If NOSUFFIX is nil, then if a file could not be found, try looking for a different representation of the file by adding non-empty suffixes to @@ -1074,12 +1085,12 @@ Return t if the file exists and loads successfully. */) if (! NILP (must_suffix)) { /* Don't insist on adding a suffix if FILE already ends with one. */ - ptrdiff_t size = SBYTES (file); - if (size > 3 - && !strcmp (SSDATA (file) + size - 3, ".el")) - must_suffix = Qnil; - else if (size > 4 - && !strcmp (SSDATA (file) + size - 4, ".elc")) + if (suffix_p (file, ".el") + || suffix_p (file, ".elc") +#ifdef HAVE_MODULES + || suffix_p (file, MODULES_SUFFIX) +#endif + ) must_suffix = Qnil; /* Don't insist on adding a suffix if the argument includes a directory name. */ @@ -1151,6 +1162,11 @@ Return t if the file exists and loads successfully. */) record_unwind_protect_int (close_file_unwind, fd); } +#ifdef HAVE_MODULES + if (suffix_p (found, MODULES_SUFFIX)) + return unbind_to (count, Fmodule_load (found)); +#endif + /* Check if we're stuck in a recursive load cycle. 2000-09-21: It's not possible to just check for the file loaded @@ -1189,8 +1205,7 @@ Return t if the file exists and loads successfully. */) specbind (Qold_style_backquotes, Qnil); record_unwind_protect (load_warn_old_style_backquotes, file); - if (!memcmp (SDATA (found) + SBYTES (found) - 4, ".elc", 4) - || (fd >= 0 && (version = safe_to_load_version (fd)) > 0)) + if (suffix_p (found, ".elc") || (fd >= 0 && (version = safe_to_load_version (fd)) > 0)) /* Load .elc files directly, but not when they are remote and have no handler! */ { @@ -1926,17 +1941,22 @@ readevalloop (Lisp_Object readcharfun, } DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 5, "", - doc: /* Execute the current buffer as Lisp code. + doc: /* Execute the accessible portion of current buffer as Lisp code. +You can use \\[narrow-to-region] to limit the part of buffer to be evaluated. When called from a Lisp program (i.e., not interactively), this function accepts up to five optional arguments: -BUFFER is the buffer to evaluate (nil means use current buffer). -PRINTFLAG controls printing of output: - A value of nil means discard it; anything else is stream for print. +BUFFER is the buffer to evaluate (nil means use current buffer), + or a name of a buffer (a string). +PRINTFLAG controls printing of output by any output functions in the + evaluated code, such as `print', `princ', and `prin1': + a value of nil means discard it; anything else is the stream to print to. + See Info node `(elisp)Output Streams' for details on streams. FILENAME specifies the file name to use for `load-history'. UNIBYTE, if non-nil, specifies `load-convert-to-unibyte' for this invocation. -DO-ALLOW-PRINT, if non-nil, specifies that `print' and related - functions should work normally even if PRINTFLAG is nil. +DO-ALLOW-PRINT, if non-nil, specifies that output functions in the + evaluated code should work normally even if PRINTFLAG is nil, in + which case the output is displayed in the echo area. This function preserves the position of point. */) (Lisp_Object buffer, Lisp_Object printflag, Lisp_Object filename, Lisp_Object unibyte, Lisp_Object do_allow_print) @@ -1977,7 +1997,8 @@ When called from programs, expects two arguments, giving starting and ending indices in the current buffer of the text to be executed. Programs can pass third argument PRINTFLAG which controls output: -A value of nil means discard it; anything else is stream for printing it. + a value of nil means discard it; anything else is stream for printing it. + See Info node `(elisp)Output Streams' for details on streams. Also the fourth argument READ-FUNCTION, if non-nil, is used instead of `read' to read each expression. It gets one argument which is the input stream for reading characters. @@ -3926,10 +3947,8 @@ oblookup (Lisp_Object obarray, register const char *ptr, ptrdiff_t size, ptrdiff Lisp_Object bucket, tem; obarray = check_obarray (obarray); - obsize = ASIZE (obarray); - /* This is sometimes needed in the middle of GC. */ - obsize &= ~ARRAY_MARK_FLAG; + obsize = gc_asize (obarray); hash = hash_string (ptr, size_byte) % obsize; bucket = AREF (obarray, hash); oblookup_last_bucket_number = hash; @@ -4334,7 +4353,7 @@ init_lread (void) load_path_check (default_lpath); /* Add the site-lisp directories to the front of the default. */ - if (!no_site_lisp) + if (!no_site_lisp && PATH_SITELOADSEARCH[0] != '\0') { Lisp_Object sitelisp; sitelisp = decode_env_path (0, PATH_SITELOADSEARCH, 0); @@ -4365,7 +4384,7 @@ init_lread (void) load_path_check (Vload_path); /* Add the site-lisp directories at the front. */ - if (initialized && !no_site_lisp) + if (initialized && !no_site_lisp && PATH_SITELOADSEARCH[0] != '\0') { Lisp_Object sitelisp; sitelisp = decode_env_path (0, PATH_SITELOADSEARCH, 0); @@ -4436,7 +4455,7 @@ to find all the symbols in an obarray, use `mapatoms'. */); DEFVAR_LISP ("values", Vvalues, doc: /* List of values of all expressions which were read, evaluated and printed. - Order is reverse chronological. */); +Order is reverse chronological. */); XSYMBOL (intern ("values"))->declared_special = 0; DEFVAR_LISP ("standard-input", Vstandard_input, @@ -4487,12 +4506,26 @@ programs that process this list should tolerate directories both with and without trailing slashes. */); DEFVAR_LISP ("load-suffixes", Vload_suffixes, - doc: /* List of suffixes for (compiled or source) Emacs Lisp files. + doc: /* List of suffixes for Emacs Lisp files and dynamic modules. +This list includes suffixes for both compiled and source Emacs Lisp files. This list should not include the empty string. `load' and related functions try to append these suffixes, in order, -to the specified file name if a Lisp suffix is allowed or required. */); +to the specified file name if a suffix is allowed or required. */); +#ifdef HAVE_MODULES + Vload_suffixes = list3 (build_pure_c_string (".elc"), + build_pure_c_string (".el"), + build_pure_c_string (MODULES_SUFFIX)); +#else Vload_suffixes = list2 (build_pure_c_string (".elc"), build_pure_c_string (".el")); +#endif + DEFVAR_LISP ("module-file-suffix", Vmodule_file_suffix, + doc: /* Suffix of loadable module file, or nil of modules are not supported. */); +#ifdef HAVE_MODULES + Vmodule_file_suffix = build_pure_c_string (MODULES_SUFFIX); +#else + Vmodule_file_suffix = Qnil; +#endif DEFVAR_LISP ("load-file-rep-suffixes", Vload_file_rep_suffixes, doc: /* List of suffixes that indicate representations of \ the same file. diff --git a/src/macfont.m b/src/macfont.m index fae284fad89..3023fbea78c 100644 --- a/src/macfont.m +++ b/src/macfont.m @@ -771,7 +771,7 @@ mac_font_descriptor_get_adjusted_weight (CTFontDescriptorRef desc, CGFloat val) { long percent_val = lround (val * 100); - if (percent_val == -40 || percent_val == 56) + if (percent_val == -40) { CTFontRef font = NULL; CFStringRef name = @@ -786,19 +786,10 @@ mac_font_descriptor_get_adjusted_weight (CTFontDescriptorRef desc, CGFloat val) { CFIndex weight = mac_font_get_weight (font); - if (percent_val == -40) - { - /* Workaround for crash when displaying Oriya characters - with Arial Unicode MS on OS X 10.11. */ - if (weight == 5) - val = 0; - } - else /* percent_val == 56 */ - { - if (weight == 9) - /* Adjustment for HiraginoSans-W7 on OS X 10.11. */ - val = 0.4; - } + /* Workaround for crash when displaying Oriya characters + with Arial Unicode MS on OS X 10.11. */ + if (weight == 5) + val = 0; CFRelease (font); } } diff --git a/src/nsfns.m b/src/nsfns.m index c24344436ad..5fa68c0a15c 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -405,10 +405,12 @@ ns_set_name_internal (struct frame *f, Lisp_Object name) NSString *str; NSView *view = FRAME_NS_VIEW (f); + encoded_name = ENCODE_UTF_8 (name); str = [NSString stringWithUTF8String: SSDATA (encoded_name)]; + /* Don't change the name if it's already NAME. */ if (! [[[view window] title] isEqualToString: str]) [[view window] setTitle: str]; @@ -483,9 +485,14 @@ x_implicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { NSTRACE ("x_implicitly_set_name"); + Lisp_Object frame_title = buffer_local_value + (Qframe_title_format, XWINDOW (f->selected_window)->contents); + Lisp_Object icon_title = buffer_local_value + (Qicon_title_format, XWINDOW (f->selected_window)->contents); + /* Deal with NS specific format t. */ - if (FRAME_NS_P (f) && ((FRAME_ICONIFIED_P (f) && EQ (Vicon_title_format, Qt)) - || EQ (Vframe_title_format, Qt))) + if (FRAME_NS_P (f) && ((FRAME_ICONIFIED_P (f) && EQ (icon_title, Qt)) + || EQ (frame_title, Qt))) ns_set_name_as_filename (f); else ns_set_name (f, arg, 0); @@ -648,8 +655,15 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) void x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) { + /* Currently, when the tool bar change state, the frame is resized. + + TODO: It would be better if this didn't occur when 1) the frame + is full height or maximized or 2) when specified by + `frame-inhibit-implied-resize'. */ int nlines; + NSTRACE ("x_set_tool_bar_lines"); + if (FRAME_MINIBUF_ONLY_P (f)) return; @@ -669,7 +683,21 @@ x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) { free_frame_tool_bar (f); FRAME_EXTERNAL_TOOL_BAR (f) = 0; - } + + { + EmacsView *view = FRAME_NS_VIEW (f); + int fs_state = [view fullscreenState]; + + if (fs_state == FULLSCREEN_MAXIMIZED) + { + [view setFSValue:FULLSCREEN_WIDTH]; + } + else if (fs_state == FULLSCREEN_HEIGHT) + { + [view setFSValue:FULLSCREEN_NONE]; + } + } + } } { @@ -680,12 +708,12 @@ x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) || (CONSP (frame_inhibit_implied_resize) && !NILP (Fmemq (Qtool_bar_lines, frame_inhibit_implied_resize)))) - /* This will probably fail to DTRT in the - fullheight/-width cases. */ && NILP (get_frame_param (f, Qfullscreen))) ? 0 : 2); + NSTRACE_MSG ("inhibit:%d", inhibit); + frame_size_history_add (f, Qupdate_frame_tool_bar, 0, 0, Qnil); adjust_frame_size (f, -1, -1, inhibit, 0, Qtool_bar_lines); } @@ -2071,39 +2099,6 @@ there was no result. */) } -DEFUN ("ns-convert-utf8-nfd-to-nfc", Fns_convert_utf8_nfd_to_nfc, - Sns_convert_utf8_nfd_to_nfc, 1, 1, 0, - doc: /* Return an NFC string that matches the UTF-8 NFD string STR. */) - (Lisp_Object str) -{ -/* TODO: If GNUstep ever implements precomposedStringWithCanonicalMapping, - remove this. */ - NSString *utfStr; - Lisp_Object ret = Qnil; - NSAutoreleasePool *pool; - - CHECK_STRING (str); - pool = [[NSAutoreleasePool alloc] init]; - utfStr = [NSString stringWithUTF8String: SSDATA (str)]; -#ifdef NS_IMPL_COCOA - if (utfStr) - utfStr = [utfStr precomposedStringWithCanonicalMapping]; -#endif - if (utfStr) - { - const char *cstr = [utfStr UTF8String]; - if (cstr) - ret = build_string (cstr); - } - - [pool release]; - if (NILP (ret)) - error ("Invalid UTF-8"); - - return ret; -} - - #ifdef NS_IMPL_COCOA /* Compile and execute the AppleScript SCRIPT and return the error @@ -3113,6 +3108,8 @@ void syms_of_nsfns (void) { DEFSYM (Qfontsize, "fontsize"); + DEFSYM (Qframe_title_format, "frame-title-format"); + DEFSYM (Qicon_title_format, "icon-title-format"); DEFVAR_LISP ("ns-icon-type-alist", Vns_icon_type_alist, doc: /* Alist of elements (REGEXP . IMAGE) for images of icons associated to frames. @@ -3177,7 +3174,6 @@ be used as the image of the icon representing the frame. */); defsubr (&Sns_emacs_info_panel); defsubr (&Sns_list_services); defsubr (&Sns_perform_service); - defsubr (&Sns_convert_utf8_nfd_to_nfc); defsubr (&Sns_popup_font_panel); defsubr (&Sns_popup_color_panel); diff --git a/src/nsimage.m b/src/nsimage.m index bdaf6a46b83..fad2538a0cb 100644 --- a/src/nsimage.m +++ b/src/nsimage.m @@ -66,7 +66,7 @@ ns_image_for_XPM (int width, int height, int depth) void * ns_image_from_file (Lisp_Object file) { - NSTRACE ("ns_image_from_bitmap_file"); + NSTRACE ("ns_image_from_file"); return [EmacsImage allocInitFromFile: file]; } diff --git a/src/nsmenu.m b/src/nsmenu.m index ddc5dc20a82..3cb61e50f7f 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m @@ -1293,6 +1293,14 @@ update_frame_tool_bar (struct frame *f) //return [identifierToItem allKeys]; } +- (void)setVisible:(BOOL)shown +{ + NSTRACE ("[EmacsToolbar setVisible:%d]", shown); + + [super setVisible:shown]; +} + + /* optional and unneeded */ /* - toolbarWillAddItem: (NSNotification *)notification { } */ /* - toolbarDidRemoveItem: (NSNotification *)notification { } */ diff --git a/src/nsterm.h b/src/nsterm.h index 1b330f08636..7e6e8efc478 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -67,12 +67,27 @@ typedef float EmacsCGFloat; /* Uncomment the following line to enable trace. + Uncomment suitable NSTRACE_GROUP_xxx lines to trace more. + Hint: keep the trailing whitespace -- the version control system will reject accidental commits. */ /* #define NSTRACE_ENABLED 1 */ +/* When non-zero, trace output is enabled for all parts, except those + explicitly disabled. */ +/* #define NSTRACE_ALL_GROUPS 1 */ + +/* When non-zero, trace output is enabled in the corresponding part. */ +/* #define NSTRACE_GROUP_EVENTS 1 */ +/* #define NSTRACE_GROUP_UPDATES 1 */ +/* #define NSTRACE_GROUP_FRINGE 1 */ +/* #define NSTRACE_GROUP_COLOR 1 */ +/* #define NSTRACE_GROUP_GLYPHS 1 */ +/* #define NSTRACE_GROUP_FOCUS 1 */ + + /* Print a call tree containing all annotated functions. The call structure of the functions is represented using @@ -87,60 +102,94 @@ typedef float EmacsCGFloat; The first column contains the file name, the second the line number, and the third a number increasing for each trace line. + Note, when trace output from several threads are mixed, the output + can become misaligned, as all threads (currently) share one state. + This is post prominent when the EVENTS part is enabled. + Note that the trace system, when enabled, use the GCC/Clang - "cleanup" extension. - - For example (long lines manually split to reduce width): - -nsterm.m : 1600: [ 4428] ns_fullscreen_hook -nsterm.m : 7006: [ 4429] | handleFS -nsterm.m : 7035: [ 4430] | +--- FULLSCREEN_MAXIMIZED -nsterm.m : 7627: [ 4431] | | performZoom -nsterm.m : 7636: [ 4432] | | | zoom -nsterm.m : 874: [ 4433] | | | | ns_update_auto_hide_menu_bar -nsterm.m : 6615: [ 4434] | | | | [windowWillUseStandardFrame: - defaultFrame:(X:0 Y:0)/(W:1600 H:1177)] -nsterm.m : 99: [ 4435] | | | | +--- fs_state: FULLSCREEN_NONE -nsterm.m : 119: [ 4436] | | | | +--- fs_before_fs: -1 -nsterm.m : 115: [ 4437] | | | | +--- next_maximized: FULLSCREEN_MAXIMIZED -nsterm.m : 6619: [ 4438] | | | | +--- ns_userRect: (X:0 Y:0)/(W:0 H:0) -nsterm.m : 6620: [ 4439] | | | | +--- [sender frame]: - (X:0 Y:626)/(W:595 H:551) -nsterm.m : 6644: [ 4440] | | | | +--- ns_userRect (2): - (X:0 Y:626)/(W:595 H:551) -nsterm.m : 6684: [ 4441] | | | | +--- FULLSCREEN_MAXIMIZED -nsterm.m : 7057: [ 4442] | | | | | setFSValue -nsterm.m : 115: [ 4443] | | | | | +--- value: FULLSCREEN_MAXIMIZED -nsterm.m : 6711: [ 4444] | | | | +--- Final ns_userRect: - (X:0 Y:626)/(W:595 H:551) -nsterm.m : 6712: [ 4445] | | | | +--- Final maximized_width: 1600 -nsterm.m : 6713: [ 4446] | | | | +--- Final maximized_height: 1177 -nsterm.m : 119: [ 4447] | | | | +--- Final next_maximized: -1 -nsterm.m : 6209: [ 4448] | | | | | windowWillResize: toSize: (W:1600 H:1177) -nsterm.m : 6210: [ 4449] | | | | | +--- [sender frame]: - (X:0 Y:626)/(W:595 H:551) -nsterm.m : 115: [ 4450] | | | | | +--- fs_state: FULLSCREEN_MAXIMIZED -nsterm.m : 6274: [ 4451] | | | | | +--- cols: 223 rows: 79 -nsterm.m : 6299: [ 4452] | | | | | +->> (W:1596 H:1167) -nsterm.m : 6718: [ 4453] | | | | +->> (X:0 Y:0)/(W:1600 H:1177) - - Here, "ns_fullscreen_hook" calls "handleFS", which is turn calls - "performZoom". This function calls "[super performZoom]", which - isn't annotated (so it doesn't show up in the trace). However, it - calls "zoom" which is annotated so it is part of the call trace. - Later, the method "windowWillUseStandardFrame" and the function - "setFSValue" are called. The lines with "+---" contain extra - information and lines containing "->>" represent return values. */ + "cleanup" extension. */ + +/* For example, the following is the output of `M-x + toggle-frame-maximized RET'. + + (Long lines manually split to reduced width): + +nsterm.m : 1608: [ 354] ns_fullscreen_hook +nsterm.m : 7180: [ 355] | [EmacsView handleFS] +nsterm.m : 7209: [ 356] | +--- FULLSCREEN_MAXIMIZED +nsterm.m : 7706: [ 357] | | [EmacsWindow performZoom:] +nsterm.m : 7715: [ 358] | | | [EmacsWindow zoom:] +nsterm.m : 882: [ 359] | | | | ns_update_auto_hide_menu_bar +nsterm.m : 6752: [ 360] | | | | + [EmacsView windowWillUseStandardFrame:defaultFrame:(X:0 Y:0)/(W:1600 H:1177)] +nsterm.m : 6753: [ 361] | | | | +--- fs_state: FULLSCREEN_NONE +nsterm.m : 6754: [ 362] | | | | +--- fs_before_fs: -1 +nsterm.m : 6755: [ 363] | | | | +--- next_maximized: FULLSCREEN_MAXIMIZED +nsterm.m : 6756: [ 364] | | | | +--- ns_userRect: (X:0 Y:0)/(W:0 H:0) +nsterm.m : 6757: [ 365] | | | | +--- + [sender frame]: (X:0 Y:626)/(W:595 H:551) +nsterm.m : 6781: [ 366] | | | | +--- + ns_userRect (2): (X:0 Y:626)/(W:595 H:551) +nsterm.m : 6821: [ 367] | | | | +--- FULLSCREEN_MAXIMIZED +nsterm.m : 7232: [ 368] | | | | | + [EmacsView setFSValue:FULLSCREEN_MAXIMIZED] +nsterm.m : 6848: [ 369] | | | | +--- + Final ns_userRect: (X:0 Y:626)/(W:595 H:551) +nsterm.m : 6849: [ 370] | | | | +--- Final maximized_width: 1600 +nsterm.m : 6850: [ 371] | | | | +--- Final maximized_height: 1177 +nsterm.m : 6851: [ 372] | | | | +--- Final next_maximized: -1 +nsterm.m : 6322: [ 373] | | | | | + [EmacsView windowWillResize:toSize: (W:1600 H:1177)] +nsterm.m : 6323: [ 374] | | | | | +--- + [sender frame]: (X:0 Y:626)/(W:595 H:551) +nsterm.m : 6324: [ 375] | | | | | +--- fs_state: FULLSCREEN_MAXIMIZED +nsterm.m : 7027: [ 376] | | | | | | [EmacsView isFullscreen] +nsterm.m : 6387: [ 377] | | | | | +--- cols: 223 rows: 79 +nsterm.m : 6412: [ 378] | | | | | +->> (W:1596 H:1167) +nsterm.m : 6855: [ 379] | | | | +->> (X:0 Y:0)/(W:1600 H:1177) +*/ #ifndef NSTRACE_ENABLED #define NSTRACE_ENABLED 0 #endif #if NSTRACE_ENABLED -extern int nstrace_num; -extern int nstrace_depth; + +#ifndef NSTRACE_ALL_GROUPS +#define NSTRACE_ALL_GROUPS 0 +#endif + +#ifndef NSTRACE_GROUP_EVENTS +#define NSTRACE_GROUP_EVENTS NSTRACE_ALL_GROUPS +#endif + +#ifndef NSTRACE_GROUP_UPDATES +#define NSTRACE_GROUP_UPDATES NSTRACE_ALL_GROUPS +#endif + +#ifndef NSTRACE_GROUP_FRINGE +#define NSTRACE_GROUP_FRINGE NSTRACE_ALL_GROUPS +#endif + +#ifndef NSTRACE_GROUP_COLOR +#define NSTRACE_GROUP_COLOR NSTRACE_ALL_GROUPS +#endif + +#ifndef NSTRACE_GROUP_GLYPHS +#define NSTRACE_GROUP_GLYPHS NSTRACE_ALL_GROUPS +#endif + +#ifndef NSTRACE_GROUP_FOCUS +#define NSTRACE_GROUP_FOCUS NSTRACE_ALL_GROUPS +#endif + +extern volatile int nstrace_num; +extern volatile int nstrace_depth; +extern volatile int nstrace_enabled_global; void nstrace_leave(int *); +void nstrace_restore_global_trace_state(int *); +char const * nstrace_fullscreen_type_name (int); /* printf-style trace output. Output is aligned with contained heading. */ #define NSTRACE_MSG_NO_DASHES(...) \ @@ -149,7 +198,7 @@ void nstrace_leave(int *); if (nstrace_enabled) \ { \ fprintf (stderr, "%-10s:%5d: [%5d]%.*s", \ - __FILE__, __LINE__, ++nstrace_num, \ + __FILE__, __LINE__, nstrace_num++, \ 2*nstrace_depth, " | | | | | | | | | | | | | | | .."); \ fprintf (stderr, __VA_ARGS__); \ fprintf (stderr, "\n"); \ @@ -176,6 +225,9 @@ void nstrace_leave(int *); #define NSTRACE_ARG_RECT(elt) \ NSTRACE_ARG_POINT((elt).origin), NSTRACE_ARG_SIZE((elt).size) +#define NSTRACE_FMT_FSTYPE "%s" +#define NSTRACE_ARG_FSTYPE(elt) nstrace_fullscreen_type_name(elt) + /* Macros for printing complex types as extra information. */ @@ -192,14 +244,8 @@ void nstrace_leave(int *); NSTRACE_ARG_RECT (rect)); #define NSTRACE_FSTYPE(str,fs_type) \ - do \ - { \ - if (nstrace_enabled) \ - { \ - ns_print_fullscreen_type_name(str, fs_type); \ - } \ - } \ - while(0) + NSTRACE_MSG (str ": " NSTRACE_FMT_FSTYPE, \ + NSTRACE_ARG_FSTYPE (fs_type)); /* Return value macros. @@ -242,17 +288,25 @@ void nstrace_leave(int *); #define NSTRACE_WHEN(cond, ...) \ + __attribute__((cleanup(nstrace_restore_global_trace_state))) \ + int nstrace_saved_enabled_global = nstrace_enabled_global; \ __attribute__((cleanup(nstrace_leave))) \ - int nstrace_enabled = (cond); \ + int nstrace_enabled = nstrace_enabled_global && (cond); \ if (nstrace_enabled) { ++nstrace_depth; } \ + else { nstrace_enabled_global = 0; } \ NSTRACE_MSG_NO_DASHES(__VA_ARGS__); +/* Unsilence called functions. + + Concretely, this us used to allow "event" functions to be silenced + while trace output can be printed for functions they call. */ +#define NSTRACE_UNSILENCE() do { nstrace_enabled_global = 1; } while(0) + #endif /* NSTRACE_ENABLED */ #define NSTRACE(...) NSTRACE_WHEN(1, __VA_ARGS__) #define NSTRACE_UNLESS(cond, ...) NSTRACE_WHEN(!(cond), __VA_ARGS__) - /* Non-trace replacement versions. */ #ifndef NSTRACE_WHEN #define NSTRACE_WHEN(...) @@ -294,6 +348,9 @@ void nstrace_leave(int *); #define NSTRACE_RETURN_FSTYPE(fs_type) #endif +#ifndef NSTRACE_UNSILENCE +#define NSTRACE_UNSILENCE() +#endif /* ========================================================================== @@ -412,6 +469,13 @@ void nstrace_leave(int *); - (void)windowDidMove: (id)sender; #endif - (int)fullscreenState; + +/* Non-notification versions of NSView methods. Used for direct calls. */ +- (void)windowWillEnterFullScreen; +- (void)windowDidEnterFullScreen; +- (void)windowWillExitFullScreen; +- (void)windowDidExitFullScreen; +- (void)windowDidBecomeKey; @end diff --git a/src/nsterm.m b/src/nsterm.m index 5c39d5c0e4d..36e08c60575 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -72,9 +72,26 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu) extern NSString *NSMenuDidBeginTrackingNotification; +/* ========================================================================== + + NSTRACE, Trace support. + + ========================================================================== */ + #if NSTRACE_ENABLED -int nstrace_num = 0; -int nstrace_depth = 0; + +/* The following use "volatile" since they can be accessed from + parallel threads. */ +volatile int nstrace_num = 0; +volatile int nstrace_depth = 0; + +/* When 0, no trace is emitted. This is used by NSTRACE_WHEN and + NSTRACE_UNLESS to silence functions called. + + TODO: This should really be a thread-local variable, to avoid that + a function with disabled trace thread silence trace output in + another. However, in practice this seldom is a problem. */ +volatile int nstrace_enabled_global = 1; /* Called when nstrace_enabled goes out of scope. */ void nstrace_leave(int * pointer_to_nstrace_enabled) @@ -86,38 +103,24 @@ void nstrace_leave(int * pointer_to_nstrace_enabled) } -void ns_print_fullscreen_type_name (char const * s, int fs_type) +/* Called when nstrace_saved_enabled_global goes out of scope. */ +void nstrace_restore_global_trace_state(int * pointer_to_saved_enabled_global) { - // This is a support function for the NSTRACE system, don't add a - // NSTRACE () here. However, a local `nstrace_enabled' variable is - // needed by the NSTRACE_MSG macros. - int nstrace_enabled = 1; + nstrace_enabled_global = *pointer_to_saved_enabled_global; +} + +char const * nstrace_fullscreen_type_name (int fs_type) +{ switch (fs_type) { - case FULLSCREEN_NONE: - NSTRACE_MSG ("%s: FULLSCREEN_NONE", s); - break; - - case FULLSCREEN_WIDTH: - NSTRACE_MSG ("%s: FULLSCREEN_WIDTH", s); - break; - - case FULLSCREEN_HEIGHT: - NSTRACE_MSG ("%s: FULLSCREEN_HEIGHT", s); - break; - - case FULLSCREEN_BOTH: - NSTRACE_MSG ("%s: FULLSCREEN_BOTH", s); - break; - - case FULLSCREEN_MAXIMIZED: - NSTRACE_MSG ("%s: FULLSCREEN_MAXIMIZED", s); - break; - - default: - NSTRACE_MSG ("%s: %d", s, fs_type); - break; + case -1: return "-1"; + case FULLSCREEN_NONE: return "FULLSCREEN_NONE"; + case FULLSCREEN_WIDTH: return "FULLSCREEN_WIDTH"; + case FULLSCREEN_HEIGHT: return "FULLSCREEN_HEIGHT"; + case FULLSCREEN_BOTH: return "FULLSCREEN_BOTH"; + case FULLSCREEN_MAXIMIZED: return "FULLSCREEN_MAXIMIZED"; + default: return "FULLSCREEN_?????"; } } #endif @@ -581,28 +584,6 @@ ns_load_path (void) return NULL; } -static void -ns_timeout (int usecs) -/* -------------------------------------------------------------------------- - Blocking timer utility used by ns_ring_bell - -------------------------------------------------------------------------- */ -{ - struct timespec wakeup = timespec_add (current_timespec (), - make_timespec (0, usecs * 1000)); - - /* Keep waiting until past the time wakeup. */ - while (1) - { - struct timespec timeout, now = current_timespec (); - if (timespec_cmp (wakeup, now) <= 0) - break; - timeout = timespec_sub (wakeup, now); - - /* Try to wait that long--but we might wake up sooner. */ - pselect (0, NULL, NULL, NULL, &timeout, NULL); - } -} - void ns_release_object (void *obj) @@ -919,7 +900,7 @@ ns_update_begin (struct frame *f) -------------------------------------------------------------------------- */ { EmacsView *view = FRAME_NS_VIEW (f); - NSTRACE ("ns_update_begin"); + NSTRACE_WHEN (NSTRACE_GROUP_UPDATES, "ns_update_begin"); ns_update_auto_hide_menu_bar (); @@ -976,7 +957,7 @@ ns_update_window_begin (struct window *w) struct frame *f = XFRAME (WINDOW_FRAME (w)); Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); - NSTRACE ("ns_update_window_begin"); + NSTRACE_WHEN (NSTRACE_GROUP_UPDATES, "ns_update_window_begin"); w->output_cursor = w->cursor; block_input (); @@ -1006,7 +987,7 @@ ns_update_window_end (struct window *w, bool cursor_on_p, external (RIF) call; for one window called before update_end -------------------------------------------------------------------------- */ { - NSTRACE ("update_window_end"); + NSTRACE_WHEN (NSTRACE_GROUP_UPDATES, "ns_update_window_end"); /* note: this fn is nearly identical in all terms */ if (!w->pseudo_window_p) @@ -1045,7 +1026,7 @@ ns_update_end (struct frame *f) { EmacsView *view = FRAME_NS_VIEW (f); - NSTRACE ("ns_update_end"); + NSTRACE_WHEN (NSTRACE_GROUP_UPDATES, "ns_update_end"); /* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */ MOUSE_HL_INFO (f)->mouse_face_defer = 0; @@ -1070,11 +1051,11 @@ ns_focus (struct frame *f, NSRect *r, int n) the entire window. -------------------------------------------------------------------------- */ { -// NSTRACE ("ns_focus"); -/* static int c =0; - fprintf (stderr, "focus: %d", c++); - if (r) fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", r->origin.x, r->origin.y, r->size.width, r->size.height); - fprintf (stderr, "\n"); */ + NSTRACE_WHEN (NSTRACE_GROUP_FOCUS, "ns_focus"); + if (r != NULL) + { + NSTRACE_RECT ("r", *r); + } if (f != ns_updating_frame) { @@ -1114,7 +1095,7 @@ ns_unfocus (struct frame *f) Internal: Remove focus on given frame -------------------------------------------------------------------------- */ { -// NSTRACE ("ns_unfocus"); + NSTRACE_WHEN (NSTRACE_GROUP_FOCUS, "ns_unfocus"); if (gsaved) { @@ -1158,6 +1139,77 @@ ns_clip_to_row (struct window *w, struct glyph_row *row, } +/* ========================================================================== + + Visible bell and beep. + + ========================================================================== */ + + +@interface EmacsBell : NSImageView +{ + // Number of currently active bell:s. + unsigned int nestCount; +} +- (void)show:(NSView *)view; +- (void)hide; +@end + +@implementation EmacsBell + +- (id)init; +{ + if ((self = [super init])) + { + nestCount = 0; + self.image = [NSImage imageNamed:NSImageNameCaution]; + } + return self; +} + +- (void)show:(NSView *)view +{ + NSTRACE ("[EmacsBell show:]"); + NSTRACE_MSG ("nestCount: %u", nestCount); + + // Show the image, unless it's already shown. + if (nestCount == 0) + { + NSRect rect = [view bounds]; + NSPoint pos; + pos.x = rect.origin.x + (rect.size.width - self.image.size.width )/2; + pos.y = rect.origin.y + (rect.size.height - self.image.size.height)/2; + + [self setFrameOrigin:pos]; + [self setFrameSize:self.image.size]; + + [[[view window] contentView] addSubview:self + positioned:NSWindowAbove + relativeTo:nil]; + } + + ++nestCount; + + [self performSelector:@selector(hide) withObject:self afterDelay:0.5]; +} + + +- (void)hide +{ + // Note: Trace output from this method isn't shown, reason unknown. + // NSTRACE ("[EmacsBell hide]"); + + --nestCount; + + // Remove the image once the last bell became inactive. + if (nestCount == 0) + { + [self removeFromSuperview]; + } +} + +@end + static void ns_ring_bell (struct frame *f) /* -------------------------------------------------------------------------- @@ -1167,37 +1219,24 @@ ns_ring_bell (struct frame *f) NSTRACE ("ns_ring_bell"); if (visible_bell) { - NSAutoreleasePool *pool; struct frame *frame = SELECTED_FRAME (); NSView *view; + static EmacsBell * bell_view = nil; + if (bell_view == nil) + { + bell_view = [[EmacsBell alloc] init]; + [bell_view retain]; + } + block_input (); - pool = [[NSAutoreleasePool alloc] init]; view = FRAME_NS_VIEW (frame); if (view != nil) { - NSRect r, surr; - NSPoint dim = NSMakePoint (128, 128); - - r = [view bounds]; - r.origin.x += (r.size.width - dim.x) / 2; - r.origin.y += (r.size.height - dim.y) / 2; - r.size.width = dim.x; - r.size.height = dim.y; - surr = NSInsetRect (r, -2, -2); - ns_focus (frame, &surr, 1); - [[view window] cacheImageInRect: [view convertRect: surr toView:nil]]; - [ns_lookup_indexed_color (NS_FACE_FOREGROUND - (FRAME_DEFAULT_FACE (frame)), frame) set]; - NSRectFill (r); - [[view window] flushWindow]; - ns_timeout (150000); - [[view window] restoreCachedImage]; - [[view window] flushWindow]; - ns_unfocus (frame); + [bell_view show:view]; } - [pool release]; + unblock_input (); } else @@ -1206,6 +1245,7 @@ ns_ring_bell (struct frame *f) } } + /* ========================================================================== Frame / window manager related functions @@ -1220,6 +1260,7 @@ ns_raise_frame (struct frame *f) -------------------------------------------------------------------------- */ { NSView *view; + check_window_system (f); view = FRAME_NS_VIEW (f); block_input (); @@ -1236,6 +1277,7 @@ ns_lower_frame (struct frame *f) -------------------------------------------------------------------------- */ { NSView *view; + check_window_system (f); view = FRAME_NS_VIEW (f); block_input (); @@ -1510,8 +1552,8 @@ x_set_window_size (struct frame *f, return; NSTRACE_RECT ("current", wr); - -/*fprintf (stderr, "\tsetWindowSize: %d x %d, pixelwise %d, font size %d x %d\n", width, height, pixelwise, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f));*/ + NSTRACE_MSG ("Width:%d Height:%d Pixelwise:%d", width, height, pixelwise); + NSTRACE_MSG ("Font %d x %d", FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); block_input (); @@ -1571,7 +1613,6 @@ x_set_window_size (struct frame *f, make_number (FRAME_NS_TITLEBAR_HEIGHT (f)), make_number (FRAME_TOOLBAR_HEIGHT (f)))); - NSTRACE_RECT ("setFrame", wr); [window setFrame: wr display: YES]; /* This is a trick to compensate for Emacs' managing the scrollbar area @@ -1586,7 +1627,7 @@ x_set_window_size (struct frame *f, ? NSMakePoint (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f) - NS_SCROLL_BAR_WIDTH (f), 0) : NSMakePoint (0, 0); - NSTRACE_RECT ("setFrame", wr); + [view setFrame: NSMakeRect (0, 0, pixelwidth, pixelheight)]; [view setBoundsOrigin: origin]; } @@ -1728,7 +1769,8 @@ ns_get_color (const char *name, NSColor **col) float r = -1.0, g, b; NSString *nsname = [NSString stringWithUTF8String: name]; -/*fprintf (stderr, "ns_get_color: '%s'\n", name); */ + NSTRACE ("ns_get_color(%s, **)", name); + block_input (); if ([nsname isEqualToString: @"ns_selection_bg_color"]) @@ -1935,7 +1977,7 @@ ns_defined_color (struct frame *f, -------------------------------------------------------------------------- */ { NSColor *col; - NSTRACE ("ns_defined_color"); + NSTRACE_WHEN (NSTRACE_GROUP_COLOR, "ns_defined_color"); block_input (); if (ns_get_color (name, &col) != 0) /* Color not found */ @@ -1961,6 +2003,8 @@ x_set_frame_alpha (struct frame *f) double alpha = 1.0; double alpha_min = 1.0; + NSTRACE ("x_set_frame_alpha"); + if (dpyinfo->x_highlight_frame == f) alpha = f->alpha[0]; else @@ -2097,7 +2141,7 @@ ns_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, position = [view convertPoint: position fromView: nil]; remember_mouse_glyph (f, position.x, position.y, &dpyinfo->last_mouse_glyph); -/*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */ + NSTRACE_POINT ("position", position); if (bar_window) *bar_window = Qnil; if (part) *part = scroll_bar_above_handle; @@ -2120,7 +2164,7 @@ ns_frame_up_to_date (struct frame *f) Can't use FRAME_MOUSE_UPDATE due to ns_frame_begin and ns_frame_end calls. -------------------------------------------------------------------------- */ { - NSTRACE ("ns_frame_up_to_date"); + NSTRACE_WHEN (NSTRACE_GROUP_UPDATES, "ns_frame_up_to_date"); if (FRAME_NS_P (f)) { @@ -2231,7 +2275,7 @@ ns_clear_frame (struct frame *f) NSView *view = FRAME_NS_VIEW (f); NSRect r; - NSTRACE ("ns_clear_frame"); + NSTRACE_WHEN (NSTRACE_GROUP_UPDATES, "ns_clear_frame"); /* comes on initial frame because we have after-make-frame-functions = select-frame */ @@ -2267,7 +2311,7 @@ ns_clear_frame_area (struct frame *f, int x, int y, int width, int height) if (!view || !face) return; - NSTRACE ("ns_clear_frame_area"); + NSTRACE_WHEN (NSTRACE_GROUP_UPDATES, "ns_clear_frame_area"); r = NSIntersectionRect (r, [view frame]); ns_focus (f, &r, 1); @@ -2360,7 +2404,7 @@ ns_after_update_window_line (struct window *w, struct glyph_row *desired_row) struct frame *f; int width, height; - NSTRACE ("ns_after_update_window_line"); + NSTRACE_WHEN (NSTRACE_GROUP_UPDATES, "ns_after_update_window_line"); /* begin copy from other terms */ eassert (w); @@ -2485,7 +2529,7 @@ ns_draw_fringe_bitmap (struct window *w, struct glyph_row *row, static EmacsImage **bimgs = NULL; static int nBimgs = 0; - NSTRACE ("ns_draw_fringe_bitmap"); + NSTRACE_WHEN (NSTRACE_GROUP_FRINGE, "ns_draw_fringe_bitmap"); NSTRACE_MSG ("which:%d cursor:%d overlay:%d width:%d height:%d period:%d", p->which, p->cursor_p, p->overlay_p, p->wd, p->h, p->dh); @@ -2602,7 +2646,7 @@ ns_draw_window_cursor (struct window *w, struct glyph_row *glyph_row, in mini-buffer windows when switching between echo area glyphs and mini-buffer. */ - NSTRACE ("dumpcursor"); + NSTRACE ("ns_draw_window_cursor"); if (!on_p) return; @@ -3519,7 +3563,7 @@ ns_draw_glyph_string (struct glyph_string *s) struct font *font = s->face->font; if (! font) font = FRAME_FONT (s->f); - NSTRACE ("ns_draw_glyph_string"); + NSTRACE_WHEN (NSTRACE_GROUP_GLYPHS, "ns_draw_glyph_string"); if (s->next && s->right_overhang && !s->for_overlaps/*&&s->hl!=DRAW_CURSOR*/) { @@ -3677,7 +3721,7 @@ ns_send_appdefined (int value) recognize and take as a command to halt the event loop. -------------------------------------------------------------------------- */ { - NSTRACE ("ns_send_appdefined"); + NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_send_appdefined(%d)", value); #ifdef NS_IMPL_GNUSTEP // GNUstep needs postEvent to happen on the main thread. @@ -3851,7 +3895,7 @@ ns_read_socket (struct terminal *terminal, struct input_event *hold_quit) struct input_event ev; int nevents; -/* NSTRACE ("ns_read_socket"); */ + NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_read_socket"); #ifdef HAVE_NATIVE_FS check_native_fs (); @@ -3935,7 +3979,7 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds, struct input_event event; char c; -/* NSTRACE ("ns_select"); */ + NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_select"); #ifdef HAVE_NATIVE_FS check_native_fs (); @@ -4905,7 +4949,7 @@ ns_term_shutdown (int sig) - (void)stop: (id)sender { - NSTRACE ("[EmacsApp stop]"); + NSTRACE ("[EmacsApp stop:]"); shouldKeepRunning = NO; // Stop possible dialog also. Noop if no dialog present. @@ -4916,7 +4960,7 @@ ns_term_shutdown (int sig) - (void)logNotification: (NSNotification *)notification { - NSTRACE ("[EmacsApp logNotification]"); + NSTRACE ("[EmacsApp logNotification:]"); const char *name = [[notification name] UTF8String]; if (!strstr (name, "Update") && !strstr (name, "NSMenu") @@ -4934,8 +4978,8 @@ ns_term_shutdown (int sig) int type = [theEvent type]; NSWindow *window = [theEvent window]; - NSTRACE ("[EmacsApp sendEvent]"); -/*fprintf (stderr, "received event of type %d\t%d\n", type);*/ + NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "[EmacsApp sendEvent:]"); + NSTRACE_MSG ("Type: %d", type); #ifdef NS_IMPL_GNUSTEP // Keyboard events aren't propagated to file dialogs for some reason. @@ -5021,6 +5065,8 @@ ns_term_shutdown (int sig) } #endif + NSTRACE_UNSILENCE(); + [super sendEvent: theEvent]; } @@ -5041,7 +5087,7 @@ ns_term_shutdown (int sig) - (void)newFrame: (id)sender { - NSTRACE ("[EmacsApp newFrame]"); + NSTRACE ("[EmacsApp newFrame:]"); struct frame *emacsframe = SELECTED_FRAME (); NSEvent *theEvent = [NSApp currentEvent]; @@ -5058,7 +5104,7 @@ ns_term_shutdown (int sig) /* Open a file (used by below, after going into queue read by ns_read_socket) */ - (BOOL) openFile: (NSString *)fileName { - NSTRACE ("[EmacsApp openFile]"); + NSTRACE ("[EmacsApp openFile:]"); struct frame *emacsframe = SELECTED_FRAME (); NSEvent *theEvent = [NSApp currentEvent]; @@ -5088,7 +5134,7 @@ ns_term_shutdown (int sig) When application is loaded, terminate event loop in ns_term_init -------------------------------------------------------------------------- */ { - NSTRACE ("[EmacsApp applicationDidFinishLaunching]"); + NSTRACE ("[EmacsApp applicationDidFinishLaunching:]"); #ifdef NS_IMPL_GNUSTEP ((EmacsApp *)self)->applicationDidFinishLaunchingCalled = YES; @@ -5138,7 +5184,7 @@ ns_term_shutdown (int sig) - (void) terminate: (id)sender { - NSTRACE ("[EmacsApp terminate]"); + NSTRACE ("[EmacsApp terminate:]"); struct frame *emacsframe = SELECTED_FRAME (); @@ -5176,7 +5222,7 @@ runAlertPanel(NSString *title, - (NSApplicationTerminateReply)applicationShouldTerminate: (id)sender { - NSTRACE ("[EmacsApp applicationShouldTerminate]"); + NSTRACE ("[EmacsApp applicationShouldTerminate:]"); bool ret; @@ -5257,13 +5303,13 @@ not_in_argv (NSString *arg) /* TODO: these may help w/IO switching btwn terminal and NSApp */ - (void)applicationWillBecomeActive: (NSNotification *)notification { - NSTRACE ("[EmacsApp applicationWillBecomeActive]"); + NSTRACE ("[EmacsApp applicationWillBecomeActive:]"); //ns_app_active=YES; } - (void)applicationDidBecomeActive: (NSNotification *)notification { - NSTRACE ("[EmacsApp applicationDidBecomeActive]"); + NSTRACE ("[EmacsApp applicationDidBecomeActive:]"); #ifdef NS_IMPL_GNUSTEP if (! applicationDidFinishLaunchingCalled) @@ -5277,7 +5323,7 @@ not_in_argv (NSString *arg) } - (void)applicationDidResignActive: (NSNotification *)notification { - NSTRACE ("[EmacsApp applicationDidResignActive]"); + NSTRACE ("[EmacsApp applicationDidResignActive:]"); //ns_app_active=NO; ns_send_appdefined (-1); @@ -5422,6 +5468,8 @@ not_in_argv (NSString *arg) struct frame *emacsframe = SELECTED_FRAME (); NSEvent *theEvent = [NSApp currentEvent]; + NSTRACE ("[EmacsApp fulfillService:withArg:]"); + if (!emacs_event) return NO; @@ -5452,13 +5500,15 @@ not_in_argv (NSString *arg) /* needed to inform when window closed from LISP */ - (void) setWindowClosing: (BOOL)closing { + NSTRACE ("[EmacsView setWindowClosing:%d]", closing); + windowClosing = closing; } - (void)dealloc { - NSTRACE ("EmacsView_dealloc"); + NSTRACE ("[EmacsView dealloc]"); [toolbar release]; if (fs_state == FULLSCREEN_BOTH) [nonfs_window release]; @@ -5476,7 +5526,7 @@ not_in_argv (NSString *arg) CGFloat size; NSFont *nsfont; - NSTRACE ("changeFont"); + NSTRACE ("[EmacsView changeFont:]"); if (!emacs_event) return; @@ -5506,7 +5556,7 @@ not_in_argv (NSString *arg) - (BOOL)acceptsFirstResponder { - NSTRACE ("acceptsFirstResponder"); + NSTRACE ("[EmacsView acceptsFirstResponder]"); return YES; } @@ -5515,7 +5565,7 @@ not_in_argv (NSString *arg) { NSRect visible = [self visibleRect]; NSCursor *currentCursor = FRAME_POINTER_TYPE (emacsframe); - NSTRACE ("resetCursorRects"); + NSTRACE ("[EmacsView resetCursorRects]"); if (currentCursor == nil) currentCursor = [NSCursor arrowCursor]; @@ -5540,7 +5590,7 @@ not_in_argv (NSString *arg) int left_is_none; unsigned int flags = [theEvent modifierFlags]; - NSTRACE ("keyDown"); + NSTRACE ("[EmacsView keyDown:]"); /* Rhapsody and OS X give up and down events for the arrow keys */ if (ns_fake_keydown == YES) @@ -5785,6 +5835,9 @@ not_in_argv (NSString *arg) { int flags = [theEvent modifierFlags]; int code = [theEvent keyCode]; + + NSTRACE ("[EmacsView keyUp:]"); + if (floor (NSAppKitVersionNumber) <= 824 /*NSAppKitVersionNumber10_4*/ && code == 0x30 && (flags & NSControlKeyMask) && !(flags & NSCommandKeyMask)) { @@ -5809,6 +5862,8 @@ not_in_argv (NSString *arg) int len = [(NSString *)aString length]; int i; + NSTRACE ("[EmacsView insertText:]"); + if (NS_KEYLOG) NSLog (@"insertText '%@'\tlen = %d", aString, len); processingCompose = NO; @@ -5842,6 +5897,9 @@ not_in_argv (NSString *arg) { NSString *str = [aString respondsToSelector: @selector (string)] ? [aString string] : aString; + + NSTRACE ("[EmacsView setMarkedText:selectedRange:]"); + if (NS_KEYLOG) NSLog (@"setMarkedText '%@' len =%lu range %lu from %lu", str, (unsigned long)[str length], @@ -5869,6 +5927,8 @@ not_in_argv (NSString *arg) /* delete display of composing characters [not in <NSTextInput>] */ - (void)deleteWorkingText { + NSTRACE ("[EmacsView deleteWorkingText]"); + if (workingText == nil) return; if (NS_KEYLOG) @@ -5888,12 +5948,16 @@ not_in_argv (NSString *arg) - (BOOL)hasMarkedText { + NSTRACE ("[EmacsView hasMarkedText]"); + return workingText != nil; } - (NSRange)markedRange { + NSTRACE ("[EmacsView markedRange]"); + NSRange rng = workingText != nil ? NSMakeRange (0, [workingText length]) : NSMakeRange (NSNotFound, 0); if (NS_KEYLOG) @@ -5904,6 +5968,8 @@ not_in_argv (NSString *arg) - (void)unmarkText { + NSTRACE ("[EmacsView unmarkText]"); + if (NS_KEYLOG) NSLog (@"unmark (accept) text"); [self deleteWorkingText]; @@ -5917,6 +5983,9 @@ not_in_argv (NSString *arg) NSRect rect; NSPoint pt; struct window *win = XWINDOW (FRAME_SELECTED_WINDOW (emacsframe)); + + NSTRACE ("[EmacsView firstRectForCharacterRange:]"); + if (NS_KEYLOG) NSLog (@"firstRectForCharRange request"); @@ -5941,6 +6010,8 @@ not_in_argv (NSString *arg) - (void)doCommandBySelector: (SEL)aSelector { + NSTRACE ("[EmacsView doCommandBySelector:]"); + if (NS_KEYLOG) NSLog (@"doCommandBySelector: %@", NSStringFromSelector (aSelector)); @@ -6003,7 +6074,7 @@ not_in_argv (NSString *arg) struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (emacsframe); NSPoint p = [self convertPoint: [theEvent locationInWindow] fromView: nil]; - NSTRACE ("mouseDown"); + NSTRACE ("[EmacsView mouseDown:]"); [self deleteWorkingText]; @@ -6024,7 +6095,7 @@ not_in_argv (NSString *arg) delta = [theEvent deltaX]; if (delta == 0) { - NSTRACE ("deltaIsZero"); + NSTRACE_MSG ("deltaIsZero"); return; } emacs_event->kind = HORIZ_WHEEL_EVENT; @@ -6051,42 +6122,42 @@ not_in_argv (NSString *arg) - (void)rightMouseDown: (NSEvent *)theEvent { - NSTRACE ("rightMouseDown"); + NSTRACE ("[EmacsView rightMouseDown:]"); [self mouseDown: theEvent]; } - (void)otherMouseDown: (NSEvent *)theEvent { - NSTRACE ("otherMouseDown"); + NSTRACE ("[EmacsView otherMouseDown:]"); [self mouseDown: theEvent]; } - (void)mouseUp: (NSEvent *)theEvent { - NSTRACE ("mouseUp"); + NSTRACE ("[EmacsView mouseUp:]"); [self mouseDown: theEvent]; } - (void)rightMouseUp: (NSEvent *)theEvent { - NSTRACE ("rightMouseUp"); + NSTRACE ("[EmacsView rightMouseUp:]"); [self mouseDown: theEvent]; } - (void)otherMouseUp: (NSEvent *)theEvent { - NSTRACE ("otherMouseUp"); + NSTRACE ("[EmacsView otherMouseUp:]"); [self mouseDown: theEvent]; } - (void) scrollWheel: (NSEvent *)theEvent { - NSTRACE ("scrollWheel"); + NSTRACE ("[EmacsView scrollWheel:]"); [self mouseDown: theEvent]; } @@ -6099,7 +6170,7 @@ not_in_argv (NSString *arg) Lisp_Object frame; NSPoint pt; -// NSTRACE ("mouseMoved"); + NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "[EmacsView mouseMoved:]"); dpyinfo->last_mouse_movement_time = EV_TIMESTAMP (e); pt = [self convertPoint: [e locationInWindow] fromView: nil]; @@ -6119,7 +6190,7 @@ not_in_argv (NSString *arg) if (!NILP (Vmouse_autoselect_window)) { - NSTRACE ("mouse_autoselect_window"); + NSTRACE_MSG ("mouse_autoselect_window"); static Lisp_Object last_mouse_window; Lisp_Object window = window_from_coordinates (emacsframe, pt.x, pt.y, 0, 0); @@ -6131,7 +6202,7 @@ not_in_argv (NSString *arg) || (EQ (XWINDOW (window)->frame, XWINDOW (selected_window)->frame)))) { - NSTRACE ("in_window"); + NSTRACE_MSG ("in_window"); emacs_event->kind = SELECT_WINDOW_EVENT; emacs_event->frame_or_window = window; EV_TRAILER2 (e); @@ -6161,21 +6232,21 @@ not_in_argv (NSString *arg) - (void)mouseDragged: (NSEvent *)e { - NSTRACE ("mouseDragged"); + NSTRACE ("[EmacsView mouseDragged:]"); [self mouseMoved: e]; } - (void)rightMouseDragged: (NSEvent *)e { - NSTRACE ("rightMouseDragged"); + NSTRACE ("[EmacsView rightMouseDragged:]"); [self mouseMoved: e]; } - (void)otherMouseDragged: (NSEvent *)e { - NSTRACE ("otherMouseDragged"); + NSTRACE ("[EmacsView otherMouseDragged:]"); [self mouseMoved: e]; } @@ -6184,7 +6255,7 @@ not_in_argv (NSString *arg) { NSEvent *e =[[self window] currentEvent]; - NSTRACE ("windowShouldClose"); + NSTRACE ("[EmacsView windowShouldClose:]"); windowClosing = YES; if (!emacs_event) return NO; @@ -6206,7 +6277,7 @@ not_in_argv (NSString *arg) int oldh = FRAME_PIXEL_HEIGHT (emacsframe); int neww, newh; - NSTRACE ("updateFrameSize"); + NSTRACE ("[EmacsView updateFrameSize:]"); NSTRACE_SIZE ("Original size", NSMakeSize (oldw, oldh)); NSTRACE_RECT ("Original frame", wr); NSTRACE_MSG ("Original columns: %d", cols); @@ -6249,8 +6320,8 @@ not_in_argv (NSString *arg) if (rows < MINHEIGHT) rows = MINHEIGHT; - NSTRACE_MSG ("New columns: %d", cols); - NSTRACE_MSG ("New rows: %d", rows); + NSTRACE_MSG ("New columns: %d", cols); + NSTRACE_MSG ("New rows: %d", rows); if (oldr != rows || oldc != cols || neww != oldw || newh != oldh) { @@ -6265,8 +6336,9 @@ not_in_argv (NSString *arg) cancel_mouse_face (emacsframe); wr = NSMakeRect (0, 0, neww, newh); - NSTRACE_RECT ("setFrame", wr); + [view setFrame: wr]; + // to do: consider using [NSNotificationCenter postNotificationName:]. [self windowDidMove: // Update top/left. [NSNotification notificationWithName:NSWindowDidMoveNotification @@ -6283,7 +6355,7 @@ not_in_argv (NSString *arg) { int extra = 0; - NSTRACE ("windowWillResize: toSize: " NSTRACE_FMT_SIZE, + NSTRACE ("[EmacsView windowWillResize:toSize: " NSTRACE_FMT_SIZE "]", NSTRACE_ARG_SIZE (frameSize)); NSTRACE_RECT ("[sender frame]", [sender frame]); NSTRACE_FSTYPE ("fs_state", fs_state); @@ -6382,7 +6454,7 @@ not_in_argv (NSString *arg) - (void)windowDidResize: (NSNotification *)notification { - NSTRACE ("windowDidResize"); + NSTRACE ("[EmacsView windowDidResize:]"); if (!FRAME_LIVE_P (emacsframe)) { NSTRACE_MSG ("Ignored (frame dead)"); @@ -6425,6 +6497,8 @@ not_in_argv (NSString *arg) #ifdef NS_IMPL_COCOA - (void)viewDidEndLiveResize { + NSTRACE ("[EmacsView viewDidEndLiveResize]"); + [super viewDidEndLiveResize]; if (old_title != 0) { @@ -6440,10 +6514,16 @@ not_in_argv (NSString *arg) - (void)windowDidBecomeKey: (NSNotification *)notification /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */ { + [self windowDidBecomeKey]; +} + + +- (void)windowDidBecomeKey /* for direct calls */ +{ struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (emacsframe); struct frame *old_focus = dpyinfo->x_focus_frame; - NSTRACE ("windowDidBecomeKey"); + NSTRACE ("[EmacsView windowDidBecomeKey]"); if (emacsframe != old_focus) dpyinfo->x_focus_frame = emacsframe; @@ -6463,7 +6543,7 @@ not_in_argv (NSString *arg) { struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (emacsframe); BOOL is_focus_frame = dpyinfo->x_focus_frame == emacsframe; - NSTRACE ("windowDidResignKey"); + NSTRACE ("[EmacsView windowDidResignKey:]"); if (is_focus_frame) dpyinfo->x_focus_frame = 0; @@ -6498,7 +6578,16 @@ not_in_argv (NSString *arg) - (void)windowWillMiniaturize: sender { - NSTRACE ("windowWillMiniaturize"); + NSTRACE ("[EmacsView windowWillMiniaturize:]"); +} + + +- (void)setFrame:(NSRect)frameRect; +{ + NSTRACE ("[EmacsView setFrame:" NSTRACE_FMT_RECT "]", + NSTRACE_ARG_RECT (frameRect)); + + [super setFrame:(NSRect)frameRect]; } @@ -6522,7 +6611,8 @@ not_in_argv (NSString *arg) NSColor *col; NSString *name; - NSTRACE ("initFrameFromEmacs"); + NSTRACE ("[EmacsView initFrameFromEmacs:]"); + NSTRACE_MSG ("cols:%d lines:%d\n", f->text_cols, f->text_lines); windowClosing = NO; processingCompose = NO; @@ -6537,8 +6627,6 @@ not_in_argv (NSString *arg) maximized_width = maximized_height = -1; nonfs_window = nil; -/*fprintf (stderr,"init with %d, %d\n",f->text_cols, f->text_lines); */ - ns_userRect = NSMakeRect (0, 0, 0, 0); r = NSMakeRect (0, 0, FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, f->text_cols), FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, f->text_lines)); @@ -6626,8 +6714,6 @@ not_in_argv (NSString *arg) IN_BOUND (-SCREENMAX, [screen frame].size.height - NS_TOP_POS (f), SCREENMAX)); - NSTRACE_POINT ("setFrameTopLeftPoint", pt); - [win setFrameTopLeftPoint: pt]; NSTRACE_RECT ("new frame", [win frame]); @@ -6661,7 +6747,7 @@ not_in_argv (NSString *arg) NSArray *screens = [NSScreen screens]; NSScreen *screen = [screens objectAtIndex: 0]; - NSTRACE ("windowDidMove"); + NSTRACE ("[EmacsView windowDidMove:]"); if (!emacsframe->output_data.ns) return; @@ -6679,7 +6765,7 @@ not_in_argv (NSString *arg) location so set_window_size moves the frame. */ - (BOOL)windowShouldZoom: (NSWindow *)sender toFrame: (NSRect)newFrame { - NSTRACE (("[windowShouldZoom:win toFrame:" NSTRACE_FMT_RECT "]" + NSTRACE (("[EmacsView windowShouldZoom:toFrame:" NSTRACE_FMT_RECT "]" NSTRACE_FMT_RETURN "YES"), NSTRACE_ARG_RECT (newFrame)); @@ -6698,7 +6784,7 @@ not_in_argv (NSString *arg) // all paths. NSRect result = [sender frame]; - NSTRACE (("[windowWillUseStandardFrame: defaultFrame:" + NSTRACE (("[EmacsView windowWillUseStandardFrame:defaultFrame:" NSTRACE_FMT_RECT "]"), NSTRACE_ARG_RECT (defaultFrame)); NSTRACE_FSTYPE ("fs_state", fs_state); @@ -6811,7 +6897,7 @@ not_in_argv (NSString *arg) - (void)windowDidDeminiaturize: sender { - NSTRACE ("windowDidDeminiaturize"); + NSTRACE ("[EmacsView windowDidDeminiaturize:]"); if (!emacsframe->output_data.ns) return; @@ -6829,7 +6915,7 @@ not_in_argv (NSString *arg) - (void)windowDidExpose: sender { - NSTRACE ("windowDidExpose"); + NSTRACE ("[EmacsView windowDidExpose:]"); if (!emacsframe->output_data.ns) return; @@ -6843,7 +6929,7 @@ not_in_argv (NSString *arg) - (void)windowDidMiniaturize: sender { - NSTRACE ("windowDidMiniaturize"); + NSTRACE ("[EmacsView windowDidMiniaturize:]"); if (!emacsframe->output_data.ns) return; @@ -6866,33 +6952,30 @@ not_in_argv (NSString *arg) } #endif -#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 -#define NSWindowDidEnterFullScreenNotification "NSWindowDidEnterFullScreenNotification" -#endif - - (void)windowWillEnterFullScreen:(NSNotification *)notification { + NSTRACE ("[EmacsView windowWillEnterFullScreen:]"); [self windowWillEnterFullScreen]; } - (void)windowWillEnterFullScreen /* provided for direct calls */ { - NSTRACE ("windowWillEnterFullScreen"); + NSTRACE ("[EmacsView windowWillEnterFullScreen]"); fs_before_fs = fs_state; } -- (void)windowDidEnterFullScreen /* provided for direct calls */ +- (void)windowDidEnterFullScreen:(NSNotification *)notification { - [self windowDidEnterFullScreen: - [NSNotification notificationWithName:NSWindowDidEnterFullScreenNotification - object:[self window]]]; + NSTRACE ("[EmacsView windowDidEnterFullScreen:]"); + [self windowDidEnterFullScreen]; } -- (void)windowDidEnterFullScreen:(NSNotification *)notification + +- (void)windowDidEnterFullScreen /* provided for direct calls */ { - NSTRACE ("windowDidEnterFullScreen"); + NSTRACE ("[EmacsView windowDidEnterFullScreen]"); [self setFSValue: FULLSCREEN_BOTH]; if (! [self fsIsNative]) { - [self windowDidBecomeKey:notification]; + [self windowDidBecomeKey]; [nonfs_window orderOut:self]; } else @@ -6922,12 +7005,13 @@ not_in_argv (NSString *arg) - (void)windowWillExitFullScreen:(NSNotification *)notification { + NSTRACE ("[EmacsView windowWillExitFullScreen:]"); [self windowWillExitFullScreen]; } - (void)windowWillExitFullScreen /* provided for direct calls */ { - NSTRACE ("windowWillExitFullScreen"); + NSTRACE ("[EmacsView windowWillExitFullScreen]"); if (!FRAME_LIVE_P (emacsframe)) { NSTRACE_MSG ("Ignored (frame dead)"); @@ -6939,12 +7023,13 @@ not_in_argv (NSString *arg) - (void)windowDidExitFullScreen:(NSNotification *)notification { + NSTRACE ("[EmacsView windowDidExitFullScreen:]"); [self windowDidExitFullScreen]; } - (void)windowDidExitFullScreen /* provided for direct calls */ { - NSTRACE ("windowDidExitFullScreen"); + NSTRACE ("[EmacsView windowDidExitFullScreen]"); if (!FRAME_LIVE_P (emacsframe)) { NSTRACE_MSG ("Ignored (frame dead)"); @@ -6976,6 +7061,8 @@ not_in_argv (NSString *arg) - (BOOL)isFullscreen { + NSTRACE ("[EmacsView isFullscreen]"); + if (! fs_is_native) return nonfs_window != nil; #ifdef HAVE_NATIVE_FS return ([[self window] styleMask] & NSFullScreenWindowMask) != 0; @@ -6987,6 +7074,8 @@ not_in_argv (NSString *arg) #ifdef HAVE_NATIVE_FS - (void)updateCollectionBehavior { + NSTRACE ("[EmacsView updateCollectionBehavior]"); + if (! [self isFullscreen]) { NSWindow *win = [self window]; @@ -7010,7 +7099,7 @@ not_in_argv (NSString *arg) NSRect r, wr; NSColor *col; - NSTRACE ("toggleFullScreen"); + NSTRACE ("[EmacsView toggleFullScreen:]"); if (fs_is_native) { @@ -7125,7 +7214,7 @@ not_in_argv (NSString *arg) - (void)handleFS { - NSTRACE ("handleFS"); + NSTRACE ("[EmacsView handleFS]"); if (fs_state != emacsframe->want_fullscreen) { @@ -7176,8 +7265,8 @@ not_in_argv (NSString *arg) - (void) setFSValue: (int)value { - NSTRACE ("setFSValue"); - NSTRACE_FSTYPE ("value", value); + NSTRACE ("[EmacsView setFSValue:" NSTRACE_FMT_FSTYPE "]", + NSTRACE_ARG_FSTYPE(value)); Lisp_Object lval = Qnil; switch (value) @@ -7201,7 +7290,7 @@ not_in_argv (NSString *arg) - (void)mouseEntered: (NSEvent *)theEvent { - NSTRACE ("mouseEntered"); + NSTRACE ("[EmacsView mouseEntered:]"); if (emacsframe) FRAME_DISPLAY_INFO (emacsframe)->last_mouse_movement_time = EV_TIMESTAMP (theEvent); @@ -7212,7 +7301,7 @@ not_in_argv (NSString *arg) { Mouse_HLInfo *hlinfo = emacsframe ? MOUSE_HL_INFO (emacsframe) : NULL; - NSTRACE ("mouseExited"); + NSTRACE ("[EmacsView mouseExited:]"); if (!hlinfo) return; @@ -7230,7 +7319,7 @@ not_in_argv (NSString *arg) - menuDown: sender { - NSTRACE ("menuDown"); + NSTRACE ("[EmacsView menuDown:]"); if (context_menu_value == -1) context_menu_value = [sender tag]; else @@ -7258,7 +7347,7 @@ not_in_argv (NSString *arg) NSEvent *theEvent; int idx = [item tag] * TOOL_BAR_ITEM_NSLOTS; - NSTRACE ("toolbarClicked"); + NSTRACE ("[EmacsView toolbarClicked:]"); if (!emacs_event) return self; @@ -7281,6 +7370,8 @@ not_in_argv (NSString *arg) - toggleToolbar: (id)sender { + NSTRACE ("[EmacsView toggleToolbar:]"); + if (!emacs_event) return self; @@ -7296,8 +7387,8 @@ not_in_argv (NSString *arg) int x = NSMinX (rect), y = NSMinY (rect); int width = NSWidth (rect), height = NSHeight (rect); - NSTRACE ("drawRect"); - NSTRACE_RECT ("input", rect); + NSTRACE ("[EmacsView drawRect:" NSTRACE_FMT_RECT "]", + NSTRACE_ARG_RECT(rect)); if (!emacsframe || !emacsframe->output_data.ns) return; @@ -7323,7 +7414,7 @@ not_in_argv (NSString *arg) -(NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender { - NSTRACE ("draggingEntered"); + NSTRACE ("[EmacsView draggingEntered:]"); return NSDragOperationGeneric; } @@ -7344,7 +7435,7 @@ not_in_argv (NSString *arg) NSDragOperation op = [sender draggingSourceOperationMask]; int modifiers = 0; - NSTRACE ("performDragOperation"); + NSTRACE ("[EmacsView performDragOperation:]"); if (!emacs_event) return NO; @@ -7444,7 +7535,7 @@ not_in_argv (NSString *arg) - (id) validRequestorForSendType: (NSString *)typeSent returnType: (NSString *)typeReturned { - NSTRACE ("validRequestorForSendType"); + NSTRACE ("[EmacsView validRequestorForSendType:returnType:]"); if (typeSent != nil && [ns_send_types indexOfObject: typeSent] != NSNotFound && typeReturned == nil) { @@ -7477,6 +7568,8 @@ not_in_argv (NSString *arg) NSArray *typesDeclared; Lisp_Object val; + NSTRACE ("[EmacsView writeSelectionToPasteboard:types:]"); + /* We only support NSStringPboardType */ if ([types containsObject:NSStringPboardType] == NO) { return NO; @@ -7506,7 +7599,7 @@ not_in_argv (NSString *arg) - setMiniwindowImage: (BOOL) setMini { id image = [[self window] miniwindowImage]; - NSTRACE ("setMiniwindowImage"); + NSTRACE ("[EmacsView setMiniwindowImage:%d]", setMini); /* NOTE: under Cocoa miniwindowImage always returns nil, documentation about "AppleDockIconEnabled" notwithstanding, however the set message @@ -7554,6 +7647,8 @@ not_in_argv (NSString *arg) struct frame *f = SELECTED_FRAME (); struct buffer *curbuf = XBUFFER (XWINDOW (f->selected_window)->contents); + NSTRACE ("[EmacsWindow accessibilityAttributeValue:]"); + if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) return NSAccessibilityTextFieldRole; @@ -7622,7 +7717,7 @@ not_in_argv (NSString *arg) large screen). */ - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen { - NSTRACE ("constrainFrameRect:" NSTRACE_FMT_RECT " toScreen:", + NSTRACE ("[EmacsWindow constrainFrameRect:" NSTRACE_FMT_RECT " toScreen:]", NSTRACE_ARG_RECT (frameRect)); #ifdef NS_IMPL_COCOA @@ -7645,7 +7740,7 @@ not_in_argv (NSString *arg) - (void)performZoom:(id)sender { - NSTRACE ("performZoom"); + NSTRACE ("[EmacsWindow performZoom:]"); return [super performZoom:sender]; } @@ -7654,7 +7749,7 @@ not_in_argv (NSString *arg) { struct frame * f = SELECTED_FRAME (); - NSTRACE ("zoom"); + NSTRACE ("[EmacsWindow zoom:]"); ns_update_auto_hide_menu_bar(); @@ -7713,7 +7808,7 @@ not_in_argv (NSString *arg) || newWr.origin.x != wr.origin.x || newWr.origin.y != wr.origin.y) { - NSTRACE_RECT ("Corrected rect", newWr); + NSTRACE_MSG ("New frame different"); [self setFrame: newWr display: NO]; } } @@ -7733,6 +7828,33 @@ not_in_argv (NSString *arg) #endif } +- (void)setFrame:(NSRect)windowFrame + display:(BOOL)displayViews +{ + NSTRACE ("[EmacsWindow setFrame:" NSTRACE_FMT_RECT " display:%d]", + NSTRACE_ARG_RECT (windowFrame), displayViews); + + [super setFrame:windowFrame display:displayViews]; +} + +- (void)setFrame:(NSRect)windowFrame + display:(BOOL)displayViews + animate:(BOOL)performAnimation +{ + NSTRACE ("[EmacsWindow setFrame:" NSTRACE_FMT_RECT + " display:%d performAnimation:%d]", + NSTRACE_ARG_RECT (windowFrame), displayViews, performAnimation); + + [super setFrame:windowFrame display:displayViews animate:performAnimation]; +} + +- (void)setFrameTopLeftPoint:(NSPoint)point +{ + NSTRACE ("[EmacsWindow setFrameTopLeftPoint:" NSTRACE_FMT_POINT "]", + NSTRACE_ARG_POINT (point)); + + [super setFrameTopLeftPoint:point]; +} @end /* EmacsWindow */ @@ -7781,7 +7903,7 @@ not_in_argv (NSString *arg) - initFrame: (NSRect )r window: (Lisp_Object)nwin { - NSTRACE ("EmacsScroller_initFrame"); + NSTRACE ("[EmacsScroller initFrame: window:]"); r.size.width = [EmacsScroller scrollerWidth]; [super initWithFrame: r/*NSMakeRect (0, 0, 0, 0)*/]; @@ -7827,7 +7949,8 @@ not_in_argv (NSString *arg) - (void)setFrame: (NSRect)newRect { - NSTRACE ("EmacsScroller_setFrame"); + NSTRACE ("[EmacsScroller setFrame:]"); + /* block_input (); */ pixel_height = NSHeight (newRect); if (pixel_height == 0) pixel_height = 1; @@ -7839,7 +7962,7 @@ not_in_argv (NSString *arg) - (void)dealloc { - NSTRACE ("EmacsScroller_dealloc"); + NSTRACE ("[EmacsScroller dealloc]"); if (window) wset_vertical_scroll_bar (window, Qnil); window = 0; @@ -7849,7 +7972,7 @@ not_in_argv (NSString *arg) - condemn { - NSTRACE ("condemn"); + NSTRACE ("[EmacsScroller condemn]"); condemned =YES; return self; } @@ -7857,7 +7980,7 @@ not_in_argv (NSString *arg) - reprieve { - NSTRACE ("reprieve"); + NSTRACE ("[EmacsScroller reprieve]"); condemned =NO; return self; } @@ -7865,7 +7988,7 @@ not_in_argv (NSString *arg) -(bool)judge { - NSTRACE ("judge"); + NSTRACE ("[EmacsScroller judge]"); bool ret = condemned; if (condemned) { @@ -7889,7 +8012,7 @@ not_in_argv (NSString *arg) - (void)resetCursorRects { NSRect visible = [self visibleRect]; - NSTRACE ("resetCursorRects"); + NSTRACE ("[EmacsScroller resetCursorRects]"); if (!NSIsEmptyRect (visible)) [self addCursorRect: visible cursor: [NSCursor arrowCursor]]; @@ -7907,7 +8030,7 @@ not_in_argv (NSString *arg) - setPosition: (int)position portion: (int)portion whole: (int)whole { - NSTRACE ("setPosition"); + NSTRACE ("[EmacsScroller setPosition:portion:whole:]"); em_position = position; em_portion = portion; @@ -7944,6 +8067,9 @@ not_in_argv (NSString *arg) - (void) sendScrollEventAtLoc: (float)loc fromEvent: (NSEvent *)e { Lisp_Object win; + + NSTRACE ("[EmacsScroller sendScrollEventAtLoc:fromEvent:]"); + if (!emacs_event) return; @@ -7977,6 +8103,8 @@ not_in_argv (NSString *arg) NSPoint p = [[self window] mouseLocationOutsideOfEventStream]; BOOL inKnob = [self testPart: p] == NSScrollerKnob; + NSTRACE ("[EmacsScroller repeatScroll:]"); + /* clear timer if need be */ if (inKnob || [scroll_repeat_entry timeInterval] == SCROLL_BAR_FIRST_DELAY) { @@ -8012,7 +8140,7 @@ not_in_argv (NSString *arg) CGFloat inc = 0.0, loc, kloc, pos; int edge = 0; - NSTRACE ("EmacsScroller_mouseDown"); + NSTRACE ("[EmacsScroller mouseDown:]"); switch (part) { @@ -8109,7 +8237,7 @@ not_in_argv (NSString *arg) NSRect sr; double loc, pos; - NSTRACE ("EmacsScroller_mouseDragged"); + NSTRACE ("[EmacsScroller mouseDragged:]"); sr = [self convertRect: [self rectForPart: NSScrollerKnobSlot] toView: nil]; @@ -8131,6 +8259,8 @@ not_in_argv (NSString *arg) - (void)mouseUp: (NSEvent *)e { + NSTRACE ("[EmacsScroller mouseUp:]"); + if (scroll_repeat_entry) { [scroll_repeat_entry invalidate]; @@ -8144,6 +8274,8 @@ not_in_argv (NSString *arg) /* treat scrollwheel events in the bar as though they were in the main window */ - (void) scrollWheel: (NSEvent *)theEvent { + NSTRACE ("[EmacsScroller scrollWheel:]"); + EmacsView *view = (EmacsView *)FRAME_NS_VIEW (frame); [view mouseDown: theEvent]; } diff --git a/src/print.c b/src/print.c index 6f868ceff84..420e6f55b4c 100644 --- a/src/print.c +++ b/src/print.c @@ -1990,6 +1990,19 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag) printchar ('>', printcharfun); break; +#ifdef HAVE_MODULES + case Lisp_Misc_User_Ptr: + { + print_c_string ("#<user-ptr ", printcharfun); + int i = sprintf (buf, "ptr=%p finalizer=%p", + XUSER_PTR (obj)->p, + XUSER_PTR (obj)->finalizer); + strout (buf, i, i, printcharfun); + printchar ('>', printcharfun); + break; + } +#endif + case Lisp_Misc_Finalizer: print_c_string ("#<finalizer", printcharfun); if (NILP (XFINALIZER (obj)->function)) diff --git a/src/puresize.h b/src/puresize.h index f07562429d5..96ddcde24a6 100644 --- a/src/puresize.h +++ b/src/puresize.h @@ -81,21 +81,35 @@ extern _Noreturn void pure_write_error (Lisp_Object); extern EMACS_INT pure[]; +/* The puresize_h_* macros are private to this include file. */ + /* True if PTR is pure. */ + +#define puresize_h_PURE_P(ptr) \ + ((uintptr_t) (ptr) - (uintptr_t) pure <= PURESIZE) + INLINE bool PURE_P (void *ptr) { - return (uintptr_t) (ptr) - (uintptr_t) pure <= PURESIZE; + return puresize_h_PURE_P (ptr); } /* Signal an error if OBJ is pure. PTR is OBJ untagged. */ + +#define puresize_h_CHECK_IMPURE(obj, ptr) \ + (PURE_P (ptr) ? pure_write_error (obj) : (void) 0) + INLINE void CHECK_IMPURE (Lisp_Object obj, void *ptr) { - if (PURE_P (ptr)) - pure_write_error (obj); + puresize_h_CHECK_IMPURE (obj, ptr); } +#if DEFINE_KEY_OPS_AS_MACROS +# define PURE_P(ptr) puresize_h_PURE_P (ptr) +# define CHECK_IMPURE(obj, ptr) puresize_h_CHECK_IMPURE (obj, ptr) +#endif + INLINE_HEADER_END #endif /* EMACS_PURESIZE_H */ diff --git a/src/regex.c b/src/regex.c index dcf286454b3..4e00fd15dc9 100644 --- a/src/regex.c +++ b/src/regex.c @@ -5945,12 +5945,12 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1, #ifdef emacs ssize_t offset = PTR_TO_OFFSET (d - 1); ssize_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); - UPDATE_SYNTAX_TABLE (charpos); + UPDATE_SYNTAX_TABLE_FAST (charpos); #endif GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); s1 = SYNTAX (c1); #ifdef emacs - UPDATE_SYNTAX_TABLE_FORWARD (charpos + 1); + UPDATE_SYNTAX_TABLE_FORWARD_FAST (charpos + 1); #endif PREFETCH_NOLIMIT (); GET_CHAR_AFTER (c2, d, dummy); @@ -5987,7 +5987,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1, #ifdef emacs ssize_t offset = PTR_TO_OFFSET (d); ssize_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); - UPDATE_SYNTAX_TABLE (charpos); + UPDATE_SYNTAX_TABLE_FAST (charpos); #endif PREFETCH (); GET_CHAR_AFTER (c2, d, dummy); @@ -6032,7 +6032,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1, #ifdef emacs ssize_t offset = PTR_TO_OFFSET (d) - 1; ssize_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); - UPDATE_SYNTAX_TABLE (charpos); + UPDATE_SYNTAX_TABLE_FAST (charpos); #endif GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); s1 = SYNTAX (c1); @@ -6047,7 +6047,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1, PREFETCH_NOLIMIT (); GET_CHAR_AFTER (c2, d, dummy); #ifdef emacs - UPDATE_SYNTAX_TABLE_FORWARD (charpos); + UPDATE_SYNTAX_TABLE_FORWARD_FAST (charpos); #endif s2 = SYNTAX (c2); @@ -6076,7 +6076,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1, #ifdef emacs ssize_t offset = PTR_TO_OFFSET (d); ssize_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); - UPDATE_SYNTAX_TABLE (charpos); + UPDATE_SYNTAX_TABLE_FAST (charpos); #endif PREFETCH (); c2 = RE_STRING_CHAR (d, target_multibyte); @@ -6119,7 +6119,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1, #ifdef emacs ssize_t offset = PTR_TO_OFFSET (d) - 1; ssize_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); - UPDATE_SYNTAX_TABLE (charpos); + UPDATE_SYNTAX_TABLE_FAST (charpos); #endif GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); s1 = SYNTAX (c1); @@ -6134,7 +6134,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1, PREFETCH_NOLIMIT (); c2 = RE_STRING_CHAR (d, target_multibyte); #ifdef emacs - UPDATE_SYNTAX_TABLE_FORWARD (charpos + 1); + UPDATE_SYNTAX_TABLE_FORWARD_FAST (charpos + 1); #endif s2 = SYNTAX (c2); @@ -6157,7 +6157,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1, { ssize_t offset = PTR_TO_OFFSET (d); ssize_t pos1 = SYNTAX_TABLE_BYTE_TO_CHAR (offset); - UPDATE_SYNTAX_TABLE (pos1); + UPDATE_SYNTAX_TABLE_FAST (pos1); } #endif { diff --git a/src/syntax.c b/src/syntax.c index 1dcb3a5d15d..2acbd413858 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -519,8 +519,7 @@ update_syntax_table_forward (ptrdiff_t charpos, bool init, else { update_syntax_table (charpos, 1, init, object); - if (gl_state.e_property > syntax_propertize__done - && NILP (object)) + if (NILP (object) && gl_state.e_property > syntax_propertize__done) parse_sexp_propertize (charpos); } } @@ -791,8 +790,10 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, || SYNTAX_FLAGS_COMMENT_NESTED (syntax) != comnested)) continue; - /* Ignore escaped characters, except comment-enders. */ - if (code != Sendcomment && char_quoted (from, from_byte)) + /* Ignore escaped characters, except comment-enders which cannot + be escaped. */ + if ((Vcomment_end_can_be_escaped || code != Sendcomment) + && char_quoted (from, from_byte)) continue; switch (code) @@ -2347,7 +2348,8 @@ forw_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, if (code == Sendcomment && SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0) == style && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ? - (nesting > 0 && --nesting == 0) : nesting < 0)) + (nesting > 0 && --nesting == 0) : nesting < 0) + && !(Vcomment_end_can_be_escaped && char_quoted (from, from_byte))) /* We have encountered a comment end of the same style as the comment sequence which began this comment section. */ @@ -3703,6 +3705,12 @@ character of that word. In both cases, LIMIT bounds the search. */); Vfind_word_boundary_function_table = Fmake_char_table (Qnil, Qnil); + DEFVAR_BOOL ("comment-end-can-be-escaped", Vcomment_end_can_be_escaped, + doc: /* Non-nil means an escaped ender inside a comment doesn'tend the comment. */); + Vcomment_end_can_be_escaped = 0; + DEFSYM (Qcomment_end_can_be_escaped, "comment-end-can-be-escaped"); + Fmake_variable_buffer_local (Qcomment_end_can_be_escaped); + defsubr (&Ssyntax_table_p); defsubr (&Ssyntax_table); defsubr (&Sstandard_syntax_table); diff --git a/src/syntax.h b/src/syntax.h index 06ce0ec55df..eb154e088c9 100644 --- a/src/syntax.h +++ b/src/syntax.h @@ -186,6 +186,13 @@ UPDATE_SYNTAX_TABLE_FORWARD (ptrdiff_t charpos) false, gl_state.object); } +INLINE void +UPDATE_SYNTAX_TABLE_FORWARD_FAST (ptrdiff_t charpos) +{ + if (parse_sexp_lookup_properties && charpos >= gl_state.e_property) + update_syntax_table (charpos + gl_state.offset, 1, false, gl_state.object); +} + /* Make syntax table state (gl_state) good for CHARPOS, assuming it is currently good for a position after CHARPOS. */ @@ -205,6 +212,13 @@ UPDATE_SYNTAX_TABLE (ptrdiff_t charpos) UPDATE_SYNTAX_TABLE_FORWARD (charpos); } +INLINE void +UPDATE_SYNTAX_TABLE_FAST (ptrdiff_t charpos) +{ + UPDATE_SYNTAX_TABLE_BACKWARD (charpos); + UPDATE_SYNTAX_TABLE_FORWARD_FAST (charpos); +} + /* Set up the buffer-global syntax table. */ INLINE void diff --git a/src/undo.c b/src/undo.c index 214beaeb9ea..1cc6de48393 100644 --- a/src/undo.c +++ b/src/undo.c @@ -22,10 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include "lisp.h" #include "buffer.h" - -/* Position of point last time we inserted a boundary. */ -static struct buffer *last_boundary_buffer; -static ptrdiff_t last_boundary_position; +#include "keyboard.h" /* The first time a command records something for undo. it also allocates the undo-boundary object @@ -34,45 +31,42 @@ static ptrdiff_t last_boundary_position; an undo-boundary. */ static Lisp_Object pending_boundary; +/* Record point as it was at beginning of this command (if necessary) + and prepare the undo info for recording a change. + Prepare the undo info for recording a change. */ static void -run_undoable_change (void) +prepare_record (void) { - call0 (Qundo_auto__undoable_change); + /* Allocate a cons cell to be the undo boundary after this command. */ + if (NILP (pending_boundary)) + pending_boundary = Fcons (Qnil, Qnil); + + if (MODIFF <= SAVE_MODIFF) + record_first_change (); } -/* Record point as it was at beginning of this command (if necessary) - and prepare the undo info for recording a change. +/* Record point as it was at beginning of this command. PT is the position of point that will naturally occur as a result of the undo record that will be added just after this command terminates. */ - static void record_point (ptrdiff_t pt) { - bool at_boundary; - /* Don't record position of pt when undo_inhibit_record_point holds. */ if (undo_inhibit_record_point) return; - /* Allocate a cons cell to be the undo boundary after this command. */ - if (NILP (pending_boundary)) - pending_boundary = Fcons (Qnil, Qnil); - - run_undoable_change (); + bool at_boundary; at_boundary = ! CONSP (BVAR (current_buffer, undo_list)) || NILP (XCAR (BVAR (current_buffer, undo_list))); - if (MODIFF <= SAVE_MODIFF) - record_first_change (); + prepare_record (); /* If we are just after an undo boundary, and point wasn't at start of deleted range, record where it was. */ - if (at_boundary - && current_buffer == last_boundary_buffer - && last_boundary_position != pt) + if (at_boundary) bset_undo_list (current_buffer, - Fcons (make_number (last_boundary_position), + Fcons (make_number (pt), BVAR (current_buffer, undo_list))); } @@ -89,7 +83,7 @@ record_insert (ptrdiff_t beg, ptrdiff_t length) if (EQ (BVAR (current_buffer, undo_list), Qt)) return; - record_point (beg); + prepare_record (); /* If this is following another insertion and consecutive with it in the buffer, combine the two. */ @@ -130,8 +124,6 @@ record_marker_adjustments (ptrdiff_t from, ptrdiff_t to) if (NILP (pending_boundary)) pending_boundary = Fcons (Qnil, Qnil); - run_undoable_change (); - for (m = BUF_MARKERS (current_buffer); m; m = m->next) { charpos = m->charpos; @@ -163,7 +155,6 @@ record_marker_adjustments (ptrdiff_t from, ptrdiff_t to) /* Record that a deletion is about to take place, of the characters in STRING, at location BEG. Optionally record adjustments for markers in the region STRING occupies in the current buffer. */ - void record_delete (ptrdiff_t beg, Lisp_Object string, bool record_markers) { @@ -172,15 +163,19 @@ record_delete (ptrdiff_t beg, Lisp_Object string, bool record_markers) if (EQ (BVAR (current_buffer, undo_list), Qt)) return; + if (point_before_last_command_or_undo != beg + && buffer_before_last_command_or_undo == current_buffer) + record_point (point_before_last_command_or_undo); + if (PT == beg + SCHARS (string)) { XSETINT (sbeg, -beg); - record_point (PT); + prepare_record (); } else { XSETFASTINT (sbeg, beg); - record_point (beg); + prepare_record (); } /* primitive-undo assumes marker adjustments are recorded @@ -234,7 +229,7 @@ record_property_change (ptrdiff_t beg, ptrdiff_t length, Lisp_Object buffer) { Lisp_Object lbeg, lend, entry; - struct buffer *obuf = current_buffer, *buf = XBUFFER (buffer); + struct buffer *buf = XBUFFER (buffer); if (EQ (BVAR (buf, undo_list), Qt)) return; @@ -243,11 +238,6 @@ record_property_change (ptrdiff_t beg, ptrdiff_t length, if (NILP (pending_boundary)) pending_boundary = Fcons (Qnil, Qnil); - /* Switch temporarily to the buffer that was changed. */ - set_buffer_internal (buf); - - run_undoable_change (); - if (MODIFF <= SAVE_MODIFF) record_first_change (); @@ -256,9 +246,6 @@ record_property_change (ptrdiff_t beg, ptrdiff_t length, entry = Fcons (Qnil, Fcons (prop, Fcons (value, Fcons (lbeg, lend)))); bset_undo_list (current_buffer, Fcons (entry, BVAR (current_buffer, undo_list))); - - /* Reset the buffer */ - set_buffer_internal (obuf); } DEFUN ("undo-boundary", Fundo_boundary, Sundo_boundary, 0, 0, 0, @@ -286,10 +273,11 @@ but another undo command will undo to the previous boundary. */) bset_undo_list (current_buffer, Fcons (Qnil, BVAR (current_buffer, undo_list))); } - last_boundary_position = PT; - last_boundary_buffer = current_buffer; Fset (Qundo_auto__last_boundary_cause, Qexplicit); + point_before_last_command_or_undo = PT; + buffer_before_last_command_or_undo = current_buffer; + return Qnil; } @@ -432,7 +420,6 @@ void syms_of_undo (void) { DEFSYM (Qinhibit_read_only, "inhibit-read-only"); - DEFSYM (Qundo_auto__undoable_change, "undo-auto--undoable-change"); DEFSYM (Qundo_auto__last_boundary_cause, "undo-auto--last-boundary-cause"); DEFSYM (Qexplicit, "explicit"); @@ -442,8 +429,6 @@ syms_of_undo (void) pending_boundary = Qnil; staticpro (&pending_boundary); - last_boundary_buffer = NULL; - defsubr (&Sundo_boundary); DEFVAR_INT ("undo-limit", undo_limit, diff --git a/src/unexelf.c b/src/unexelf.c index c10c7f21bf2..03e6dafe8ee 100644 --- a/src/unexelf.c +++ b/src/unexelf.c @@ -247,7 +247,7 @@ unexec (const char *new_name, const char *old_name) ElfW (Phdr) *old_bss_seg, *new_bss_seg; ElfW (Addr) old_bss_addr, new_bss_addr; - ElfW (Word) old_bss_size, new_data2_size; + ElfW (Word) old_bss_size, bss_size_growth, new_data2_size; ElfW (Off) old_bss_offset, new_data2_offset; ptrdiff_t n; @@ -331,7 +331,11 @@ unexec (const char *new_name, const char *old_name) new_break = sbrk (0); new_bss_addr = (ElfW (Addr)) new_break; - new_data2_size = new_bss_addr - old_bss_addr; + bss_size_growth = new_bss_addr - old_bss_addr; + new_data2_size = bss_size_growth; + new_data2_size += alignof (ElfW (Shdr)) - 1; + new_data2_size -= new_data2_size % alignof (ElfW (Shdr)); + new_data2_offset = old_bss_offset; #ifdef UNEXELF_DEBUG @@ -399,7 +403,8 @@ unexec (const char *new_name, const char *old_name) new_bss_seg->p_memsz = new_bss_seg->p_filesz; /* Copy over what we have in memory now for the bss area. */ - memcpy (new_base + new_data2_offset, (caddr_t) old_bss_addr, new_data2_size); + memcpy (new_base + new_data2_offset, (caddr_t) old_bss_addr, + bss_size_growth); /* Walk through all section headers, copying data and updating. */ for (n = 1; n < old_file_h->e_shnum; n++) diff --git a/src/w32.c b/src/w32.c index 15cfd92a29a..9b1d94de786 100644 --- a/src/w32.c +++ b/src/w32.c @@ -7432,7 +7432,7 @@ sys_socket (int af, int type, int protocol) if (winsock_lib == NULL) { errno = ENETDOWN; - return INVALID_SOCKET; + return -1; } check_errno (); @@ -9270,8 +9270,10 @@ maybe_load_unicows_dll (void) pointers, and assign the correct addresses to these pointers at program startup (see emacs.c, which calls this function early on). */ - pMultiByteToWideChar = GetProcAddress (ret, "MultiByteToWideChar"); - pWideCharToMultiByte = GetProcAddress (ret, "WideCharToMultiByte"); + pMultiByteToWideChar = + (MultiByteToWideChar_Proc)GetProcAddress (ret, "MultiByteToWideChar"); + pWideCharToMultiByte = + (WideCharToMultiByte_Proc)GetProcAddress (ret, "WideCharToMultiByte"); return ret; } else @@ -9379,6 +9381,11 @@ globals_of_w32 (void) w32_unicode_filenames = 0; else w32_unicode_filenames = 1; + +#ifdef HAVE_MODULES + extern void dynlib_reset_last_error (void); + dynlib_reset_last_error (); +#endif } /* For make-serial-process */ diff --git a/src/w32.h b/src/w32.h index 2c711502593..1efd562eadb 100644 --- a/src/w32.h +++ b/src/w32.h @@ -179,8 +179,10 @@ extern int _sys_wait_connect (int fd); extern HMODULE w32_delayed_load (Lisp_Object); -extern int (WINAPI *pMultiByteToWideChar)(UINT,DWORD,LPCSTR,int,LPWSTR,int); -extern int (WINAPI *pWideCharToMultiByte)(UINT,DWORD,LPCWSTR,int,LPSTR,int,LPCSTR,LPBOOL); +typedef int (WINAPI *MultiByteToWideChar_Proc)(UINT,DWORD,LPCSTR,int,LPWSTR,int); +typedef int (WINAPI *WideCharToMultiByte_Proc)(UINT,DWORD,LPCWSTR,int,LPSTR,int,LPCSTR,LPBOOL); +extern MultiByteToWideChar_Proc pMultiByteToWideChar; +extern WideCharToMultiByte_Proc pWideCharToMultiByte; extern void init_environment (char **); extern void check_windows_init_file (void); diff --git a/src/w32console.c b/src/w32console.c index ec54f83129f..7fffabf3853 100644 --- a/src/w32console.c +++ b/src/w32console.c @@ -757,13 +757,8 @@ initialize_w32_display (struct terminal *term, int *width, int *height) else w32_console_unicode_input = 0; - /* This is needed by w32notify.c:send_notifications. */ - dwMainThreadId = GetCurrentThreadId (); - /* Setup w32_display_info structure for this frame. */ - w32_initialize_display_info (build_string ("Console")); - } diff --git a/src/w32fns.c b/src/w32fns.c index f3391cb98f0..c1d9bff98ab 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -1666,10 +1666,7 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) FRAME_MENU_BAR_LINES (f) = 0; FRAME_MENU_BAR_HEIGHT (f) = 0; if (nlines) - { - FRAME_EXTERNAL_MENU_BAR (f) = 1; - windows_or_buffers_changed = 23; - } + FRAME_EXTERNAL_MENU_BAR (f) = 1; else { if (FRAME_EXTERNAL_MENU_BAR (f) == 1) @@ -4620,8 +4617,7 @@ my_create_tip_window (struct frame *f) rect.right = FRAME_PIXEL_WIDTH (f); rect.bottom = FRAME_PIXEL_HEIGHT (f); - AdjustWindowRect (&rect, f->output_data.w32->dwStyle, - FRAME_EXTERNAL_MENU_BAR (f)); + AdjustWindowRect (&rect, f->output_data.w32->dwStyle, false); tip_window = FRAME_W32_WINDOW (f) = CreateWindow (EMACS_CLASS, @@ -6381,7 +6377,7 @@ compute_tip_xy (struct frame *f, if (INTEGERP (left)) *root_x = XINT (left); else if (INTEGERP (right)) - *root_y = XINT (right) - width; + *root_x = XINT (right) - width; else if (*root_x + XINT (dx) <= min_x) *root_x = 0; /* Can happen for negative dx */ else if (*root_x + XINT (dx) + width <= max_x) @@ -6681,8 +6677,7 @@ Text larger than the specified size is clipped. */) rect.left = rect.top = 0; rect.right = width; rect.bottom = height; - AdjustWindowRect (&rect, f->output_data.w32->dwStyle, - FRAME_EXTERNAL_MENU_BAR (f)); + 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 @@ -8098,11 +8093,22 @@ The coordinates X and Y are interpreted in pixels relative to a position (0, 0) of the selected frame's display. */) (Lisp_Object x, Lisp_Object y) { + UINT trail_num = 0; + BOOL ret = false; + CHECK_TYPE_RANGED_INTEGER (int, x); CHECK_TYPE_RANGED_INTEGER (int, y); block_input (); + /* When "mouse trails" are in effect, moving the mouse cursor + sometimes leaves behind an annoying "ghost" of the pointer. + Avoid that by momentarily switching off mouse trails. */ + if (os_subtype == OS_NT + && w32_major_version + w32_minor_version >= 6) + ret = SystemParametersInfo (SPI_GETMOUSETRAILS, 0, &trail_num, 0); SetCursorPos (XINT (x), XINT (y)); + if (ret) + SystemParametersInfo (SPI_SETMOUSETRAILS, trail_num, NULL, 0); unblock_input (); return Qnil; @@ -9925,10 +9931,6 @@ globals_of_w32fns (void) InitCommonControls (); syms_of_w32uniscribe (); - - /* Needed for recovery from C stack overflows in batch mode. */ - if (noninteractive) - dwMainThreadId = GetCurrentThreadId (); } #ifdef NTGUI_UNICODE diff --git a/src/w32menu.c b/src/w32menu.c index 6af69f482d4..964b965fac1 100644 --- a/src/w32menu.c +++ b/src/w32menu.c @@ -494,7 +494,10 @@ set_frame_menubar (struct frame *f, bool first_time, bool deep_p) /* Force the window size to be recomputed so that the frame's text area remains the same, if menubar has just been created. */ if (old_widget == NULL) - adjust_frame_size (f, -1, -1, 2, false, Qmenu_bar_lines); + { + windows_or_buffers_changed = 23; + adjust_frame_size (f, -1, -1, 2, false, Qmenu_bar_lines); + } } unblock_input (); diff --git a/src/w32term.c b/src/w32term.c index f764e250aa8..60d64f7fd0f 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -23,6 +23,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include "lisp.h" #include "blockinput.h" #include "w32term.h" +#include "w32common.h" /* for OS version info */ #include <ctype.h> #include <errno.h> @@ -6115,9 +6116,22 @@ x_set_window_size (struct frame *f, bool change_gravity, int pixelwidth, pixelheight; Lisp_Object fullscreen = get_frame_param (f, Qfullscreen); RECT rect; + MENUBARINFO info; + int menu_bar_height; block_input (); + /* Get the height of the menu bar here. It's used below to detect + whether the menu bar is wrapped. It's also used to specify the + third argument for AdjustWindowRect. FRAME_EXTERNAL_MENU_BAR which + has been used before for that reason is unreliable because it only + specifies whether we _want_ a menu bar for this frame and not + whether this frame _has_ a menu bar. See bug#22105. */ + info.cbSize = sizeof (info); + info.rcBar.top = info.rcBar.bottom = 0; + GetMenuBarInfo (FRAME_W32_WINDOW (f), 0xFFFFFFFD, 0, &info); + menu_bar_height = info.rcBar.bottom - info.rcBar.top; + if (pixelwise) { pixelwidth = FRAME_TEXT_TO_PIXEL_WIDTH (f, width); @@ -6135,17 +6149,11 @@ x_set_window_size (struct frame *f, bool change_gravity, height of the frame then the wrapped menu bar lines are not accounted for (Bug#15174 and Bug#18720). Here we add these extra lines to the frame height. */ - MENUBARINFO info; int default_menu_bar_height; - int menu_bar_height; /* Why is (apparently) SM_CYMENUSIZE needed here instead of SM_CYMENU ?? */ default_menu_bar_height = GetSystemMetrics (SM_CYMENUSIZE); - info.cbSize = sizeof (info); - info.rcBar.top = info.rcBar.bottom = 0; - GetMenuBarInfo (FRAME_W32_WINDOW (f), 0xFFFFFFFD, 0, &info); - menu_bar_height = info.rcBar.bottom - info.rcBar.top; if ((default_menu_bar_height > 0) && (menu_bar_height > default_menu_bar_height) @@ -6160,8 +6168,7 @@ x_set_window_size (struct frame *f, bool change_gravity, rect.right = pixelwidth; rect.bottom = pixelheight; - AdjustWindowRect (&rect, f->output_data.w32->dwStyle, - FRAME_EXTERNAL_MENU_BAR (f)); + AdjustWindowRect (&rect, f->output_data.w32->dwStyle, menu_bar_height > 0); if (!(f->after_make_frame) && !(f->want_fullscreen & FULLSCREEN_WAIT) @@ -6231,6 +6238,8 @@ x_set_window_size (struct frame *f, bool change_gravity, void frame_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y) { + UINT trail_num = 0; + BOOL ret = false; RECT rect; POINT pt; @@ -6241,7 +6250,15 @@ frame_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y) pt.y = rect.top + pix_y; ClientToScreen (FRAME_W32_WINDOW (f), &pt); + /* When "mouse trails" are in effect, moving the mouse cursor + sometimes leaves behind an annoying "ghost" of the pointer. + Avoid that by momentarily switching off mouse trails. */ + if (os_subtype == OS_NT + && w32_major_version + w32_minor_version >= 6) + ret = SystemParametersInfo (SPI_GETMOUSETRAILS, 0, &trail_num, 0); SetCursorPos (pt.x, pt.y); + if (ret) + SystemParametersInfo (SPI_SETMOUSETRAILS, trail_num, NULL, 0); unblock_input (); } @@ -6925,6 +6942,15 @@ x_delete_display (struct w32_display_info *dpyinfo) /* Set up use of W32. */ +void +w32_init_main_thread (void) +{ + dwMainThreadId = GetCurrentThreadId (); + DuplicateHandle (GetCurrentProcess (), GetCurrentThread (), + GetCurrentProcess (), &hMainThread, 0, TRUE, + DUPLICATE_SAME_ACCESS); +} + DWORD WINAPI w32_msg_worker (void * arg); static void @@ -6985,10 +7011,6 @@ w32_initialize (void) terminates */ init_crit (); - dwMainThreadId = GetCurrentThreadId (); - DuplicateHandle (GetCurrentProcess (), GetCurrentThread (), - GetCurrentProcess (), &hMainThread, 0, TRUE, DUPLICATE_SAME_ACCESS); - /* Wait for thread to start */ { MSG msg; diff --git a/src/w32term.h b/src/w32term.h index 467da10c3b7..3377b53608e 100644 --- a/src/w32term.h +++ b/src/w32term.h @@ -855,6 +855,8 @@ extern void globals_of_w32menu (void); extern void globals_of_w32fns (void); extern void globals_of_w32notify (void); +extern void w32_init_main_thread (void); + #ifdef CYGWIN extern int w32_message_fd; #endif /* CYGWIN */ diff --git a/src/window.c b/src/window.c index 0ac76d41861..9f6b489e74a 100644 --- a/src/window.c +++ b/src/window.c @@ -4064,37 +4064,6 @@ resize_frame_windows (struct frame *f, int size, bool horflag, bool pixelwise) { window_resize_apply (r, horflag); window_pixel_to_total (r->frame, horflag ? Qt : Qnil); -#if false /* Let's try without safe sizes and/or killing other windows. */ - } - else - { - /* Finally, try with "safe" minimum sizes. */ - resize_root_window (root, delta, horflag ? Qt : Qnil, Qsafe, - pixelwise ? Qt : Qnil); - if (window_resize_check (r, horflag) - && new_pixel_size == XINT (r->new_pixel)) - { - window_resize_apply (r, horflag); - window_pixel_to_total (r->frame, horflag ? Qt : Qnil); - } - else - { - /* We lost. Delete all windows but the frame's - selected one. */ - root = f->selected_window; - Fdelete_other_windows_internal (root, Qnil); - if (horflag) - { - XWINDOW (root)->total_cols = new_size; - XWINDOW (root)->pixel_width = new_pixel_size; - } - else - { - XWINDOW (root)->total_lines = new_size; - XWINDOW (root)->pixel_height = new_pixel_size; - } - } -#endif /* false */ } } } @@ -4117,6 +4086,7 @@ resize_frame_windows (struct frame *f, int size, bool horflag, bool pixelwise) } } + FRAME_WINDOW_SIZES_CHANGED (f) = true; fset_redisplay (f); } @@ -4555,6 +4525,7 @@ 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 (); } @@ -4594,6 +4565,7 @@ 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 (); } diff --git a/src/xdisp.c b/src/xdisp.c index 30dfac55601..37dc6047e58 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -10733,6 +10733,9 @@ display_echo_area (struct window *w) reset the echo_area_buffer in question to nil at the end because with_echo_area_buffer will sets it to an empty buffer. */ bool i = display_last_displayed_message_p; + /* According to the C99, C11 and C++11 standards, the integral value + of a "bool" is always 0 or 1, so this array access is safe here, + if oddly typed. */ no_message_p = NILP (echo_area_buffer[i]); window_height_changed_p @@ -13536,6 +13539,32 @@ redisplay_internal (void) { echo_area_display (false); + /* If echo_area_display resizes the mini-window, the redisplay and + window_sizes_changed flags of the selected frame are set, but + 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)) + { + 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); + } + + unbind_to (count1, Qnil); + } + if (message_cleared_p) update_miniwindow_p = true; @@ -13552,6 +13581,27 @@ redisplay_internal (void) && (current_buffer->clip_changed || window_outdated (w)) && resize_mini_window (w, false)) { + 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); + } + + unbind_to (count1, Qnil); + } + /* Resized active mini-window to fit the size of what it is showing if its contents might have changed. */ must_finish = true; @@ -16251,9 +16301,33 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) if (w->cursor.vpos < 0) { /* If point does not appear, try to move point so it does - appear. The desired matrix has been built above, so we - can use it here. */ - new_vpos = window_box_height (w) / 2; + appear. The desired matrix has been built above, so we + can use it here. First see if point is in invisible + text, and if so, move it to the first visible buffer + position past that. */ + struct glyph_row *r = NULL; + Lisp_Object invprop = + get_char_property_and_overlay (make_number (PT), Qinvisible, + Qnil, NULL); + + if (TEXT_PROP_MEANS_INVISIBLE (invprop) != 0) + { + ptrdiff_t alt_pt; + Lisp_Object invprop_end = + Fnext_single_char_property_change (make_number (PT), Qinvisible, + Qnil, Qnil); + + if (NATNUMP (invprop_end)) + alt_pt = XFASTINT (invprop_end); + else + alt_pt = ZV; + r = row_containing_pos (w, alt_pt, w->desired_matrix->rows, + NULL, 0); + } + if (r) + new_vpos = MATRIX_ROW_BOTTOM_Y (r); + else /* Give up and just move to the middle of the window. */ + new_vpos = window_box_height (w) / 2; } if (!cursor_row_fully_visible_p (w, false, false)) @@ -16670,6 +16744,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; if (!current_matrix_up_to_date_p || windows_or_buffers_changed || f->cursor_type_changed @@ -16680,7 +16755,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) || MINI_WINDOW_P (w) || !(used_current_matrix_p = try_window_reusing_current_matrix (w))) - try_window (window, startp, 0); + use_desired_matrix = (try_window (window, startp, 0) == 1); /* If new fonts have been loaded (due to fontsets), give up. We have to start a new redisplay since we need to re-adjust glyph @@ -16720,9 +16795,15 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) and similar ones. */ if (w->cursor.vpos < 0) { + /* Prefer the desired matrix to the current matrix, if possible, + in the fallback calculations below. This is because using + the current matrix might completely goof, e.g. if its first + row is after point. */ + struct glyph_matrix *matrix = + use_desired_matrix ? w->desired_matrix : w->current_matrix; /* First, try locating the proper glyph row for PT. */ struct glyph_row *row = - row_containing_pos (w, PT, w->current_matrix->rows, NULL, 0); + row_containing_pos (w, PT, matrix->rows, NULL, 0); /* Sometimes point is at the beginning of invisible text that is before the 1st character displayed in the row. In that case, @@ -16747,8 +16828,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) alt_pos = XFASTINT (invis_end); else alt_pos = ZV; - row = row_containing_pos (w, alt_pos, w->current_matrix->rows, - NULL, 0); + row = row_containing_pos (w, alt_pos, matrix->rows, NULL, 0); } } /* Finally, fall back on the first row of the window after the @@ -16756,11 +16836,11 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) displaying the cursor at all. */ if (!row) { - row = w->current_matrix->rows; + row = matrix->rows; if (row->mode_line_p) ++row; } - set_cursor_from_row (w, row, w->current_matrix, 0, 0, 0, 0); + set_cursor_from_row (w, row, matrix, 0, 0, 0, 0); } if (!cursor_row_fully_visible_p (w, false, false)) @@ -17745,7 +17825,7 @@ row_containing_pos (struct window *w, ptrdiff_t charpos, while (true) { /* Give up if we have gone too far. */ - if (end && row >= end) + if ((end && row >= end) || !row->enabled_p) return NULL; /* This formerly returned if they were equal. I think that both quantities are of a "last plus one" type; @@ -31132,11 +31212,13 @@ 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 before redisplay, if window sizes have changed. + doc: /* Functions called during redisplay, if window sizes have changed. The value should be a list of functions that take one argument. -Just before 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. */); +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, diff --git a/src/xfns.c b/src/xfns.c index 313ac52f12a..3f95f7b79fb 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -5582,6 +5582,8 @@ x_create_tip_frame (struct x_display_info *dpyinfo, "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN); x_default_parameter (f, parms, Qcursor_type, Qbox, "cursorType", "CursorType", RES_TYPE_SYMBOL); + x_default_parameter (f, parms, Qalpha, Qnil, + "alpha", "Alpha", RES_TYPE_NUMBER); /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size. Change will not be effected unless different from the current @@ -5719,7 +5721,7 @@ compute_tip_xy (struct frame *f, Lisp_Object parms, Lisp_Object dx, Lisp_Object if (INTEGERP (left)) *root_x = XINT (left); else if (INTEGERP (right)) - *root_y = XINT (right) - width; + *root_x = XINT (right) - width; else if (*root_x + XINT (dx) <= 0) *root_x = 0; /* Can happen for negative dx */ else if (*root_x + XINT (dx) + width |