Skip to content

Commit ef3f119

Browse files
author
Steinar H. Gunderson
committed
Bug #26781567: REMOVE C LEGACY [noclose]
Rename st_mem_root to MEM_ROOT (with no typedef), which means we no longer need to jump through hoops with a separate .h file to forward-declare it. Change-Id: I672415c4821f4feccbb93eeea789ee1218931dbd
1 parent 2a1e958 commit ef3f119

29 files changed

+52
-101
lines changed

include/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
# automatically generated.
2222
SET(HEADERS
2323
errmsg.h
24-
mem_root_fwd.h
2524
my_command.h
2625
my_list.h
2726
mysql.h

include/mem_root_fwd.h

Lines changed: 0 additions & 30 deletions
This file was deleted.

include/my_alloc.h

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#ifndef _my_alloc_h
2222
#define _my_alloc_h
2323

24-
#include <stdbool.h>
25-
2624
/*
2725
How much overhead does malloc have. The code often allocates
2826
something like 1024-MALLOC_OVERHEAD bytes
@@ -35,19 +33,18 @@
3533
#define ALLOC_MAX_BLOCK_TO_DROP 4096
3634
#define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP 10
3735

36+
#include <stdbool.h>
3837
#include <string.h>
3938
#include <sys/types.h>
4039

40+
#include <memory>
41+
#include <new>
42+
4143
#include "my_compiler.h"
4244
#include "my_inttypes.h"
4345
#include "mysql/psi/psi_memory.h"
4446

45-
#include "mem_root_fwd.h" // Contains the typedef to MEM_ROOT. IWYU pragma: keep
46-
47-
#ifdef __cplusplus
48-
49-
#include <memory>
50-
#include <new>
47+
struct MEM_ROOT;
5148

5249
extern "C" {
5350

@@ -59,8 +56,6 @@ extern void init_alloc_root(PSI_memory_key key,
5956

6057
}
6158

62-
#endif
63-
6459
typedef struct st_used_mem
6560
{ /* struct for once_alloc (block) */
6661
struct st_used_mem *next; /* Next block in use */
@@ -69,29 +64,28 @@ typedef struct st_used_mem
6964
} USED_MEM;
7065

7166

