Skip to content

Commit

Permalink
Fix createCXString
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnimuc committed Jun 7, 2024
1 parent 4eabf46 commit ec15b64
Showing 1 changed file with 31 additions and 34 deletions.
65 changes: 31 additions & 34 deletions lib/Interpreter/CXCppInterOp.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#include "clang-c/CXCppInterOp.h"
#include "Compatibility.h"
#include "CppInterOpInterpreter.h"
#include "clang/Interpreter/CppInterOp.h"
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
#include <cstring>
#include <memory>
#include "clang-c/CXString.h"

CXString createCXString(const std::string& str) {
char* s = new char[str.length() + 1];
std::strcpy(s, str.c_str());

CXString createCXString(const std::string& S) {

Check warning on line 8 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L8

Added line #L8 was not covered by tests
CXString Str;
Str.data = s && s[0] == '\0' ? "" : s;
Str.private_flags = 1; // CXS_Malloc
if (S.empty()) {
Str.data = "";
Str.private_flags = 0; // CXS_Unmanaged

Check warning on line 12 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L10-L12

Added lines #L10 - L12 were not covered by tests
} else {
Str.data = strdup(S.c_str());
Str.private_flags = 1; // CXS_Malloc

Check warning on line 15 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L14-L15

Added lines #L14 - L15 were not covered by tests
}
return Str;

Check warning on line 17 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L17

Added line #L17 was not covered by tests
}

Expand All @@ -27,37 +27,33 @@ void clang_interpreter_dispose(CXInterpreter I) {
}

CXCompilerInstance clang_interpreter_getCompilerInstance(CXInterpreter I) {
return const_cast<clang::CompilerInstance*>(
static_cast<compat::Interpreter*>(I)->getCI());
auto* interp = static_cast<compat::Interpreter*>(I);
return const_cast<clang::CompilerInstance*>(interp->getCI());

Check warning on line 31 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L29-L31

Added lines #L29 - L31 were not covered by tests
}

LLVMOrcLLJITRef clang_interpreter_getExecutionEngine(CXInterpreter I) {

Check warning on line 34 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L34

Added line #L34 was not covered by tests
#ifdef USE_CLING
return nullptr;
#else
auto* interp = static_cast<compat::Interpreter*>(I);

Check warning on line 38 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L38

Added line #L38 was not covered by tests
return reinterpret_cast<LLVMOrcLLJITRef>(const_cast<llvm::orc::LLJIT*>(
static_cast<Cpp::Interpreter*>(I)
->getExecutionEngine())); // NOLINT(cppcoreguidelines-pro-type-const-cast,
// cppcoreguidelines-pro-type-reinterpret-cast)
interp->getExecutionEngine())); // NOLINT(*-cast)

Check warning on line 40 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L40

Added line #L40 was not covered by tests
#endif
}

void clang_interpreter_addSearchPath(CXInterpreter I, const char* dir,

Check warning on line 44 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L44

Added line #L44 was not covered by tests
bool isUser, bool prepend) {
static_cast<compat::Interpreter*>(I)
->getDynamicLibraryManager()
->addSearchPath(dir, isUser, prepend);
auto* interp = static_cast<compat::Interpreter*>(I);
interp->getDynamicLibraryManager()->addSearchPath(dir, isUser, prepend);

Check warning on line 47 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L46-L47

Added lines #L46 - L47 were not covered by tests
}

void clang_interpreter_addIncludePath(CXInterpreter I, const char* dir) {
static_cast<compat::Interpreter*>(I)->AddIncludePath(dir);

Check warning on line 51 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L50-L51

Added lines #L50 - L51 were not covered by tests
}

const char* clang_interpreter_getResourceDir(CXInterpreter I) {
return static_cast<compat::Interpreter*>(I)
->getCI()
->getHeaderSearchOpts()
.ResourceDir.c_str();
auto* interp = static_cast<compat::Interpreter*>(I);
return interp->getCI()->getHeaderSearchOpts().ResourceDir.c_str();

Check warning on line 56 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L54-L56

Added lines #L54 - L56 were not covered by tests
}

