Skip to content

Commit 4a87db6

Browse files
authored
[libc++][print] Enables it on Apple backdeployment. (#76293)
As suggested in #73262 this enable the stream printing on Apple backdeployment targets. This omits the check whether the file is a terminal. This is not entirely conforming, but the differences should be minor and are typically not observable. Fixes #75225
1 parent 34933d1 commit 4a87db6

File tree

10 files changed

+14
-21
lines changed

10 files changed

+14
-21
lines changed

libcxx/include/__availability

+4
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@
264264
# define _LIBCPP_AVAILABILITY_HAS_TZDB 0
265265
# define _LIBCPP_AVAILABILITY_TZDB __attribute__((unavailable))
266266

267+
// Warning: This availability macro works differently than the other macros.
268+
// The dylib part of print is not needed on Apple platforms. Therefore when
269+
// the macro is not available the code calling the dylib is commented out.
270+
// The macro _LIBCPP_AVAILABILITY_PRINT is not used.
267271
# define _LIBCPP_AVAILABILITY_HAS_PRINT 0
268272
# define _LIBCPP_AVAILABILITY_PRINT __attribute__((unavailable))
269273

libcxx/include/ostream

+9-5
Original file line numberDiff line numberDiff line change
@@ -1083,12 +1083,15 @@ _LIBCPP_HIDE_FROM_ABI inline void vprint_nonunicode(ostream& __os, string_view _
10831083
// native Unicode API;
10841084
// Whether the returned FILE* is "a terminal capable of displaying Unicode"
10851085
// is determined in the same way as the print(FILE*, ...) overloads.
1086-
_LIBCPP_AVAILABILITY_PRINT _LIBCPP_EXPORTED_FROM_ABI FILE* __get_ostream_file(ostream& __os);
1086+
_LIBCPP_EXPORTED_FROM_ABI FILE* __get_ostream_file(ostream& __os);
10871087

10881088
# ifndef _LIBCPP_HAS_NO_UNICODE
10891089
template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
1090-
_LIBCPP_AVAILABILITY_PRINT _LIBCPP_HIDE_FROM_ABI void
1090+
_LIBCPP_HIDE_FROM_ABI void
10911091
__vprint_unicode(ostream& __os, string_view __fmt, format_args __args, bool __write_nl) {
1092+
#if _LIBCPP_AVAILABILITY_HAS_PRINT == 0
1093+
return std::__vprint_nonunicode(__os, __fmt, __args, __write_nl);
1094+
#else
10921095
FILE* __file = std::__get_ostream_file(__os);
10931096
if (!__file || !__print::__is_terminal(__file))
10941097
return std::__vprint_nonunicode(__os, __fmt, __args, __write_nl);
@@ -1123,17 +1126,18 @@ __vprint_unicode(ostream& __os, string_view __fmt, format_args __args, bool __wr
11231126
__os.__set_badbit_and_consider_rethrow();
11241127
}
11251128
# endif // _LIBCPP_HAS_NO_EXCEPTIONS
1129+
#endif // _LIBCPP_AVAILABILITY_HAS_PRINT
11261130
}
11271131

11281132
template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
1129-
_LIBCPP_AVAILABILITY_PRINT _LIBCPP_HIDE_FROM_ABI inline void
1133+
_LIBCPP_HIDE_FROM_ABI inline void
11301134
vprint_unicode(ostream& __os, string_view __fmt, format_args __args) {
11311135
std::__vprint_unicode(__os, __fmt, __args, false);
11321136
}
11331137
# endif // _LIBCPP_HAS_NO_UNICODE
11341138

11351139
template <class... _Args>
1136-
_LIBCPP_AVAILABILITY_PRINT _LIBCPP_HIDE_FROM_ABI void
1140+
_LIBCPP_HIDE_FROM_ABI void
11371141
print(ostream& __os, format_string<_Args...> __fmt, _Args&&... __args) {
11381142
# ifndef _LIBCPP_HAS_NO_UNICODE
11391143
if constexpr (__print::__use_unicode_execution_charset)
@@ -1146,7 +1150,7 @@ print(ostream& __os, format_string<_Args...> __fmt, _Args&&... __args) {
11461150
}
11471151

11481152
template <class... _Args>
1149-
_LIBCPP_AVAILABILITY_PRINT _LIBCPP_HIDE_FROM_ABI void
1153+
_LIBCPP_HIDE_FROM_ABI void
11501154
println(ostream& __os, format_string<_Args...> __fmt, _Args&&... __args) {
11511155
# ifndef _LIBCPP_HAS_NO_UNICODE
11521156
// Note the wording in the Standard is inefficient. The output of

libcxx/src/ostream.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
_LIBCPP_BEGIN_NAMESPACE_STD
1919

20-
_LIBCPP_AVAILABILITY_PRINT _LIBCPP_EXPORTED_FROM_ABI FILE* __get_ostream_file(ostream& __os) {
20+
_LIBCPP_EXPORTED_FROM_ABI FILE* __get_ostream_file(ostream& __os) {
2121
// dynamic_cast requires RTTI, this only affects users whose vendor builds
2222
// the dylib with RTTI disabled. It does not affect users who build with RTTI
2323
// disabled but use a dylib where the RTTI is enabled.

libcxx/test/libcxx/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/vprint_unicode.pass.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
1111

1212
// XFAIL: availability-fp_to_chars-missing
13-
// XFAIL: availability-print-missing
1413

1514
// Clang modules do not work with the definiton of _LIBCPP_TESTING_PRINT_IS_TERMINAL
1615
// XFAIL: clang-modules-build

libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/locale-specific_form.pass.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// UNSUPPORTED: no-filesystem
1414

1515
// XFAIL: availability-fp_to_chars-missing
16-
// XFAIL: availability-print-missing
1716

1817
// Bionic has minimal locale support, investigate this later.
1918
// XFAIL: LIBCXX-ANDROID-FIXME

libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/print.pass.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// UNSUPPORTED: no-filesystem
1313

1414
// XFAIL: availability-fp_to_chars-missing
15-
// XFAIL: availability-print-missing
1615

1716
// <ostream>
1817

libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/println.pass.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// UNSUPPORTED: no-filesystem
1313

1414
// XFAIL: availability-fp_to_chars-missing
15-
// XFAIL: availability-print-missing
1615

1716
// <ostream>
1817

libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/vprint_nonunicode.pass.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// UNSUPPORTED: no-filesystem
1313

1414
// XFAIL: availability-fp_to_chars-missing
15-
// XFAIL: availability-print-missing
1615

1716
// <ostream>
1817

libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/vprint_unicode.pass.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// UNSUPPORTED: no-filesystem
1313

1414
// XFAIL: availability-fp_to_chars-missing
15-
// XFAIL: availability-print-missing
1615

1716
// <ostream>
1817

libcxx/utils/libcxx/test/features.py

-9
Original file line numberDiff line numberDiff line change
@@ -586,13 +586,4 @@ def check_gdb(cfg):
586586
cfg.available_features,
587587
),
588588
),
589-
# Tests that require support for <print> and std::print in <ostream> in the built library.
590-
Feature(
591-
name="availability-print-missing",
592-
when=lambda cfg: BooleanExpression.evaluate(
593-
# TODO(ldionne) Please provide the correct value.
594-
"stdlib=apple-libc++ && target={{.+}}-apple-macosx{{(10.9|10.10|10.11|10.12|10.13|10.14|10.15|11.0|12.0|13.0)(.0)?}}",
595-
cfg.available_features,
596-
),
597-
),
598589
]

0 commit comments

Comments
 (0)