diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 8bccabd94..103aec3d9 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -349,4 +349,5 @@ build_lib( HEADER_FILES ${header_files} LIBRARIES_TO_LINK ${libraries_to_link} TEST_SOURCES ${test_sources} + GENERATE_EXPORT_HEADER ) diff --git a/src/core/model/cairo-wideint-private.h b/src/core/model/cairo-wideint-private.h index 22d503ec4..c93d87fe0 100644 --- a/src/core/model/cairo-wideint-private.h +++ b/src/core/model/cairo-wideint-private.h @@ -70,7 +70,10 @@ extern "C" { #if !HAVE_UINT64_T -extern const char * cairo_impl64; +//PDB original string literal causes access violation on Windows when accessed +// by binaries that link to core, e.g. tests +// Substitute function call +const char * cairo_impl64(); typedef struct _cairo_uint64 { uint32_t lo, hi; @@ -111,7 +114,10 @@ int cairo_I _cairo_int64_lt (cairo_uint64_t a, cairo_uint64_t b); #else -extern const char * cairo_impl64; +//PDB original string literal causes access violation on Windows when accessed +// by binaries that link to core, e.g. tests +// Substitute function call +const char * cairo_impl64(); typedef uint64_t cairo_uint64_t; typedef int64_t cairo_int64_t; @@ -193,7 +199,10 @@ _cairo_int64_divrem (cairo_int64_t num, cairo_int64_t den); #if !HAVE_UINT128_T -extern const char * cairo_impl128; +//PDB original string literal causes access violation on Windows when accessed +// by binaries that link to core, e.g. tests +// Substitute function call +const char * cairo_impl128(); typedef struct cairo_uint128 { cairo_uint64_t lo, hi; @@ -238,7 +247,10 @@ int cairo_I _cairo_int128_lt (cairo_int128_t a, cairo_int128_t b); #else /* !HAVE_UINT128_T */ -extern const char * cairo_impl128; +//PDB original string literal causes access violation on Windows when accessed +// by binaries that link to core, e.g. tests +// Substitute function call +const char * cairo_impl128(); typedef uint128_t cairo_uint128_t; typedef int128_t cairo_int128_t; diff --git a/src/core/model/cairo-wideint.c b/src/core/model/cairo-wideint.c index d8abe2da6..8143f0c0a 100644 --- a/src/core/model/cairo-wideint.c +++ b/src/core/model/cairo-wideint.c @@ -45,7 +45,14 @@ #if HAVE_UINT64_T -const char * cairo_impl64 = "uint64_t"; +//PDB original string literal causes access violation on Windows when accessed +// by binaries that link to core, e.g. tests +// Substitute function call +const char * +cairo_impl64() +{ + return "uint64_t"; +} #define _cairo_uint32s_to_uint64(h,l) ((uint64_t) (h) << 32 | (l)) @@ -61,7 +68,14 @@ _cairo_uint64_divrem (cairo_uint64_t num, cairo_uint64_t den) #else -const char * cairo_impl64 = "uint32_t"; +//PDB original string literal causes access violation on Windows when accessed +// by binaries that link to core, e.g. tests +// Substitute function call +const char * +cairo_impl64() +{ + return "uint32_t"; +} cairo_uint64_t _cairo_uint32_to_uint64 (uint32_t i) @@ -329,7 +343,14 @@ _cairo_int64_divrem (cairo_int64_t num, cairo_int64_t den) #if HAVE_UINT128_T -const char * cairo_impl128 = "uint128_t"; +//PDB original string literal causes access violation on Windows when accessed +// by binaries that link to core, e.g. tests +// Substitute function call +const char * +cairo_impl128() +{ + return "uint128_t"; +} cairo_uquorem128_t _cairo_uint128_divrem (cairo_uint128_t num, cairo_uint128_t den) @@ -343,7 +364,14 @@ _cairo_uint128_divrem (cairo_uint128_t num, cairo_uint128_t den) #else -const char * cairo_impl128 = "cairo_uint64_t"; +//PDB original string literal causes access violation on Windows when accessed +// by binaries that link to core, e.g. tests +// Substitute function call +const char * +cairo_impl128() +{ + return "cairo_uint64_t"; +} cairo_uint128_t _cairo_uint32_to_uint128 (uint32_t i) @@ -550,7 +578,7 @@ _cairo_uint128_rsl (cairo_uint128_t a, int shift) } cairo_uint128_t -_cairo_uint128_rsa (cairo_int128_t a, int shift) +_cairo_uint128_rsa (cairo_uint128_t a, int shift) { if (shift >= 64) { diff --git a/src/core/model/log.h b/src/core/model/log.h index 39792ee70..1ddd85e07 100644 --- a/src/core/model/log.h +++ b/src/core/model/log.h @@ -487,6 +487,10 @@ ParameterLogger::operator<<(const T& param) // Use + unary operator to cast uint8_t / int8_t to uint32_t / int32_t, respectively m_os << +param; } + else if constexpr (std::is_pointer_v) + { + m_os << static_cast(¶m); + } else { m_os << param; diff --git a/src/core/model/nstime.h b/src/core/model/nstime.h index 2eabddce3..34cf54819 100644 --- a/src/core/model/nstime.h +++ b/src/core/model/nstime.h @@ -15,6 +15,8 @@ #include "int64x64.h" #include "type-name.h" +#include "ns3/core-export.h" + #include #include #include @@ -90,7 +92,7 @@ class TimeWithUnit; * if you use picoseconds is 2^64 ps = 2^24 s = 7 months, whereas, * had you used nanoseconds, you could have run for 584 years. */ -class Time +class CORE_EXPORT Time { public: /** @@ -127,7 +129,7 @@ class Time inline Time() : m_data() { - if (g_markingTimes) + if (MarkingTimes()) { Mark(this); } @@ -141,7 +143,7 @@ class Time inline Time(const Time& o) : m_data(o.m_data) { - if (g_markingTimes) + if (MarkingTimes()) { Mark(this); } @@ -155,7 +157,7 @@ class Time Time(Time&& o) : m_data(o.m_data) { - if (g_markingTimes) + if (MarkingTimes()) { Mark(this); } @@ -174,7 +176,7 @@ class Time explicit inline Time(double v) : m_data(llround(v)) { - if (g_markingTimes) + if (MarkingTimes()) { Mark(this); } @@ -183,7 +185,7 @@ class Time explicit inline Time(int v) : m_data(v) { - if (g_markingTimes) + if (MarkingTimes()) { Mark(this); } @@ -192,7 +194,7 @@ class Time explicit inline Time(long int v) : m_data(v) { - if (g_markingTimes) + if (MarkingTimes()) { Mark(this); } @@ -201,7 +203,7 @@ class Time explicit inline Time(long long int v) : m_data(v) { - if (g_markingTimes) + if (MarkingTimes()) { Mark(this); } @@ -210,7 +212,7 @@ class Time explicit inline Time(unsigned int v) : m_data(v) { - if (g_markingTimes) + if (MarkingTimes()) { Mark(this); } @@ -219,7 +221,7 @@ class Time explicit inline Time(unsigned long int v) : m_data(v) { - if (g_markingTimes) + if (MarkingTimes()) { Mark(this); } @@ -228,7 +230,7 @@ class Time explicit inline Time(unsigned long long int v) : m_data(v) { - if (g_markingTimes) + if (MarkingTimes()) { Mark(this); } @@ -237,7 +239,7 @@ class Time explicit inline Time(const int64x64_t& v) : m_data(v.Round()) { - if (g_markingTimes) + if (MarkingTimes()) { Mark(this); } @@ -291,7 +293,7 @@ class Time /** Destructor */ ~Time() { - if (g_markingTimes) + if (MarkingTimes()) { Clear(this); } @@ -746,6 +748,21 @@ class Time */ static MarkedTimes* g_markingTimes; + /** + * Null check for g_markingTimes from outside time.cc + * + * @return \c true if g_markingTimes is not null + * + * @internal + * + * The inline Time ctors need to check if g_markingTimes is allocated + * before calling Mark(). Likewise, the dtor also needs to check before + * calling Clear(). On Windows, attempting to access g_markingTimes + * directly from outside the compilation unit is an access violation so + * this method is provided to work around that limitation. + */ + static bool MarkingTimes(); + public: /** * Function to force static initialization of Time. @@ -866,6 +883,13 @@ typedef void (*Time)(Time oldValue, Time newValue); } // namespace TracedValueCallback +/** + * Force static initialization order of Time in each compilation unit. + * This is internal to the Time implementation. + * @relates Time + */ +static bool g_TimeStaticInit [[maybe_unused]] = Time::StaticInit(); + /** * Equality operator for Time. * @param [in] lhs The first value @@ -1510,27 +1534,6 @@ class TimeWithUnit */ TYPENAMEGET_DEFINE(Time); -/** - * @ingroup time - * - * @brief Helper class to force static initialization - * of Time in each compilation unit, ensuring it is - * initialized before usage. - * This is internal to the Time implementation. - * @relates Time - */ -class TimeInitializationHelper -{ - public: - /** Default constructor calls Time::StaticInit */ - TimeInitializationHelper() - { - Time::StaticInit(); - } -}; - -static TimeInitializationHelper g_timeInitHelper; ///< Instance of Time static initialization helper - } // namespace ns3 #endif /* TIME_H */ diff --git a/src/core/model/random-variable-stream.cc b/src/core/model/random-variable-stream.cc index aff427b3a..c08e83ef1 100644 --- a/src/core/model/random-variable-stream.cc +++ b/src/core/model/random-variable-stream.cc @@ -652,8 +652,6 @@ WeibullRandomVariable::GetValue() NS_OBJECT_ENSURE_REGISTERED(NormalRandomVariable); -const double NormalRandomVariable::INFINITE_VALUE = 1e307; - TypeId NormalRandomVariable::GetTypeId() { diff --git a/src/core/model/random-variable-stream.h b/src/core/model/random-variable-stream.h index d29bbb42a..2820c8d5b 100644 --- a/src/core/model/random-variable-stream.h +++ b/src/core/model/random-variable-stream.h @@ -19,6 +19,7 @@ #include "object.h" #include "type-id.h" +#include #include #include @@ -978,8 +979,8 @@ class WeibullRandomVariable : public RandomVariableStream class NormalRandomVariable : public RandomVariableStream { public: - /** Large constant to bound the range. */ - static const double INFINITE_VALUE; + /// Large constant to bound the range. + static constexpr double INFINITE_VALUE = std::numeric_limits::max(); /** * @brief Register this type. diff --git a/src/core/model/time.cc b/src/core/model/time.cc index afcf5a9ff..e5ac8c03d 100644 --- a/src/core/model/time.cc +++ b/src/core/model/time.cc @@ -181,7 +181,7 @@ Time::Time(const std::string& s) *this = Time::FromDouble(v, Time::S); } - if (g_markingTimes) + if (MarkingTimes()) { Mark(this); } @@ -280,6 +280,12 @@ Time::SetResolution(Unit unit, Resolution* resolution, const bool convert /* = t resolution->unit = unit; } +bool +Time::MarkingTimes() +{ + return (g_markingTimes != nullptr); +} + // static void Time::ClearMarkedTimes() diff --git a/src/core/test/int64x64-test-suite.cc b/src/core/test/int64x64-test-suite.cc index eb4df0e82..cc108922e 100644 --- a/src/core/test/int64x64-test-suite.cc +++ b/src/core/test/int64x64-test-suite.cc @@ -1540,8 +1540,8 @@ Int64x64ImplTestCase::DoRun() std::cout << std::endl; #if defined(INT64X64_USE_CAIRO) && !defined(PYTHON_SCAN) - std::cout << "cairo_impl64: " << cairo_impl64 << std::endl; - std::cout << "cairo_impl128: " << cairo_impl128 << std::endl; + std::cout << "cairo_impl64: " << cairo_impl64() << std::endl; + std::cout << "cairo_impl128: " << cairo_impl128() << std::endl; #endif if (RUNNING_WITH_LIMITED_PRECISION != 0)