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,");
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@
|
||||
* -- SINGLE-THREADED
|
||||
* ObjectIntrospection::options opts = { .configFilePath = "sample.oid.toml" };
|
||||
* size_t size;
|
||||
* int responseCode = ObjectIntrospection::getObjectSize(&obj, &size, opts);
|
||||
* int responseCode = ObjectIntrospection::getObjectSize(obj, size, opts);
|
||||
* if (responseCode != ObjectIntrospection::Response::OIL_SUCCESS) {
|
||||
* // handle error
|
||||
* }
|
||||
@ -46,7 +46,7 @@
|
||||
* -- MULTI-THREADED (NO SETUP)
|
||||
* ObjectIntrospection::options opts = { .configFilePath = "sample.oid.toml" };
|
||||
* size_t size;
|
||||
* int responseCode = ObjectIntrospection::getObjectSize(&obj, &size, opts);
|
||||
* int responseCode = ObjectIntrospection::getObjectSize(obj, size, opts);
|
||||
* if (responseCode > ObjectIntrospection::Response::OIL_INITIALISING) {
|
||||
* // handle error
|
||||
* } else if (responseCode == ObjectIntrospection::Response::OIL_SUCCESS) {
|
||||
@ -60,7 +60,7 @@
|
||||
* // handle error
|
||||
* }
|
||||
* size_t size;
|
||||
* int responseCode = ObjectIntrospection::getObjectSize(&obj, &size);
|
||||
* int responseCode = ObjectIntrospection::getObjectSize(obj, size);
|
||||
* if (responseCode == ObjectIntrospection::Response::OIL_UNINITIALISED) {
|
||||
* // handle error - impossible if successfully inited
|
||||
* }
|
||||
@ -111,7 +111,7 @@ class OILibrary {
|
||||
OILibrary(void *TemplateFunc, options opt);
|
||||
~OILibrary();
|
||||
int init();
|
||||
int getObjectSize(void *ObjectAddr, size_t *size);
|
||||
int getObjectSize(void *ObjectAddr, size_t &size);
|
||||
|
||||
options opts;
|
||||
|
||||
@ -141,17 +141,17 @@ class CodegenHandler {
|
||||
delete lib;
|
||||
}
|
||||
|
||||
static int getObjectSize(T *ObjectAddr, size_t *ObjectSize) {
|
||||
static int getObjectSize(T &ObjectAddr, size_t &ObjectSize) {
|
||||
OILibrary *lib;
|
||||
if (int responseCode = getLibrary(lib);
|
||||
responseCode != Response::OIL_SUCCESS) {
|
||||
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) {
|
||||
OILibrary *lib;
|
||||
if (int responseCode = getLibrary(lib, opts, checkOptions);
|
||||
@ -159,7 +159,7 @@ class CodegenHandler {
|
||||
return responseCode;
|
||||
}
|
||||
|
||||
return lib->getObjectSize((void *)ObjectAddr, ObjectSize);
|
||||
return lib->getObjectSize((void *)&ObjectAddr, ObjectSize);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -196,7 +196,7 @@ class CodegenHandler {
|
||||
}
|
||||
curBoxedLib = getLib();
|
||||
|
||||
int (*sizeFp)(T *, size_t *) = &getObjectSize;
|
||||
int (*sizeFp)(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(T &ObjectAddr, size_t &ObjectSize, const options &opts,
|
||||
bool checkOptions = true) {
|
||||
return CodegenHandler<T>::getObjectSize(ObjectAddr, ObjectSize, opts,
|
||||
checkOptions);
|
||||
@ -248,7 +248,7 @@ 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(T &ObjectAddr, size_t &ObjectSize) {
|
||||
#ifdef OIL_AOT_COMPILATION
|
||||
return Response::OIL_UNINITIALISED;
|
||||
#else
|
||||
|
@ -52,12 +52,12 @@ int OILibrary::init() {
|
||||
return pimpl_->compileCode();
|
||||
}
|
||||
|
||||
int OILibrary::getObjectSize(void* ObjectAddr, size_t* size) {
|
||||
int OILibrary::getObjectSize(void* ObjectAddr, size_t& size) {
|
||||
if (fp == nullptr) {
|
||||
return Response::OIL_UNINITIALISED;
|
||||
}
|
||||
|
||||
*size = (*fp)(ObjectAddr);
|
||||
size = (*fp)(ObjectAddr);
|
||||
return Response::OIL_SUCCESS;
|
||||
}
|
||||
} // 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 << "," << std::endl;\n'.join(
|
||||
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'
|
||||
for i in range(len(case["param_types"]))
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user