Repository: celix Updated Branches: refs/heads/feature/CELIX-237_rsa-ffi 3a1503988 -> eb9ec11ea
CELIX-237: Added support for (external) type references for dyn_function and dyn_closure Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/de9db0c9 Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/de9db0c9 Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/de9db0c9 Branch: refs/heads/feature/CELIX-237_rsa-ffi Commit: de9db0c9766849da1132dc041f65d6d1a256de3f Parents: 3a15039 Author: Pepijn Noltes <pepijnnol...@gmail.com> Authored: Wed Jul 8 11:00:50 2015 +0200 Committer: Pepijn Noltes <pepijnnol...@gmail.com> Committed: Wed Jul 8 11:00:50 2015 +0200 ---------------------------------------------------------------------- .../dynamic_function_interface/dyn_function.c | 16 ++++++++-------- .../dynamic_function_interface/dyn_function.h | 4 ++-- .../dynamic_function_interface/dyn_type.c | 6 +++--- .../dynamic_function_interface/dyn_type.h | 9 +++++---- .../tst/dyn_closure_tests.cpp | 12 ++++++------ .../tst/dyn_function_tests.cpp | 8 ++++---- 6 files changed, 28 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/de9db0c9/remote_services/dynamic_function_interface/dyn_function.c ---------------------------------------------------------------------- diff --git a/remote_services/dynamic_function_interface/dyn_function.c b/remote_services/dynamic_function_interface/dyn_function.c index 0bb0d53..9d0de7d 100644 --- a/remote_services/dynamic_function_interface/dyn_function.c +++ b/remote_services/dynamic_function_interface/dyn_function.c @@ -35,10 +35,10 @@ struct _dyn_closure_type { static int dynFunction_initCif(ffi_cif *cif, dyn_type *arguments, dyn_type *funcReturn); -static int dynFunction_parseDescriptor(const char *functionDescriptor, dyn_type **arguments, dyn_type **funcReturn); +static int dynFunction_parseDescriptor(const char *functionDescriptor, dyn_type_list_type *typeReferences, dyn_type **arguments, dyn_type **funcReturn); static void dynClosure_ffiBind(ffi_cif *cif, void *ret, void *args[], void *userData); -int dynFunction_create(const char *descriptor, void (*fn)(void), dyn_function_type **out) { +int dynFunction_create(const char *descriptor, dyn_type_list_type *typeReferences, void (*fn)(void), dyn_function_type **out) { int status = 0; dyn_function_type *dynFunc = NULL; LOG_DEBUG("Creating dyn function for descriptor '%s'\n", descriptor); @@ -47,7 +47,7 @@ int dynFunction_create(const char *descriptor, void (*fn)(void), dyn_function_ty if (dynFunc != NULL) { dynFunc->fn = fn; - status = dynFunction_parseDescriptor(descriptor, &dynFunc->arguments, &dynFunc->funcReturn); + status = dynFunction_parseDescriptor(descriptor, typeReferences, &dynFunc->arguments, &dynFunc->funcReturn); if (status == 0) { status = dynFunction_initCif(&dynFunc->cif, dynFunc->arguments, dynFunc->funcReturn); } @@ -67,7 +67,7 @@ int dynFunction_create(const char *descriptor, void (*fn)(void), dyn_function_ty return status; } -static int dynFunction_parseDescriptor(const char *descriptor, dyn_type **arguments, dyn_type **funcReturn) { +static int dynFunction_parseDescriptor(const char *descriptor, dyn_type_list_type *typeReferences, dyn_type **arguments, dyn_type **funcReturn) { int status = 0; char *startPos = index(descriptor, '('); char *endPos = index(descriptor, ')'); @@ -89,9 +89,9 @@ static int dynFunction_parseDescriptor(const char *descriptor, dyn_type **argume returnDesc[len] = '\0'; LOG_DEBUG("returnDesc is '%s'\n", returnDesc); - status = dynType_create(argDesc, NULL, arguments); + status = dynType_create(argDesc, typeReferences, arguments); if (status == 0) { - status = dynType_create(returnDesc, NULL, funcReturn); + status = dynType_create(returnDesc, typeReferences, funcReturn); } } else { status = 1; @@ -144,13 +144,13 @@ static void dynClosure_ffiBind(ffi_cif *cif, void *ret, void *args[], void *user dynClosure->bind(dynClosure->userData, args, ret); } -int dynClosure_create(const char *descriptor, void (*bind)(void *, void **, void*), void *userData, dyn_closure_type **out) { +int dynClosure_create(const char *descriptor, dyn_type_list_type *typeReferences, void (*bind)(void *, void **, void*), void *userData, dyn_closure_type **out) { int status = 0; dyn_closure_type *dynClosure = calloc(1, sizeof(*dynClosure)); if (dynClosure != NULL) { dynClosure->bind = bind; dynClosure->userData = userData; - status = dynFunction_parseDescriptor(descriptor, &dynClosure->arguments, &dynClosure->funcReturn); + status = dynFunction_parseDescriptor(descriptor, typeReferences, &dynClosure->arguments, &dynClosure->funcReturn); if (status == 0) { status = dynFunction_initCif(&dynClosure->cif, dynClosure->arguments, dynClosure->funcReturn); if (status == 0) { http://git-wip-us.apache.org/repos/asf/celix/blob/de9db0c9/remote_services/dynamic_function_interface/dyn_function.h ---------------------------------------------------------------------- diff --git a/remote_services/dynamic_function_interface/dyn_function.h b/remote_services/dynamic_function_interface/dyn_function.h index 976f2d7..5f7be35 100644 --- a/remote_services/dynamic_function_interface/dyn_function.h +++ b/remote_services/dynamic_function_interface/dyn_function.h @@ -19,11 +19,11 @@ typedef struct _dyn_closure_type dyn_closure_type; DFI_SETUP_LOG_HEADER(dynFunction); -int dynFunction_create(const char *descriptor, void (*fn)(void), dyn_function_type **dynFunc); +int dynFunction_create(const char *descriptor, dyn_type_list_type *typeReferences, void (*fn)(void), dyn_function_type **dynFunc); int dynFunction_destroy(dyn_function_type *dynFunc); int dynFunction_call(dyn_function_type *dynFunc, void *returnValue, void **argValues); -int dynClosure_create(const char *descriptor, void (*bind)(void *, void **, void*), void *userData, dyn_closure_type **out); +int dynClosure_create(const char *descriptor, dyn_type_list_type *typeReferences, void (*bind)(void *, void **, void*), void *userData, dyn_closure_type **out); int dynClosure_getFnPointer(dyn_closure_type *dynClosure, void(**fn)(void)); int dynClosure_destroy(dyn_closure_type *dynClosure); http://git-wip-us.apache.org/repos/asf/celix/blob/de9db0c9/remote_services/dynamic_function_interface/dyn_type.c ---------------------------------------------------------------------- diff --git a/remote_services/dynamic_function_interface/dyn_type.c b/remote_services/dynamic_function_interface/dyn_type.c index f4c982f..cfb2c3f 100644 --- a/remote_services/dynamic_function_interface/dyn_type.c +++ b/remote_services/dynamic_function_interface/dyn_type.c @@ -15,7 +15,7 @@ DFI_SETUP_LOG(dynType) -static int dynType_createWithStream(FILE *stream, dyn_type *parent, struct dyn_type_list_head *typeReferences, dyn_type **result); +static int dynType_createWithStream(FILE *stream, dyn_type *parent, dyn_type_list_type *typeReferences, dyn_type **result); static void dynType_clear(dyn_type *type); static void dynType_clearComplex(dyn_type *type); static void dynType_clearSequence(dyn_type *type); @@ -57,7 +57,7 @@ static const int DT_ERROR = 1; static const int DT_MEM_ERROR = 2; static const int DT_PARSE_ERROR = 3; -int dynType_create(const char *descriptor, struct dyn_type_list_head *typeReferences, dyn_type **type) { +int dynType_create(const char *descriptor, dyn_type_list_type *typeReferences, dyn_type **type) { int status = DT_OK; FILE *stream = fmemopen((char *)descriptor, strlen(descriptor), "r"); if (stream != NULL) { @@ -77,7 +77,7 @@ int dynType_create(const char *descriptor, struct dyn_type_list_head *typeRefere return status; } -static int dynType_createWithStream(FILE *stream, dyn_type *parent, struct dyn_type_list_head *typeReferences, dyn_type **result) { +static int dynType_createWithStream(FILE *stream, dyn_type *parent, dyn_type_list_type *typeReferences, dyn_type **result) { int status = DT_OK; dyn_type *type = calloc(1, sizeof(*type)); if (type != NULL) { http://git-wip-us.apache.org/repos/asf/celix/blob/de9db0c9/remote_services/dynamic_function_interface/dyn_type.h ---------------------------------------------------------------------- diff --git a/remote_services/dynamic_function_interface/dyn_type.h b/remote_services/dynamic_function_interface/dyn_type.h index 904487a..2495811 100644 --- a/remote_services/dynamic_function_interface/dyn_type.h +++ b/remote_services/dynamic_function_interface/dyn_type.h @@ -76,7 +76,8 @@ typedef struct _dyn_type dyn_type; -TAILQ_HEAD(dyn_type_list_head, nested_entry); +TAILQ_HEAD(_dyn_type_list_type, nested_entry); +typedef struct _dyn_type_list_type dyn_type_list_type; struct _dyn_type { char *name; @@ -84,8 +85,8 @@ struct _dyn_type { int type; ffi_type *ffiType; dyn_type *parent; - struct dyn_type_list_head *typeReferences; //NOTE: not owned - struct dyn_type_list_head nestedTypesHead; + dyn_type_list_type *typeReferences; //NOTE: not owned + dyn_type_list_type nestedTypesHead; union { struct { TAILQ_HEAD(, complex_type_entry) entriesHead; @@ -121,7 +122,7 @@ struct nested_entry { DFI_SETUP_LOG_HEADER(dynType); //generic -int dynType_create(const char *descriptor, struct dyn_type_list_head *typeReferences, dyn_type **type); +int dynType_create(const char *descriptor, dyn_type_list_type *typeReferences, dyn_type **type); void dynType_destroy(dyn_type *type); int dynType_alloc(dyn_type *type, void **bufLoc); void dynType_print(dyn_type *type); http://git-wip-us.apache.org/repos/asf/celix/blob/de9db0c9/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp b/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp index 9138fb3..a017d91 100644 --- a/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp +++ b/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp @@ -25,7 +25,7 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch fprintf(stderr, "\n"); } -#define EXAMPLE1_SCHEMA "example(III)I" +#define EXAMPLE1_DESCRIPTOR "example(III)I" static void example1_binding(void *userData, void* args[], void *out) { printf("example1 closure called\n"); int32_t a = *((int32_t *)args[0]); @@ -36,7 +36,7 @@ static void example1_binding(void *userData, void* args[], void *out) { g_count += 1; } -#define EXAMPLE2_SCHEMA "example(I{DDD val1 val2 val3}I)D" +#define EXAMPLE2_DESCRIPTOR "example(I{DDD val1 val2 val3}I)D" struct example2_arg2 { double val1; double val2; @@ -53,7 +53,7 @@ void example2_binding(void *userData, void* args[], void *out) { } -#define EXAMPLE3_SCHEMA "example(III){III sum max min}" +#define EXAMPLE3_DESCRIPTOR "example(III){III sum max min}" struct example3_ret { int32_t sum; int32_t max; @@ -82,7 +82,7 @@ static void tests() { int rc = 0; { - rc = dynClosure_create(EXAMPLE1_SCHEMA, example1_binding, NULL, &dynClosure); + rc = dynClosure_create(EXAMPLE1_DESCRIPTOR, NULL, example1_binding, NULL, &dynClosure); CHECK_EQUAL(0, rc); int32_t (*func)(int32_t a, int32_t b, int32_t c) = NULL; int rc = dynClosure_getFnPointer(dynClosure, (void(**)(void))&func); @@ -96,7 +96,7 @@ static void tests() { { dynClosure = NULL; - rc = dynClosure_create(EXAMPLE2_SCHEMA, example2_binding, NULL, &dynClosure); + rc = dynClosure_create(EXAMPLE2_DESCRIPTOR, NULL, example2_binding, NULL, &dynClosure); CHECK_EQUAL(0, rc); double (*func)(int32_t a, struct example2_arg2 b, int32_t c) = NULL; rc = dynClosure_getFnPointer(dynClosure, (void(**)(void))&func); @@ -114,7 +114,7 @@ static void tests() { { dynClosure = NULL; - rc = dynClosure_create(EXAMPLE3_SCHEMA, example3_binding, NULL, &dynClosure); + rc = dynClosure_create(EXAMPLE3_DESCRIPTOR, NULL, example3_binding, NULL, &dynClosure); CHECK_EQUAL(0, rc); struct example3_ret * (*func)(int32_t a, int32_t b, int32_t c) = NULL; rc = dynClosure_getFnPointer(dynClosure, (void(**)(void))&func); http://git-wip-us.apache.org/repos/asf/celix/blob/de9db0c9/remote_services/dynamic_function_interface/tst/dyn_function_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/dynamic_function_interface/tst/dyn_function_tests.cpp b/remote_services/dynamic_function_interface/tst/dyn_function_tests.cpp index 9b7ff20..714b4b5 100644 --- a/remote_services/dynamic_function_interface/tst/dyn_function_tests.cpp +++ b/remote_services/dynamic_function_interface/tst/dyn_function_tests.cpp @@ -22,7 +22,7 @@ extern "C" { fprintf(stderr, "\n"); } - #define EXAMPLE1_SCHEMA "example(III)I" + #define EXAMPLE1_DESCRIPTOR "example(III)I" int32_t example1(int32_t a, int32_t b, int32_t c) { CHECK_EQUAL(2, a); CHECK_EQUAL(4, b); @@ -35,7 +35,7 @@ extern "C" { int rc; void (*fp)(void) = (void (*)(void)) example1; - rc = dynFunction_create(EXAMPLE1_SCHEMA, fp, &dynFunc); + rc = dynFunction_create(EXAMPLE1_DESCRIPTOR, NULL, fp, &dynFunc); CHECK_EQUAL(0, rc); int32_t a = 2; @@ -53,7 +53,7 @@ extern "C" { dynFunction_destroy(dynFunc); } - #define EXAMPLE2_SCHEMA "example(I{IID val1 val2 val3}D)D" + #define EXAMPLE2_DESCRIPTOR "example(I{IID val1 val2 val3}D)D" struct example2_arg { int32_t val1; int32_t val2; @@ -74,7 +74,7 @@ extern "C" { int rc; void (*fp)(void) = (void (*)(void)) example2; - rc = dynFunction_create(EXAMPLE2_SCHEMA, fp, &dynFunc); + rc = dynFunction_create(EXAMPLE2_DESCRIPTOR, NULL, fp, &dynFunc); CHECK_EQUAL(0, rc); int32_t arg1 = 2;