72-
struct st_mem_root
67+
struct MEM_ROOT
7368
{
74-
#ifdef __cplusplus
75-
st_mem_root() :
69+
MEM_ROOT() :
7670
free(nullptr), used(nullptr), pre_alloc(nullptr),
7771
min_malloc(0) // for alloc_root_inited()
7872
{}
7973

80-
st_mem_root(PSI_memory_key key, size_t block_size, size_t pre_alloc_size)
74+
MEM_ROOT(PSI_memory_key key, size_t block_size, size_t pre_alloc_size)
8175
{
8276
init_alloc_root(key, this, block_size, pre_alloc_size);
8377
}
8478

8579
// Make the class movable but not copyable.
86-
st_mem_root(const st_mem_root &) = delete;
87-
st_mem_root(st_mem_root &&other) noexcept {
80+
MEM_ROOT(const MEM_ROOT &) = delete;
81+
MEM_ROOT(MEM_ROOT &&other) noexcept {
8882
memcpy(this, &other, sizeof(*this));
8983
other.free= other.used= other.pre_alloc= nullptr;
9084
other.min_malloc= 0;
9185
}
9286

93-
st_mem_root& operator= (const st_mem_root &) = delete;
94-
st_mem_root& operator= (st_mem_root &&other) noexcept {
87+
MEM_ROOT& operator= (const MEM_ROOT &) = delete;
88+
MEM_ROOT& operator= (MEM_ROOT &&other) noexcept {
9589
memcpy(this, &other, sizeof(*this));
9690
other.free= other.used= other.pre_alloc= nullptr;
9791
other.min_malloc= 0;
@@ -103,13 +97,11 @@ struct st_mem_root
10397
It's harmless to call free_root() multiple times, and thus also to call
10498
free_root() on a to-be-destructed object.
10599
*/
106-
~st_mem_root()
100+
~MEM_ROOT()
107101
{
108102
free_root(this, MYF(0));
109103
}
110104

111-
#endif
112-
113105
USED_MEM *free; /* blocks with free memory in it */
114106
USED_MEM *used; /* blocks almost without free memory */
115107
USED_MEM *pre_alloc; /* preallocated block */
@@ -141,7 +133,6 @@ struct st_mem_root
141133
PSI_memory_key m_psi_key;
142134
};
143135

144-
#ifdef __cplusplus
145136
/**
146137
Allocate an object of the given type. Use like this:
147138
@@ -200,6 +191,4 @@ class Destroy_only
200191
template<class T>
201192
using unique_ptr_destroy_only = std::unique_ptr<T, Destroy_only<T>>;
202193

203-
#endif // __cplusplus
204-
205194
#endif

include/my_tree.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <stddef.h>
2424
#include <sys/types.h>
2525

26-
#include "mem_root_fwd.h"
2726
#include "my_alloc.h" /* MEM_ROOT */
2827
#include "my_base.h" /* get 'enum ha_rkey_function' */
2928
#include "my_inttypes.h"

include/mysql.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ typedef int my_socket;
6666

6767

6868
#include "binary_log_types.h"
69-
#include "mem_root_fwd.h"
7069
#include "my_list.h"
7170
#include "mysql_com.h"
7271

@@ -147,11 +146,13 @@ typedef struct st_mysql_rows {
147146

148147
typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */
149148

149+
struct MEM_ROOT;
150+
150151
typedef struct embedded_query_result EMBEDDED_QUERY_RESULT;
151152
typedef struct st_mysql_data {
152153
MYSQL_ROWS *data;
153154
struct embedded_query_result *embedded_info;
154-
MEM_ROOT *alloc;
155+
struct MEM_ROOT *alloc;
155156
my_ulonglong rows;
156157
unsigned int fields;
157158
/* extra info for embedded library */
@@ -281,7 +282,7 @@ typedef struct st_mysql
281282
char *info, *db;
282283
struct charset_info_st *charset;
283284
MYSQL_FIELD *fields;
284-
MEM_ROOT *field_alloc;
285+
struct MEM_ROOT *field_alloc;
285286
my_ulonglong affected_rows;
286287
my_ulonglong insert_id; /* id if insert on table with NEXTNR */
287288
my_ulonglong extra_info; /* Not used */
@@ -329,7 +330,7 @@ typedef struct st_mysql_res {
329330
const struct st_mysql_methods *methods;
330331
MYSQL_ROW row; /* If unbuffered read */
331332
MYSQL_ROW current_row; /* buffer to current row */
332-
MEM_ROOT *field_alloc;
333+
struct MEM_ROOT *field_alloc;
333334
unsigned int field_count, current_field;
334335
bool eof; /* Used by mysql_fetch_row */
335336
/* mysql_stmt_close() had to cancel this result */
@@ -655,7 +656,7 @@ struct st_mysql_stmt_extension;
655656
/* statement handler */
656657
typedef struct st_mysql_stmt
657658
{
658-
MEM_ROOT *mem_root; /* root allocations */
659+
struct MEM_ROOT *mem_root; /* root allocations */
659660
LIST list; /* list to keep track of all stmts */
660661
MYSQL *mysql; /* connection handle */
661662
MYSQL_BIND *params; /* input parameters */

include/mysql.h.pp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
MYSQL_TYPE_STRING=254,
2727
MYSQL_TYPE_GEOMETRY=255
2828
} enum_field_types;
29-
#include "mem_root_fwd.h"
30-
struct st_mem_root;
31-
typedef struct st_mem_root MEM_ROOT;
3229
#include "my_list.h"
3330
typedef struct st_list {
3431
struct st_list *prev,*next;
@@ -348,11 +345,12 @@
348345
unsigned long length;
349346
} MYSQL_ROWS;
350347
typedef MYSQL_ROWS *MYSQL_ROW_OFFSET;
348+
struct MEM_ROOT;
351349
typedef struct embedded_query_result EMBEDDED_QUERY_RESULT;
352350
typedef struct st_mysql_data {
353351
MYSQL_ROWS *data;
354352
struct embedded_query_result *embedded_info;
355-
MEM_ROOT *alloc;
353+
struct MEM_ROOT *alloc;
356354
my_ulonglong rows;
357355
unsigned int fields;
358356
void *extension;
@@ -455,7 +453,7 @@
455453
char *info, *db;
456454
struct charset_info_st *charset;
457455
MYSQL_FIELD *fields;
458-
MEM_ROOT *field_alloc;
456+
struct MEM_ROOT *field_alloc;
459457
my_ulonglong affected_rows;
460458
my_ulonglong insert_id;
461459
my_ulonglong extra_info;
@@ -493,7 +491,7 @@
493491
const struct st_mysql_methods *methods;
494492
MYSQL_ROW row;
495493
MYSQL_ROW current_row;
496-
MEM_ROOT *field_alloc;
494+
struct MEM_ROOT *field_alloc;
497495
unsigned int field_count, current_field;
498496
bool eof;
499497
bool unbuffered_fetch_cancelled;
@@ -670,7 +668,7 @@
670668
struct st_mysql_stmt_extension;
671669
typedef struct st_mysql_stmt
672670
{
673-
MEM_ROOT *mem_root;
671+
struct MEM_ROOT *mem_root;
674672
LIST list;
675673
MYSQL *mysql;
676674
MYSQL_BIND *params;

include/mysql/psi/psi_memory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
MAINTAINER:
2525
Note that this file is part of the public API,
2626
because mysql.h exports
27-
struct st_mem_root
27+
struct MEM_ROOT
2828
See
29-
- PSI_memory_key st_mem_root::m_psi_key
29+
- PSI_memory_key MEM_ROOT::m_psi_key
3030
- include/mysql.h.pp
3131
*/
3232

include/sql_common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
#include <sys/types.h>
2828

2929
#include "errmsg.h"
30-
#include "mem_root_fwd.h"
3130
#include "my_command.h"
3231
#include "my_compiler.h"
3332
#include "my_inttypes.h"
3433
#include "my_list.h"
3534
#include "mysql_com.h"
3635

36+
struct MEM_ROOT;
37+
3738
#ifdef __cplusplus
3839
extern "C" {
3940
#endif

include/sql_string.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "lex_string.h"
3131
#include "m_ctype.h" // my_convert
3232
#include "m_string.h" // LEX_CSTRING
33-
#include "mem_root_fwd.h"
3433
#include "my_byteorder.h"
3534
#include "my_compiler.h"
3635
#include "my_dbug.h"
@@ -41,6 +40,8 @@
4140
#include "mysql/psi/psi_memory.h"
4241
#include "mysql/service_mysql_alloc.h" // my_free
4342

43+
struct MEM_ROOT;
44+
4445
#ifdef MYSQL_SERVER
4546
extern "C" {
4647
extern PSI_memory_key key_memory_String_value;

include/typelib.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
@file include/typelib.h
2222
*/
2323

24-
#include "mem_root_fwd.h"
2524
#include "my_inttypes.h"
2625

26+
struct MEM_ROOT;
27+
2728
#ifdef __cplusplus
2829
extern "C" {
2930
#endif

sql/aggregate_check.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,6 @@ class Opt_trace_object;
465465
class SELECT_LEX;
466466
class THD;
467467
struct TABLE_LIST;
468-
struct st_mem_root;
469468
template <class T> class List;
470469

471470
/**
@@ -577,7 +576,7 @@ class Group_check: public Item_tree_walker, public Sql_alloc
577576
{
578577
public:
579578

580-
Group_check(SELECT_LEX *select_arg, st_mem_root *root)
579+
Group_check(SELECT_LEX *select_arg, MEM_ROOT *root)
581580
: select(select_arg), search_in_underlying(false),
582581
non_null_in_source(false),
583582
table(NULL), group_in_fd(~0ULL), m_root(root), fd(root),
@@ -639,7 +638,7 @@ class Group_check: public Item_tree_walker, public Sql_alloc
639638
ulonglong group_in_fd;
640639

641640
/// Memory for allocations (like of 'fd')
642-
st_mem_root *const m_root;
641+
MEM_ROOT *const m_root;
643642

644643
/**
645644
Columns which are local to 'select' and functionally dependent on an
@@ -660,7 +659,7 @@ class Group_check: public Item_tree_walker, public Sql_alloc
660659
bool is_child() const { return table != NULL; }
661660

662661
/// Private ctor, for a Group_check to build a child Group_check
663-
Group_check(SELECT_LEX *select_arg, st_mem_root *root,
662+
Group_check(SELECT_LEX *select_arg, MEM_ROOT *root,
664663
TABLE_LIST *table_arg)
665664
: select(select_arg), search_in_underlying(false),
666665
non_null_in_source(false), table(table_arg),

sql/auth/sql_auth_cache.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "lf.h"
3333
#include "m_ctype.h"
3434
#include "map_helpers.h"
35-
#include "mem_root_fwd.h"
3635
#include "mf_wcomp.h" // wild_many, wild_one, wild_prefix
3736
#include "my_alloc.h"
3837
#include "my_inttypes.h"
@@ -60,8 +59,8 @@
6059
#include "typelib.h"
6160
#include "violite.h" // SSL_type
6261

62+
struct MEM_ROOT;
6363
class Security_context;
64-
/* Forward Declarations */
6564
class String;
6665
class THD;
6766
struct TABLE;

sql/dd/dd_tablespace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
#ifndef DD_TABLESPACE_INCLUDED
1717
#define DD_TABLESPACE_INCLUDED
1818

19-
#include "mem_root_fwd.h"
2019
#include "sql/lock.h" // Tablespace_hash_set
2120
#include "sql/thr_malloc.h"
2221

22+
struct MEM_ROOT;
2323
class THD;
2424
class st_alter_tablespace;
2525
struct handlerton;

sql/dd/dd_trigger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
#include "lex_string.h"
2020
#include "sql/trigger_def.h" // enum_trigger_order_type
2121

22+
struct MEM_ROOT;
2223
class THD;
2324
class Trigger;
2425

25-
typedef struct st_mem_root MEM_ROOT;
2626
template <class T> class List;
2727

2828
namespace dd

0 commit comments

Comments
 (0)