From 85bd8cfcdbf530e2aabc39494ec2f2a70507c245 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerd=20M=C3=B6llmann?= Date: Fri, 14 Oct 2022 13:15:24 +0200 Subject: [PATCH] Mapping over symbols in a package, mapatoms --- src/lisp.h | 1 + src/lread.c | 13 +------------ src/pkg.c | 12 ++++++++++++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/lisp.h b/src/lisp.h index 5fde67310e3..9bd66eaedca 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -2263,6 +2263,7 @@ extern bool pkg_intern_name_c_string (const char *p, ptrdiff_t len, Lisp_Object extern void pkg_early_intern_symbol (Lisp_Object symbol); extern Lisp_Object pkg_lookup_c_string (const char *ptr, ptrdiff_t nchars, ptrdiff_t nbytes); extern void pkg_break (void); +extern void pkg_map_symbols (Lisp_Object function, Lisp_Object oackage); extern bool package_system_ready; diff --git a/src/lread.c b/src/lread.c index 365e47d1468..d72fa3471fb 100644 --- a/src/lread.c +++ b/src/lread.c @@ -4948,23 +4948,12 @@ map_obarray (Lisp_Object obarray, void (*fn) (Lisp_Object, Lisp_Object), Lisp_Ob } } -static void -mapatoms_1 (Lisp_Object sym, Lisp_Object function) -{ - eassert (package_system_ready); - call1 (function, sym); -} - DEFUN ("mapatoms", Fmapatoms, Smapatoms, 1, 2, 0, doc: /* Call FUNCTION on every symbol in OBARRAY. OBARRAY defaults to the value of `obarray'. */) (Lisp_Object function, Lisp_Object obarray) { - eassert (package_system_ready); - if (NILP (obarray)) obarray = Vobarray; - obarray = check_obarray (obarray); - - map_obarray (obarray, mapatoms_1, function); + pkg_map_symbols (function, obarray); return Qnil; } diff --git a/src/pkg.c b/src/pkg.c index 09fe8408e3e..fc11388f5d5 100644 --- a/src/pkg.c +++ b/src/pkg.c @@ -721,6 +721,18 @@ pkg_keywordp (Lisp_Object obj) return !NILP (Fmemq (obj, early_keywords)); } + +/* Map FUNCTION over all symbols in PACKAGE. */ + +void +pkg_map_symbols (Lisp_Object function, Lisp_Object package) +{ + eassert (package_system_ready); + package = package_or_default (package); + FOR_EACH_KEY_VALUE (it, XPACKAGE (package)->symbols) + call1 (function, it.key); +} + /*********************************************************************** Lisp functions -- 2.39.2