1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-05 22:20:24 -08:00

Fix mis-declarations of non-const functions

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.
This commit is contained in:
Paul Eggert 2025-11-19 11:18:13 -08:00
parent a1f36dc3b8
commit 20fd47e741
6 changed files with 27 additions and 19 deletions

View file

@ -577,7 +577,13 @@ struct global
}; };
/* Bit values for FLAGS field from the above. Applied for DEFUNs only. */ /* 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' /* All the variable names we saw while scanning C sources in `-g'
mode. */ mode. */
@ -752,6 +758,8 @@ write_globals (void)
fputs (" ATTRIBUTE_COLD", stdout); fputs (" ATTRIBUTE_COLD", stdout);
if (globals[i].flags & DEFUN_const) if (globals[i].flags & DEFUN_const)
fputs (" ATTRIBUTE_CONST", stdout); fputs (" ATTRIBUTE_CONST", stdout);
if (globals[i].flags & DEFUN_pure)
fputs (" ATTRIBUTE_PURE", stdout);
puts (";"); puts (";");
} }
@ -1062,7 +1070,7 @@ scan_c_stream (FILE *infile)
attributes: attribute1 attribute2 ...) attributes: attribute1 attribute2 ...)
(Lisp_Object arg...) (Lisp_Object arg...)
Now only `const', `noinline' and `noreturn' attributes Now only 'const', 'noinline', 'noreturn', and 'pure' attributes
are used. */ are used. */
/* Advance to the end of docstring. */ /* Advance to the end of docstring. */
@ -1110,6 +1118,8 @@ scan_c_stream (FILE *infile)
g->flags |= DEFUN_noreturn; g->flags |= DEFUN_noreturn;
if (strstr (input_buffer, "const")) if (strstr (input_buffer, "const"))
g->flags |= DEFUN_const; g->flags |= DEFUN_const;
if (strstr (input_buffer, "pure"))
g->flags |= DEFUN_pure;
/* Although the noinline attribute is no longer used, /* Although the noinline attribute is no longer used,
leave its support in, in case it's needed later. */ leave its support in, in case it's needed later. */

View file

@ -56,7 +56,7 @@ extern void emacs_mpz_mul_2exp (mpz_t, mpz_t const, EMACS_INT)
ARG_NONNULL ((1, 2)); ARG_NONNULL ((1, 2));
extern void emacs_mpz_pow_ui (mpz_t, mpz_t const, unsigned long) extern void emacs_mpz_pow_ui (mpz_t, mpz_t const, unsigned long)
ARG_NONNULL ((1, 2)); ARG_NONNULL ((1, 2));
extern double mpz_get_d_rounded (mpz_t const) ATTRIBUTE_CONST; extern double mpz_get_d_rounded (mpz_t const) ATTRIBUTE_PURE;
extern Lisp_Object get_random_bignum (struct Lisp_Bignum const *); extern Lisp_Object get_random_bignum (struct Lisp_Bignum const *);
INLINE_HEADER_BEGIN INLINE_HEADER_BEGIN

View file