enum CXErrorCode clang_interpreter_declare(CXInterpreter I, const char* code,

Check warning on line 59 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L59

Added line #L59 was not covered by tests
Expand Down Expand Up @@ -122,31 +118,32 @@ enum CXErrorCode clang_interpreter_evaluate(CXInterpreter I, const char* code,

CXString clang_interpreter_lookupLibrary(CXInterpreter I,

Check warning on line 119 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L119

Added line #L119 was not covered by tests
const char* lib_name) {
return createCXString(static_cast<compat::Interpreter*>(I)
->getDynamicLibraryManager()
->lookupLibrary(lib_name));
auto* interp = static_cast<compat::Interpreter*>(I);
return createCXString(
interp->getDynamicLibraryManager()->lookupLibrary(lib_name).c_str());

Check warning on line 123 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L121-L123

Added lines #L121 - L123 were not covered by tests
}

CXInterpreter_CompilationResult
clang_interpreter_loadLibrary(CXInterpreter I, const char* lib_stem,

Check warning on line 127 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L127

Added line #L127 was not covered by tests
bool lookup) {
auto* interp = static_cast<compat::Interpreter*>(I);
return static_cast<CXInterpreter_CompilationResult>(
static_cast<compat::Interpreter*>(I)->loadLibrary(lib_stem, lookup));
interp->loadLibrary(lib_stem, lookup));

Check warning on line 131 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L129-L131

Added lines #L129 - L131 were not covered by tests
}

void clang_interpreter_unloadLibrary(CXInterpreter I, const char* lib_stem) {
static_cast<compat::Interpreter*>(I)
->getDynamicLibraryManager()
->unloadLibrary(lib_stem);
auto* interp = static_cast<compat::Interpreter*>(I);
interp->getDynamicLibraryManager()->unloadLibrary(lib_stem);

Check warning on line 136 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L134-L136

Added lines #L134 - L136 were not covered by tests
}

CXString clang_interpreter_searchLibrariesForSymbol(CXInterpreter I,

Check warning on line 139 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L139

Added line #L139 was not covered by tests
const char* mangled_name,
bool search_system) {
auto* interp = static_cast<compat::Interpreter*>(I);
return createCXString(

Check warning on line 143 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L142-L143

Added lines #L142 - L143 were not covered by tests
static_cast<compat::Interpreter*>(I)
->getDynamicLibraryManager()
->searchLibrariesForSymbol(mangled_name, search_system));
interp->getDynamicLibraryManager()
->searchLibrariesForSymbol(mangled_name, search_system)
.c_str());

Check warning on line 146 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L145-L146

Added lines #L145 - L146 were not covered by tests
}

namespace Cpp {
Expand All @@ -156,15 +153,15 @@ void DestructImpl(compat::Interpreter& interp, TCppObject_t This,

void clang_interpreter_destruct(CXInterpreter I, CXObject This, CXScope type,

Check warning on line 154 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L154

Added line #L154 was not covered by tests
bool withFree) {
Cpp::DestructImpl(*static_cast<compat::Interpreter*>(I), This, type,
withFree);
auto* interp = static_cast<compat::Interpreter*>(I);
Cpp::DestructImpl(*interp, This, type, withFree);

Check warning on line 157 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L156-L157

Added lines #L156 - L157 were not covered by tests
}

CXFuncAddr
clang_interpreter_getFunctionAddressFromMangledName(CXInterpreter I,

Check warning on line 161 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L161

Added line #L161 was not covered by tests
const char* mangled_name) {
auto FDAorErr = compat::getSymbolAddress(
*static_cast<compat::Interpreter*>(I), mangled_name);
auto* interp = static_cast<compat::Interpreter*>(I);
auto FDAorErr = compat::getSymbolAddress(*interp, mangled_name);
if (llvm::Error Err = FDAorErr.takeError())
llvm::consumeError(std::move(Err)); // nullptr if missing

Check warning on line 166 in lib/Interpreter/CXCppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CXCppInterOp.cpp#L163-L166

Added lines #L163 - L166 were not covered by tests
else
Expand Down

0 comments on commit ec15b64

Please sign in to comment.