From 20fd47e741342e160d774ae6afee7182bba0de65 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 19 Nov 2025 11:18:13 -0800 Subject: Fix mis-declarations of non-const functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem for mpz_get_d_rounded reported by Helmut Eller in: https://lists.gnu.org/r/emacs-devel/2025-11/msg00795.html * lib-src/make-docfile.c (DEFUN_pure): New constant. (write_globals, scan_c_stream): Support "attributes: pure". * src/bignum.h (mpz_get_d_rounded): * src/data.c (Fsymbolp, Fmodule_function_p, Fintegerp, Fnumberp): * src/lisp.h (bignum_to_double, bignum_to_intmax) (bignum_to_uintmax, bignum_bufsize): Now pure, not const, since they depend on current state. For example, Fsymbolp now inspects symbols_with_pos_enabled, and the bignum functions inspect bignum contents in memory. * src/data.c (Feq): * src/xfaces.c (Fface_attribute_relative_p): No longer const, since they might abort when debugging. * src/pdumper.h (pdumper_object_p, pdumper_cold_object_p) (pdumper_find_object_type, pdumper_object_p_precise): These are not const functions. But there is no need to declare them to be pure, either, as they’re inline so the compiler can figure it out. --- lib-src/make-docfile.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lib-src') diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c index 6243f666955..d0ea463f299 100644 --- a/lib-src/make-docfile.c +++ b/lib-src/make-docfile.c @@ -577,7 +577,13 @@ struct global }; /* Bit values for FLAGS field from the above. Applied for DEFUNs only. */ -enum { DEFUN_noreturn = 1, DEFUN_const = 2, DEFUN_noinline = 4 }; +enum + { + DEFUN_noreturn = 1, + DEFUN_const = 2, + DEFUN_noinline = 4, + DEFUN_pure = 8, + }; /* All the variable names we saw while scanning C sources in `-g' mode. */ @@ -752,6 +758,8 @@ write_globals (void) fputs (" ATTRIBUTE_COLD", stdout); if (globals[i].flags & DEFUN_const) fputs (" ATTRIBUTE_CONST", stdout); + if (globals[i].flags & DEFUN_pure) + fputs (" ATTRIBUTE_PURE", stdout); puts (";"); } @@ -1062,7 +1070,7 @@ scan_c_stream (FILE *infile) attributes: attribute1 attribute2 ...) (Lisp_Object arg...) - Now only `const', `noinline' and `noreturn' attributes + Now only 'const', 'noinline', 'noreturn', and 'pure' attributes are used. */ /* Advance to the end of docstring. */ @@ -1110,6 +1118,8 @@ scan_c_stream (FILE *infile) g->flags |= DEFUN_noreturn; if (strstr (input_buffer, "const")) g->flags |= DEFUN_const; + if (strstr (input_buffer, "pure")) + g->flags |= DEFUN_pure; /* Although the noinline attribute is no longer used, leave its support in, in case it's needed later. */ -- cgit v1.3