Skip to content

Commit 25da99f

Browse files
author
Steinar H. Gunderson
committed
Bug #26927386: REDUCE COMPILATION TIME [noclose]
Remove some links to my_sys.h. This included splitting out the Valgrind macros (TRASH etc.) into a separate header file. Change-Id: If300f1bcdc6783b30bd9d3507d8fe476a5250c55
1 parent 11f288d commit 25da99f

29 files changed

+287
-226
lines changed

client/mysql_secure_installation.cc

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include <sys/types.h>
2121

2222
#include "client/client_priv.h"
23+
#ifdef _WIN32
24+
#include "m_ctype.h"
25+
#endif
2326
#include "my_alloc.h"
2427
#include "my_compiler.h"
2528
#include "my_dbug.h"

client/mysql_ssl_rsa_setup.cc

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131

3232
#include "client/logger.h"
3333
#include "client/path.h"
34+
#ifdef _WIN32
35+
#include "m_ctype.h"
36+
#endif
3437
#include "my_alloc.h"
3538
#include "my_compiler.h"
3639
#include "my_dbug.h"

include/memory_debugging.h

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; version 2 of the License.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program; if not, write to the Free Software
14+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15+
16+
#ifndef MEMORY_DEBUGGING_INCLUDED
17+
#define MEMORY_DEBUGGING_INCLUDED
18+
19+
/**
20+
@file memory_debugging.h
21+
22+
Various macros useful for communicating with memory debuggers,
23+
such as Valgrind.
24+
*/
25+
26+
#ifdef HAVE_VALGRIND
27+
# include <valgrind/valgrind.h>
28+
29+
# define MEM_MALLOCLIKE_BLOCK(p1, p2, p3, p4) VALGRIND_MALLOCLIKE_BLOCK(p1, p2, p3, p4)
30+
# define MEM_FREELIKE_BLOCK(p1, p2) VALGRIND_FREELIKE_BLOCK(p1, p2)
31+
# include <valgrind/memcheck.h>
32+
33+
# define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len)
34+
# define MEM_DEFINED_IF_ADDRESSABLE(a,len) \
35+
VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(a,len)
36+
# define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len)
37+
# define MEM_CHECK_ADDRESSABLE(a,len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,len)
38+
39+
#else /* HAVE_VALGRIND */
40+
41+
# define MEM_MALLOCLIKE_BLOCK(p1, p2, p3, p4) do {} while (0)
42+
# define MEM_FREELIKE_BLOCK(p1, p2) do {} while (0)
43+
# define MEM_UNDEFINED(a,len) ((void) 0)
44+
# define MEM_DEFINED_IF_ADDRESSABLE(a,len) ((void) 0)
45+
# define MEM_NOACCESS(a,len) ((void) 0)
46+
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
47+
48+
#endif
49+
50+
51+
#if !defined(DBUG_OFF) || defined(HAVE_VALGRIND)
52+
53+
/**
54+
Put bad content in memory to be sure it will segfault if dereferenced.
55+
With Valgrind, verify that memory is addressable, and mark it undefined.
56+
We cache value of B because if B is expression which depends on A, memset()
57+
trashes value of B.
58+
*/
59+
#define TRASH(A,B) do { \
60+
const size_t l= (B); \
61+
MEM_CHECK_ADDRESSABLE(A, l); \
62+
memset(A, 0x8F, l); \
63+
MEM_UNDEFINED(A, l); \
64+
} while (0)
65+
66+
#else
67+
68+
#define TRASH(A,B) do {} while(0)
69+
70+
#endif
71+
72+
#endif // MEMORY_DEBUGGING_INCLUDED

include/my_sys.h

-37
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,6 @@ struct MEM_ROOT;
7272

7373
C_MODE_START
7474

75-
#ifdef HAVE_VALGRIND
76-
# include <valgrind/valgrind.h>
77-
78-
# define MEM_MALLOCLIKE_BLOCK(p1, p2, p3, p4) VALGRIND_MALLOCLIKE_BLOCK(p1, p2, p3, p4)
79-
# define MEM_FREELIKE_BLOCK(p1, p2) VALGRIND_FREELIKE_BLOCK(p1, p2)
80-
# include <valgrind/memcheck.h>
81-
82-
# define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len)
83-
# define MEM_DEFINED_IF_ADDRESSABLE(a,len) \
84-
VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(a,len)
85-
# define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len)
86-
# define MEM_CHECK_ADDRESSABLE(a,len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,len)
87-
#else /* HAVE_VALGRIND */
88-
# define MEM_MALLOCLIKE_BLOCK(p1, p2, p3, p4) do {} while (0)
89-
# define MEM_FREELIKE_BLOCK(p1, p2) do {} while (0)
90-
# define MEM_UNDEFINED(a,len) ((void) 0)
91-
# define MEM_DEFINED_IF_ADDRESSABLE(a,len) ((void) 0)
92-
# define MEM_NOACCESS(a,len) ((void) 0)
93-
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
94-
#endif /* HAVE_VALGRIND */
95-
9675
#define MY_INIT(name) { my_progname= name; my_init(); }
9776

