Skip to content

Commit 2472d38

Browse files
authored
[libc++] Move unused basic_string function definition to the dylib sources (llvm#126219)
`__init(const value_type*, size_type, size_type)` is part of our ABI, but we don't actually use the function anymore in the dylib. THis moves the definition to the `src/` directory to make it clear that the code is unused. This also allows us to remove it entirely in the unstable ABI.
1 parent c17df0a commit 2472d38

File tree

3 files changed

+44
-27
lines changed

3 files changed

+44
-27
lines changed

libcxx/include/__string/extern_template_lists.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#define _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_Func, _CharType) \
3333
_Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*, size_type)) \
3434
_Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type const*, size_type, size_type) const) \
35-
_Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::__init(value_type const*, size_type, size_type)) \
3635
_Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::basic_string(basic_string const&)) \
3736
_Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*)) \
3837
_Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::basic_string(basic_string const&, allocator<_CharType> const&)) \
@@ -82,7 +81,6 @@
8281
#define _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_Func, _CharType) \
8382
_Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*, size_type)) \
8483
_Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type const*, size_type, size_type) const) \
85-
_Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::__init(value_type const*, size_type, size_type)) \
8684
_Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*)) \
8785
_Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::find_last_not_of(value_type const*, size_type, size_type) const) \
8886
_Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::~basic_string()) \

libcxx/include/string

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,7 +2254,6 @@ private:
22542254
return __guess;
22552255
}
22562256

2257-
inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init(const value_type* __s, size_type __sz, size_type __reserve);
22582257
inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init(const value_type* __s, size_type __sz);
22592258
inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init(size_type __n, value_type __c);
22602259

@@ -2439,6 +2438,12 @@ private:
24392438
template <class _CharT2, class _Traits2, class _Allocator2>
24402439
friend inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool
24412440
operator==(const basic_string<_CharT2, _Traits2, _Allocator2>&, const _CharT2*) _NOEXCEPT;
2441+
2442+
// These functions aren't used anymore but are part of out ABI, so we need to provide them in the dylib for backwards
2443+
// compatibility
2444+
# ifdef _LIBCPP_BUILDING_LIBRARY
2445+
void __init(const value_type* __s, size_type __sz, size_type __reserve);
2446+
# endif
24422447
};
24432448

24442449
// These declarations must appear before any functions are implicitly used
@@ -2490,30 +2495,6 @@ basic_string(from_range_t, _Range&&, _Allocator = _Allocator())
24902495
-> basic_string<ranges::range_value_t<_Range>, char_traits<ranges::range_value_t<_Range>>, _Allocator>;
24912496
# endif
24922497

2493-
template <class _CharT, class _Traits, class _Allocator>
2494-
_LIBCPP_CONSTEXPR_SINCE_CXX20 void
2495-
basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve) {
2496-
if (__libcpp_is_constant_evaluated())
2497-
__rep_ = __rep();
2498-
if (__reserve > max_size())
2499-
__throw_length_error();
2500-
pointer __p;
2501-
if (__fits_in_sso(__reserve)) {
2502-
__set_short_size(__sz);
2503-
__p = __get_short_pointer();
2504-
} else {
2505-
auto __allocation = std::__allocate_at_least(__alloc_, __recommend(__reserve) + 1);
2506-
__p = __allocation.ptr;
2507-
__begin_lifetime(__p, __allocation.count);
2508-
__set_long_pointer(__p);
2509-
__set_long_cap(__allocation.count);
2510-
__set_long_size(__sz);
2511-
}
2512-
traits_type::copy(std::__to_address(__p), __s, __sz);
2513-
traits_type::assign(__p[__sz], value_type());
2514-
__annotate_new(__sz);
2515-
}
2516-
25172498
template <class _CharT, class _Traits, class _Allocator>
25182499
_LIBCPP_CONSTEXPR_SINCE_CXX20 void
25192500
basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz) {

libcxx/src/string.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,44 @@ void __basic_string_common<true>::__throw_out_of_range() const { std::__throw_ou
3737

3838
#endif // _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
3939

40+
// Define legacy ABI functions
41+
// ---------------------------
42+
43+
#ifndef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
44+
45+
template <class _CharT, class _Traits, class _Allocator>
46+
void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve) {
47+
if (__libcpp_is_constant_evaluated())
48+
__rep_ = __rep();
49+
if (__reserve > max_size())
50+
__throw_length_error();
51+
pointer __p;
52+
if (__fits_in_sso(__reserve)) {
53+
__set_short_size(__sz);
54+
__p = __get_short_pointer();
55+
} else {
56+
auto __allocation = std::__allocate_at_least(__alloc_, __recommend(__reserve) + 1);
57+
__p = __allocation.ptr;
58+
__begin_lifetime(__p, __allocation.count);
59+
__set_long_pointer(__p);
60+
__set_long_cap(__allocation.count);
61+
__set_long_size(__sz);
62+
}
63+
traits_type::copy(std::__to_address(__p), __s, __sz);
64+
traits_type::assign(__p[__sz], value_type());
65+
__annotate_new(__sz);
66+
}
67+
68+
# define STRING_LEGACY_API(CharT) \
69+
template _LIBCPP_EXPORTED_FROM_ABI void basic_string<CharT>::__init(const value_type*, size_type, size_type)
70+
71+
STRING_LEGACY_API(char);
72+
# if _LIBCPP_HAS_WIDE_CHARACTERS
73+
STRING_LEGACY_API(wchar_t);
74+
# endif
75+
76+
#endif // _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
77+
4078
#define _LIBCPP_EXTERN_TEMPLATE_DEFINE(...) template __VA_ARGS__;
4179
#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
4280
_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)

0 commit comments

Comments
 (0)