mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Added a way to forbid static initialization of a class
This commit is contained in:
parent
30cc569845
commit
cf57a88495
@ -21,6 +21,7 @@
|
||||
#include <Common/StringUtils/StringUtils.h>
|
||||
|
||||
#include <common/phdr_cache.h>
|
||||
#include <ext/scope_guard.h>
|
||||
|
||||
|
||||
/// Universal executable for various clickhouse applications
|
||||
@ -130,8 +131,19 @@ bool isClickhouseApp(const std::string & app_suffix, std::vector<char *> & argv)
|
||||
}
|
||||
|
||||
|
||||
/// This allows to implement assert to forbid initialization of a class in static constructors.
|
||||
/// Usage:
|
||||
///
|
||||
/// extern bool inside_main;
|
||||
/// class C { C() { assert(inside_main); } };
|
||||
bool inside_main = false;
|
||||
|
||||
|
||||
int main(int argc_, char ** argv_)
|
||||
{
|
||||
inside_main = true;
|
||||
SCOPE_EXIT({ inside_main = false; });
|
||||
|
||||
/// Reset new handler to default (that throws std::bad_alloc)
|
||||
/// It is needed because LLVM library clobbers it.
|
||||
std::set_new_handler(nullptr);
|
||||
|
@ -44,9 +44,16 @@ UInt8 getDayOfWeek(const cctz::civil_day & date)
|
||||
}
|
||||
|
||||
|
||||
__attribute__((__weak__)) extern bool inside_main;
|
||||
|
||||
DateLUTImpl::DateLUTImpl(const std::string & time_zone_)
|
||||
: time_zone(time_zone_)
|
||||
{
|
||||
/// DateLUT should not be initialized in global constructors for the following reasons:
|
||||
/// 1. It is too heavy.
|
||||
if (&inside_main)
|
||||
assert(inside_main);
|
||||
|
||||
size_t i = 0;
|
||||
time_t start_of_day = DATE_LUT_MIN;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user