summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2020-10-13 06:51:06 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2020-10-13 06:51:06 +0200
commit12175a339e2a2214fdd0ab4e16d8d8b1e92a78d3 (patch)
treec68e82a585d8a760b569b536d8951e18166a9d9d /src
parent45cb0403deeba1cc121147b1884e7fea6cd15338 (diff)
downloademacs-12175a339e2a2214fdd0ab4e16d8d8b1e92a78d3.tar.gz
Allow creating unibyte strings from Emacs modules
* doc/lispref/internals.texi (Module Values): Document make_unibyte_string (bug#34873). * src/emacs-module.c (module_make_unibyte_string): New function. (initialize_environment): Export it. * src/module-env-25.h: Define it. * test/data/emacs-module/mod-test.c (Fmod_test_return_unibyte): Test it. * test/src/emacs-module-tests.el (module/unibyte): Test it.
Diffstat (limited to 'src')
-rw-r--r--src/emacs-module.c13
-rw-r--r--src/module-env-25.h5
2 files changed, 18 insertions, 0 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c
index 3581daad112..ba9de58de54 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -791,6 +791,18 @@ module_make_string (emacs_env *env, const char *str, ptrdiff_t len)
}
static emacs_value
+module_make_unibyte_string (emacs_env *env, const char *str, ptrdiff_t length)
+{
+ MODULE_FUNCTION_BEGIN (NULL);
+ if (! (0 <= length && length <= STRING_BYTES_BOUND))
+ overflow_error ();
+ Lisp_Object lstr = make_uninit_string (length);
+ memcpy (SDATA (lstr), str, length);
+ SDATA (lstr)[length] = 0;
+ return lisp_to_value (env, lstr);
+}
+
+static emacs_value
module_make_user_ptr (emacs_env *env, emacs_finalizer fin, void *ptr)
{
MODULE_FUNCTION_BEGIN (NULL);
@@ -1464,6 +1476,7 @@ initialize_environment (emacs_env *env, struct emacs_env_private *priv)
env->make_float = module_make_float;
env->copy_string_contents = module_copy_string_contents;
env->make_string = module_make_string;
+ env->make_unibyte_string = module_make_unibyte_string;
env->make_user_ptr = module_make_user_ptr;
env->get_user_ptr = module_get_user_ptr;
env->set_user_ptr = module_set_user_ptr;
diff --git a/src/module-env-25.h b/src/module-env-25.h
index 97c7787da34..01c06d5400d 100644
--- a/src/module-env-25.h
+++ b/src/module-env-25.h
@@ -102,6 +102,11 @@
const char *str, ptrdiff_t len)
EMACS_ATTRIBUTE_NONNULL(1, 2);
+ /* Create a unibyte Lisp string from a string. */
+ emacs_value (*make_unibyte_string) (emacs_env *env,
+ const char *str, ptrdiff_t len)
+ EMACS_ATTRIBUTE_NONNULL(1, 2);
+
/* Embedded pointer type. */
emacs_value (*make_user_ptr) (emacs_env *env,
void (*fin) (void *) EMACS_NOEXCEPT,