1 // Copyright 2016 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //   https://www.apache.org/licenses/LICENSE-2.0
8 //
9 //   Unless required by applicable law or agreed to in writing, software
10 //   distributed under the License is distributed on an "AS IS" BASIS,
11 //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 //   See the License for the specific language governing permissions and
13 //   limitations under the License.
14 
15 #include "absl/time/internal/cctz/include/cctz/zone_info_source.h"
16 
17 #include "absl/base/config.h"
18 
19 namespace absl {
20 ABSL_NAMESPACE_BEGIN
21 namespace time_internal {
22 namespace cctz {
23 
24 // Defined out-of-line to avoid emitting a weak vtable in all TUs.
~ZoneInfoSource()25 ZoneInfoSource::~ZoneInfoSource() {}
Version() const26 std::string ZoneInfoSource::Version() const { return std::string(); }
27 
28 }  // namespace cctz
29 }  // namespace time_internal
30 ABSL_NAMESPACE_END
31 }  // namespace absl
32 
33 namespace absl {
34 ABSL_NAMESPACE_BEGIN
35 namespace time_internal {
36 namespace cctz_extension {
37 
38 namespace {
39 
40 // A default for cctz_extension::zone_info_source_factory, which simply
41 // defers to the fallback factory.
DefaultFactory(const std::string & name,const std::function<std::unique_ptr<absl::time_internal::cctz::ZoneInfoSource> (const std::string & name)> & fallback_factory)42 std::unique_ptr<absl::time_internal::cctz::ZoneInfoSource> DefaultFactory(
43     const std::string& name,
44     const std::function<
45         std::unique_ptr<absl::time_internal::cctz::ZoneInfoSource>(
46             const std::string& name)>& fallback_factory) {
47   return fallback_factory(name);
48 }
49 
50 }  // namespace
51 
52 // A "weak" definition for cctz_extension::zone_info_source_factory.
53 // The user may override this with their own "strong" definition (see
54 // zone_info_source.h).
55 #if !defined(__has_attribute)
56 #define __has_attribute(x) 0
57 #endif
58 // MinGW is GCC on Windows, so while it asserts __has_attribute(weak), the
59 // Windows linker cannot handle that. Nor does the MinGW compiler know how to
60 // pass "#pragma comment(linker, ...)" to the Windows linker.
61 #if (__has_attribute(weak) || defined(__GNUC__)) && !defined(__MINGW32__) && \
62     !defined(__CYGWIN__)
63 ZoneInfoSourceFactory zone_info_source_factory __attribute__((weak)) =
64     DefaultFactory;
65 #elif defined(_MSC_VER) && !defined(__MINGW32__) && !defined(_LIBCPP_VERSION)
66 extern ZoneInfoSourceFactory zone_info_source_factory;
67 extern ZoneInfoSourceFactory default_factory;
68 ZoneInfoSourceFactory default_factory = DefaultFactory;
69 #if defined(_M_IX86) || defined(_M_ARM)
70 #pragma comment(                                                                                                                 \
71         linker,                                                                                                                  \
72             "/alternatename:?zone_info_source_factory@cctz_extension@time_internal@" ABSL_INTERNAL_MANGLED_NS                    \
73             "@@3P6A?AV?$unique_ptr@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                 \
74             "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                   \
75             "@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@" ABSL_INTERNAL_MANGLED_BACKREFERENCE      \
76             "@ABV?$function@$$A6A?AV?$unique_ptr@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                   \
77             "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                   \
78             "@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@" ABSL_INTERNAL_MANGLED_BACKREFERENCE \
79             "@@ZA=?default_factory@cctz_extension@time_internal@" ABSL_INTERNAL_MANGLED_NS                                       \
80             "@@3P6A?AV?$unique_ptr@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                 \
81             "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                   \
82             "@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@" ABSL_INTERNAL_MANGLED_BACKREFERENCE      \
83             "@ABV?$function@$$A6A?AV?$unique_ptr@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                   \
84             "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                   \
85             "@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@" ABSL_INTERNAL_MANGLED_BACKREFERENCE \
86             "@@ZA")
87 #elif defined(_M_IA_64) || defined(_M_AMD64) || defined(_M_ARM64)
88 #pragma comment(                                                                                                                  \
89         linker,                                                                                                                   \
90             "/alternatename:?zone_info_source_factory@cctz_extension@time_internal@" ABSL_INTERNAL_MANGLED_NS                     \
91             "@@3P6A?AV?$unique_ptr@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                  \
92             "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                    \
93             "@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@" ABSL_INTERNAL_MANGLED_BACKREFERENCE      \
94             "@AEBV?$function@$$A6A?AV?$unique_ptr@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                   \
95             "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                    \
96             "@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@" ABSL_INTERNAL_MANGLED_BACKREFERENCE \
97             "@@ZEA=?default_factory@cctz_extension@time_internal@" ABSL_INTERNAL_MANGLED_NS                                       \
98             "@@3P6A?AV?$unique_ptr@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                  \
99             "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                    \
100             "@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@" ABSL_INTERNAL_MANGLED_BACKREFERENCE      \
101             "@AEBV?$function@$$A6A?AV?$unique_ptr@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                   \
102             "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                    \
103             "@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@" ABSL_INTERNAL_MANGLED_BACKREFERENCE \
104             "@@ZEA")
105 #else
106 #error Unsupported MSVC platform
107 #endif  // _M_<PLATFORM>
108 #else
109 // Make it a "strong" definition if we have no other choice.
110 ZoneInfoSourceFactory zone_info_source_factory = DefaultFactory;
111 #endif
112 
113 }  // namespace cctz_extension
114 }  // namespace time_internal
115 ABSL_NAMESPACE_END
116 }  // namespace absl
117