Commit Graph

195 Commits

Author SHA1 Message Date
徐未来
b110613bee cxx 1.0.91升级至1.0.97
Signed-off-by: 徐未来 <xuweilai2@huawei.com>
2024-04-02 19:59:25 +08:00
openharmony_ci
96698d870d
回退 'Pull Request !11 : cxx1.0.91升级至1.0.97' 2024-04-02 03:30:32 +00:00
徐未来
e4f6feee96 1.0.91升级至1.0.97
Signed-off-by: 徐未来 <xuweilai2@huawei.com>
2024-03-08 16:36:47 +08:00
David Tolnay
47465d2bf1
Touch up PR 984 2021-12-31 13:36:34 -08:00
David Tolnay
fa7380675e
Implement rust::Vec clear in terms of truncate(0) 2021-12-31 13:26:53 -08:00
David Tolnay
a4bc81f48a
Merge pull request #984 from benesch/lossy
Add String::lossy constructors to C++ API
2021-12-31 13:19:37 -08:00
Nikhil Benesch
3724105cea
Add String::lossy constructors to C++ API
This constructor maps to `String::from_utf8_lossy` or
`String::from_utf16_lossy`. It's useful in situations where producing a
slightly garbled string on invalid Unicode data is preferable to
crashing the process, e.g. when passing error messages from C++ to Rust.
2021-12-27 13:26:09 -05:00
Nikhil Benesch
e3918b5422
Add Vec<T>::truncate to C++ API
Based on the model of #951, which added `Vec<T>::clear`. The `truncate`
method is the more general form of clear.

(If we wanted to, we could delete the binding for `clear` and implement
`clear` as a call to `truncate(0)` on the C++ side, but seemed worth
leaving in in case the Rust `clear` implementation one day gets
smarter.)
2021-12-26 15:18:50 -05:00
David Tolnay
8bb18c37ff
Touch up PR 951 2021-12-08 17:13:41 -08:00
Johan Verwey
8be52606f5
Expose Rust's Vec<T>::clear() method. 2021-10-29 07:36:57 -07:00
Johan Verwey
54187c9e82
Added 'clear' method to rust::Vec 2021-10-20 08:10:32 -07:00
David Tolnay
8f56cbbace
Expose capacity and reserve on rust::String 2021-08-27 13:14:05 -07:00
David Tolnay
a7bde2b7d2
Consistently use new_cap in signatures of reserve_total 2021-08-27 12:01:24 -07:00
Isaac Goldberg
c3fc2a4b38 Switch from 'index' to 'ptr' 2021-08-26 13:17:15 -07:00
Isaac Goldberg
921629cfb5 Don't shadow pos 2021-08-26 12:56:01 -07:00
Gerhard de Clercq
31a410246a Added UTF-16 rust::String initialization
This patch exposes String::from_utf16 to the C++ interface
for rust::String.
2021-08-03 07:17:20 +02:00
David Tolnay
99f79c0677
Add 'bool empty() const noexcept' to Str, String 2021-04-28 00:32:11 -07:00
David Tolnay
51c335309e
Fix rust::Fn call with non-const reference argument 2021-04-08 20:47:30 -07:00
David Tolnay
bb98d9eb09
Allow slice null ptr safely if slice is empty 2021-03-28 02:03:21 -04:00
David Tolnay
96ee470356
Debug assert that rust::Slice isn't constructed with C++ null ptr 2021-03-28 02:02:18 -04:00
David Tolnay
a9449375d0
Fix warning on unused unsafe_bitcopy variable 2021-03-26 16:42:46 -04:00
David Tolnay
de01edf706
Update C++ formatting to clang-format 11 2021-03-22 15:00:59 -07:00
David Tolnay
5d12f1d4c5
Format PR 714 with clang-format 10
This change in formatting seems to be due to https://reviews.llvm.org/D68695.
2021-03-22 14:59:33 -07:00
David Tolnay
63bec40599
Disallow assignment to rvalue 2021-02-11 23:19:16 -08:00
David Tolnay
7bc397cac0
Remove this != &other checks from move assignment operators 2021-02-11 23:07:58 -08:00
David Tolnay
e5cd1489e3
Fix remaining "C-linkage specified, but returns UDT" warnings on macOS 2021-01-02 21:28:14 -08:00
David Tolnay
bf6731a13b
Clean up stray whitespace from PR 642 2021-01-02 17:31:34 -08:00
David Tolnay
0e1cc3da8c
Hide slice implementation details from name lookup 2021-01-02 15:09:03 -08:00
David Tolnay
0e3f776362
Fix slice compilation on MSVC
cxxbridge-demo.lib(blobstore.o) : error LNK2019: unresolved external symbol "void __cdecl sliceInit(void *,void const *,unsigned __int64)" (?sliceInit@@YAXPEAXPEBX_K@Z) referenced in function "public: __cdecl rust::cxxbridge1::Slice<unsigned char const >::Slice<unsigned char const >(unsigned char const *,unsigned __int64)" (??0?$Slice@$$CBE@cxxbridge1@rust@@QEAA@PEBE_K@Z)
    cxxbridge-demo.lib(blobstore.o) : error LNK2001: unresolved external symbol "void __cdecl sliceInit(void *,void const *,unsigned __int64)" (?sliceInit@@YAXPEAXPEBX_K@Z)
    cxxbridge-demo.lib(main.rs.o) : error LNK2001: unresolved external symbol "void __cdecl sliceInit(void *,void const *,unsigned __int64)" (?sliceInit@@YAXPEAXPEBX_K@Z)
    cxxbridge-demo.lib(main.rs.o) : error LNK2001: unresolved external symbol "void __cdecl sliceInit(void *,void const *,unsigned __int64)" (?sliceInit@@YAXPEAXPEBX_K@Z)
      Hint on symbols that are defined and could potentially match:
        "void __cdecl rust::cxxbridge1::sliceInit(void *,void const *,unsigned __int64)" (?sliceInit@cxxbridge1@rust@@YAXPEAXPEBX_K@Z)
    cxxbridge-demo.lib(blobstore.o) : error LNK2019: unresolved external symbol "unsigned __int64 __cdecl sliceLen(void const *)" (?sliceLen@@YA_KPEBX@Z) referenced in function "public: unsigned __int64 __cdecl rust::cxxbridge1::Slice<unsigned char const >::size(void)const " (?size@?$Slice@$$CBE@cxxbridge1@rust@@QEBA_KXZ)
    cxxbridge-demo.lib(main.rs.o) : error LNK2001: unresolved external symbol "unsigned __int64 __cdecl sliceLen(void const *)" (?sliceLen@@YA_KPEBX@Z)
      Hint on symbols that are defined and could potentially match:
        "unsigned __int64 __cdecl rust::cxxbridge1::sliceLen(void const *)" (?sliceLen@cxxbridge1@rust@@YA_KPEBX@Z)
    cxxbridge-demo.lib(blobstore.o) : error LNK2019: unresolved external symbol "void * __cdecl slicePtr(void const *)" (?slicePtr@@YAPEAXPEBX@Z) referenced in function "private: void * __cdecl rust::cxxbridge1::Slice<unsigned char const >::ptr(void)const " (?ptr@?$Slice@$$CBE@cxxbridge1@rust@@AEBAPEAXXZ)
    cxxbridge-demo.lib(main.rs.o) : error LNK2001: unresolved external symbol "void * __cdecl slicePtr(void const *)" (?slicePtr@@YAPEAXPEBX@Z)
      Hint on symbols that are defined and could potentially match:
        "void * __cdecl rust::cxxbridge1::slicePtr(void const *)" (?slicePtr@cxxbridge1@rust@@YAPEAXPEBX@Z)
    D:\a\cxx\cxx\target\debug\deps\demo.exe : fatal error LNK1120: 3 unresolved externals
