Skip to content

Commit

Permalink
Fix errors preventing clean compilation with NDEBUG defined
Browse files Browse the repository at this point in the history
Summary:
The intent of these changes is to make sure that we'll compile cleanly with `NDEBUG` defined. Clean compilation is necessary for clearly separating and producing release builds. `NDEBUG` macro is //de facto// way to distinguish between debug and release code paths. It is also notably used in `<assert.h>` to determine the behavior of assertions.

There are two types of problems fixed in this set of changes:

  # Incorrect use of assertions, //i.e.//, assertions have side-effects and are evaluating invariants which are actually meant to be executed in release builds as well.
  # Warnings caused by unused variables (which when treated as errors will cause build breaks) which are fixed by adding `MY_ATTRIBUTE((unused))` to the variable definitions.

Test Plan:
  ```
  mysqlbuild.sh
  mysqltest.sh
  mysqltest.sh --testset=RocksDB

  mysqlbuild.sh --release
  mysqltest.sh --release
  mysqltest.sh --release --testset=RocksDB
  ```

Reviewers: jtolmer, tianx

Reviewed By: tianx

Subscribers: webscalesql-eng

Differential Revision: https://reviews.facebook.net/D54111
  • Loading branch information
Gunnar Kudrjavets authored and Herman Lee committed Jan 24, 2017
1 parent 4f3e2c0 commit 9d9e8bd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8707,7 +8707,8 @@ void run_explain(struct st_connection *cn, struct st_command *command,
char *re_eprint(int err)
{
static char epbuf[100];
size_t len= my_regerror(MY_REG_ITOA | err, NULL, epbuf, sizeof(epbuf));
size_t len MY_ATTRIBUTE((unused)) = my_regerror(MY_REG_ITOA | err, NULL,
epbuf, sizeof(epbuf));
assert(len <= sizeof(epbuf));
return(epbuf);
}
Expand Down
13 changes: 9 additions & 4 deletions fbson/FbsonUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ class FbsonUpdater {

// Get the current node and because we want to delete it, pop it from stack
NodeInfo curr_node = path_node_.back();
int pack_size = (int)((char*)curr_node.fbson_value -
int pack_size = (int)((char*)
curr_node.fbson_value -
curr_node.addr +
curr_node.fbson_value->numPackedBytes());

// Move the data after the current node to new place
assert(moveTo(curr_node.addr + pack_size,
curr_node.addr));
if (!moveTo(curr_node.addr + pack_size,
curr_node.addr)) {
return FbsonErrType::E_OUTOFMEMORY;
}
path_node_.pop_back();
return FbsonErrType::E_NONE;
}
Expand Down Expand Up @@ -273,7 +276,9 @@ class FbsonUpdater {
if(str_len <= (int)curr->size() &&
str_len >= ((int)curr->size() * (1.0 - str_shrink_ratio_))){
// We can update string in place
assert(((StringVal*)curr)->setVal(str, str_len));
if (!((StringVal*)curr)->setVal(str, str_len)) {
return FbsonErrType::E_INVALID_OPER;
}
return FbsonErrType::E_NONE;
}
}
Expand Down
2 changes: 1 addition & 1 deletion regex/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ eprint(err)
int err;
{
static char epbuf[100];
size_t len;
size_t len MY_ATTRIBUTE((unused));

len = my_regerror(MY_REG_ITOA|err, (my_regex_t *)NULL, epbuf, sizeof(epbuf));
assert(len <= sizeof(epbuf));
Expand Down
4 changes: 3 additions & 1 deletion sql/log_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11793,7 +11793,9 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli)
&m_cols_ai : &m_cols);
table_def *tabledef= NULL;
TABLE *conv_table= NULL;
assert(rli->get_table_data(table, &tabledef, &conv_table));
bool get_success MY_ATTRIBUTE((unused)) = rli->get_table_data(table,
&tabledef, &conv_table);
assert(get_success);
if (tabledef->have_column_names())
{
bitmap_clear_all(table->write_set);
Expand Down
2 changes: 1 addition & 1 deletion tests/bug25714.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
int main (int argc, char **argv)
{
MYSQL conn;
int OK;
int OK MY_ATTRIBUTE((unused));

const char* query4= "INSERT INTO federated.t1 SET Value=54";
const char* query5= "INSERT INTO federated.t1 SET Value=55";
Expand Down

0 comments on commit 9d9e8bd

Please sign in to comment.