From: Paul Eggert Date: Mon, 3 Aug 2020 22:21:59 +0000 (-0700) Subject: Simplify use of __lsan_ignore_object X-Git-Tag: emacs-28.0.90~6843 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a1436544ff826b8c51242f4afb7c5d485c8e2e32;p=emacs.git Simplify use of __lsan_ignore_object * configure.ac: Use AC_CHECK_FUNCS_ONCE for __lsan_ignore_object. * src/buffer.c, src/data.c, src/emacs-module.c, src/regex-emacs.c: * src/search.c: Use __lsan_ignore_object unconditionally, and don’t include sanitizer/lsan_interface.h. * src/lisp.h (__lsan_ignore_object): Provide a dummy in the typical case where leak sanitization is not available. --- diff --git a/configure.ac b/configure.ac index 93463e344ab..4ee4517e11c 100644 --- a/configure.ac +++ b/configure.ac @@ -4512,11 +4512,13 @@ AC_CHECK_HEADERS(valgrind/valgrind.h) AC_CHECK_MEMBERS([struct unipair.unicode], [], [], [[#include ]]) -AC_CHECK_FUNCS_ONCE([sbrk]) +AC_CHECK_FUNCS_ONCE([__lsan_ignore_object sbrk]) AC_FUNC_FORK -AC_CHECK_FUNCS(snprintf __lsan_ignore_object) +dnl AC_CHECK_FUNCS_ONCE wouldn’t be right for snprintf, which needs +dnl the current CFLAGS etc. +AC_CHECK_FUNCS(snprintf) dnl Check for glib. This differs from other library checks in that dnl Emacs need not link to glib unless some other library is already diff --git a/src/buffer.c b/src/buffer.c index e441499aeb0..241f2d43a93 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -28,10 +28,6 @@ along with GNU Emacs. If not, see . */ #include #include -#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H -#include -#endif - #include #include "lisp.h" @@ -5087,9 +5083,7 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta) #else p = xrealloc (b->text->beg, new_nbytes); #endif -#ifdef HAVE___LSAN_IGNORE_OBJECT __lsan_ignore_object (p); -#endif if (p == NULL) { diff --git a/src/data.c b/src/data.c index 5fff52d24c2..59d148166fe 100644 --- a/src/data.c +++ b/src/data.c @@ -23,10 +23,6 @@ along with GNU Emacs. If not, see . */ #include #include -#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H -#include -#endif - #include #include #include @@ -1788,9 +1784,7 @@ make_blv (struct Lisp_Symbol *sym, bool forwarded, set_blv_defcell (blv, tem); set_blv_valcell (blv, tem); set_blv_found (blv, false); -#ifdef HAVE___LSAN_IGNORE_OBJECT __lsan_ignore_object (blv); -#endif return blv; } diff --git a/src/emacs-module.c b/src/emacs-module.c index f57101946b3..a0bab118019 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c @@ -84,10 +84,6 @@ To add a new module function, proceed as follows: #include #include -#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H -#include -#endif - #include "lisp.h" #include "bignum.h" #include "dynlib.h" @@ -1103,9 +1099,7 @@ DEFUN ("module-load", Fmodule_load, Smodule_load, 1, 1, 0, if (module_assertions) { rt = xmalloc (sizeof *rt); -#ifdef HAVE___LSAN_IGNORE_OBJECT __lsan_ignore_object (rt); -#endif } else rt = &rt_pub; @@ -1426,9 +1420,7 @@ initialize_environment (emacs_env *env, struct emacs_env_private *priv) if (module_assertions) { env = xmalloc (sizeof *env); -#ifdef HAVE___LSAN_IGNORE_OBJECT __lsan_ignore_object (env); -#endif } priv->pending_non_local_exit = emacs_funcall_exit_return; diff --git a/src/lisp.h b/src/lisp.h index fdf69ab7368..22ddf3e5faf 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4789,6 +4789,17 @@ lispstpcpy (char *dest, Lisp_Object string) return dest + len; } +#if (defined HAVE___LSAN_IGNORE_OBJECT \ + && defined HAVE_SANITIZER_LSAN_INTERFACE_H) +# include +#else +/* Treat *P as a non-leak. */ +INLINE void +__lsan_ignore_object (void const *p) +{ +} +#endif + extern void xputenv (const char *); extern char *egetenv_internal (const char *, ptrdiff_t); diff --git a/src/regex-emacs.c b/src/regex-emacs.c index 1ecbc74b96c..c44cce9f787 100644 --- a/src/regex-emacs.c +++ b/src/regex-emacs.c @@ -29,10 +29,6 @@ #include -#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H -#include -#endif - #include "character.h" #include "buffer.h" #include "syntax.h" @@ -1761,9 +1757,7 @@ regex_compile (re_char *pattern, ptrdiff_t size, /* Initialize the compile stack. */ compile_stack.stack = xmalloc (INIT_COMPILE_STACK_SIZE * sizeof *compile_stack.stack); -#ifdef HAVE___LSAN_IGNORE_OBJECT __lsan_ignore_object (compile_stack.stack); -#endif compile_stack.size = INIT_COMPILE_STACK_SIZE; compile_stack.avail = 0; diff --git a/src/search.c b/src/search.c index 7b74ff91480..38c64caf7c0 100644 --- a/src/search.c +++ b/src/search.c @@ -21,10 +21,6 @@ along with GNU Emacs. If not, see . */ #include -#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H -#include -#endif - #include "lisp.h" #include "character.h" #include "buffer.h" @@ -619,9 +615,7 @@ newline_cache_on_off (struct buffer *buf) if (base_buf->newline_cache == 0) { base_buf->newline_cache = new_region_cache (); -#ifdef HAVE___LSAN_IGNORE_OBJECT __lsan_ignore_object (base_buf->newline_cache); -#endif } } return base_buf->newline_cache;