1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-30 00:51:50 -08:00
Commit graph

39583 commits

Author SHA1 Message Date
Paul Eggert
27bb4de72b Port cleanup attribute to Oracle Studio 12.5
* INSTALL (--with-modules): List cleanup attribute as prereq.
* src/conf_post.h (__has_attribute_cleanup): Remove; no longer needed.
* src/emacs-module.c (MODULE_SETJMP_1): Don’t attempt to verify
(__has_attribute (cleanup)), as Oracle Studio 12.5 supports
__has_attribute only inside preprocessor expressions.  The C
compiler should check the cleanup attribute in the next line anyway.
(module_reset_handlerlist): Remove an unnecessary ‘const’
that causes Oracle Studio 12.5 to refuse to compile.
2017-06-13 18:20:07 -07:00
Philipp Stephani
9af2ab68ca Fix version checks for emacs-module.h
We don't need C11 or C++11 because stdbool.h is in C99, and for C++ we
don't need it at all.
2017-06-13 09:53:33 +02:00
Glenn Morris
69899d4a7e Small portability fix for emacs-module.h (bug#27346)
* src/emacs-module.h (EMACS_ATTRIBUTE_NONNULL) [!__has_attribute]:
Avoid 'error: missing binary operator before token "("'.
2017-06-12 17:43:28 -04:00
Alan Third
0f24ad7b81 Add no-focus-on-map to NS build (bug#25408)
* src/nsfns.m (ns_frame_parm_handlers): Add x_set_no_focus_on_map.
(x-create-frame): Check for no-focus-on-map.
* src/nsterm.h (x_set_no_focus_on_map): New function.
* src/nsterm.m (x_set_no_focus_on_map): New function.
(ns_raise_frame): Add parameter for specifying whether to focus the
frame.
(ns_frame_raise_lower):
(x_make_frame_visible): Handle new parameter for ns_raise_frame.
2017-06-12 18:51:57 +01:00
Paul Eggert
6b9618e813 _Noreturn not noreturn
_Noreturn is more portable to non-C11 platforms.  See:
https://www.gnu.org/software/gnulib/manual/html_node/stdnoreturn_002eh.html
* src/emacs-module.c: Use _Noreturn, not noreturn.  No need to
include <stdnoreturn.h>.  Reindent to fit in 80 columns.
2017-06-12 10:39:15 -07:00
Eli Zaretskii
e6f47a9d6c Avoid compilation warnings with pre-C99 libc
* src/emacs-module.c (module_free_global_ref)
(module_assert_runtime, module_assert_env, value_to_lisp): Use 'pD'
instead of C99 't' format descriptor.
2017-06-12 18:04:04 +03:00
Philipp Stephani
d29a9dae71 Flush all output streams before aborting
Maybe the stdout buffer still contains something interesting that
should be flushed.

* src/emacs-module.c (module_abort): Flush all output streams before
aborting.
2017-06-12 16:39:15 +02:00
Philipp Stephani
655439b71e Remove an assertion that doesn't test Emacs invariants
* src/emacs-module.c (module_copy_string_contents): Remove an
assertion that doesn't test Emacs invariants.
2017-06-12 16:37:45 +02:00
Philipp Stephani
cf97132764 Implement module assertions for users
Add a new command-line option '-module-assertions' that users can
enable developing or debugging a module.  If this option is present,
Emacs performs additional checks to verify that modules fulfill their
requirements.  These checks are expensive and crash Emacs if modules
are invalid, so disable them by default.

This is a command-line option instead of an ordinary variable because
changing it while Emacs is running would cause data structure
imbalances.

* src/emacs.c (main): New command line option '-module-assertions'.

* src/emacs-module.c (module_assert_main_thread)
(module_assert_runtime, module_assert_env, module_assert_value):
New functions to assert module requirements.
(syms_of_module): New uninterned variable 'module-runtimes'.
(init_module_assertions, in_main_thread, module_abort): New helper
functions.
(initialize_environment): Initialize value list.  If assertions are
enabled, use a heap-allocated environment object.
(finalize_environment): Add assertion that environment list is never
empty.
(finalize_runtime_unwind): Pop module runtime object stack.
(value_to_lisp): Assert that the value is valid.
(lisp_to_value): Record new value if assertions are enabled.
(mark_modules): Mark allocated object list.
(MODULE_FUNCTION_BEGIN_NO_CATCH)
(module_non_local_exit_check, module_non_local_exit_clear)
(module_non_local_exit_get, module_non_local_exit_signal)
(module_non_local_exit_throw): Assert thread and environment.
(module_get_environment): Assert thread and runtime.
(module_make_function, module_funcall, module_intern)
(module_funcall, module_make_integer, module_make_float)
(module_make_string, module_make_user_ptr, module_vec_get)
(funcall_module, Fmodule_load): Adapt callers.
(module_make_global_ref): If assertions are enabled, use the global
environment to store global values.
(module_free_global_ref): Remove value from global value list.

* test/Makefile.in (EMACSOPT): Enable module assertions when testing
modules.

* test/data/emacs-module/mod-test.c (Fmod_test_invalid_store)
(Fmod_test_invalid_load): New functions to test module assertions.
(emacs_module_init): Bind the new functions.

* test/src/emacs-module-tests.el (mod-test-emacs): New constant for
the Emacs binary file.
(mod-test-file): New constant for the test module file name.
(module--test-assertions): New unit test.
2017-06-12 15:22:27 +02:00
Philipp Stephani
b49dd3b047 emacs-module: Use __attribute__((nonnull))
Annotate all parameters with __attribute__((nonnull)) that may not be
NULL.
2017-06-12 10:57:39 +02:00
Philipp Stephani
9dc6e93b77 Explicitly require C11 or C++11 in emacs-module.h
We already implicitly require them by including stdbool.h.  Just make
the error message a bit clearer, and remove an unnecessary version
comparison.
2017-06-12 10:54:29 +02:00
Paul Eggert
bb534f6afe Remove Lisp_Misc_Float
* src/data.c (Ftype_of): Do not worry about Lisp_Misc_Float.
* src/lisp.h (Lisp_Misc_Float): Remove.  This placeholder has been
unused for two decades; if we ever want to change floats to be a
misc type we can bring it back then.
2017-06-11 17:05:29 -07:00
Paul Eggert
d0ff364fe8 Make two symbols private to emacs-module.c
* src/lisp.h (allocate_module_function, XSET_MODULE_FUNCTION):
Move from here ...
* src/emacs-module.c: ... to here.
2017-06-11 17:05:28 -07:00
Philipp Stephani
8160c7d914 Support threads in modules
Rather than checking for the main thread, check for the current
thread.

* emacs-module.c (check_thread): New function.
(MODULE_FUNCTION_BEGIN_NO_CATCH, module_get_environment)
(module_non_local_exit_check, module_non_local_exit_clear)
(module_non_local_exit_get, module_non_local_exit_signal)
(module_non_local_exit_throw, module_is_not_nil, module_eq): Use it.
2017-06-11 15:24:05 +02:00
Philipp Stephani
9a86966edb Allow non-local exits in module initializers
Previously signals, throws, and quits from module initialization
functions were ignored.  These function aren't special, and better
errors can be reported using signals than with the initialization
return code, so allow non-local exits.

* src/emacs-module.c (module_signal_or_throw): New helper function.
(Fmodule_load, funcall_module): Use it.
(Fmodule_load): Also allow quitting.
2017-06-11 14:54:05 +02:00
Alan Third
517a0394d2 Don't wait for toolbar in NS native fullscreen
* src/nsterm.m (EmacsView:updateFrameSize): Don't short-circuit the
function when in fullscreen.
2017-06-10 22:49:45 +01:00
Paul Eggert
b94472f188 ; Spelling fixes 2017-06-10 11:44:49 -07:00
Alexander Gramiak
bdf41152af Fix the placement of GTK menus on multi-monitor systems
menu_position_func did not properly use the current monitor's
resolution.  Also see commit '2016-02-06 22:12:53 +0100'.

* lisp/frame.el (frame-monitor-attribute, frame-monitor-geometry)
(frame-monitor-workarea): New functions.

* src/xmenu.c (menu_position_func): Take into account the workarea of
the monitor that contains the mouse.  (Bug#23568)
2017-06-10 12:28:03 +03:00
Philipp Stephani
517c704a63 Fix another compiler warning on macOS
* src/image.c (x_query_frame_background_color): Don't define if we
have NextStep but no image support.
2017-06-09 01:27:39 +02:00
Philipp Stephani
6e00ffe317 Add garbage collection support for module environments
* src/emacs-module.c (mark_modules): New function.
(initialize_environment): Properly initialize Lisp objects.
* src/alloc.c (garbage_collect_1): Call it.
2017-06-09 01:25:47 +02:00
Glenn Morris
6a757bead9 ; ChangeLog fixes 2017-06-05 20:33:55 -04:00
Philipp Stephani
3d9d976aa4 Fix undefined behavior in mapbacktrace
* src/eval.c (Fmapbacktrace): Don't assume that PDL is still valid.
2017-06-05 22:09:22 +02:00
Eli Zaretskii
9ae5c0a2e1 Fix emacs-module-tests on MS-Windows
* src/print.c (print_vectorlike): Make sure module function's
address prints with a leading "0x".  This fixes emacs-module-tests
on MS-Windows.  Fix whitespace.
* src/dynlib.c (dynlib_addr): Remove unused variable.  Update
commentary.
2017-06-05 19:16:04 +03:00
Philipp Stephani
5d29c0f006 Use unwind protection to clean up data structures in modules
Reuse existing functionality and simplify the code a bit.

* src/emacs-module.c (Fmodule_load): Use unwind protection to clean up
runtime object.
(funcall_module): Use unwind protection to clean up environment
object.
(finalize_environment): Simplify signature.
(finalize_environment_unwind, finalize_runtime_unwind): New functions.
2017-06-05 15:10:24 +02:00
Philipp Stephani
13e9493ea3 Inline module_has_cleanup
This constant is only used once, and we fail compilation anyway if
it's false.

* src/emacs-module.c (MODULE_SETJMP_1): Inline __has_attribute.
2017-06-05 10:19:59 +02:00
Paul Eggert
646b74e50e Omit space that broke ‘make check’
* src/print.c (print_vectorlike): Omit stray space.
2017-06-05 00:17:47 -07:00
Paul Eggert
6e4abc9d10 Remove easserts etc. from emacs-module.c
Most of these seem to run afoul of the comment "Do NOT use
'eassert' for checking validity of user code in the module."
* src/emacs-module.c (MODULE_FUNCTION_BEGIN_NO_CATCH)
(module_non_local_exit_check, module_non_local_exit_clear)
(module_non_local_exit_get, module_non_local_exit_signal)
(module_non_local_exit_throw, module_make_string):
Remove unnecessary easserts that pointers are nonnull.
Hardware checks this for us nowadays, and the checks
just clutter up the code.
(module_extract_integer): Remove unnecessary verify that
a C signed integer is in the range INTMAX_MIN..INTMAX_MAX.
The C standard guarantees this.
(module_copy_string_contents): Remove unnecessary eassert
that Lisp strings are null-terminated.
(module_function_arity): Remove unnecessary easserts that
function arities are in range.
2017-06-04 23:53:47 -07:00
Paul Eggert
620d65370a Remove unnecessary checking in emacs-module.c
* src/emacs-module.c (module_copy_string_contents):
Remove checking, as string lengths are always nonnegative and less
than STRING_BYTES_BOUND, and this is checked elsewhere.
(module_make_string): Check length against STRING_BYTES_BOUND, a
tighter bound than MOST_POSITIVE_FIXNUM.  (funcall_module): Don't
assume that an out-of-range integer is nonnegative.
2017-06-04 23:53:47 -07:00
Paul Eggert
cef90102cb SCHARS and STRING_BYTES are nonnegative
Tell the compiler that SCHARS and STRING_BYTES are nonnegative, in
the hopes that this will optimize a bit better.  Also, check this
at runtime if ENABLE_CHECKING.
* src/lisp.h (SCHARS, STRING_BYTES):
eassume that these functions return nonnegative values.
(STRING_SET_CHARS) [ENABLE_CHECKING]:
eassert that newsize is nonnegative.
2017-06-04 23:53:47 -07:00
Philipp Stephani
2aa8b1564e Remove an unused error symbol
* src/emacs-module.c (syms_of_module): Remove unused error symbol
'invalid-module-call'.
2017-06-04 19:50:52 +02:00
Philipp Stephani
66da3f4afa Support quitting in modules
The idea is that modules should call env->should_quit from time to
time and return as quickly as possible if it returns true.

* src/emacs-module.c (module_should_quit): New module function.
(initialize_environment): Use it.
(funcall_module): Process potential pending quit.

* src/eval.c (maybe_quit): Add reference to module_should_quit.
2017-06-04 19:50:52 +02:00
Philipp Stephani
d37201722e Use more specific errors for module load failure
* src/emacs-module.c (syms_of_module): Add more specific error
symbols.
(Fmodule_load): Use them.
2017-06-04 19:50:51 +02:00
Philipp Stephani
27445a82f0 Remove an unneeded assertion
* src/emacs-module.c (module_copy_string_contents): Remove unneeded
assertion.  If this assertion triggers, we raise an error anyway.
2017-06-04 19:50:51 +02:00
Philipp Stephani
a8a93b11cf Guard against signed integer overflows
* src/emacs-module.c (module_extract_integer)
(module_copy_string_contents, module_make_string): Guard against
signed integer overflows.
2017-06-04 19:50:51 +02:00
Philipp Stephani
549706241e Add a couple more assertions to the module code
These can help module authors debug crashes.

* emacs-module.c (module_non_local_exit_check)
(module_non_local_exit_clear, module_non_local_exit_get)
(module_non_local_exit_signal, module_non_local_exit_throw)
(module_copy_string_contents, module_make_string)
(funcall_module, initialize_environment): Add assertions
2017-06-04 19:50:51 +02:00
Philipp Stephani
fb3a9fd318 ; Grammar fix 2017-06-04 19:50:50 +02:00
Philipp Stephani
034275ebe8 ; Small comment fix
* emacs-module.c (MODULE_FUNCTION_BEGIN): Don't say that the error
value should be a sentinel value, because in almost all cases it
isn't.
2017-06-04 19:50:50 +02:00
Philipp Stephani
9be8b2bf1d Use ATTRIBUTE_MAY_ALIAS where alias violations are likely
In particular, alias violations are likely for the return values of
dlsym(3), which get cast around arbitrarily.

* src/emacs-module.c (Fmodule_load): Use ATTRIBUTE_MAY_ALIAS.
2017-06-04 19:50:50 +02:00
Philipp Stephani
366e25a6d1 Simplify interface of dynlib_attr.
Instead of returning bool, set the argument pointers to NULL if the
information is not available.

* src/dynlib.c (dynlib_addr): Don't return bool.
2017-06-04 19:50:50 +02:00
Philipp Stephani
045d21c20a Rationalize environment lifetime management functions
* src/emacs-module.c (Fmodule_load, funcall_module): Adapt callers.
(finalize_environment): Add parameter for public part of the
environment, like 'initialize_environment'.  Add assertions.
2017-06-04 19:50:50 +02:00
Philipp Stephani
3b0080de52 Rework printing of module functions
Fix a FIXME in emacs-module.c.  Put the printing into print.c, like
other types.

* src/print.c (print_vectorlike): Add code to print module functions.

* src/emacs-module.c (funcall_module): Stop calling
'module_format_fun_env'.  Now that module functions are first-class
objects, they can be added to signal data directly.
(module_handle_signal): Remove now-unused function
'module_format_fun_env'.

* test/src/emacs-module-tests.el (mod-test-sum-test): Adapt unit test.

* src/eval.c (funcall_lambda): Adapt call to changed signature of
'funcall_module'.
2017-06-04 19:50:49 +02:00
Philipp Stephani
18396997b3 Define helper macro to reduce code duplication
* src/emacs-module.c (MODULE_FUNCTION_BEGIN_NO_CATCH): New helper
macro.
(MODULE_FUNCTION_BEGIN, module_type_of, module_is_not_nil, module_eq):
Use it.
2017-06-04 19:50:49 +02:00
Philipp Stephani
db7438426a Remove two FIXMEs that can't be fixed 2017-06-04 19:50:49 +02:00
Paul Eggert
d5fcf9e458 Tune ‘format’ after recent fix
* doc/lispref/strings.texi (Formatting Strings):
* src/editfns.c (Fformat): Format field numbers no longer need
to be unique, reverting the previous doc change since that has
now been fixed.  Also, document that %% should not have modifiers.
* src/editfns.c (styled_format): Improve performance.  Remove
the need for the new prepass over the format string, by using
a typically-more-generous bound for the info array size.
Initialize the info array lazily.  Move string inspection to
the same area to help caching.  Avoid the need for a
converted_to_string bitfield by using EQ.  Cache arg in a
local and avoid some potential aliasing issues to help the
compiler.  Info array is now 0-origin, not 1-origin.
2017-06-04 08:42:53 -07:00
Philipp Stephani
e3b7eeade4 ; Fix off-by-one error 2017-06-03 11:42:07 +02:00
Philipp Stephani
7d413cb4da Fix a bug when using format field numbers
Previously styled_format overwrite the argument vector.  This is no
longer possible because there might be more than one specification per
argument.  Use the existing auxiliary info array instead.

* src/editfns.c (styled_format): Record arguments in the info
structure instead of overwriting them.
* test/src/editfns-tests.el (format-with-field): Add unit test.
2017-06-03 11:19:02 +02:00
Paul Eggert
0147cdd4d9 Document uniqueness limitation of ‘format’
* doc/lispref/strings.texi (Formatting Strings):
* src/editfns.c (Fformat):
Document that field numbers should be unique within a format.
2017-06-03 01:31:52 -07:00
Eli Zaretskii
5e6481bdc5 Fix cursor position in Dired buffers after dired-sort-toggle
* src/xdisp.c (display_and_set_cursor): Record cursor coordinates
even if the frame is marked as garbaged.  (Bug#27187)
2017-06-02 12:53:57 +03:00
Paul Eggert
8de2581a64 Limit format fields to more POSIX-like spec
* doc/lispref/strings.texi (Formatting Strings):
Don’t allow mixing numbered with unnumbered format specs.
* src/editfns.c (styled_format): Don’t bother checking for field 0,
since it doesn’t crash and the behavior is not specified.
* test/src/editfns-tests.el (format-with-field): Adjust tests to
match current doc.  Add more tests for out-of-range fields.
2017-06-01 16:06:38 -07:00
Paul Eggert
178d0cb5f5 Improve performance by avoiding strtoumax
This made (string-to-number "10") 20% faster on my old desktop,
an AMD Phenom II X4 910e running Fedora 25 x86-64.
* admin/merge-gnulib (GNULIB_MODULES): Remove strtoumax.
* lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
* lib/strtoul.c, lib/strtoull.c, lib/strtoumax.c, m4/strtoull.m4:
* m4/strtoumax.m4: Remove.
* src/editfns.c (str2num): New function.
(styled_format): Use it instead of strtoumax.  Use ptrdiff_t
instead of uintmax_t.  Check for integer overflow.
* src/lread.c (LEAD_INT, DOT_CHAR, TRAIL_INT, E_EXP):
Move to private scope and make them enums.
(string_to_number): Compute integer value directly during
first pass instead of revisiting it with strtoumax later.
2017-06-01 16:06:38 -07:00