Skip to content

Commit b214264

Browse files
committed
MDEV-20525 rocksdb debug compilation fails on Windows due to unresolved my_assert variable
MYSQL_PLUGIN_IMPORT did not work correctly for the RocksDB helper library rocksdb_aux_lib, because that library was not compiled with -DMYSQL_DYNAMIC_PLUGIN. Fix DBUG such that it does not depend on exported data, only on functions (which do not need MYSQL_PLUGIN_IMPORT decoration) Use a "getter" function _db_my_assert() instead of DLL-exported variable. Also, reduce object code duplication by moving more of the DBUG_ASSERT logic inside the _db_my_assert() function, and add unlikely() and ATTRIBUTE_COLD hints to ensure that the 'assertion failed' code will be separated from the main control flow logic. Thus, the compiler can move the unlikely() code to the end of the compiled function, reachable via a forward conditional branch, which the processor's branch predictor could assume 'not taken'.
1 parent 41290e9 commit b214264

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

dbug/dbug.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,16 @@ static int default_my_dbug_sanity(void)
22582258
return 0;
22592259
}
22602260

2261+
extern my_bool my_assert;
2262+
ATTRIBUTE_COLD
2263+
my_bool _db_my_assert(const char *file, int line, const char *msg)
2264+
{
2265+
_db_flush_();
2266+
my_bool a = my_assert;
2267+
if (!a)
2268+
fprintf(stderr, "%s:%d: assert: %s\n", file, line, msg);
2269+
return a;
2270+
}
22612271
#else
22622272

22632273
/*

include/my_dbug.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ struct _db_stack_frame_ {
3535
};
3636

3737
struct _db_code_state_;
38-
extern MYSQL_PLUGIN_IMPORT my_bool my_assert;
3938
extern my_bool _dbug_on_;
4039
extern my_bool _db_keyword_(struct _db_code_state_ *, const char *, int);
4140
extern int _db_explain_(struct _db_code_state_ *cs, char *buf, size_t len);
@@ -59,6 +58,8 @@ extern void _db_dump_(uint _line_,const char *keyword,
5958
extern void _db_end_(void);
6059
extern void _db_lock_file_(void);
6160
extern void _db_unlock_file_(void);
61+
ATTRIBUTE_COLD
62+
extern my_bool _db_my_assert(const char *file, int line, const char *msg);
6263
extern FILE *_db_fp_(void);
6364
extern void _db_flush_(void);
6465
extern void dbug_swap_code_state(void **code_state_store);
@@ -104,10 +105,9 @@ extern int (*dbug_sanity)(void);
104105
#define DBUG_END() _db_end_ ()
105106
#define DBUG_LOCK_FILE _db_lock_file_()
106107
#define DBUG_UNLOCK_FILE _db_unlock_file_()
107-
#define DBUG_ASSERT(A) do { if (!(A)) { _db_flush_(); \
108-
if (my_assert) assert(A); \
109-
else fprintf(stderr, "%s:%d: assert: %s\n", __FILE__, __LINE__, #A); \
110-
}} while (0)
108+
#define DBUG_ASSERT(A) do { \
109+
if (unlikely(!(A)) && _db_my_assert(__FILE__, __LINE__, #A)) assert(A); \
110+
} while (0)
111111
#define DBUG_SLOW_ASSERT(A) DBUG_ASSERT(A)
112112
#define DBUG_ASSERT_EXISTS
113113
#define DBUG_EXPLAIN(buf,len) _db_explain_(0, (buf),(len))

include/my_sys.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ extern ulong my_sync_count;
267267
extern uint mysys_usage_id;
268268
extern int32 my_file_opened;
269269
extern my_bool my_init_done, my_thr_key_mysys_exists;
270-
extern MYSQL_PLUGIN_IMPORT my_bool my_assert;
270+
extern my_bool my_assert;
271271
extern my_bool my_assert_on_error;
272272
extern myf my_global_flags; /* Set to MY_WME for more error messages */
273273
/* Point to current my_message() */

0 commit comments

Comments
 (0)