Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/clang-c/CXCppInterOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ CINDEX_LINKAGE enum CXErrorCode clang_Interpreter_undo(CXInterpreter I,
/**
* Dispose of the given interpreter context.
*/
CINDEX_LINKAGE void clang_Interpreter_dispose(CXInterpreter I);
CINDEX_LINKAGE void clang_Interpreter_deleteInterpreter(CXInterpreter I);

/**
* Describes the return result of the different routines that do the incremental
Expand Down
4 changes: 2 additions & 2 deletions lib/CppInterOp/CXCppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ enum CXErrorCode clang_Interpreter_undo(CXInterpreter I, unsigned int N) {
#endif // CPPINTEROP_USE_CLING
}

void clang_Interpreter_dispose(CXInterpreter I) {
delete I; // NOLINT(*-owning-memory)
void clang_Interpreter_deleteInterpreter(CXInterpreter I) {
Cpp::DeleteInterpreter(getInterpreter(I));
}

void clang_Interpreter_addSearchPath(CXInterpreter I, const char* dir,
Expand Down
3 changes: 1 addition & 2 deletions unittests/CppInterOp/CommentReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, CommentReflection_DoxygenBlockAndLine) {
CXString Doc = clang_getDoxygenComment(S, /*strip_comment_markers=*/true);
EXPECT_STREQ(get_c_string(Doc), sDoc.c_str());
dispose_string(Doc);
clang_Interpreter_takeInterpreterAsPtr(I);
clang_Interpreter_dispose(I);
clang_Interpreter_deleteInterpreter(I);
}

TYPED_TEST(CPPINTEROP_TEST_MODE, CommentReflection_DoxygenNullScope) {
Expand Down
24 changes: 8 additions & 16 deletions unittests/CppInterOp/FunctionReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, FunctionReflection_GetClassMethods) {
};
EXPECT_EQ(C_API_SHIM(methods0[0]), "int A::f1(int a, int b)");
// Clean up resources
clang_Interpreter_takeInterpreterAsPtr(I);
clang_Interpreter_dispose(I);
clang_Interpreter_deleteInterpreter(I);
}

TYPED_TEST(CPPINTEROP_TEST_MODE,
Expand Down Expand Up @@ -239,8 +238,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, FunctionReflection_HasDefaultConstructor) {
EXPECT_TRUE(clang_hasDefaultConstructor(make_scope(Decls[1], I)));
EXPECT_FALSE(clang_hasDefaultConstructor(make_scope(Decls[3], I)));
// Clean up resources
clang_Interpreter_takeInterpreterAsPtr(I);
clang_Interpreter_dispose(I);
clang_Interpreter_deleteInterpreter(I);
}

TYPED_TEST(CPPINTEROP_TEST_MODE, FunctionReflection_GetDestructor) {
Expand Down Expand Up @@ -275,8 +273,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, FunctionReflection_GetDestructor) {
EXPECT_TRUE(clang_getDestructor(make_scope(Decls[0], I)).data[0]);
EXPECT_TRUE(clang_getDestructor(make_scope(Decls[1], I)).data[0]);
// Clean up resources
clang_Interpreter_takeInterpreterAsPtr(I);
clang_Interpreter_dispose(I);
clang_Interpreter_deleteInterpreter(I);
}

TYPED_TEST(CPPINTEROP_TEST_MODE, FunctionReflection_GetFunctionsUsingName) {
Expand Down Expand Up @@ -669,8 +666,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, FunctionReflection_IsTemplatedFunction) {
EXPECT_FALSE(clang_isTemplatedFunction(make_scope(SubDeclsC1[1], I)));
EXPECT_TRUE(clang_isTemplatedFunction(make_scope(SubDeclsC1[2], I)));
// Clean up resources
clang_Interpreter_takeInterpreterAsPtr(I);
clang_Interpreter_dispose(I);
clang_Interpreter_deleteInterpreter(I);
}

TYPED_TEST(CPPINTEROP_TEST_MODE, FunctionReflection_ExistsFunctionTemplate) {
Expand All @@ -697,8 +693,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, FunctionReflection_ExistsFunctionTemplate) {
EXPECT_TRUE(clang_existsFunctionTemplate("f", make_scope(Decls[1], I)));
EXPECT_FALSE(clang_existsFunctionTemplate("f", make_scope(Decls[2], I)));
// Clean up resources
clang_Interpreter_takeInterpreterAsPtr(I);
clang_Interpreter_dispose(I);
clang_Interpreter_deleteInterpreter(I);
}

TYPED_TEST(CPPINTEROP_TEST_MODE,
Expand Down Expand Up @@ -1670,8 +1665,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, FunctionReflection_JitCallAdvanced) {
EXPECT_TRUE(object_c) << "Failed to call the ctor.";
clang_destruct(object_c, make_scope(Decls[1], I), true);
// Clean up resources
clang_Interpreter_takeInterpreterAsPtr(I);
clang_Interpreter_dispose(I);
clang_Interpreter_deleteInterpreter(I);
}