@ -166,8 +166,7 @@ slow_eq (Lisp_Object x, Lisp_Object y)
} }
DEFUN ("eq", Feq, Seq, 2, 2, 0, DEFUN ("eq", Feq, Seq, 2, 2, 0,
doc: /* Return t if the two args are the same Lisp object. */ doc: /* Return t if the two args are the same Lisp object. */)
attributes: const)
(Lisp_Object obj1, Lisp_Object obj2) (Lisp_Object obj1, Lisp_Object obj2)
{ {
if (EQ (obj1, obj2)) if (EQ (obj1, obj2))
@ -373,7 +372,7 @@ Ignore `symbols-with-pos-enabled'. */
DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0, DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0,
doc: /* Return t if OBJECT is a symbol. */ doc: /* Return t if OBJECT is a symbol. */
attributes: const) attributes: pure)
(Lisp_Object object) (Lisp_Object object)
{ {
if (SYMBOLP (object)) if (SYMBOLP (object))
@ -551,7 +550,7 @@ DEFUN ("interpreted-function-p", Finterpreted_function_p,
DEFUN ("module-function-p", Fmodule_function_p, Smodule_function_p, 1, 1, NULL, DEFUN ("module-function-p", Fmodule_function_p, Smodule_function_p, 1, 1, NULL,
doc: /* Return t if OBJECT is a function loaded from a dynamic module. */ doc: /* Return t if OBJECT is a function loaded from a dynamic module. */
attributes: const) attributes: pure)
(Lisp_Object object) (Lisp_Object object)
{ {
return MODULE_FUNCTIONP (object) ? Qt : Qnil; return MODULE_FUNCTIONP (object) ? Qt : Qnil;
@ -569,7 +568,7 @@ DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0,
DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0, DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0,
doc: /* Return t if OBJECT is an integer. */ doc: /* Return t if OBJECT is an integer. */
attributes: const) attributes: pure)
(Lisp_Object object) (Lisp_Object object)
{ {
if (INTEGERP (object)) if (INTEGERP (object))
@ -598,7 +597,7 @@ DEFUN ("natnump", Fnatnump, Snatnump, 1, 1, 0,
DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0, DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0,
doc: /* Return t if OBJECT is a number (floating point or integer). */ doc: /* Return t if OBJECT is a number (floating point or integer). */
attributes: const) attributes: pure)
(Lisp_Object object) (Lisp_Object object)
{ {
if (NUMBERP (object)) if (NUMBERP (object))

View file

@ -619,7 +619,7 @@ INLINE void set_sub_char_table_contents (Lisp_Object, ptrdiff_t,
/* Defined in bignum.c. */ /* Defined in bignum.c. */
extern int check_int_nonnegative (Lisp_Object); extern int check_int_nonnegative (Lisp_Object);
extern intmax_t check_integer_range (Lisp_Object, intmax_t, intmax_t); extern intmax_t check_integer_range (Lisp_Object, intmax_t, intmax_t);
extern double bignum_to_double (Lisp_Object) ATTRIBUTE_CONST; extern double bignum_to_double (Lisp_Object) ATTRIBUTE_PURE;
extern Lisp_Object make_bigint (intmax_t); extern Lisp_Object make_bigint (intmax_t);
extern Lisp_Object make_biguint (uintmax_t); extern Lisp_Object make_biguint (uintmax_t);
extern uintmax_t check_uinteger_max (Lisp_Object, uintmax_t); extern uintmax_t check_uinteger_max (Lisp_Object, uintmax_t);
@ -4105,9 +4105,9 @@ set_sub_char_table_contents (Lisp_Object table, ptrdiff_t idx, Lisp_Object val)
/* Defined in bignum.c. This part of bignum.c's API does not require /* Defined in bignum.c. This part of bignum.c's API does not require
the caller to access bignum internals; see bignum.h for that. */ the caller to access bignum internals; see bignum.h for that. */
extern intmax_t bignum_to_intmax (Lisp_Object) ATTRIBUTE_CONST; extern intmax_t bignum_to_intmax (Lisp_Object) ATTRIBUTE_PURE;
extern uintmax_t bignum_to_uintmax (Lisp_Object) ATTRIBUTE_CONST; extern uintmax_t bignum_to_uintmax (Lisp_Object) ATTRIBUTE_PURE;
extern ptrdiff_t bignum_bufsize (Lisp_Object, int) ATTRIBUTE_CONST; extern ptrdiff_t bignum_bufsize (Lisp_Object, int) ATTRIBUTE_PURE;
extern ptrdiff_t bignum_to_c_string (char *, ptrdiff_t, Lisp_Object, int); extern ptrdiff_t bignum_to_c_string (char *, ptrdiff_t, Lisp_Object, int);
extern Lisp_Object bignum_to_string (Lisp_Object, int); extern Lisp_Object bignum_to_string (Lisp_Object, int);
extern Lisp_Object make_bignum_str (char const *, int); extern Lisp_Object make_bignum_str (char const *, int);

View file

@ -158,7 +158,7 @@ extern struct pdumper_loaded_dump dump_public;
/* Return whether the OBJ points somewhere into the loaded dump image. /* Return whether the OBJ points somewhere into the loaded dump image.
Works even when we have no dump loaded --- in this case, it just Works even when we have no dump loaded --- in this case, it just
returns false. */ returns false. */
INLINE _GL_ATTRIBUTE_CONST bool INLINE bool
pdumper_object_p (const void *obj) pdumper_object_p (const void *obj)
{ {
#ifdef HAVE_PDUMPER #ifdef HAVE_PDUMPER
@ -176,7 +176,7 @@ extern bool pdumper_cold_object_p_impl (const void *obj);
Only bool-vectors and floats should end up there. Only bool-vectors and floats should end up there.
pdumper_object_p() and pdumper_object_p_precise() must have pdumper_object_p() and pdumper_object_p_precise() must have
returned true for OBJ before calling this function. */ returned true for OBJ before calling this function. */
INLINE _GL_ATTRIBUTE_CONST bool INLINE bool
pdumper_cold_object_p (const void *obj) pdumper_cold_object_p (const void *obj)
{ {
#ifdef HAVE_PDUMPER #ifdef HAVE_PDUMPER
@ -193,7 +193,7 @@ extern int pdumper_find_object_type_impl (const void *obj);
/* Return the type of the dumped object that starts at OBJ. It is a /* Return the type of the dumped object that starts at OBJ. It is a
programming error to call this routine for an OBJ for which programming error to call this routine for an OBJ for which
pdumper_object_p would return false. */ pdumper_object_p would return false. */
INLINE _GL_ATTRIBUTE_CONST int INLINE int
pdumper_find_object_type (const void *obj) pdumper_find_object_type (const void *obj)
{ {
#ifdef HAVE_PDUMPER #ifdef HAVE_PDUMPER
@ -216,7 +216,7 @@ pdumper_valid_object_type_p (int type)
the loaded dump image. It is a programming error to call this the loaded dump image. It is a programming error to call this
routine for an OBJ for which pdumper_object_p would return routine for an OBJ for which pdumper_object_p would return
false. */ false. */
INLINE _GL_ATTRIBUTE_CONST bool INLINE bool
pdumper_object_p_precise (const void *obj) pdumper_object_p_precise (const void *obj)
{ {
#ifdef HAVE_PDUMPER #ifdef HAVE_PDUMPER

View file

@ -4194,8 +4194,7 @@ with the value VALUE is relative.
A relative value is one that doesn't entirely override whatever is A relative value is one that doesn't entirely override whatever is
inherited from another face. For most possible attributes, inherited from another face. For most possible attributes,
the only relative value that users see is `unspecified'. the only relative value that users see is `unspecified'.
However, for :height, floating point values are also relative. */ However, for :height, floating point values are also relative. */)
attributes: const)
(Lisp_Object attribute, Lisp_Object value) (Lisp_Object attribute, Lisp_Object value)
{ {
if (EQ (value, Qunspecified) || (EQ (value, QCignore_defface))) if (EQ (value, Qunspecified) || (EQ (value, QCignore_defface)))