1999 Commits

Author SHA1 Message Date
David Tolnay
36614d60d4
Move triviality static assertions to implementation files only 2021-01-02 18:30:15 -08:00
David Tolnay
e05de8796e
Move template class workaround to implementation files only 2021-01-02 18:21:06 -08:00
David Tolnay
bf6731a13b
Clean up stray whitespace from PR 642 2021-01-02 17:31:34 -08:00
David Tolnay
4ddae80e7d
Allow through bad_alloc from Error(const Error &) and operator= 2021-01-02 16:48:50 -08:00
David Tolnay
10c48f5904
Resolve msvc warning on strncpy by replacing with memcpy
src/cxx.cc(356): error C2220: the following warning is treated as an error
    src/cxx.cc(356): warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
2021-01-02 16:40:08 -08:00
David Tolnay
837eefee5e
Simplify to_c_error by using NonNull inline 2021-01-02 16:24:00 -08:00
David Tolnay
6c12520836
Clean some unneeded string manipulation from exception conversion
These used to be needed prior to #644.
2021-01-02 16:24:00 -08:00
David Tolnay
ba750b626d
Silence -Wunused-private-field warning on macOS
In file included from src/cxx.cc:1:
    src/../include/cxx.h:131:33: error: private field 'repr' is not used [-Werror,-Wunused-private-field]
      std::array<std::uintptr_t, 2> repr;
                                    ^
2021-01-02 16:24:00 -08:00
David Tolnay
dc2d4c3747
Mark error conversion function noexcept
This prevents a std::bad_alloc exception from operator new[] from
potentially propagating into Rust, which would be UB.
2021-01-02 16:14:31 -08:00
David Tolnay
0194dc5947
Merge pull request #647 from dtolnay/slice
Preserve &[T]'s Rust representation in rust::Slice
2021-01-02 15:28:21 -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
2a58a8afdf
Merge pull request #646 from dtolnay/swap
Restore swapping Str and Slice in member function form only
2021-01-02 14:05:11 -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
815ca8cafc
Revert "Omit swap member functions from website"
This reverts commit d835ac6cadf7cf1cee76f2e108248e083e4236ea.
2021-01-02 13:57:30 -08:00
David Tolnay
d1812baec0
Merge pull request #645 from dtolnay/str
Preserve &str's original Rust representation in C++
2021-01-02 13:22:28 -08:00
David Tolnay
1202de50b7
Preserve &str's original Rust representation in C++ 2021-01-02 13:15:08 -08:00
David Tolnay
aec3f24fb1
Merge pull request #644 from dtolnay/result
Decouple C++ exception representation from Rust str
2021-01-02 13:14:58 -08:00
David Tolnay
8ce57ec900
Decouple C++ exception representation from Rust str 2021-01-02 13:04:40 -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
4f2b30e1a6
Merge pull request #643 from dtolnay/swap
Remove Str and Slice swaps
2021-01-02 12:44:09 -08:00
David Tolnay
8f68939ae9
Remove Str and Slice swaps 2021-01-02 12:34:12 -08:00
David Tolnay
2ae80499c1
Clean up trailing whitespaces 2021-01-02 12:28:02 -08:00
David Tolnay
d835ac6cad
Omit swap member functions from website
I feel it's sufficient that std::swap "does the right thing". These do
not need to be explicitly presented as part of the API.
2021-01-02 12:26:20 -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
1ca730e0a1
Update Box website page to match header 2021-01-02 12:14:03 -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
David Tolnay
357d9ed5e4
Fix invalid json in vscode launch.json 2021-01-02 11:34:23 -08:00
David Tolnay
958f875178
Merge pull request #641 from capickett/cargo_tests
Include a launch config for cargo tests
2021-01-02 11:33:58 -08:00
David Tolnay
3b338886fc
Merge pull request #640 from capickett/abi
Fix warning mismatching struct and class
2021-01-02 11:29:59 -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
Cameron Pickett
f91e4731a8 Include a launch config for cargo tests
First time using VS Code to develop and I found this config made it easier to jump into breakpoint debugging the cargo tests
2021-01-02 14:31:19 +00:00
Cameron Pickett
3351bc7898 Fix warning mismatching struct and class
Fix for warning when running cargo test.

```
warning: /Users/pickett/Documents/GitHub/cxx/target/debug/build/cxx-test-suite-de711daed7f2e46d/out/cxxbridge/sources/tests/ffi/lib.rs.cc:1256:10: warning: struct template 'Slice' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI [-Wmismatched-tags]
warning: template struct ::rust::Slice<const char>;
warning:          ^
warning: /Users/pickett/Documents/GitHub/cxx/target/debug/build/cxx-test-suite-de711daed7f2e46d/out/cxxbridge/include/rust/cxx.h:146:7: note: previous use is here
warning: class Slice final
warning:       ^
warning: /Users/pickett/Documents/GitHub/cxx/target/debug/build/cxx-test-suite-de711daed7f2e46d/out/cxxbridge/sources/tests/ffi/lib.rs.cc:1256:10: note: did you mean class here?
warning: template struct ::rust::Slice<const char>;
warning:          ^~~~~~
warning:          class
```
2021-01-02 12:21:24 +00:00
David Tolnay
d00bc40aa7
Merge pull request #639 from dtolnay/msvc
Restrict MSVC instantiation workaround to return positions only
2021-01-02 01:29:43 -08:00
David Tolnay
14dc792980
Restrict MSVC instantiation workaround to return positions only 2021-01-02 01:14:44 -08:00
David Tolnay
b4ea5b0943
Merge pull request #636 from dtolnay/pod
Remove rust::Slice repr conversion in C++
2021-01-02 00:52:40 -08:00
David Tolnay
681f5c82cd
Remove rust::Slice repr conversion on the C++ side 2021-01-02 00:46:49 -08:00
David Tolnay
c45b6766f5
Merge pull request #637 from dtolnay/msvc
MSVC workaround for "C linkage function cannot return C++ class"
2021-01-02 00:46:05 -08:00
David Tolnay
113108931b
Merge pull request #638 from dtolnay/podstr
Remove rust::Str repr conversion in C++
2021-01-02 00:45:54 -08:00
David Tolnay
7f65e7cda7
Remove rust::Str repr conversion on the C++ side 2021-01-02 00:34:19 -08:00
David Tolnay
440e24a29a
MSVC workaround for "C linkage function cannot return C++ class"
MSVC fails to compile code like the following unless there is an
explicit instantiation of the class template:

    template <typename T>
    class slice {};

    //template class slice<int>;

    extern "C" slice<int> repro() { return {}; }

Error:

    <source>(6): error C2526: 'repro': C linkage function cannot return C++ class 'slice<int>'
    <source>(6): note: see declaration of 'slice<int>'
    <source>(6): error C2562: 'repro': 'void' function returning a value
    <source>(6): note: see declaration of 'repro'
    Compiler returned: 2
2021-01-02 00:27:15 -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
2b4f07d8d8
Explicit instantiations for easy typecheck coverage in test suite 2021-01-02 00:06:59 -08:00
David Tolnay
233e60e231
Resolve unnecessary_wraps clippy lint 2021-01-01 22:12:50 -08:00
David Tolnay
dc09c52a3d
Tweak enum generics error handling 2021-01-01 21:52:08 -08:00
David Tolnay
dc415ccf8e
Merge pull request #635 from dtolnay/lifetimes
Parameterize shim trait impl blocks over lifetimes
2021-01-01 20:09:14 -08:00