mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
oil: change interface to references
This commit is contained in:
parent
499b8c6f74
commit
ee56decc10
@ -32,7 +32,7 @@ int main() {
|
|||||||
foo.strings.push_back("consectetur adipiscing elit,");
|
foo.strings.push_back("consectetur adipiscing elit,");
|
||||||
|
|
||||||
size_t size = -1;
|
size_t size = -1;
|
||||||
int ret = ObjectIntrospection::getObjectSize<Foo>(&foo, &size);
|
int ret = ObjectIntrospection::getObjectSize(foo, size);
|
||||||
|
|
||||||
std::cout << "oil returned: " << ret << "; with size: " << size << std::endl;
|
std::cout << "oil returned: " << ret << "; with size: " << size << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
* -- SINGLE-THREADED
|
* -- SINGLE-THREADED
|
||||||
* ObjectIntrospection::options opts = { .configFilePath = "sample.oid.toml" };
|
* ObjectIntrospection::options opts = { .configFilePath = "sample.oid.toml" };
|
||||||
* size_t size;
|
* size_t size;
|
||||||
* int responseCode = ObjectIntrospection::getObjectSize(&obj, &size, opts);
|
* int responseCode = ObjectIntrospection::getObjectSize(obj, size, opts);
|
||||||
* if (responseCode != ObjectIntrospection::Response::OIL_SUCCESS) {
|
* if (responseCode != ObjectIntrospection::Response::OIL_SUCCESS) {
|
||||||
* // handle error
|
* // handle error
|
||||||
* }
|
* }
|
||||||
@ -46,7 +46,7 @@
|
|||||||
* -- MULTI-THREADED (NO SETUP)
|
* -- MULTI-THREADED (NO SETUP)
|
||||||
* ObjectIntrospection::options opts = { .configFilePath = "sample.oid.toml" };
|
* ObjectIntrospection::options opts = { .configFilePath = "sample.oid.toml" };
|
||||||
* size_t size;
|
* size_t size;
|
||||||
* int responseCode = ObjectIntrospection::getObjectSize(&obj, &size, opts);
|
* int responseCode = ObjectIntrospection::getObjectSize(obj, size, opts);
|
||||||
* if (responseCode > ObjectIntrospection::Response::OIL_INITIALISING) {
|
* if (responseCode > ObjectIntrospection::Response::OIL_INITIALISING) {
|
||||||
* // handle error
|
* // handle error
|
||||||
* } else if (responseCode == ObjectIntrospection::Response::OIL_SUCCESS) {
|
* } else if (responseCode == ObjectIntrospection::Response::OIL_SUCCESS) {
|
||||||
@ -60,7 +60,7 @@
|
|||||||
* // handle error
|
* // handle error
|
||||||
* }
|
* }
|
||||||
* size_t size;
|
* size_t size;
|
||||||
* int responseCode = ObjectIntrospection::getObjectSize(&obj, &size);
|
* int responseCode = ObjectIntrospection::getObjectSize(obj, size);
|
||||||
* if (responseCode == ObjectIntrospection::Response::OIL_UNINITIALISED) {
|
* if (responseCode == ObjectIntrospection::Response::OIL_UNINITIALISED) {
|
||||||
* // handle error - impossible if successfully inited
|
* // handle error - impossible if successfully inited
|
||||||
* }
|
* }
|
||||||
@ -111,7 +111,7 @@ class OILibrary {
|
|||||||
OILibrary(void *TemplateFunc, options opt);
|
OILibrary(void *TemplateFunc, options opt);
|
||||||
~OILibrary();
|
~OILibrary();
|
||||||
int init();
|
int init();
|
||||||
int getObjectSize(void *ObjectAddr, size_t *size);
|
int getObjectSize(void *ObjectAddr, size_t &size);
|
||||||
|
|
||||||
options opts;
|
options opts;
|
||||||
|
|
||||||
@ -141,17 +141,17 @@ class CodegenHandler {
|
|||||||
delete lib;
|
delete lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getObjectSize(T *ObjectAddr, size_t *ObjectSize) {
|
static int getObjectSize(T &ObjectAddr, size_t &ObjectSize) {
|
||||||
OILibrary *lib;
|
OILibrary *lib;
|
||||||
if (int responseCode = getLibrary(lib);
|
if (int responseCode = getLibrary(lib);
|
||||||
responseCode != Response::OIL_SUCCESS) {
|
responseCode != Response::OIL_SUCCESS) {
|
||||||
return responseCode;
|
return responseCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return lib->getObjectSize((void *)ObjectAddr, ObjectSize);
|
return lib->getObjectSize((void *)&ObjectAddr, ObjectSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getObjectSize(T *ObjectAddr, size_t *ObjectSize,
|
static int getObjectSize(T &ObjectAddr, size_t &ObjectSize,
|
||||||
const options &opts, bool checkOptions = true) {
|
const options &opts, bool checkOptions = true) {
|
||||||
OILibrary *lib;
|
OILibrary *lib;
|
||||||
if (int responseCode = getLibrary(lib, opts, checkOptions);
|
if (int responseCode = getLibrary(lib, opts, checkOptions);
|
||||||
@ -159,7 +159,7 @@ class CodegenHandler {
|
|||||||
return responseCode;
|
return responseCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return lib->getObjectSize((void *)ObjectAddr, ObjectSize);
|
return lib->getObjectSize((void *)&ObjectAddr, ObjectSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -196,7 +196,7 @@ class CodegenHandler {
|
|||||||
}
|
}
|
||||||
curBoxedLib = getLib();
|
curBoxedLib = getLib();
|
||||||
|
|
||||||
int (*sizeFp)(T *, size_t *) = &getObjectSize;
|
int (*sizeFp)(T &, size_t &) = &getObjectSize;
|
||||||
void *typedFp = reinterpret_cast<void *>(sizeFp);
|
void *typedFp = reinterpret_cast<void *>(sizeFp);
|
||||||
OILibrary *newLib = new OILibrary(typedFp, opts);
|
OILibrary *newLib = new OILibrary(typedFp, opts);
|
||||||
|
|
||||||
@ -230,7 +230,7 @@ class CodegenHandler {
|
|||||||
* Ahead-Of-Time (AOT) compilation.
|
* Ahead-Of-Time (AOT) compilation.
|
||||||
*/
|
*/
|
||||||
template <class T>
|
template <class T>
|
||||||
int getObjectSize(T *ObjectAddr, size_t *ObjectSize, const options &opts,
|
int getObjectSize(T &ObjectAddr, size_t &ObjectSize, const options &opts,
|
||||||
bool checkOptions = true) {
|
bool checkOptions = true) {
|
||||||
return CodegenHandler<T>::getObjectSize(ObjectAddr, ObjectSize, opts,
|
return CodegenHandler<T>::getObjectSize(ObjectAddr, ObjectSize, opts,
|
||||||
checkOptions);
|
checkOptions);
|
||||||
@ -248,7 +248,7 @@ int getObjectSize(T *ObjectAddr, size_t *ObjectSize, const options &opts,
|
|||||||
* production system.
|
* production system.
|
||||||
*/
|
*/
|
||||||
template <class T>
|
template <class T>
|
||||||
int __attribute__((weak)) getObjectSize(T *ObjectAddr, size_t *ObjectSize) {
|
int __attribute__((weak)) getObjectSize(T &ObjectAddr, size_t &ObjectSize) {
|
||||||
#ifdef OIL_AOT_COMPILATION
|
#ifdef OIL_AOT_COMPILATION
|
||||||
return Response::OIL_UNINITIALISED;
|
return Response::OIL_UNINITIALISED;
|
||||||
#else
|
#else
|
||||||
|
@ -52,12 +52,12 @@ int OILibrary::init() {
|
|||||||
return pimpl_->compileCode();
|
return pimpl_->compileCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
int OILibrary::getObjectSize(void* ObjectAddr, size_t* size) {
|
int OILibrary::getObjectSize(void* ObjectAddr, size_t& size) {
|
||||||
if (fp == nullptr) {
|
if (fp == nullptr) {
|
||||||
return Response::OIL_UNINITIALISED;
|
return Response::OIL_UNINITIALISED;
|
||||||
}
|
}
|
||||||
|
|
||||||
*size = (*fp)(ObjectAddr);
|
size = (*fp)(ObjectAddr);
|
||||||
return Response::OIL_SUCCESS;
|
return Response::OIL_SUCCESS;
|
||||||
}
|
}
|
||||||
} // namespace ObjectIntrospection
|
} // namespace ObjectIntrospection
|
||||||
|
@ -121,7 +121,7 @@ def add_test_setup(f, config):
|
|||||||
oil_func_body += ' std::cout << "{\\"results\\": [" << std::endl;\n'
|
oil_func_body += ' std::cout << "{\\"results\\": [" << std::endl;\n'
|
||||||
oil_func_body += ' std::cout << "," << std::endl;\n'.join(
|
oil_func_body += ' std::cout << "," << std::endl;\n'.join(
|
||||||
f" size_t size{i} = 0;\n"
|
f" size_t size{i} = 0;\n"
|
||||||
f" auto ret{i} = ObjectIntrospection::getObjectSize(&a{i}, &size{i}, opts);\n"
|
f" auto ret{i} = ObjectIntrospection::getObjectSize(a{i}, size{i}, opts);\n"
|
||||||
f' std::cout << "{{\\"ret\\": " << ret{i} << ", \\"size\\": " << size{i} << "}}" << std::endl;\n'
|
f' std::cout << "{{\\"ret\\": " << ret{i} << ", \\"size\\": " << size{i} << "}}" << std::endl;\n'
|
||||||
for i in range(len(case["param_types"]))
|
for i in range(len(case["param_types"]))
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user