Skip to content

Commit ff46291

Browse files
committed
adapt to updated Cpp::Destruct in C-API and tests
1 parent 7172de6 commit ff46291

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

include/clang-c/CXCppInterOp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,10 @@ CINDEX_LINKAGE void clang_invoke(CXScope func, void* result, void** args,
361361
* \param type The type of the object.
362362
*
363363
* \param withFree Whether to call operator delete/free or not.
364+
*
365+
* \returns true if wrapper generation and invocation succeeded.
364366
*/
365-
CINDEX_LINKAGE void clang_destruct(CXObject This, CXScope S,
367+
CINDEX_LINKAGE bool clang_destruct(CXObject This, CXScope S,
366368
bool withFree = true, size_t nary = 0UL);
367369

368370
/**

lib/CppInterOp/CXCppInterOp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -613,10 +613,10 @@ void clang_invoke(CXScope func, void* result, void** args, size_t n,
613613
}
614614

615615
namespace Cpp {
616-
void Destruct(compat::Interpreter& interp, TCppObject_t This,
616+
bool Destruct(compat::Interpreter& interp, TCppObject_t This,
617617
clang::Decl* Class, bool withFree, size_t nary);
618618
} // namespace Cpp
619619

620-
void clang_destruct(CXObject This, CXScope S, bool withFree, size_t nary) {
621-
Cpp::Destruct(*getInterpreter(S), This, getDecl(S), withFree, nary);
620+
bool clang_destruct(CXObject This, CXScope S, bool withFree, size_t nary) {
621+
return Cpp::Destruct(*getInterpreter(S), This, getDecl(S), withFree, nary);
622622
}

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ TEST(FunctionReflectionTest, JitCallAdvanced) {
14771477
Ctor.Invoke(&object);
14781478
EXPECT_TRUE(object) << "Failed to call the ctor.";
14791479
// Building a wrapper with a typedef decl must be possible.
1480-
Cpp::Destruct(object, Decls[1]);
1480+
EXPECT_TRUE(Cpp::Destruct(object, Decls[1]));
14811481

14821482
// C API
14831483
auto* I = clang_createInterpreterFromRawPtr(Cpp::GetInterpreter());
@@ -2342,7 +2342,7 @@ TEST(FunctionReflectionTest, ConstructArray) {
23422342
obj = reinterpret_cast<int*>(reinterpret_cast<char*>(where) +
23432343
(Cpp::SizeOf(scope) * 4));
23442344
EXPECT_TRUE(*obj == 42);
2345-
Cpp::Destruct(where, scope, /*withFree=*/false, 5);
2345+
EXPECT_TRUE(Cpp::Destruct(where, scope, /*withFree=*/false, 5));
23462346
Cpp::Deallocate(scope, where, 5);
23472347
output = testing::internal::GetCapturedStdout();
23482348
EXPECT_EQ(output,
@@ -2379,7 +2379,7 @@ TEST(FunctionReflectionTest, Destruct) {
23792379
testing::internal::CaptureStdout();
23802380
Cpp::TCppScope_t scope = Cpp::GetNamed("C");
23812381
Cpp::TCppObject_t object = Cpp::Construct(scope);
2382-
Cpp::Destruct(object, scope);
2382+
EXPECT_TRUE(Cpp::Destruct(object, scope));
23832383
std::string output = testing::internal::GetCapturedStdout();
23842384

23852385
EXPECT_EQ(output, "Destructor Executed");
@@ -2389,7 +2389,7 @@ TEST(FunctionReflectionTest, Destruct) {
23892389
object = Cpp::Construct(scope);
23902390
// Make sure we do not call delete by adding an explicit Deallocate. If we
23912391
// called delete the Deallocate will cause a double deletion error.
2392-
Cpp::Destruct(object, scope, /*withFree=*/false);
2392+
EXPECT_TRUE(Cpp::Destruct(object, scope, /*withFree=*/false));
23932393
Cpp::Deallocate(scope, object);
23942394
output = testing::internal::GetCapturedStdout();
23952395
EXPECT_EQ(output, "Destructor Executed");
@@ -2454,7 +2454,7 @@ TEST(FunctionReflectionTest, DestructArray) {
24542454

24552455
testing::internal::CaptureStdout();
24562456
// destruct 3 out of 5 objects
2457-
Cpp::Destruct(where, scope, false, 3);
2457+
EXPECT_TRUE(Cpp::Destruct(where, scope, false, 3));
24582458
output = testing::internal::GetCapturedStdout();
24592459

24602460
EXPECT_EQ(
@@ -2466,7 +2466,7 @@ TEST(FunctionReflectionTest, DestructArray) {
24662466
// destruct the rest
24672467
auto *new_head = reinterpret_cast<void*>(reinterpret_cast<char*>(where) +
24682468
(Cpp::SizeOf(scope) * 3));
2469-
Cpp::Destruct(new_head, scope, false, 2);
2469+
EXPECT_TRUE(Cpp::Destruct(new_head, scope, false, 2));
24702470

24712471
output = testing::internal::GetCapturedStdout();
24722472
EXPECT_EQ(output, "\nDestructor Executed\n\nDestructor Executed\n");
@@ -2481,7 +2481,7 @@ TEST(FunctionReflectionTest, DestructArray) {
24812481
testing::internal::CaptureStdout();
24822482
// FIXME : This should work with the array of objects as well
24832483
// Cpp::Destruct(where, scope, true, 5);
2484-
Cpp::Destruct(where, scope, true);
2484+
EXPECT_TRUE(Cpp::Destruct(where, scope, true));
24852485
output = testing::internal::GetCapturedStdout();
24862486
EXPECT_EQ(output, "\nDestructor Executed\n");
24872487
output.clear();

0 commit comments

Comments
 (0)