summaryrefslogtreecommitdiff
path: root/src/emacs-module.c
Commit message (Collapse)AuthorAgeFilesLines
* Update copyright year to 2016Paul Eggert2016-01-011-1/+1
| | | | Run admin/update-copyright.
* ; Clarify comment added in previous commit.Eli Zaretskii2015-12-211-1/+1
|
* Add FIXME comment re stack overflow and modulesPaul Eggert2015-12-211-0/+3
|
* Revert some recent emacs-module commentaryPaul Eggert2015-12-201-7/+4
| | | | | Most of the recently-added commentary was incorrect, due to the possibility of stack overflow.
* Improve commentary for emacs-module.cPhilipp Stephani2015-12-201-2/+6
| | | | | | | | * src/lisp.h: Document emacs-module.c assumptions about EQ and NILP. * src/emacs-module.c (module_non_local_exit_get): Document that we cannot use the current implementation. (module_is_not_nil, module_eq): Document assumptions about EQ and NILP.
* Remove attempt to use C11 threadsPaul Eggert2015-12-151-10/+3
| | | | | | | | | | C11 threads are not needed for Emacs now, and their use is causing hassles on FreeBSD 10.x. Problem reported by Ashish SHUKLA in: http://lists.gnu.org/archive/html/emacs-devel/2015-12/msg00648.html * configure.ac: Do not check for C11 threads. Remove unnecessary fiddling with CPPFLAGS when configuring pthreads. * src/emacs-module.c (main_thread, check_main_thread) (module_init): Do not worry about C11 threads.
* Spelling fixesPaul Eggert2015-12-071-3/+3
| | | | | | | | | | * doc/misc/calc.texi (Predefined Units): Use the bland modern scientific style for spelling the units “ampere” and “angstrom” rather than the older style “Ampere” and “Ångstrom”. The latter spelling was wrong anyway (it should have been “Ångström”). * lisp/emacs-lisp/ert.el (ert--explain-equal-rec): Fix misspelling of ‘atom’ in code.
* Improve module interface when WIDE_EMACS_INTPaul Eggert2015-12-061-102/+116
| | | | | | | | | | | | | | | | | | | | | | | | | * src/emacs-module.c (plain_values): New constant. (module_nil): Now a constant. (Finternal_module_call, value_to_lisp_bits, lisp_to_value_bits) (syms_of_module): Use if, not #ifdef, so that both sides are checked at compile-time, and so that GCC doesn’t complain about an unused var in the typical case. Also, depend on plain_values, not on WIDE_EMACS_INT; the code shouldn’t assume that WIDE_EMACS_INT implies !USE_LSB_TAG. (value_to_lisp_bits, lisp_to_value_bits): New functions. Sign-extend integers rather than zero-extending them, as small negative integers are more likely. (value_to_lisp, lisp_to_value): Rewrite in terms of the new *_bits functions. (HAVE_STRUCT_ATTRIBUTE_ALIGNED): Define to 0 if not already defined. (mark_modules): Remove. All uses removed. (lisp_to_value): Don’t assume Fcons returns a pointer aligned to GCALIGNMENT. (syms_of_module): Check that module_nil converts to Qnil. * src/lisp.h (lisp_h_XSYMBOL, XSYMBOL): Use signed conversion, since we prefer signed to unsigned when either will do. (TAG_PTR): Sign-extend pointers when USE_LSB_TAG, as this is a bit better for emacs-module.c.
* More emacs-module.c fixes for wide intsEli Zaretskii2015-12-021-2/+2
| | | | | | | | | | * src/emacs-module.c (value_to_lisp) [WIDE_EMACS_INT]: Use unsigned data types to manipulate pointers, to avoid sign extension coming after us with a vengeance. * modules/mod-test/test.el (mod-test-sum-test): Add tests for Emacs with wide ints that verify integer values near the critical value that requires us to switch to a cons cell.
* Fix emacs-module.c for wide intsEli Zaretskii2015-12-011-10/+14
| | | | | | | | | | * src/emacs-module.c (lisp_to_value): Compare the produced value with the original Lisp object, not with the one potentially converted into a Lisp_Cons. Fixes assertion violations when working with integers larger than fit into a 32-bit value. * modules/mod-test/test.el (mod-test-sum-test): Add tests for large integers, to test --with-wide-int.
* Fix last changeEli Zaretskii2015-11-301-7/+8
| | | | | * src/emacs-module.c (lisp_to_value, value_to_lisp) [WIDE_EMACS_INT]: Avoid compiler warnings.
* Rely on conservative stack scanning to find "emacs_value"sStefan Monnier2015-11-301-172/+146
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/emacs-module.c (struct emacs_value_tag) (struct emacs_value_frame, struct emacs_value_storage): Remove. (value_frame_size): Remove constant. (struct emacs_env_private): Use Lisp_Object for non_local_exit info. (lisp_to_value): Remove first arg. (module_nil): New constant. Use it instead of NULL when returning an emacs_value. (module_make_function): Adjust to new calling convention of Qinternal_module_call. (DEFUN): Receive args in an array rather than a list. Use SAFE_ALLOCA rather than xnmalloc. Skip the lisp_to_value loop when we don't have WIDE_EMACS_INT. Adjust to new type of non_local_exit info. (module_non_local_exit_signal_1, module_non_local_exit_throw_1): Adjust to new type of non_local_exit info. (ltv_mark) [WIDE_EMACS_INT]: New constant. (value_to_lisp, lisp_to_value): Rewrite. (initialize_frame, initialize_storage, finalize_storage): Remove functions. (allocate_emacs_value): Remove function. (mark_modules): Gut it. (initialize_environment): Don't initialize storage any more. Keep the actual env object on Vmodule_environments. (finalize_environment): Don't finalize storage any more. (syms_of_module): Initialize ltv_mark and module_nil. * src/emacs-module.h (emacs_value): Make it more clear that this type is really opaque, including the fact that NULL may not be valid. * modules/mod-test/mod-test.c (Fmod_test_signal, Fmod_test_throw): Don't assume that NULL is a valid emacs_value.
* Spelling and grammar fixesPaul Eggert2015-11-291-1/+1
|
* Simplify the prologue of emacs-module.c functionsPhilipp Stephani2015-11-281-86/+46
| | | | | | | | | | | | | * emacs-module.c (MODULE_FUNCTION_BEGIN): New macro. (module_make_global_ref) (module_free_global_ref, module_make_function, module_funcall) (module_intern, module_type_of, module_extract_integer) (module_make_integer, module_extract_float, module_make_float) (module_copy_string_contents, module_make_string) (module_make_user_ptr, module_get_user_ptr, module_set_user_ptr) (module_get_user_finalizer, module_set_user_finalizer) (module_vec_set, module_vec_get, module_vec_size): Use new helper macro MODULE_FUNCTION_BEGIN.
* Don't reject module calls with no argumentsEli Zaretskii2015-11-281-2/+3
| | | | * src/emacs-module.c (Finternal_module_call): Allow ARGLIST be nil.
* Make module-call be visible from LispPhilipp Stephani2015-11-281-19/+17
| | | | | | | | * src/emacs-module.c (module_make_function): Use internal--module-call. (Finternal_module_call): Renamed from Fmodule_call. Add safety checks. (syms_of_module): DEFSYM save-value-p and save-pointer-p. Do defsubr internal--module-call.
* * src/emacs-module.c (struct env_storage): DeleteStefan Monnier2015-11-271-66/+63
| | | | | | | | | (struct emacs_runtime_private): Keep an emacs_env instead. (Fmodule_load, Fmodule_call): Declare emacs_env_private separately. (initialize_environment): Split the arg in two. Adjust all callers. Only store the private part in Vmodule_environments. (finalize_environment): Change the arg to only be the private env. Adjust all callers.
* Improve handling of signals and 'throw' in modulesEli Zaretskii2015-11-271-37/+96
| | | | | | | | | | | | | | | | | | | | * src/emacs-module.c: Add commentary explaining how to write functions in this file. (module_make_global_ref, module_free_global_ref) (module_non_local_exit_signal, module_non_local_exit_throw) (module_make_function, module_funcall, module_intern) (module_type_of, module_is_not_nil, module_eq) (module_extract_integer, module_make_integer) (module_extract_float, module_make_float) (module_copy_string_contents, module_make_string) (module_make_user_ptr, module_get_user_ptr, module_set_user_ptr) (module_get_user_finalizer, module_set_user_finalizer) (module_vec_set, module_vec_get, module_vec_size) (module_non_local_exit_signal_1, module_non_local_exit_throw_1): Do nothing and return with failure indication immediately, if some previous module call signaled an error or wants to throw. See http://lists.gnu.org/archive/html/emacs-devel/2015-11/msg02133.html for the relevant discussions.
* Fix module_format_fun_env when dynlib_addr failsPaul Eggert2015-11-241-3/+3
| | | | | | * src/emacs-module.c (module_format_fun_env): exprintf doesn’t support %p, so use %x. Reported by Eli Zaretskii in: http://lists.gnu.org/archive/html/emacs-devel/2015-11/msg02122.html
* Simplify module_make_functionPaul Eggert2015-11-231-10/+5
| | | | | * src/emacs-module.c (module_make_function): Simplify by calling build_unibyte_string.
* Port better to FreeBSD’s dlfunc vs dlsymPaul Eggert2015-11-231-2/+3
| | | | | | | | | | | This avoids warnings when converting between void * and function pointers, which strict C11 does not allow. * configure.ac (dlfunc): Check for existence. * src/dynlib.c (dlfunc) [!HAVE_DLFUNC]: New macro. (dynlib_func): New function. * src/dynlib.h (dynlib_function_ptr, dynlib_func): New decls. * src/emacs-module.c (Fmodule_load): Use dynlib_func, not dynlib_sym, for function pointers.
* module_format_fun_env fixesPaul Eggert2015-11-231-19/+13
| | | | | | | | | | * src/doprnt.c (exprintf) [HAVE_MODULES]: Also define in this case. * src/emacs-module.c (module_format_fun_env): Convert path and sym to UTF-8. Don’t use VLAs, as the C11 standard says they’re optional, and anyway they can cause core dumps with large allocations. Use exprintf rather than snprintf, as exprintf handles arbitrarily long strings. Simplify the code a bit.
* Improve how non-ASCII strings are accepted from modulesEli Zaretskii2015-11-231-10/+6
| | | | | | | * src/emacs-module.c (module_make_function, module_make_string): Build a unibyte Lisp string and then decode it by UTF-8, instead of building a multibyte string without decoding. This is more tolerant to deviations from UTF-8.
* Port recent module changes to pickier compilersPaul Eggert2015-11-231-2/+4
| | | | | * src/emacs-module.c (module_make_function) (module_make_string): Add casts to fix pointer signedness issues.
* Fix how strings are accepted from modulesPhilipp Stephani2015-11-231-13/+39
| | | | | | | * emacs-module.c (module_make_function, module_make_string): Use make_multibyte_string. (module_copy_string_contents): Encode before reading the byte size. Return false if and only if an error occurred.
* Add a few safety checks when ENABLE_CHECKINGPaul Eggert2015-11-211-10/+2
| | | | | | | | | | | | | | | | | | | | | | This was motivated by the recent addition of module code, which added some ENABLE_CHECKING-enabled checks that are useful elsewhere too. * src/alloc.c (compact_font_cache_entry): * src/fns.c (sweep_weak_table): * src/lread.c (oblookup): Use gc_asize rather than doing it by hand. * src/emacs-module.c (module_make_global_ref) (module_free_global_ref, module_vec_size): Omit assertions that lisp.h now checks. * src/lisp.h (XFASTINT, ASIZE): In functional implementations, check that the result is nonnegative. Use eassume, as this info can help a bit when optimizing production code. (XSYMBOL) [!USE_LSB_TAG]: Assert that argument is a symbol, to be consistent with the USE_LSB_TAG case. (gc_asize): New function, when ASIZE is needed in the gc. (gc_aset): Use it. (HASH_TABLE_P): Move definition up, so that it can be used ... (XHASH_TABLE): ... here, to assert that the arg is a hash table.
* Simplify recording of main thread's ID on MS-WindowsEli Zaretskii2015-11-211-28/+7
| | | | | | | | | | | | | | | | | | | | | * src/w32term.c (w32_initialize): * src/w32console.c (initialize_w32_display): * src/w32fns.c (globals_of_w32fns): Don't record the main thread ID independently for each type of session (GUI, TTY, batch). * src/w32term.c (w32_init_main_thread): New function, records the main thread's thread ID. * src/w32term.h: Add prototype for w32_init_main_thread. * src/emacs.c (main) [WINDOWSNT]: Call w32_init_main_thread. * src/emacs-module.c [WINDOWSNT]: Rename main_thread_id to main_thread, for consistency with other threading libraries. All users changed. Include w32term.h. (check_main_thread) [WINDOWSNT]: Simplify the test: no need to make sure the main thread is alive, as we hold a handle on it opened by w32_init_main_thread. (module_init) [WINDOWSNT]: Reuse the thread ID recorded by w32_init_main_thread, instead of calling the requisite APIs once more.
* Fix double-decrement bug when freeing global refsPaul Eggert2015-11-201-1/+3
| | | | | | * src/emacs-module.c (module_free_global_ref): Add a FIXME comment about error reporting. Fix a recently-introduced typo that double-decremented the refcount.
* Fix reindent-introduced typo in module codePaul Eggert2015-11-201-17/+22
| | | | | | * src/emacs-module.c (MODULE_SETJMP_1): Fix typo that I introduced while reindenting the code earlier, and add a comment explaining the unusual use of do-while here.
* Module function arg counts are ptrdiff_t, not intPaul Eggert2015-11-201-40/+35
| | | | | | | | | | | | | | | | | | | | | | * src/emacs-module.c (struct module_fun_env) (module_make_function, module_funcall, Fmodule_call): * src/emacs-module.h (struct emacs_runtime, struct emacs_env_25): Use ptrdiff_t, not int, for arg counts. * src/emacs-module.c (module_make_function): Don’t bother checking arity against MOST_POSITIVE_FIXNUM, as that’s unnecessary here. Make the checking clearer by negating it. (module_make_function, Fmodule_call): No need to use xzalloc since the storage doesn’t need to be cleared. (module_funcall): Don’t use VLA, since C11 doesn’t guarantee support for it, and many implementations are buggy with large VLAs anyway. Use SAFE_ALLOCA_LISP instead. (module_vec_set): Don’t crash if i < 0. (module_vec_get): Don’t crash if i < MOST_NEGATIVE_FIXNUM. (module_vec_set, module_vec_get): Do fixnum checks only when i is out of array bounds, for efficiency in the usual case. (Fmodule_load): Simplify fixnum range check. (Fmodule_call): Simplify arity check. Use xnmalloc to detect integer overflow in array allocation size.
* Include-file tweaks for modulesPaul Eggert2015-11-201-2/+4
| | | | | | | | | * src/dynlib.c, src/emacs-module.c: Include <config.h> first. * src/dynlib.h: Do not include config.h. It’s every .c file’s responsibility to include config.h first. * src/emacs-module.c: Include emacs-module.h immediately after config.h, to test that emacs-module.h doesn’t depend on include files other than config.h.
* Simplify push_handler and profile its mallocPaul Eggert2015-11-191-2/+2
| | | | | | | | | | | | | | * src/lisp.h (PUSH_HANDLER): Remove. All callers changed to use push_handler directly. * src/eval.c (internal_condition_case) (internal_condition_case_1, internal_condition_case_2) (internal_condition_case_n): Use same pattern as for other invokers of push_handler. (push_handler, push_handler_nosignal): Use call-by-value instead of call-by-reference. All uses changed. (push_handler): Simplify by rewriting in terms of push_handler_nosignal. (push_handler_nosignal): Profile any newly allocated memory.
* Omit unnecessary clear in Fmodule_loadPaul Eggert2015-11-191-13/+10
| | | | | | | * src/emacs-module.c (Fmodule_load): Simplify and avoid unnecessary initialization of priv member to 0. * src/emacs-module.c: (module_vec_set, module_vec_get, module_vec_size)
* Prefer signed integer types in module codePaul Eggert2015-11-191-29/+17
| | | | | | | | | | | | | | | | | | Generally speaking, at the C level the Emacs source code prefers signed types like ‘ptrdiff_t’ to unsigned types like ‘size_t’, partly to avoid the usual signedness confusion when comparing values. Change the module API to follow this convention. Use ‘int’ for small values that can’t exceed INT_MAX. * modules/mod-test/mod-test.c (Fmod_test_globref_make) (Fmod_test_string_a_to_b, Fmod_test_vector_fill) (Fmod_test_vector_eq): * src/emacs-module.c (struct emacs_value_frame) (module_make_global_ref, module_free_global_ref) (module_copy_string_contents, module_make_string) (module_vec_set, module_vec_get, module_vec_size): * src/emacs-module.h (struct emacs_runtime, struct emacs_env_25): * src/lread.c (suffix_p): Prefer signed to unsigned integer types.
* Omit ‘const’ on localsPaul Eggert2015-11-191-35/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | Remove ‘const’ qualifier from locals that were newly added. We don’t normally bother declaring locals with ‘const’ even though they are not modified, for the same reason we don’t bother declaring them with ‘register’ even though their addresses are not taken; the advantage in compile-time checking isn’t worth the loss of readability. * modules/mod-test/mod-test.c (Fmod_test_non_local_exit_funcall) (Fmod_test_vector_fill, Fmod_test_vector_eq): * src/emacs-module.c (MODULE_SETJMP_1) (module_make_global_ref, module_free_global_ref) (module_non_local_exit_get, module_make_function) (module_extract_integer, module_extract_float) (module_get_user_ptr, module_set_user_ptr) (module_get_user_finalizer, module_set_user_finalizer) (module_vec_get, Fmodule_call) (module_non_local_exit_signal_1) (module_non_local_exit_throw_1, lisp_to_value) (finalize_storage, allocate_emacs_value, mark_modules) (module_handle_signal, module_handle_throw) (module_format_fun_env): * src/eval.c (push_handler, push_handler_nosignal) (init_handler): * src/lread.c (suffix_p): Omit unnecessary ‘const’.
* Prefer intmax_t to int64_t in module codePaul Eggert2015-11-191-10/+3
| | | | | | | | | | | * modules/mod-test/mod-test.c (sum, Fmod_test_sum): * src/emacs-module.c (module_extract_integer) (module_make_integer): * src/emacs-module.h (struct emacs_env_25): Prefer intmax_t to int64_t. This doesn’t change the generated code on any of the machines Emacs currently ports to, but it’s at least in theory more future-proof as C99 doesn’t guarantee that int64_t exists.
* Rename module.c to emacs-module.c, etc.Paul Eggert2015-11-191-0/+1160
* src/emacs-module.c: Rename from src/module.c. * src/emacs-module.h: Rename from src/module.h. All uses changed.