9877
/**
@@ -201,22 +180,6 @@ extern PSI_memory_key key_memory_max_alloca;
201180
#define my_safe_afree(ptr, size, max_alloca_sz) if (size > max_alloca_sz) \
202181
my_free(ptr)
203182

204-
#if !defined(DBUG_OFF) || defined(HAVE_VALGRIND)
205-
/**
206-
Put bad content in memory to be sure it will segfault if dereferenced.
207-
With Valgrind, verify that memory is addressable, and mark it undefined.
208-
We cache value of B because if B is expression which depends on A, memset()
209-
trashes value of B.
210-
*/
211-
#define TRASH(A,B) do { \
212-
const size_t l= (B); \
213-
MEM_CHECK_ADDRESSABLE(A, l); \
214-
memset(A, 0x8F, l); \
215-
MEM_UNDEFINED(A, l); \
216-
} while (0)
217-
#else
218-
#define TRASH(A,B) do {} while(0)
219-
#endif
220183
#if defined(ENABLED_DEBUG_SYNC)
221184
extern void (*debug_sync_C_callback_ptr)(const char *, size_t);
222185
#define DEBUG_SYNC_C(_sync_point_name_) do { \

include/sql_string.h

+2-15
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
#include "lex_string.h"
3131
#include "m_ctype.h" // my_convert
3232
#include "m_string.h" // LEX_CSTRING
33+
#include "memory_debugging.h"
3334
#include "my_alloc.h"
3435
#include "my_byteorder.h"
3536
#include "my_compiler.h"
3637
#include "my_dbug.h"
3738
#include "my_inttypes.h"
38-
#include "my_sys.h" // alloc_root
3939
#include "mysql/mysql_lex_string.h" // LEX_STRING
4040
#include "mysql/psi/psi_base.h"
4141
#include "mysql/psi/psi_memory.h"
@@ -673,20 +673,7 @@ class String
673673
674674
@return allocated string or NULL
675675
*/
676-
char *dup(MEM_ROOT *root) const
677-
{
678-
if (m_length > 0 && m_ptr[m_length - 1] == 0)
679-
return static_cast<char *>(memdup_root(root, m_ptr, m_length));
680-
681-
char *ret= static_cast<char*>(alloc_root(root, m_length + 1));
682-
if (ret != NULL)
683-
{
684-
if (m_length > 0)
685-
memcpy(ret, m_ptr, m_length);
686-
ret[m_length]= 0;
687-
}
688-
return ret;
689-
}
676+
char *dup(MEM_ROOT *root) const;
690677
};
691678

692679
static inline void swap(String &a, String &b) noexcept

mysys/mf_dirname.cc

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
#include <stddef.h>
1717

18+
#ifdef _WIN32
19+
#include "m_ctype.h"
20+
#endif
1821
#include "m_string.h"
1922
#include "my_dbug.h"
2023
#include "my_io.h"

mysys/mf_pack.cc

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
#include <string.h>
2424

25+
#ifdef _WIN32
26+
#include "m_ctype.h"
27+
#endif
2528
#include "m_string.h"
2629
#include "my_dbug.h"
2730
#include "my_inttypes.h"

mysys/my_conio.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
@file mysys/my_conio.cc
1818
*/
1919

20+
#ifdef _WIN32
21+
22+
#include "m_ctype.h"
2023
#include "my_dbug.h"
2124
#include "mysys_priv.h"
2225

23-
#ifdef _WIN32
24-
2526
extern CHARSET_INFO my_charset_utf16le_bin;
2627

2728

mysys/my_malloc.cc

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <string.h>
2323
#include <sys/types.h>
2424

25+
#include "memory_debugging.h"
2526
#include "my_compiler.h"
2627
#include "my_dbug.h"
2728
#include "my_inttypes.h"

sql-common/sql_string.cc

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "my_dbug.h"
2323
#include "my_macros.h"
2424
#include "my_pointer_arithmetic.h"
25+
#include "my_sys.h"
2526
#include "mysql_com.h" // MAX_BIGINT_WIDTH
2627

2728
using std::min;
@@ -1178,6 +1179,11 @@ void String::swap(String &s) noexcept
11781179
swap(m_charset, s.m_charset);
11791180
}
11801181

1182+
char *String::dup(MEM_ROOT *root) const
1183+
{
1184+
return strmake_root(root, m_ptr, m_length);
1185+
}
1186+
11811187

11821188
/**
11831189
Convert string to printable ASCII string

sql/item.h

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "lex_string.h"
2929
#include "m_ctype.h"
3030
#include "m_string.h"
31+
#include "memory_debugging.h"
3132
#include "my_bitmap.h"
3233
#include "my_compiler.h"
3334
#include "my_dbug.h"

0 commit comments

Comments
 (0)