mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
oil: make ObjectAddr a const reference
This commit is contained in:
parent
ee56decc10
commit
fcaede9e7d
@ -118,7 +118,7 @@ class OILibrary {
|
||||
private:
|
||||
class OILibraryImpl *pimpl_;
|
||||
|
||||
size_t (*fp)(void *) = nullptr;
|
||||
size_t (*fp)(const void *) = nullptr;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
@ -141,7 +141,7 @@ class CodegenHandler {
|
||||
delete lib;
|
||||
}
|
||||
|
||||
static int getObjectSize(T &ObjectAddr, size_t &ObjectSize) {
|
||||
static int getObjectSize(const T &ObjectAddr, size_t &ObjectSize) {
|
||||
OILibrary *lib;
|
||||
if (int responseCode = getLibrary(lib);
|
||||
responseCode != Response::OIL_SUCCESS) {
|
||||
@ -151,7 +151,7 @@ class CodegenHandler {
|
||||
return lib->getObjectSize((void *)&ObjectAddr, ObjectSize);
|
||||
}
|
||||
|
||||
static int getObjectSize(T &ObjectAddr, size_t &ObjectSize,
|
||||
static int getObjectSize(const T &ObjectAddr, size_t &ObjectSize,
|
||||
const options &opts, bool checkOptions = true) {
|
||||
OILibrary *lib;
|
||||
if (int responseCode = getLibrary(lib, opts, checkOptions);
|
||||
@ -196,7 +196,7 @@ class CodegenHandler {
|
||||
}
|
||||
curBoxedLib = getLib();
|
||||
|
||||
int (*sizeFp)(T &, size_t &) = &getObjectSize;
|
||||
int (*sizeFp)(const T &, size_t &) = &getObjectSize;
|
||||
void *typedFp = reinterpret_cast<void *>(sizeFp);
|
||||
OILibrary *newLib = new OILibrary(typedFp, opts);
|
||||
|
||||
@ -230,7 +230,7 @@ class CodegenHandler {
|
||||
* Ahead-Of-Time (AOT) compilation.
|
||||
*/
|
||||
template <class T>
|
||||
int getObjectSize(T &ObjectAddr, size_t &ObjectSize, const options &opts,
|
||||
int getObjectSize(const T &ObjectAddr, size_t &ObjectSize, const options &opts,
|
||||
bool checkOptions = true) {
|
||||
return CodegenHandler<T>::getObjectSize(ObjectAddr, ObjectSize, opts,
|
||||
checkOptions);
|
||||
@ -248,7 +248,8 @@ int getObjectSize(T &ObjectAddr, size_t &ObjectSize, const options &opts,
|
||||
* production system.
|
||||
*/
|
||||
template <class T>
|
||||
int __attribute__((weak)) getObjectSize(T &ObjectAddr, size_t &ObjectSize) {
|
||||
int __attribute__((weak))
|
||||
getObjectSize(const T &ObjectAddr, size_t &ObjectSize) {
|
||||
#ifdef OIL_AOT_COMPILATION
|
||||
return Response::OIL_UNINITIALISED;
|
||||
#else
|
||||
|
@ -267,6 +267,28 @@ void FuncGen::DefineTopLevelGetSizeRef(std::string& testCode,
|
||||
testCode.append(fmt.str());
|
||||
}
|
||||
|
||||
void FuncGen::DefineTopLevelGetSizeRefRet(std::string& testCode,
|
||||
const std::string& rawType) {
|
||||
std::string func = R"(
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunknown-attributes"
|
||||
/* Raw Type: %1% */
|
||||
size_t __attribute__((used, retain)) getSize(const OIInternal::__ROOT_TYPE__& t)
|
||||
#pragma GCC diagnostic pop
|
||||
{
|
||||
pointers.initialize();
|
||||
size_t ret = 0;
|
||||
pointers.add((uintptr_t)&t);
|
||||
SAVE_DATA((uintptr_t)t);
|
||||
OIInternal::getSizeType(t, ret);
|
||||
return ret;
|
||||
}
|
||||
)";
|
||||
|
||||
boost::format fmt = boost::format(func) % rawType;
|
||||
testCode.append(fmt.str());
|
||||
}
|
||||
|
||||
void FuncGen::DefineTopLevelGetSizePtr(std::string& testCode,
|
||||
const std::string& type,
|
||||
const std::string& rawType) {
|
||||
@ -299,28 +321,6 @@ void FuncGen::DefineTopLevelGetSizePtr(std::string& testCode,
|
||||
testCode.append(fmt.str());
|
||||
}
|
||||
|
||||
void FuncGen::DefineTopLevelGetSizePtrRet(std::string& testCode,
|
||||
const std::string& rawType) {
|
||||
std::string func = R"(
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunknown-attributes"
|
||||
/* Raw Type: %1% */
|
||||
size_t __attribute__((used, retain)) getSize(const OIInternal::__ROOT_TYPE__* t)
|
||||
#pragma GCC diagnostic pop
|
||||
{
|
||||
pointers.initialize();
|
||||
size_t ret = 0;
|
||||
pointers.add((uintptr_t)t);
|
||||
SAVE_DATA((uintptr_t)t);
|
||||
OIInternal::getSizeType(*t, ret);
|
||||
return ret;
|
||||
}
|
||||
)";
|
||||
|
||||
boost::format fmt = boost::format(func) % rawType;
|
||||
testCode.append(fmt.str());
|
||||
}
|
||||
|
||||
void FuncGen::DefineTopLevelGetSizeSmartPtr(std::string& testCode,
|
||||
const std::string& rawType) {
|
||||
std::string func = R"(
|
||||
|
@ -61,7 +61,7 @@ class FuncGen {
|
||||
void DefineTopLevelGetSizeRef(std::string& testCode,
|
||||
const std::string& rawType);
|
||||
|
||||
void DefineTopLevelGetSizePtrRet(std::string& testCode,
|
||||
void DefineTopLevelGetSizeRefRet(std::string& testCode,
|
||||
const std::string& type);
|
||||
|
||||
void DefineTopLevelGetSizeSmartPtr(std::string& testCode,
|
||||
|
@ -3450,7 +3450,7 @@ bool OICodeGen::generateJitCode(std::string &code) {
|
||||
}
|
||||
} else {
|
||||
if (linkageName.empty()) {
|
||||
funcGen.DefineTopLevelGetSizePtrRet(functionsCode, rawTypeName);
|
||||
funcGen.DefineTopLevelGetSizeRefRet(functionsCode, rawTypeName);
|
||||
} else {
|
||||
funcGen.DefineTopLevelGetObjectSize(functionsCode, rawTypeName,
|
||||
linkageName);
|
||||
|
@ -281,7 +281,7 @@ int OILibraryImpl::compileCode() {
|
||||
_self->fp = nullptr;
|
||||
for (const auto &[symName, symAddr] : jitSymbols) {
|
||||
if (symName.starts_with("_Z7getSize")) {
|
||||
_self->fp = (size_t(*)(void *))symAddr;
|
||||
_self->fp = (size_t(*)(const void *))symAddr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user