Skip to content

Commit 3ddce45

Browse files
authored
Merge pull request #31 from NordSecurity/scaffolding_error_fixes
Scaffolding error fixes
2 parents 5a29c22 + ce24dd6 commit 3ddce45

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

bindgen/src/bindings/cpp/templates/scaffolding/callback.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ class {{ iface.name() }}Proxy: public {{ iface.name() }} {
1111
~{{ iface.name() }}Proxy() override {
1212
ForeignCallback *callback_stub = reinterpret_cast<ForeignCallback *>({{ ffi_converter_name|class_name }}::fn_handle.load());
1313

14-
callback_stub(this->handle, 0, nullptr, 0, nullptr);
14+
RustBuffer out_buf = {
15+
.capacity = 0,
16+
.len = 0,
17+
.data = nullptr,
18+
};
19+
20+
callback_stub(this->handle, 0, nullptr, 0, &out_buf);
21+
22+
rustbuffer_free(out_buf);
1523
}
1624

1725
{% for m in iface.methods() %}

cpp-tests/scaffolding_tests/coverall/lib_coverall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ bool coverall::Coveralls::maybe_throw_complex(uint8_t input) {
9696
}
9797

9898
void coverall::Coveralls::panic(std::string message) {
99-
throw std::runtime_error("coveralls->panic()");
99+
throw std::runtime_error(message);
100100
}
101101

102102
void coverall::Coveralls::fallible_panic(std::string message) {

cpp-tests/scaffolding_tests/coverall/lib_coverall.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ namespace {
197197
namespace coverall_error {
198198
class TooManyHoles: public std::runtime_error {
199199
public:
200-
TooManyHoles() : TooManyHoles("") {}
200+
TooManyHoles() : TooManyHoles("The coverall has too many holes") {}
201201
TooManyHoles(const std::string &what_arg) : std::runtime_error(what_arg) {}
202202
};
203203
}

cpp-tests/scaffolding_tests/fixture_callbacks/lib_fixture_callbacks.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ std::optional<std::string> fixture_callbacks::RustGetters::get_option(std::share
1717
return foreign->get_option(v, argument_two);
1818
} catch (const fixture_callbacks::complex_error::ReallyBadArgument &e) {
1919
throw e;
20+
} catch (const fixture_callbacks::complex_error::UnexpectedErrorWithReason &e) {
21+
throw fixture_callbacks::complex_error::UnexpectedErrorWithReason(e.reason);
2022
} catch (const std::runtime_error &e) {
2123
throw fixture_callbacks::complex_error::UnexpectedErrorWithReason(e.what());
2224
}
@@ -28,7 +30,13 @@ std::vector<int32_t> fixture_callbacks::RustGetters::get_list(std::shared_ptr<fi
2830

2931
std::optional<std::string> fixture_callbacks::RustGetters::get_string_optional_callback(std::shared_ptr<fixture_callbacks::ForeignGetters> foreign, std::string v, bool argument_two) {
3032
if (foreign) {
31-
return foreign->get_string(v, argument_two);
33+
try {
34+
return foreign->get_string(v, argument_two);
35+
} catch (const fixture_callbacks::simple_error::BadArgument &e) {
36+
throw e;
37+
} catch (const std::runtime_error &e) {
38+
throw fixture_callbacks::simple_error::UnexpectedError();
39+
}
3240
}
3341

3442
return std::nullopt;

cpp-tests/scaffolding_tests/fixture_callbacks/lib_fixture_callbacks.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ namespace {
1616
namespace simple_error {
1717
class BadArgument : public SimpleError {
1818
public:
19-
BadArgument() : SimpleError("") {}
19+
BadArgument() : SimpleError("BadArgument") {}
2020
BadArgument(const std::string &what_arg) : SimpleError(what_arg) {}
2121
};
2222

2323
class UnexpectedError : public SimpleError {
2424
public:
25-
UnexpectedError() : SimpleError("") {}
25+
UnexpectedError() : SimpleError("UnexpectedError") {}
2626
UnexpectedError(const std::string &what_arg) : SimpleError(what_arg) {}
2727
};
2828
}
@@ -36,15 +36,15 @@ namespace {
3636
namespace complex_error {
3737
class ReallyBadArgument : public ComplexError {
3838
public:
39-
ReallyBadArgument() : ComplexError("") {}
39+
ReallyBadArgument() : ComplexError("ReallyBadArgument") {}
4040
ReallyBadArgument(const std::string &what_arg) : ComplexError(what_arg) {}
4141

4242
uint32_t code;
4343
};
4444

4545
class UnexpectedErrorWithReason : public ComplexError {
4646
public:
47-
UnexpectedErrorWithReason() : ComplexError("") {}
47+
UnexpectedErrorWithReason() : ComplexError("InternalTelephoneError") {}
4848
UnexpectedErrorWithReason(const std::string &what_arg) : ComplexError(what_arg), reason(what_arg) {}
4949

5050
std::string reason;

0 commit comments

Comments
 (0)