From d6d9cbc15cbebfe466756a7a75601173c15287a2 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Tue, 24 Sep 2013 10:43:20 +0400 Subject: Use union for the payload of struct Lisp_Vector. This helps to avoid a few glitches dictated by C's aliasing rules. * lisp.h (struct Lisp_Vector): Use union for next and contents member. Adjust comment. Change related users. * alloc.c (next_in_free_list, set_next_in_free_list): Remove. Related users changed. * buffer.c, bytecode.c, ccl.c, character.h, chartab.c, composite.c: * composite.h, disptab.h, fns.c, fontset.c, indent.c, keyboard.c: * lread.c, msdos.c, process.c, w32menu.c, window.c, xdisp.c: * xfaces.c, xfont.c, xmenu.c: Related users changed. --- src/bytecode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bytecode.c') diff --git a/src/bytecode.c b/src/bytecode.c index 3ac8b452fbe..23e50826633 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -536,7 +536,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, #ifdef BYTE_CODE_SAFE bytestr_length = SBYTES (bytestr); #endif - vectorp = XVECTOR (vector)->contents; + vectorp = XVECTOR (vector)->u.contents; stack.byte_string = bytestr; stack.pc = stack.byte_string_start = SDATA (bytestr); -- cgit v1.2.1 From adf2aa61404305e58e71cde0193bb650aff2c4b3 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 3 Oct 2013 00:58:56 -0400 Subject: Introduce new bytecodes for efficient catch/condition-case in lexbind. * lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker): Optimize under `condition-case' and `catch' if byte-compile--use-old-handlers is nil. (disassemble-offset): Handle new bytecodes. * lisp/emacs-lisp/bytecomp.el (byte-pushcatch, byte-pushconditioncase) (byte-pophandler): New byte codes. (byte-goto-ops): Adjust accordingly. (byte-compile--use-old-handlers): New var. (byte-compile-catch): Use new byte codes depending on byte-compile--use-old-handlers. (byte-compile-condition-case--old): Rename from byte-compile-condition-case. (byte-compile-condition-case--new): New function. (byte-compile-condition-case): New function that dispatches depending on byte-compile--use-old-handlers. (byte-compile-unwind-protect): Pass a function to byte-unwind-protect when we can. * lisp/emacs-lisp/cconv.el (cconv-convert, cconv-analyse-form): Adjust for the new compilation scheme using the new byte-codes. * src/alloc.c (Fgarbage_collect): Merge scans of handlerlist and catchlist, and make them unconditional now that they're heap-allocated. * src/bytecode.c (BYTE_CODES): Add Bpushcatch, Bpushconditioncase and Bpophandler. (bcall0): New function. (exec_byte_code): Add corresponding cases. Improve error message when encountering an invalid byte-code. Let Bunwind_protect accept a function (rather than a list of expressions) as argument. * src/eval.c (catchlist): Remove (merge with handlerlist). (handlerlist, lisp_eval_depth): Not static any more. (internal_catch, internal_condition_case, internal_condition_case_1) (internal_condition_case_2, internal_condition_case_n): Use PUSH_HANDLER. (unwind_to_catch, Fthrow, Fsignal): Adjust to merged handlerlist/catchlist. (internal_lisp_condition_case): Use PUSH_HANDLER. Adjust to new handlerlist which can only handle a single condition-case handler at a time. (find_handler_clause): Simplify since we only a single branch here any more. * src/lisp.h (struct handler): Merge struct handler and struct catchtag. (PUSH_HANDLER): New macro. (catchlist): Remove. (handlerlist): Always declare. --- src/bytecode.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 10 deletions(-) (limited to 'src/bytecode.c') diff --git a/src/bytecode.c b/src/bytecode.c index 23e50826633..f7ccd35cbba 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -141,6 +141,10 @@ DEFINE (Bunbind5, 055) \ DEFINE (Bunbind6, 056) \ DEFINE (Bunbind7, 057) \ \ +DEFINE (Bpophandler, 060) \ +DEFINE (Bpushconditioncase, 061) \ +DEFINE (Bpushcatch, 062) \ + \ DEFINE (Bnth, 070) \ DEFINE (Bsymbolp, 071) \ DEFINE (Bconsp, 072) \ @@ -478,6 +482,12 @@ If the third argument is incorrect, Emacs may crash. */) return exec_byte_code (bytestr, vector, maxdepth, Qnil, 0, NULL); } +static void +bcall0 (Lisp_Object f) +{ + Ffuncall (1, &f); +} + /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect, emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp @@ -506,6 +516,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, struct byte_stack stack; Lisp_Object *top; Lisp_Object result; + enum handlertype type; #if 0 /* CHECK_FRAME_FONT */ { @@ -1078,7 +1089,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, save_restriction_save ()); NEXT; - CASE (Bcatch): /* FIXME: ill-suited for lexbind. */ + CASE (Bcatch): /* Obsolete since 24.4. */ { Lisp_Object v1; BEFORE_POTENTIAL_GC (); @@ -1088,11 +1099,56 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, NEXT; } + CASE (Bpushcatch): /* New in 24.4. */ + type = CATCHER; + goto pushhandler; + CASE (Bpushconditioncase): /* New in 24.4. */ + { + extern EMACS_INT lisp_eval_depth; + extern int poll_suppress_count; + extern int interrupt_input_blocked; + struct handler *c; + Lisp_Object tag; + int dest; + + type = CONDITION_CASE; + pushhandler: + tag = POP; + dest = FETCH2; + + PUSH_HANDLER (c, tag, type); + c->bytecode_dest = dest; + c->bytecode_top = top; + if (sys_setjmp (c->jmp)) + { + struct handler *c = handlerlist; + top = c->bytecode_top; + int dest = c->bytecode_dest; + handlerlist = c->next; + PUSH (c->val); + CHECK_RANGE (dest); + stack.pc = stack.byte_string_start + dest; + } + NEXT; + } + + CASE (Bpophandler): /* New in 24.4. */ + { + handlerlist = handlerlist->next; + NEXT; + } + CASE (Bunwind_protect): /* FIXME: avoid closure for lexbind. */ - record_unwind_protect (unwind_body, POP); - NEXT; + { + Lisp_Object handler = POP; + /* Support for a function here is new in 24.4. */ + record_unwind_protect (NILP (Ffunctionp (handler)) + ? unwind_body : bcall0, + handler); + NEXT; + } - CASE (Bcondition_case): /* FIXME: ill-suited for lexbind. */ + CASE (Bcondition_case): /* Obsolete since 24.4. */ { Lisp_Object handlers, body; handlers = POP; @@ -1884,7 +1940,10 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, /* Actually this is Bstack_ref with offset 0, but we use Bdup for that instead. */ /* CASE (Bstack_ref): */ - error ("Invalid byte opcode"); + call3 (intern ("error"), + build_string ("Invalid byte opcode: op=%s, ptr=%d"), + make_number (op), + make_number ((stack.pc - 1) - stack.byte_string_start)); /* Handy byte-codes for lexical binding. */ CASE (Bstack_ref1): @@ -1957,11 +2016,11 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, /* Binds and unbinds are supposed to be compiled balanced. */ if (SPECPDL_INDEX () != count) -#ifdef BYTE_CODE_SAFE - error ("binding stack not balanced (serious byte compiler bug)"); -#else - emacs_abort (); -#endif + { + if (SPECPDL_INDEX () > count) + unbind_to (count, Qnil); + error ("binding stack not balanced (serious byte compiler bug)"); + } return result; } -- cgit v1.2.1 From 157fec2e190a84345138a0cc69e35f177c4d4a56 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 3 Oct 2013 23:51:50 -0700 Subject: * bytecode.c (exec_byte_code): Use some more volatile variables to work around local variables getting clobbered by longjmp. Port to pre-C99, which doesn't allow decls after stmts. --- src/bytecode.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/bytecode.c') diff --git a/src/bytecode.c b/src/bytecode.c index f7ccd35cbba..b9cb36c871f 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -332,7 +332,7 @@ struct byte_stack /* A list of currently active byte-code execution value stacks. Fbyte_code adds an entry to the head of this list before it starts - processing byte-code, and it removed the entry again when it is + processing byte-code, and it removes the entry again when it is done. Signaling an error truncates the list analogous to gcprolist. */ @@ -501,19 +501,22 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, Lisp_Object args_template, ptrdiff_t nargs, Lisp_Object *args) { ptrdiff_t count = SPECPDL_INDEX (); + ptrdiff_t volatile count_volatile; #ifdef BYTE_CODE_METER - int this_op = 0; + int volatile this_op = 0; int prev_op; #endif int op; /* Lisp_Object v1, v2; */ Lisp_Object *vectorp; + Lisp_Object *volatile vectorp_volatile; #ifdef BYTE_CODE_SAFE - ptrdiff_t const_length; - Lisp_Object *stacke; - ptrdiff_t bytestr_length; + ptrdiff_t volatile const_length; + Lisp_Object *volatile stacke; + ptrdiff_t volatile bytestr_length; #endif struct byte_stack stack; + struct byte_stack volatile stack_volatile; Lisp_Object *top; Lisp_Object result; enum handlertype type; @@ -1119,16 +1122,25 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, PUSH_HANDLER (c, tag, type); c->bytecode_dest = dest; c->bytecode_top = top; + count_volatile = count; + stack_volatile = stack; + vectorp_volatile = vectorp; + if (sys_setjmp (c->jmp)) { struct handler *c = handlerlist; + int dest; top = c->bytecode_top; - int dest = c->bytecode_dest; + dest = c->bytecode_dest; handlerlist = c->next; PUSH (c->val); CHECK_RANGE (dest); + stack = stack_volatile; stack.pc = stack.byte_string_start + dest; } + + count = count_volatile; + vectorp = vectorp_volatile; NEXT; } -- cgit v1.2.1 From 91f2d272895257f23596075a0cc42e6e5f4e490f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 3 Nov 2013 22:09:03 -0800 Subject: Port to stricter C99 platforms. Especially, C99 prohibits nesting a struct X inside struct Y if struct X has a flexible array member. Also, merge from gnulib, incorporating: 2013-11-03 intprops: port to Oracle Studio c99 * lib/intprops.h: Update from gnulib. * src/alloc.c (struct sdata): New type. (sdata): Implement in terms of struct sdata. Remove u member; all uses replaced by next_vector, set_next_vector. (SDATA_SELECTOR, SDATA_DATA, SDATA_DATA_OFFSET): Adjust to sdata change. (SDATA_DATA_OFFSET): Now a constant, not a macro. (struct sblock): Rename first_data member to data, which is now a flexible array member. All uses changed. (next_vector, set_next_vector, large_vector_vec): New functions. (vector_alignment): New constant. (roundup_size): Make it a multiple of ALIGNOF_STRUCT_LISP_VECTOR, too. (struct large-vector): Now merely a NEXT member, since the old approach ran afoul of stricter C99. All uses changed to use large_vector_vec or large_vector_offset. (large_vector_offset): New constant. * src/dispnew.c: Include tparam.h, for tgetent. Do not include term.h; no longer needed. * src/gnutls.c (Fgnutls_boot): Don't continue after calling a _Noreturn. * src/lisp.h (ENUM_BF) [__SUNPRO_C && __STDC__]: Use unsigned int. (struct Lisp_Vector): Use a flexible array member for contents, instead of a union with a member that is an array of size 1. All uses changed. (ALIGNOF_STRUCT_LISP_VECTOR): New constant, to make up for the fact that the struct no longer contains a union. (struct Lisp_Misc_Any, struct Lisp_Marker, struct Lisp_Overlay) (struct Lisp_Save_Value, struct Lisp_Free): Use unsigned, not int, for spacers, to avoid c99 warning. (union specbinding): Use unsigned, not bool, for bitfield, as bool is not portable to pre-C99 hosts. --- src/bytecode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bytecode.c') diff --git a/src/bytecode.c b/src/bytecode.c index b9cb36c871f..f34e702c71d 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -550,7 +550,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, #ifdef BYTE_CODE_SAFE bytestr_length = SBYTES (bytestr); #endif - vectorp = XVECTOR (vector)->u.contents; + vectorp = XVECTOR (vector)->contents; stack.byte_string = bytestr; stack.pc = stack.byte_string_start = SDATA (bytestr); -- cgit v1.2.1 From ba3189039adc8ec5eba5ed3e21d42019a4616b7c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 1 Jan 2014 07:43:34 +0000 Subject: Update copyright year to 2014 by running admin/update-copyright. --- src/bytecode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bytecode.c') diff --git a/src/bytecode.c b/src/bytecode.c index f34e702c71d..0ea646a9741 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -1,5 +1,5 @@ /* Execution of byte code produced by bytecomp.el. - Copyright (C) 1985-1988, 1993, 2000-2013 Free Software Foundation, + Copyright (C) 1985-1988, 1993, 2000-2014 Free Software Foundation, Inc. This file is part of GNU Emacs. -- cgit v1.2.1 From 285d6d5d0fde973a31986877fb04a85be0e362ea Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sat, 12 Apr 2014 22:51:11 -0400 Subject: * src/bytecode.c (exec_byte_code): Rework the volatiles. Most importantly, make sure stack.byte_string_start is not de-adjusted by pushhandler. --- src/bytecode.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'src/bytecode.c') diff --git a/src/bytecode.c b/src/bytecode.c index 0ea646a9741..f1bdfd9d9c5 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -501,7 +501,6 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, Lisp_Object args_template, ptrdiff_t nargs, Lisp_Object *args) { ptrdiff_t count = SPECPDL_INDEX (); - ptrdiff_t volatile count_volatile; #ifdef BYTE_CODE_METER int volatile this_op = 0; int prev_op; @@ -509,14 +508,12 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, int op; /* Lisp_Object v1, v2; */ Lisp_Object *vectorp; - Lisp_Object *volatile vectorp_volatile; #ifdef BYTE_CODE_SAFE - ptrdiff_t volatile const_length; - Lisp_Object *volatile stacke; - ptrdiff_t volatile bytestr_length; + ptrdiff_t const_length; + Lisp_Object *stacke; + ptrdiff_t bytestr_length; #endif struct byte_stack stack; - struct byte_stack volatile stack_volatile; Lisp_Object *top; Lisp_Object result; enum handlertype type; @@ -1122,9 +1119,6 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, PUSH_HANDLER (c, tag, type); c->bytecode_dest = dest; c->bytecode_top = top; - count_volatile = count; - stack_volatile = stack; - vectorp_volatile = vectorp; if (sys_setjmp (c->jmp)) { @@ -1135,12 +1129,11 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, handlerlist = c->next; PUSH (c->val); CHECK_RANGE (dest); - stack = stack_volatile; + /* Might have been re-set by longjmp! */ + stack.byte_string_start = SDATA (stack.byte_string); stack.pc = stack.byte_string_start + dest; } - count = count_volatile; - vectorp = vectorp_volatile; NEXT; } -- cgit v1.2.1 From 8208d2bf95f924ed810dc06e84fc4c7d5ac004a5 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 17 May 2014 01:11:31 -0700 Subject: Assume C99 or later. * lib/stdarg.in.h, lib/stdbool.in.h, m4/stdarg.m4, m4/stdbool.m4: Remove. * configure.ac (_AC_PROG_CC_C89): Define a dummy, to keep 'configure' smaller. (gl_PROG_CC_C99): Use this to get C99 or later. * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate. * admin/merge-gnulib (GNULIB_MODULES): Remove stdarg, stdbool. (GNULIB_TOOL_FLAGS): Avoid stdarg, stdbool. * doc/lispref/internals.texi (C Dialect): Document this. * etc/NEWS: Document this. * nt/gnulib.mk: Remove stdarg and stdbool modules. * src/bytecode.c (B__dummy__): Remove. * src/conf_post.h (bool_bf) [!NS_IMPL_GNUSTEP]: Use bool. (FLEXIBLE_ARRAY_MEMBER): Now always empty. * src/dbusbind.c (XD_DEBUG_MESSAGE) [!DBUS_DEBUG]: * src/regex.c (DEBUG_PRINT): Assume varargs macros. * src/lisp.h (DEFUN_FUNCTION_INIT): Remove. All uses now assume C99. Fixes: debbugs:17487 --- src/bytecode.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/bytecode.c') diff --git a/src/bytecode.c b/src/bytecode.c index f1bdfd9d9c5..f489c74a144 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -292,8 +292,6 @@ enum byte_code_op Bscan_buffer = 0153, /* No longer generated as of v18. */ Bset_mark = 0163, /* this loser is no longer generated as of v18 */ #endif - - B__dummy__ = 0 /* Pacify C89. */ }; /* Whether to maintain a `top' and `bottom' field in the stack frame. */ -- cgit v1.2.1 From 9da43ddc9d3e5031d43bf0f5e73ec60b42af2461 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Tue, 27 May 2014 19:48:35 -0400 Subject: * src/bytecode.c (FETCH) [BYTE_CODE_SAFE]: Check the bytecode wasn't relocated from under us. --- src/bytecode.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/bytecode.c') diff --git a/src/bytecode.c b/src/bytecode.c index f489c74a144..ca6681f21e9 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -388,7 +388,11 @@ unmark_byte_stack (void) /* Fetch the next byte from the bytecode stream. */ +#ifdef BYTE_CODE_SAFE +#define FETCH (eassert (stack.byte_string_start == SDATA (stack.byte_string)), *stack.pc++) +#else #define FETCH *stack.pc++ +#endif /* Fetch two bytes from the bytecode stream and make a 16-bit number out of them. */ -- cgit v1.2.1