2021-01-02 15:08:09 -08:00
David Tolnay
9bffb93783
Preserve &[T]'s Rust representation in rust::Slice 2021-01-02 15:01:59 -08:00
David Tolnay
0413ee2709
Restore swapping Str and Slice in member function form only 2021-01-02 13:57:48 -08:00
David Tolnay
1202de50b7
Preserve &str's original Rust representation in C++ 2021-01-02 13:15:08 -08:00
David Tolnay
cf7bb9ba76
Elide template parameters in swaps where unneeded 2021-01-02 13:03:28 -08:00
David Tolnay
fec1715ad6
Move swap member functions below less-niche functions
The swap member functions are going to be infrequently used (relative to
things like operator==, Box's operator->) so let's present it lower down
in the API.
2021-01-02 12:51:31 -08:00
David Tolnay
8f68939ae9
Remove Str and Slice swaps 2021-01-02 12:34:12 -08:00
David Tolnay
bc44ebf520
Touch up PR 642 2021-01-02 12:23:37 -08:00
David Tolnay
c9e597e938
Format PR 642 with clang-format 10 2021-01-02 12:15:11 -08:00
David Tolnay
756556e23c
Merge pull request 642 from capickett/swap 2021-01-02 12:04:19 -08:00
David Tolnay
672c464c72
Remove implicit Box copy operations to match unique_ptr 2021-01-02 11:55:25 -08:00
Cameron Pickett
f45f899cd0 Add swap members + ADL functions
Addresses #58.

Adds `swap` members to each of `Slice`, `Str`, `Vec`, `Box`, and `String`. Also adds private friend functions so that Argument Dependent Lookup may function via the `using std::swap;` idiom.
2021-01-02 18:38:05 +00:00
David Tolnay
681f5c82cd
Remove rust::Slice repr conversion on the C++ side 2021-01-02 00:46:49 -08:00
David Tolnay
7f59a693e4
Fix a wrong cast in Slice<T>::iterator::operator[]
cxx-test-suite-2b81d5f39edd0bcf/out/cxxbridge/include/rust/cxx.h:559:11: error: invalid static_cast from type ‘char*’ to type ‘const unsigned char*’
      559 |   return *static_cast<T *>(pos);
          |           ^~~~~~~~~~~~~~~~~~~~~

Doing a reinterpret_cast<> instead matches what is done a few lines
above by Slice<T>::operator[].
2021-01-02 00:07:41 -08:00
David Tolnay
78a5f8d123
Restyle Box::value_type deprecation to be preserved in generated code 2020-12-28 11:40:38 -08:00
David Tolnay
f62458f075
Define member type Slice<T>::value_type = T 2020-12-27 19:38:43 -08:00
David Tolnay
e47a4d94d0
Rename Box value_type to element_type
This matches the member type naming on unique_ptr.
https://en.cppreference.com/w/cpp/memory/unique_ptr#Member_types
It appears value_type is for a member type of a container or iterator
while element_type is for the target of a smart pointer.
2020-12-27 19:35:24 -08:00
David Tolnay
725bf505b4
Reuse Slice<T>'s iterator for Vec iteration too 2020-12-27 13:38:44 -08:00
David Tolnay
e1df7ddba0
Eliminate Vec stride symbol in favor of size_of 2020-12-27 13:29:06 -08:00
David Tolnay
5ce110e807
Update Slice implementation to respect runtime size_of 2020-12-27 13:19:45 -08:00
David Tolnay
eee622c4ac
Obtain accurate alignment for empty slice of opaque Rust type 2020-12-27 13:08:09 -08:00
David Tolnay
6f92baa8ff
Obtain Slice iterator stride in a way that works for opaque types 2020-12-27 12:59:47 -08:00