Skip to content

Commit 8fed674

Browse files
committed
Use environment() and environment_is() stubs for android
1 parent 72b1656 commit 8fed674

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

libcxx/include/__text_encoding/te_impl.h

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,19 +524,47 @@ struct __te_impl {
524524
# endif
525525
}
526526

527-
# if _LIBCPP_HAS_LOCALIZATION && !defined(__ANDROID__)
528-
_LIBCPP_HIDDEN static __te_impl __get_locale_encoding(const char* __name);
529-
# if defined(_LIBCPP_WIN32API)
527+
# if _LIBCPP_HAS_LOCALIZATION
528+
// TODO: Android has <langinfo.h> but not nl_langinfo_l which is required to implement this function.
529+
# if !defined(__ANDROID__)
530+
# if defined(_LIBCPP_WIN32API)
530531
_LIBCPP_HIDDEN static __id __get_win32_acp();
531-
# endif
532+
# endif
533+
_LIBCPP_HIDDEN static __te_impl __get_locale_encoding(const char* __name);
532534
_LIBCPP_HIDDEN static __te_impl __get_env_encoding();
535+
533536
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI static __te_impl __environment();
534537

535538
template <__id _Id>
536539
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static bool __environment_is() {
537540
return __environment() == _Id;
538541
}
542+
543+
# else
544+
_LIBCPP_HIDDEN static __te_impl __get_locale_encoding(const char* __name) = delete;
545+
_LIBCPP_HIDDEN static __te_impl __get_env_encoding() = delete;
546+
547+
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI static __te_impl __environment();
548+
549+
template <__id _Id>
550+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static bool __environment_is() {
551+
return false;
552+
}
553+
# endif
554+
555+
# else
556+
557+
# if defined(_LIBCPP_WIN32API)
558+
_LIBCPP_HIDDEN static __id __get_win32_acp() = delete;
559+
# endif
560+
_LIBCPP_HIDDEN static __te_impl __get_locale_encoding(const char* __name) = delete;
561+
_LIBCPP_HIDDEN static __te_impl __get_env_encoding() = delete;
562+
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI static __te_impl __environment() = delete;
563+
template <__id _Id>
564+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static bool __environment_is() = delete;
565+
539566
# endif
567+
540568
const __te_data* __encoding_rep_ = __text_encoding_data + 1;
541569
char __name_[__max_name_length_ + 1] = {0};
542570

libcxx/include/text_encoding

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ public:
115115
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static bool environment_is() {
116116
return __te_impl::__environment_is<_Id>();
117117
}
118+
# else
119+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static text_encoding environment() = delete;
120+
121+
template <id _Id>
122+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static bool environment_is() = delete;
118123
# endif
119124
};
120125

libcxx/src/text_encoding.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ _LIBCPP_HIDDEN __te_impl::__id __te_impl::__get_win32_acp() {
210210
}
211211
#endif // _LIBCPP_WIN32API
212212

213+
#if !defined(__ANDROID__)
213214
_LIBCPP_HIDDEN __te_impl __te_impl::__get_locale_encoding(const char* __name) {
214215
__te_impl __e;
215216

@@ -237,13 +238,17 @@ _LIBCPP_HIDDEN __te_impl __te_impl::__get_locale_encoding(const char* __name) {
237238
}
238239

239240
_LIBCPP_HIDDEN __te_impl __te_impl::__get_env_encoding() {
240-
#if defined(_LIBCPP_WIN32API)
241+
# if defined(_LIBCPP_WIN32API)
241242
return __te_impl(__get_win32_acp());
242-
#else
243+
# else
243244
return __get_locale_encoding("");
244-
#endif // _LIBCPP_WIN32API
245+
# endif // _LIBCPP_WIN32API
245246
}
246247

247248
__te_impl __te_impl::__environment() { return __te_impl::__get_env_encoding(); }
248249

250+
#else
251+
// TODO: Android stub which will always return unknown, should be inaccessible from the main text_encoding interface.
252+
__te_impl __te_impl::__environment() { return __te_impl(); }
253+
#endif
249254
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)