1. 12 Jun, 2017 1 commit
    • Philipp Stephani's avatar
      Implement module assertions for users · cf971327
      Philipp Stephani authored
      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.
      cf971327
  2. 04 Jun, 2017 1 commit
    • Philipp Stephani's avatar
      Rework printing of module functions · 3b0080de
      Philipp Stephani authored
      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'.
      3b0080de
  3. 20 May, 2017 1 commit
    • Philipp Stephani's avatar
      Reimplement module functions · 31fded03
      Philipp Stephani authored
      Instead of a lambda, create a new type containing all data required to
      call the function, and support it in the evaluator.  Because this type
      now also needs to store the function documentation, it is too big for
      Lisp_Misc; use a pseudovector instead.  That also has the nice benefit
      that we don't have to add special support to the garbage collector.
      
      Since the new type is user-visible, give it a predicate.
      
      Now we can easily support 'help-function-args' and 'func-arity'; add
      unit tests for these.
      
      * src/lisp.h (allocate_module_function, MODULE_FUNCTIONP)
      (XMODULE_FUNCTION): New pseudovector type 'module function'.
      
      * src/eval.c (FUNCTIONP): Also treat module functions as functions.
      (funcall_lambda, Ffuncall, eval_sub): Add support for calling module
      functions.
      (Ffunc_arity): Add support for detecting the arity of module
      functions.
      
      * src/emacs-module.c (module_make_function): Adapt to new structure.
      Return module function object directly instead of wrapping it in a
      lambda; remove FIXME.
      (funcall_module): New function to call module functions.  Replaces
      `internal--module-call' and is called directly from eval.c.
      (syms_of_module): Remove internal helper function, which is no longer
      needed.
      (module_function_arity): New helper function.
      
      * src/data.c (Ftype_of): Adapt to new implementation.
      (Fmodule_function_p, syms_of_data): New user-visible function.  Now
      that module functions are first-class objects, they deserve a
      predicate.  Define it even if not compiled with --enable-modules so
      that Lisp code doesn't have to check for the function's existence.
      
      * src/doc.c (Fdocumentation): Support module functions.
      
      * src/print.c (print_object): Adapt to new implementation.
      
      * src/alloc.c (mark_object): Specialized garbage collector support is
      no longer needed.
      
      * lisp/help.el (help-function-arglist): Support module functions.
      While there, simplify the arity calculation by using `func-arity',
      which does the right thing for all kinds of functions.
      
      * test/data/emacs-module/mod-test.c: Amend docstring so we can test
      the argument list.
      
      * test/src/emacs-module-tests.el (mod-test-sum-docstring): Adapt to
      new docstring.
      (mod-test-non-local-exit-signal-test): Because `internal--module-call'
      is gone, the backtrace has changed and no longer leaks the
      implementation.
      (module--func-arity): New test for `func-arity'.
      (module--help-function-arglist): New test for `help-function-arglist'.
      31fded03
  4. 19 May, 2017 1 commit
    • Philipp Stephani's avatar
      Fix module tests on some systems · 45944e01
      Philipp Stephani authored
      If dladdr(3) isn't available or didn't work, the printed
      representation of a module function will not include the file name,
      but only the address.  Make the tests pass in that case.
      
      * test/src/emacs-module-tests.el (module-function-object): Fix match for
      module function printed representation
      45944e01
  5. 06 May, 2017 3 commits
    • Eli Zaretskii's avatar
      ; Fix last change · b104d764
      Eli Zaretskii authored
      * test/src/emacs-module-tests.el (module-function-object): Fix thinko
      in last change.
      b104d764
    • Eli Zaretskii's avatar
      Fix last change for MS-Windows · 89b5a828
      Eli Zaretskii authored
      * test/src/emacs-module-tests.el (module-function-object): Port to
      MS-Windows.
      89b5a828
    • Philipp Stephani's avatar
      Introduce new misc type for module function · a3e96940
      Philipp Stephani authored
      This resolves a couple of FIXMEs in emacs-module.c.
      
      * src/lisp.h (MODULE_FUNCTIONP, XMODULE_FUNCTION): New functions.
      
      * src/alloc.c (make_module_function): New function.
      (mark_object): GC support.
      
      * src/data.c (Ftype_of, syms_of_data): Handle module function type.
      
      * src/print.c (print_object): Print support for new type.
      
      * src/emacs-module.c (module_make_function, Finternal_module_call):
      Use new module function type, remove FIXMEs.
      (module_format_fun_env): Adapt and give it external linkage.
      
      * test/src/emacs-module-tests.el (module-function-object): Add unit
      test.
      a3e96940
  6. 29 Apr, 2017 1 commit
    • Philipp Stephani's avatar
      Integrate module test with normal test suite · bfc0f610
      Philipp Stephani authored
      * test/Makefile.in (ELFILES): Exclude module test if modules aren't
      configured.
      (EMACS_TEST_DIRECTORY): Expand test directory so that it's set
      correctly even if Emacs changes the current directory.
      ($(srcdir)/src/emacs-module-tests.log)
      ($(test_module)): Proper dependency tracking for test module.
      
      * test/data/emacs-module/Makefile (ROOT): Adapt to new location.
      Remove 'check' target and EMACS variable, which are no longer
      necessary.
      (SO): Change to include period.
      
      * test/src/emacs-module-tests.el (mod-test): Use EMACS_TEST_DIRECTORY
      environment variable to reliably find test data.
      
      * configure.ac (HAVE_MODULES, MODULES_SUFFIX): Add necessary
      substitutions.
      bfc0f610
  7. 26 Mar, 2017 1 commit
  8. 01 Jan, 2017 1 commit
  9. 01 Jan, 2016 1 commit
  10. 06 Dec, 2015 2 commits
    • Paul Eggert's avatar
      Port mod-test to 32-bit Emacs --without-wide-int · ace6c253
      Paul Eggert authored
      * modules/mod-test/test.el (mod-test-sum-test):
      Bring back the 2**29 tests, but port them to 32-bit Emacs
      --without-wide-int.
      ace6c253
    • Paul Eggert's avatar
      Port mod-test to x86-64 GNU/Linux running 32-bit · 2b3f5de2
      Paul Eggert authored
      * modules/mod-test/test.el (mod-test-sum-test):
      Don’t attempt to match descriptions to operating systems.
      It didn’t work on Fedora x86-64 running a 32-bit executable,
      and it’s not worth the trouble anyway.
      Port to 32-bit platforms by removing an assumption about
      fixnum widths.
      2b3f5de2
  11. 02 Dec, 2015 1 commit
    • Eli Zaretskii's avatar
      More emacs-module.c fixes for wide ints · 36dbe6fc
      Eli Zaretskii authored
      * 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.
      36dbe6fc
  12. 01 Dec, 2015 1 commit
    • Eli Zaretskii's avatar
      Fix emacs-module.c for wide ints · bdebeb77
      Eli Zaretskii authored
      * 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.
      bdebeb77
  13. 29 Nov, 2015 1 commit
    • Ken Brown's avatar
      Update mod-test-sum-test · ff21f455
      Ken Brown authored
      * modules/mod-test/test.el (mod-test-sum-test): Update to
      accommodate the lack of dladdr on Cygwin.
      ff21f455
  14. 27 Nov, 2015 1 commit
  15. 24 Nov, 2015 1 commit
    • Eli Zaretskii's avatar
      Add one more mod-test test · 33ec2ff0
      Eli Zaretskii authored
      * modules/mod-test/test.el (mod-test-sum-test): Test the error
      signaled when the function is invoked with a wrong number of
      arguments.
      33ec2ff0
  16. 19 Nov, 2015 2 commits
  17. 18 Nov, 2015 1 commit
    • Aurélien Aptel's avatar
      Add dynamic module test and helper script · 955e25db
      Aurélien Aptel authored
      
      
      Add 'modhelp.py' script (python2) to automate module testing and
      module generation.
      
      To build and test all modules in the modules/ dir
        $ ./modhelp.py test
      
      To generate a module from template code (good starting point)
        $ ./modhelp init mynewtestmodule
      
      See the script -h option for more documentation.
      
      * modules/modhelp.py: New module helper script.
      * modules/mod-test/Makefile: New file. Makefile for the test module.
      * modules/mod-test/mod-test.c: New file. Test module source file.
      * modules/mod-test/test.el: New file. ert test suite for the test module.
      * modules/.gitignore: New file. Local .gitignore file.
      Co-authored-by: default avatarPhilipp Stephani <phst@google.com>
      955e25db