Skip to content

Commit c3588e1

Browse files
author
Steinar H. Gunderson
committed
Bug #32216281: REMOVE DBUG_OFF AND DBUG_ASSERT
Replace DBUG_OFF with NDEBUG, and DBUG_ASSERT() with assert(). These are semantically the same (DBUG_ASSERT() has been #defined to assert() for a long time), but nonstandard. Whenever a file #included my_dbug.h but no longer use any DBUG_* macros, we remove said #include and use <assert.h> instead. The change is mostly automated; the manual changes are to my_dbug.h itself, to CMake code, and a few added #includes that were neccessary in files that used to depend on transitive #includes from my_dbug.h (e.g. #include "my_dbug.h" to get malloc()). Change-Id: If4271d9f053d3235dd73bcbbae85eaab0d65a724
1 parent 3a2468d commit c3588e1

File tree

1,159 files changed

+15570
-15706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,159 files changed

+15570
-15706
lines changed

CMakeLists.txt

-16
Original file line numberDiff line numberDiff line change
@@ -1090,22 +1090,6 @@ IF(WITH_TEST_TRACE_PLUGIN AND NOT CMAKE_BUILD_TYPE_UPPER STREQUAL "DEBUG")
10901090
debug binaries. Set WITH_TEST_TRACE_PLUGIN to OFF or WITH_DEBUG to ON.")
10911091
ENDIF()
10921092

1093-
# Set DBUG_OFF for non-debug project types.
1094-
FOREACH(BUILD_TYPE RELEASE RELWITHDEBINFO MINSIZEREL)
1095-
FOREACH(LANG C CXX)
1096-
STRING_PREPEND(CMAKE_${LANG}_FLAGS_${BUILD_TYPE} "-DDBUG_OFF ")
1097-
ENDFOREACH()
1098-
ENDFOREACH()
1099-
1100-
IF(NOT CMAKE_BUILD_TYPE
1101-
AND NOT CMAKE_GENERATOR MATCHES "Visual Studio"
1102-
AND NOT CMAKE_GENERATOR MATCHES "Xcode")
1103-
# This is the case of no CMAKE_BUILD_TYPE choosen, typical for VS and Xcode
1104-
# or if custom C flags are set. In VS and Xcode for non-Debug configurations
1105-
# DBUG_OFF is already correctly set.
1106-
ADD_DEFINITIONS(-DDBUG_OFF)
1107-
ENDIF()
1108-
11091093
# Add safemutex for debug configurations
11101094
# Enable debug sync for debug builds.
11111095
FOREACH(LANG C CXX)

client/base/abstract_option.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
#ifndef ABSTRACT_OPTION_INCLUDED
2626
#define ABSTRACT_OPTION_INCLUDED
2727

28+
#include <assert.h>
2829
#include <functional>
2930
#include <string>
3031
#include <vector>
3132

3233
#include "client/base/i_option_changed_listener.h"
33-
#include "my_dbug.h"
34+
3435
#include "my_getopt.h"
3536
#include "mysql/service_mysql_alloc.h"
3637

@@ -178,7 +179,7 @@ my_option Abstract_option<T_type>::get_my_option() {
178179
template <typename T_type>
179180
void Abstract_option<T_type>::set_option_changed_listener(
180181
I_option_changed_listener *listener) {
181-
DBUG_ASSERT(this->m_option_changed_listener == nullptr);
182+
assert(this->m_option_changed_listener == nullptr);
182183

183184
this->m_option_changed_listener = listener;
184185
}

client/base/abstract_options_provider.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2001, 2020, Oracle and/or its affiliates.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -24,12 +24,13 @@
2424

2525
#include "client/base/abstract_options_provider.h"
2626

27+
#include <assert.h>
2728
#include <stdlib.h>
2829
#include <iostream>
2930
#include <vector>
3031

3132
#include "client/base/i_options_provider.h"
32-
#include "my_dbug.h"
33+
3334
#include "my_getopt.h"
3435

3536
using std::map;
@@ -133,7 +134,7 @@ Abstract_options_provider::~Abstract_options_provider() {
133134

134135
void Abstract_options_provider::set_option_changed_listener(
135136
I_option_changed_listener *listener) {
136-
DBUG_ASSERT(this->m_option_changed_listener == nullptr);
137+
assert(this->m_option_changed_listener == nullptr);
137138
this->m_option_changed_listener = listener;
138139
}
139140

client/base/composite_options_provider.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2001, 2020, Oracle and/or its affiliates.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -24,18 +24,18 @@
2424

2525
#include "client/base/composite_options_provider.h"
2626

27+
#include <assert.h>
2728
#include <stdarg.h>
2829
#include <stddef.h>
2930
#include <vector>
3031

3132
#include "client/base/i_options_provider.h"
32-
#include "my_dbug.h"
3333

3434
using std::vector;
3535
using namespace Mysql::Tools::Base::Options;
3636

3737
void Composite_options_provider::add_providers(I_options_provider *first, ...) {
38-
DBUG_ASSERT(this->m_options_providers.size() == 0);
38+
assert(this->m_options_providers.size() == 0);
3939

4040
va_list options_to_add;
4141
va_start(options_to_add, first);

client/base/debug_options.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2014, 2020, Oracle and/or its affiliates.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -54,7 +54,7 @@ Debug_options::Debug_options(Abstract_program *program) : m_program(program) {
5454
}
5555

5656
void Debug_options::create_options() {
57-
#ifdef DBUG_OFF
57+
#ifdef NDEBUG
5858
this->create_new_disabled_option(
5959
"debug", "This is a non-debug version. Catch this and exit.")
6060
->set_short_character('#');

client/check/mysqlcheck.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2001, 2020, Oracle and/or its affiliates.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -124,7 +124,7 @@ static struct my_option my_long_options[] = {
124124
"tables are given. All name arguments are regarded as database names.",
125125
&opt_databases, &opt_databases, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
126126
nullptr, 0, nullptr},
127-
#ifdef DBUG_OFF
127+
#ifdef NDEBUG
128128
{"debug", '#', "This is a non-debug version. Catch this and exit.", 0, 0, 0,
129129
GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
130130
{"debug-check", OPT_DEBUG_CHECK,
@@ -334,8 +334,8 @@ static bool get_one_option(int optid, const struct my_option *opt,
334334
if (argument == disabled_my_option) {
335335
// Don't require password
336336
static char empty_password[] = {'\0'};
337-
DBUG_ASSERT(empty_password[0] ==
338-
'\0'); // Check that it has not been overwritten
337+
assert(empty_password[0] ==
338+
'\0'); // Check that it has not been overwritten
339339
argument = empty_password;
340340
}
341341
if (argument) {

client/mysql.cc

+9-9
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ const char *default_dbug_option = "d:t:o,/tmp/mysql.trace";
250250
251251
For using this feature in test case, we add the option in debug code.
252252
*/
253-
#ifndef DBUG_OFF
253+
#ifndef NDEBUG
254254
static bool opt_build_completion_hash = false;
255255
#endif
256256

@@ -1685,7 +1685,7 @@ static struct my_option my_long_options[] = {
16851685
{"compress", 'C', "Use compression in server/client protocol.",
16861686
&opt_compress, &opt_compress, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr,
16871687
0, nullptr},
1688-
#ifdef DBUG_OFF
1688+
#ifdef NDEBUG
16891689
{"debug", '#', "This is a non-debug version. Catch this and exit.", 0, 0, 0,
16901690
GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
16911691
{"debug-check", OPT_DEBUG_CHECK,
@@ -1916,7 +1916,7 @@ static struct my_option my_long_options[] = {
19161916
"password sandbox mode.",
19171917
&opt_connect_expired_password, &opt_connect_expired_password, nullptr,
19181918
GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
1919-
#ifndef DBUG_OFF
1919+
#ifndef NDEBUG
19201920
{"build-completion-hash", 0,
19211921
"Build completion hash even when it is in batch mode. It is used for "
19221922
"test purpose, so it is just built when DEBUG is on.",
@@ -2047,8 +2047,8 @@ bool get_one_option(int optid,
20472047
if (argument == disabled_my_option) {
20482048
// Don't require password
20492049
static char empty_password[] = {'\0'};
2050-
DBUG_ASSERT(empty_password[0] ==
2051-
'\0'); // Check that it has not been overwritten
2050+
assert(empty_password[0] ==
2051+
'\0'); // Check that it has not been overwritten
20522052
argument = empty_password;
20532053
}
20542054
if (argument) {
@@ -2397,7 +2397,7 @@ static COMMANDS *find_command(char *name) {
23972397
char *end;
23982398
DBUG_TRACE;
23992399

2400-
DBUG_ASSERT(name != nullptr);
2400+
assert(name != nullptr);
24012401
DBUG_PRINT("enter", ("name: '%s'", name));
24022402

24032403
while (my_isspace(charset_info, *name)) name++;
@@ -2830,7 +2830,7 @@ static void build_completion_hash(bool rehash, bool write_info) {
28302830
int i, j, num_fields;
28312831
DBUG_TRACE;
28322832

2833-
#ifndef DBUG_OFF
2833+
#ifndef NDEBUG
28342834
if (!opt_build_completion_hash)
28352835
#endif
28362836
{
@@ -3724,9 +3724,9 @@ static int get_result_width(MYSQL_RES *result) {
37243724
MYSQL_FIELD *field;
37253725
MYSQL_FIELD_OFFSET offset;
37263726

3727-
#ifndef DBUG_OFF
3727+
#ifndef NDEBUG
37283728
offset = mysql_field_tell(result);
3729-
DBUG_ASSERT(offset == 0);
3729+
assert(offset == 0);
37303730
#else
37313731
offset = 0;
37323732
#endif

client/mysql_config_editor.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ struct my_command_data {
133133

134134
/* mysql_config_editor utility options. */
135135
static struct my_option my_program_long_options[] = {
136-
#ifdef DBUG_OFF
136+
#ifdef NDEBUG
137137
{"debug", '#', "This is a non-debug version. Catch this and exit.", 0, 0, 0,
138138
GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
139139
#else

client/mysql_secure_installation.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2013, 2020, Oracle and/or its affiliates.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -790,7 +790,7 @@ int main(int argc, char *argv[]) {
790790

791791
if ((rc = my_handle_options(&argc, &argv, my_connection_options,
792792
my_arguments_get_one_option, nullptr, true))) {
793-
DBUG_ASSERT(0);
793+
assert(0);
794794
}
795795

796796
init_connection_options(&mysql);

client/mysqladmin.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2020, Oracle and/or its affiliates.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -184,7 +184,7 @@ static struct my_option my_long_options[] = {
184184
"Number of iterations to make. This works with -i (--sleep) only.",
185185
&nr_iterations, &nr_iterations, nullptr, GET_UINT, REQUIRED_ARG, 0, 0, 0,
186186
nullptr, 0, nullptr},
187-
#ifdef DBUG_OFF
187+
#ifdef NDEBUG
188188
{"debug", '#', "This is a non-debug version. Catch this and exit.", 0, 0, 0,
189189
GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
190190
{"debug-check", OPT_DEBUG_CHECK,
@@ -330,8 +330,8 @@ bool get_one_option(int optid,
330330
if (argument == disabled_my_option) {
331331
// Don't require password
332332
static char empty_password[] = {'\0'};
333-
DBUG_ASSERT(empty_password[0] ==
334-
'\0'); // Check that it has not been overwritten
333+
assert(empty_password[0] ==
334+
'\0'); // Check that it has not been overwritten
335335
argument = empty_password;
336336
}
337337
if (argument) {
@@ -881,7 +881,7 @@ static int execute_commands(MYSQL *mysql, int argc, char **argv) {
881881
return -1;
882882
}
883883

884-
DBUG_ASSERT(mysql_num_rows(res) < MAX_MYSQL_VAR);
884+
assert(mysql_num_rows(res) < MAX_MYSQL_VAR);
885885

886886
if (!opt_vertical)
887887
print_header(res);

client/mysqlbinlog.cc

+12-12
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ class Database_rewrite {
225225
Rewrite_result rewrite_transaction_payload(
226226
unsigned char *buffer, std::size_t buffer_capacity,
227227
binary_log::Format_description_event const &fde) {
228-
DBUG_ASSERT(buffer[EVENT_TYPE_OFFSET] ==
229-
binary_log::TRANSACTION_PAYLOAD_EVENT);
228+
assert(buffer[EVENT_TYPE_OFFSET] ==
229+
binary_log::TRANSACTION_PAYLOAD_EVENT);
230230
binary_log::Transaction_payload_event tpe((const char *)buffer, &fde);
231231

232232
auto orig_payload{tpe.get_payload()};
@@ -504,7 +504,7 @@ class Database_rewrite {
504504
dbname_ptr = the_buffer + offset_dbname;
505505
memcpy(dbname_ptr, to.c_str(), to.size());
506506

507-
DBUG_ASSERT(to.size() < UINT8_MAX);
507+
assert(to.size() < UINT8_MAX);
508508
dbname_len_ptr = the_buffer + offset_dbname_len;
509509
*dbname_len_ptr = (char)to.size();
510510

@@ -602,7 +602,7 @@ class Database_rewrite {
602602
size_t data_size,
603603
binary_log::Format_description_event const &fde,
604604
bool skip_transaction_payload_event = false) {
605-
DBUG_ASSERT(buffer_capacity >= data_size);
605+
assert(buffer_capacity >= data_size);
606606
auto event_type = (Log_event_type)buffer[EVENT_TYPE_OFFSET];
607607
if (m_dict.empty() || !is_rewrite_needed_for_event(event_type))
608608
return Rewrite_result{buffer, buffer_capacity, data_size, false};
@@ -698,7 +698,7 @@ static uint opt_protocol = 0;
698698
static uint opt_compress = 0;
699699
static FILE *result_file;
700700

701-
#ifndef DBUG_OFF
701+
#ifndef NDEBUG
702702
static const char *default_dbug_option = "d:t:o,/tmp/mysqlbinlog.trace";
703703
#endif
704704
static const char *load_default_groups[] = {"mysqlbinlog", "client", nullptr};
@@ -1814,7 +1814,7 @@ static struct my_option my_long_options[] = {
18141814
"it can be applied to a new database",
18151815
&rewrite, &rewrite, nullptr, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, nullptr,
18161816
0, nullptr},
1817-
#ifdef DBUG_OFF
1817+
#ifdef NDEBUG
18181818
{"debug", '#', "This is a non-debug version. Catch this and exit.", 0, 0, 0,
18191819
GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
18201820
{"debug-check", OPT_DEBUG_CHECK,
@@ -2174,7 +2174,7 @@ extern "C" bool get_one_option(int optid, const struct my_option *opt,
21742174
char *argument) {
21752175
bool tty_password = false;
21762176
switch (optid) {
2177-
#ifndef DBUG_OFF
2177+
#ifndef NDEBUG
21782178
case '#':
21792179
DBUG_PUSH(argument ? argument : default_dbug_option);
21802180
break;
@@ -2213,8 +2213,8 @@ extern "C" bool get_one_option(int optid, const struct my_option *opt,
22132213
if (argument == disabled_my_option) {
22142214
// Don't require password
22152215
static char empty_password[] = {'\0'};
2216-
DBUG_ASSERT(empty_password[0] ==
2217-
'\0'); // Check that it has not been overwritten
2216+
assert(empty_password[0] ==
2217+
'\0'); // Check that it has not been overwritten
22182218
argument = empty_password;
22192219
}
22202220
if (argument) {
@@ -2383,7 +2383,7 @@ static Exit_status dump_single_log(PRINT_EVENT_INFO *print_event_info,
23832383
rc = dump_remote_log_entries(print_event_info, logname);
23842384
break;
23852385
default:
2386-
DBUG_ASSERT(0);
2386+
assert(0);
23872387
break;
23882388
}
23892389
return rc;
@@ -2925,7 +2925,7 @@ class Stdin_binlog_istream : public Basic_seekable_istream,
29252925
}
29262926

29272927
bool seek(my_off_t position) override {
2928-
DBUG_ASSERT(position > m_position);
2928+
assert(position > m_position);
29292929
if (Stdin_istream::skip(position - m_position)) {
29302930
error("Failed to skip %llu bytes from stdin", position - m_position);
29312931
return true;
@@ -2937,7 +2937,7 @@ class Stdin_binlog_istream : public Basic_seekable_istream,
29372937
/* purecov: begin inspected */
29382938
/** Stdin has no length. It should never be called. */
29392939
my_off_t length() override {
2940-
DBUG_ASSERT(0);
2940+
assert(0);
29412941
return 0;
29422942
}
29432943
/* purecov: end */

0 commit comments

Comments
 (0)