-
Notifications
You must be signed in to change notification settings - Fork 1
rust error callback #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -352,11 +352,11 @@ pub(super) fn write(out: &mut OutFile) { | |
writeln!(out, "template <>"); | ||
writeln!(out, "class impl<Error> final {{"); | ||
writeln!(out, "public:"); | ||
writeln!(out, " static Error error(repr::PtrLen repr) noexcept {{"); | ||
writeln!(out, " static void error(const char* msg, size_t len) {{"); | ||
writeln!(out, " Error error;"); | ||
writeln!(out, " error.msg = static_cast<char const *>(repr.ptr);"); | ||
writeln!(out, " error.len = repr.len;"); | ||
writeln!(out, " return error;"); | ||
writeln!(out, " error.msg = msg;"); | ||
writeln!(out, " error.len = len;"); | ||
writeln!(out, " throw error;"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to throw a value of type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we will set our own |
||
writeln!(out, " }}"); | ||
writeln!(out, "}};"); | ||
} | ||
|
@@ -395,6 +395,15 @@ pub(super) fn write(out: &mut OutFile) { | |
} | ||
|
||
out.end_block(Block::AnonymousNamespace); | ||
|
||
if builtin.rust_error { | ||
out.next_section(); | ||
writeln!( | ||
out, | ||
"inline void (*throw_rust_error)(const char*, size_t) = impl<Error>::error;" | ||
); | ||
} | ||
|
||
out.end_block(Block::InlineNamespace("cxxbridge1")); | ||
|
||
if builtin.trycatch { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the lifetime/ownership of
msg
? Is it pointing to Rust-owned memory?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a comment to cxx.h (not sure what's the best place for it): it points to c++ memory and will belong to c++.
https://github.com/cloudflare/workerd-cxx/blob/master/src/result.rs#L60