Commit Graph

56 Commits

Author SHA1 Message Date
David Tolnay
b8a6fb2755
Define rust::isize with Windows support 2020-04-10 11:17:28 -07:00
David Tolnay
5383891622
Do not emit UniquePtr::new for opaque C types 2020-04-09 20:56:44 -07:00
David Tolnay
737e02eeb1
Remove unneeded return from void functions 2020-04-04 21:52:46 -07:00
David Tolnay
75dca2e846
Passing function pointer from Rust to C++ 2020-03-29 21:50:25 -07:00
David Tolnay
d71eb54c13
No longer need to iterate Namespace by value 2020-03-29 21:31:26 -07:00
David Tolnay
d815de0195
Levarage the Display impl for namespace printing 2020-03-29 21:31:26 -07:00
David Tolnay
7ece56fb09
Allow write_fmt to work on &OutFile 2020-03-29 21:31:26 -07:00
David Tolnay
754e21c678
Add a Namespace type in gen 2020-03-29 21:31:26 -07:00
David Tolnay
d140274c10
Emit bitcopy forward declaration needed by String constructor 2020-03-25 22:21:42 -07:00
David Tolnay
9964262630
Implement and test some more fallible return types 2020-03-25 16:44:11 -07:00
David Tolnay
30430f13c9
Include <cstddef> for size_t 2020-03-19 20:49:34 -07:00
David Tolnay
33d3029780
Add flag to inject additional #include lines 2020-03-18 18:18:36 -07:00
David Tolnay
417305a41a
Add function pointer types to syntax tree 2020-03-18 17:03:26 -07:00
David Tolnay
e2e7bc3c9e
Update to codespan-reporting 0.9 2020-03-18 15:17:37 -07:00
David Tolnay
e68634c0a1
Fix missing newline after cxxbridge02$exception declaration 2020-03-18 12:03:40 -07:00
David Tolnay
047223384e
Make trycatch sfinae work on msvc 2020-03-18 11:35:39 -07:00
David Tolnay
3e3e0af976
Allow catch behavior to be customized
If the user's cxx::bridge invocation includes any header that defines
the following function, they get it's behavior as the exception-to-Result
conversion.

    namespace rust::behavior {
    template <typename Try, typename Fail>
    static void trycatch(Try &&func, Fail &&fail) noexcept try {
      func();
    } catch (/* up to you */) {
      fail(/* const char *msg */);
    }
    }

The default behavior is equivalent to:

    } catch (const std::exception &e) {
      fail(e.what());
    }

Codebases that use Folly, for example, may be interested in behavior
like this instead for better type information on the error messages:

    } catch (const std::exception &e) {
      fail(folly::exceptionStr(e));
    } catch (...) {
      fail("<unknown exception>");
    }
2020-03-17 23:03:24 -07:00
David Tolnay
82c1617925
Catch block isn't allowed to throw 2020-03-17 22:54:12 -07:00
David Tolnay
5d12144989
Factor catch implementation to static function 2020-03-17 22:22:24 -07:00
David Tolnay
4791f1c115
Include <utility> when using std::move 2020-03-17 21:55:19 -07:00
David Tolnay
3577d451d7
Fix blank first line if no headers emitted 2020-03-17 21:48:13 -07:00
David Tolnay
b7a7cb6785
Provide more struct definitions where needed 2020-03-17 21:40:47 -07:00
David Tolnay
26ad0bd98c
Look for end of line when finding headers ifdefs 2020-03-17 21:34:16 -07:00
David Tolnay
ebef4a23a2
Implement fallible C++ functions 2020-03-17 17:34:52 -07:00
David Tolnay
1e548174c3
Implement fallible Rust functions 2020-03-17 00:15:48 -07:00
David Tolnay
277e3ccdba
Factor out C++ indirect return predicate 2020-03-17 00:11:01 -07:00
David Tolnay
2fb14e934b
Add Type::Void variant
Not currently usable as a function argument or explicit return value,
but will be required when we introduce Result for the case of fallible
void functions, whose return type will be Result<()>.
2020-03-15 23:11:40 -07:00
David Tolnay
8c7304998e
Bump inline namespace to match minor version 2020-03-13 01:29:23 -07:00
David Tolnay
3383ae719f
Add f32 and f64 types 2020-03-13 01:14:11 -07:00
David Tolnay
736cbcad40
Move header include path to rust/cxx.h 2020-03-11 16:51:38 -07:00
David Tolnay
4b3a66edf1
Implement returning unique_ptr from Rust to C++ 2020-03-06 16:22:14 -08:00
David Tolnay
5cd8d61f9d
Implement returning Box from Rust to C++ 2020-03-06 16:18:44 -08:00
David Tolnay
09011c304b
Fix alignment of by-value returns from Rust 2020-03-06 14:46:46 -08:00
David Tolnay
f51447e2b9
Implement moving ownership of struct arguments to Rust 2020-03-06 14:22:00 -08:00
David Tolnay
33169bdd59
Safe to assume more about the Box representation
https://doc.rust-lang.org/std/boxed/index.html:
So long as T: Sized, a Box<T> is guaranteed to be represented as a
single pointer and is also ABI-compatible with C pointers (i.e. the C
type T*).
2020-03-06 13:10:58 -08:00
David Tolnay
9c68b1a0c6
Lazily compute include set 2020-03-06 11:27:29 -08:00
David Tolnay
cc3767f0ed
Format with rustfmt 2019-10-07 2020-03-06 10:42:02 -08:00
David Tolnay
a46a237fe7
Make passing String by value to C++ const 2020-03-06 10:28:15 -08:00
David Tolnay
f6292378c7
Add rust::Box member type aliases 2020-03-01 21:09:11 -08:00
David Tolnay
baae443ae2
Change Str to Repr operator to explicit 2020-03-01 20:20:10 -08:00
David Tolnay
9081beb1a0
Remove redundant prefix from mangled Box related symbols 2020-03-01 19:52:09 -08:00
David Tolnay
9ad1fbc478
Pass ending comment to end_block
Clang-format doesn't always like the same ending comment as the start of
the block. In particular it wants:

    inline namespace cxxbridge01 {
      ...
    } // namespace cxxbridge01
2020-03-01 14:05:01 -08:00
David Tolnay
750755e557
Rename namespace to rust::inline cxxbridge01 2020-03-01 13:47:29 -08:00
David Tolnay
324437a263
Rename C++ RustBox to Box 2020-03-01 13:47:29 -08:00
David Tolnay
09dbe75a5d
Rename C++ RustStr to Str 2020-03-01 13:47:28 -08:00
David Tolnay
5608216979
Rename C++ RustString to String 2020-03-01 13:47:28 -08:00
David Tolnay
b92e66f4dc
Support nested blocks in C++ emitter 2020-03-01 13:37:15 -08:00
David Tolnay
7e219b8099
Use absolute qualified identifiers in generated C++
This avoids collision with the user's namespaces having the same name.

Less important in the context of the current names right now, but more
important after we move our public C++ API from cxxbridge:: to rust::.
In fact our example code already uses org::rust:: as the namespace,
inside of which a non-absolute rust:: would cause trouble.
2020-03-01 13:14:55 -08:00
David Tolnay
2a1eaac049
Accept non-\n line endings
On Windows, include_str brings in cxxbridge.h with \r\n line endings.
2020-02-24 02:02:58 -08:00
David Tolnay
7eb9c6b2a0
Touch up cxxbridge.h emit PR 2020-01-27 22:35:59 -08:00