aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Stephani2019-04-24 10:22:18 +0200
committerPhilipp Stephani2019-04-28 20:08:25 +0200
commit4d97e1a9ea35c3a1d9f03abb7a822d57f384c1a5 (patch)
tree0ed9322698c302f7e2190f570102cc41112c0d86
parent24f717a5d7de80fdd6aa061f35d04144fe1c4e10 (diff)
downloademacs-4d97e1a9ea35c3a1d9f03abb7a822d57f384c1a5.tar.gz
emacs-4d97e1a9ea35c3a1d9f03abb7a822d57f384c1a5.zip
Export major version of latest Emacs supported by emacs-module.h.
This is useful if module authors want to support multiple versions of emacs-module.h. * configure.ac (emacs_major_version): Define substitution. * src/emacs-module.h.in (EMACS_MAJOR_VERSION): Define macro. * doc/lispref/internals.texi (Module Initialization): Document EMACS_MAJOR_VERSION preprocessor macro. * test/data/emacs-module/mod-test.c (emacs_module_init): Verify behavior of EMACS_MAJOR_VERSION.
-rw-r--r--configure.ac2
-rw-r--r--doc/lispref/internals.texi11
-rw-r--r--etc/NEWS3
-rw-r--r--src/emacs-module.h.in2
-rw-r--r--test/data/emacs-module/mod-test.c5
5 files changed, 23 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 810c3219e4f..79fe0c98c6f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3697,6 +3697,8 @@ AC_SUBST_FILE([module_env_snippet_27])
3697module_env_snippet_25="$srcdir/src/module-env-25.h" 3697module_env_snippet_25="$srcdir/src/module-env-25.h"
3698module_env_snippet_26="$srcdir/src/module-env-26.h" 3698module_env_snippet_26="$srcdir/src/module-env-26.h"
3699module_env_snippet_27="$srcdir/src/module-env-27.h" 3699module_env_snippet_27="$srcdir/src/module-env-27.h"
3700emacs_major_version="${PACKAGE_VERSION%%.*}"
3701AC_SUBST(emacs_major_version)
3700 3702
3701### Use -lpng if available, unless '--with-png=no'. 3703### Use -lpng if available, unless '--with-png=no'.
3702HAVE_PNG=no 3704HAVE_PNG=no
diff --git a/doc/lispref/internals.texi b/doc/lispref/internals.texi
index 5ae71afbef2..cfeb492af40 100644
--- a/doc/lispref/internals.texi
+++ b/doc/lispref/internals.texi
@@ -1191,6 +1191,17 @@ grow with new Emacs releases. Given the version of Emacs, the module
1191can use only the parts of the module @acronym{API} that existed in 1191can use only the parts of the module @acronym{API} that existed in
1192that version, since those parts are identical in later versions. 1192that version, since those parts are identical in later versions.
1193 1193
1194@file{emacs-module.h} defines a preprocessor macro
1195@code{EMACS_MAJOR_VERSION}. It expands to an integer literal which is
1196the latest major version of Emacs supported by the header.
1197@xref{Version Info}. Note that the value of
1198@code{EMACS_MAJOR_VERSION} is a compile-time constant and does not
1199represent the version of Emacs that is currently running and has
1200loaded your module. If you want your module to be compatible with
1201various versions of @file{emacs-module.h} as well as various versions
1202of Emacs, you can use conditional compilation based on
1203@code{EMACS_MAJOR_VERSION}.
1204
1194We recommend that modules always perform the compatibility 1205We recommend that modules always perform the compatibility
1195verification, unless they do their job entirely in the initialization 1206verification, unless they do their job entirely in the initialization
1196function, and don't access any Lisp objects or use any Emacs functions 1207function, and don't access any Lisp objects or use any Emacs functions
diff --git a/etc/NEWS b/etc/NEWS
index cf6f4fea3e9..9b32d720b62 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1933,6 +1933,9 @@ convert between timespec structures and Emacs Lisp time values.
1933'extract_big_integer' to create and extract arbitrary-size integer 1933'extract_big_integer' to create and extract arbitrary-size integer
1934values. 1934values.
1935 1935
1936** emacs-module.h now defines a macro EMACS_MAJOR_VERSION that expands
1937to the major version of the latest Emacs supported by the header.
1938
1936 1939
1937* Changes in Emacs 27.1 on Non-Free Operating Systems 1940* Changes in Emacs 27.1 on Non-Free Operating Systems
1938 1941
diff --git a/src/emacs-module.h.in b/src/emacs-module.h.in
index fbc62a61ef4..9955e30eb7a 100644
--- a/src/emacs-module.h.in
+++ b/src/emacs-module.h.in
@@ -32,6 +32,8 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
32#include <gmp.h> 32#include <gmp.h>
33#endif 33#endif
34 34
35#define EMACS_MAJOR_VERSION @emacs_major_version@
36
35#if defined __cplusplus && __cplusplus >= 201103L 37#if defined __cplusplus && __cplusplus >= 201103L
36# define EMACS_NOEXCEPT noexcept 38# define EMACS_NOEXCEPT noexcept
37#else 39#else
diff --git a/test/data/emacs-module/mod-test.c b/test/data/emacs-module/mod-test.c
index b7007bd80ff..a9154fa167d 100644
--- a/test/data/emacs-module/mod-test.c
+++ b/test/data/emacs-module/mod-test.c
@@ -445,6 +445,11 @@ bind_function (emacs_env *env, const char *name, emacs_value Sfun)
445int 445int
446emacs_module_init (struct emacs_runtime *ert) 446emacs_module_init (struct emacs_runtime *ert)
447{ 447{
448 /* Check that EMACS_MAJOR_VERSION is defined and an integral
449 constant. */
450 char dummy[EMACS_MAJOR_VERSION];
451 assert (27 <= sizeof dummy);
452
448 if (ert->size < sizeof *ert) 453 if (ert->size < sizeof *ert)
449 { 454 {
450 fprintf (stderr, "Runtime size of runtime structure (%"pT" bytes) " 455 fprintf (stderr, "Runtime size of runtime structure (%"pT" bytes) "