#if !defined(NDEBUG) && GTEST_HAS_DEATH_TEST
Expand Down Expand Up @@ -2518,8 +2512,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, FunctionReflection_Construct) {
EXPECT_TRUE(dummy);
clang_deallocate(dummy);
// Clean up resources
clang_Interpreter_takeInterpreterAsPtr(I);
clang_Interpreter_dispose(I);
clang_Interpreter_deleteInterpreter(I);
}

// Test zero initialization of PODs and default initialization cases
Expand Down Expand Up @@ -2741,8 +2734,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, FunctionReflection_Destruct) {
EXPECT_EQ(output, "Destructor Executed");
output.clear();
// Clean up resources
clang_Interpreter_takeInterpreterAsPtr(I);
clang_Interpreter_dispose(I);
clang_Interpreter_deleteInterpreter(I);

// Failure Test, this wrapper should not compile since we explicitly delete
// the destructor
Expand Down
20 changes: 15 additions & 5 deletions unittests/CppInterOp/InterpreterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, Interpreter_DeleteInterpreter) {

EXPECT_EQ(I3, Cpp::GetInterpreter()) << "I3 is not active";

EXPECT_TRUE(Cpp::DeleteInterpreter(nullptr));
EXPECT_TRUE(Cpp::DeleteInterpreter(/*I=*/nullptr));
EXPECT_EQ(I2, Cpp::GetInterpreter());

auto* I4 = reinterpret_cast<void*>(static_cast<std::uintptr_t>(~0U));
Expand Down Expand Up @@ -173,7 +173,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, Interpreter_Process) {
auto Res = clang_Interpreter_evaluate(CXI, "c", CXV);
EXPECT_EQ(Res, CXError_Success);
clang_Value_dispose(CXV);
clang_Interpreter_dispose(CXI);
clang_Interpreter_deleteInterpreter(CXI);
}

TYPED_TEST(CPPINTEROP_TEST_MODE, Interpreter_EmscriptenExceptionHandling) {
Expand Down Expand Up @@ -230,7 +230,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, Interpreter_CreateInterpreter) {

auto I2 = clang_Interpreter_takeInterpreterAsPtr(CXI);
EXPECT_EQ(I, I2);
clang_Interpreter_dispose(CXI);
clang_Interpreter_deleteInterpreter(CXI);
#endif
}

Expand All @@ -240,7 +240,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, Interpreter_CreateInterpreterCAPI) {
auto *CXI = clang_createInterpreter(argv, 1);
auto CLI = clang_Interpreter_getClangInterpreter(CXI);
EXPECT_TRUE(CLI);
clang_Interpreter_dispose(CXI);
clang_Interpreter_deleteInterpreter(CXI);
}

TYPED_TEST(CPPINTEROP_TEST_MODE, Interpreter_CreateInterpreterCAPIFailure) {
Expand Down Expand Up @@ -370,7 +370,17 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, Interpreter_GetLanguageCAPI) {
CXInterpreterLanguage_CPlusPlus);
EXPECT_EQ(clang_Interpreter_getLanguageStandard(CXI),
CXInterpreterLanguageStandard_cxx14);
clang_Interpreter_dispose(CXI);
clang_Interpreter_deleteInterpreter(CXI);

// Make sure we did not destroy anything when disponsing the object
while (Cpp::GetInterpreter())
Cpp::DeleteInterpreter(/*I=*/nullptr);

EXPECT_FALSE(Cpp::GetInterpreter()) << "Failed to delete all interpreters";

// Create an interpreter (this calls RegisterInterpreter internally)
TInterp_t I2 = TestFixture::CreateInterpreter();
ASSERT_NE(I2, nullptr);
}

TYPED_TEST(CPPINTEROP_TEST_MODE, Interpreter_GetLanguageC) {
Expand Down
3 changes: 1 addition & 2 deletions unittests/CppInterOp/ScopeReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, ScopeReflection_InstantiateNNTPClassTemplate) {
};
EXPECT_NE(C_API_SHIM(Decls[0]), nullptr);
// Clean up resources
clang_Interpreter_takeInterpreterAsPtr(I);
clang_Interpreter_dispose(I);
clang_Interpreter_deleteInterpreter(I);
}

TYPED_TEST(CPPINTEROP_TEST_MODE, ScopeReflection_InstantiateVarTemplate) {
Expand Down
3 changes: 1 addition & 2 deletions unittests/CppInterOp/TypeReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,7 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, TypeReflection_GetComplexType) {
EXPECT_EQ(C_API_SHIM("double"), "_Complex double");

// Clean up resources
clang_Interpreter_takeInterpreterAsPtr(I);
clang_Interpreter_dispose(I);
clang_Interpreter_deleteInterpreter(I);
}

TYPED_TEST(CPPINTEROP_TEST_MODE, TypeReflection_GetTypeFromScope) {
Expand Down
Loading