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 ZoneInfoSourceFactory zone_info_source_factory __attribute__((weak)) =
63     DefaultFactory;
64 #elif defined(_MSC_VER) && !defined(__MINGW32__) && !defined(_LIBCPP_VERSION)
65 extern ZoneInfoSourceFactory zone_info_source_factory;
66 extern ZoneInfoSourceFactory default_factory;
67 ZoneInfoSourceFactory default_factory = DefaultFactory;
68 #if defined(_M_IX86)
69 #pragma comment(                                                                                                         \
70     linker,                                                                                                              \
71     "/alternatename:?zone_info_source_factory@cctz_extension@time_internal@" ABSL_INTERNAL_MANGLED_NS                    \
72     "@@3P6A?AV?$unique_ptr@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                 \
73     "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                   \
74     "@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@" ABSL_INTERNAL_MANGLED_BACKREFERENCE      \
75     "@ABV?$function@$$A6A?AV?$unique_ptr@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                   \
76     "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                   \
77     "@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@" ABSL_INTERNAL_MANGLED_BACKREFERENCE \
78     "@@ZA=?default_factory@cctz_extension@time_internal@" ABSL_INTERNAL_MANGLED_NS                                       \
79     "@@3P6A?AV?$unique_ptr@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                 \
80     "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                   \
81     "@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@" ABSL_INTERNAL_MANGLED_BACKREFERENCE      \
82     "@ABV?$function@$$A6A?AV?$unique_ptr@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                   \
83     "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                   \
84     "@@@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@" ABSL_INTERNAL_MANGLED_BACKREFERENCE \
85     "@@ZA")
86 #elif defined(_M_IA_64) || defined(_M_AMD64) || defined(_M_ARM64)
87 #pragma comment(                                                                                                          \
88     linker,                                                                                                               \
89     "/alternatename:?zone_info_source_factory@cctz_extension@time_internal@" ABSL_INTERNAL_MANGLED_NS                     \
90     "@@3P6A?AV?$unique_ptr@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                  \
91     "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                    \
92     "@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@" ABSL_INTERNAL_MANGLED_BACKREFERENCE      \
93     "@AEBV?$function@$$A6A?AV?$unique_ptr@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                   \
94     "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                    \
95     "@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@" ABSL_INTERNAL_MANGLED_BACKREFERENCE \
96     "@@ZEA=?default_factory@cctz_extension@time_internal@" ABSL_INTERNAL_MANGLED_NS                                       \
97     "@@3P6A?AV?$unique_ptr@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                  \
98     "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                    \
99     "@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@" ABSL_INTERNAL_MANGLED_BACKREFERENCE      \
100     "@AEBV?$function@$$A6A?AV?$unique_ptr@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                   \
101     "@@U?$default_delete@VZoneInfoSource@cctz@time_internal@" ABSL_INTERNAL_MANGLED_NS                                    \
102     "@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z@" ABSL_INTERNAL_MANGLED_BACKREFERENCE \
103     "@@ZEA")
104 #else
105 #error Unsupported MSVC platform
106 #endif  // _M_<PLATFORM>
107 #else
108 // Make it a "strong" definition if we have no other choice.
109 ZoneInfoSourceFactory zone_info_source_factory = DefaultFactory;
110 #endif
111 
112 }  // namespace cctz_extension
113 }  // namespace time_internal
114 ABSL_NAMESPACE_END
115 }  // namespace absl
116