You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2015/07/08 01:29:32 UTC

celix git commit: CELIX-237: Added destroy for dyn_function/dyn_closure and tested with valgrind

Repository: celix
Updated Branches:
  refs/heads/feature/CELIX-237_rsa-ffi eba9e71a8 -> 8eeec9a84


CELIX-237: Added destroy for dyn_function/dyn_closure and tested with valgrind


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/8eeec9a8
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/8eeec9a8
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/8eeec9a8

Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: 8eeec9a84bdd4aa6849df86f740a42c96a512188
Parents: eba9e71
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Jul 8 01:35:17 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Jul 8 01:35:17 2015 +0200

----------------------------------------------------------------------
 .../dynamic_function_interface/dyn_function.c   | 25 +++++++++++++++++---
 .../tst/dyn_closure_tests.cpp                   | 13 ++++++----
 2 files changed, 30 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/8eeec9a8/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 116803f..dbe414d 100644
--- a/remote_services/dynamic_function_interface/dyn_function.c
+++ b/remote_services/dynamic_function_interface/dyn_function.c
@@ -30,7 +30,7 @@ struct _dyn_closure_type {
     ffi_closure *ffiClosure;
     void (*fn)(void);
     void (*bind)(void *userData, void *args[], void *ret);
-    void *userData;
+    void *userData; //for bind
 };
 
 
@@ -122,7 +122,15 @@ static int dynFunction_initCif(ffi_cif *cif, dyn_type *arguments, dyn_type *retu
 
 int dynFunction_destroy(dyn_function_type *dynFunc) {
     int result = 0;
-    LOG_WARNING("TODO destroy dyn dync\n");
+    if (dynFunc != NULL) {
+        if (dynFunc->arguments != NULL) {
+	    dynType_destroy(dynFunc->arguments);
+	}
+        if (dynFunc->funcReturn != NULL) {
+	    dynType_destroy(dynFunc->funcReturn);
+	}
+	free(dynFunc);
+    }
     return result;
 }
 
@@ -180,6 +188,17 @@ int dynClosure_getFnPointer(dyn_closure_type *dynClosure, void (**fn)(void)) {
 
 int dynClosure_destroy(dyn_closure_type *dynClosure) {
     int result = 0;
-    LOG_WARNING("TODO destroy closure\n");
+    if (dynClosure != NULL) {
+        if (dynClosure->arguments != NULL) {
+	    dynType_destroy(dynClosure->arguments);
+	}
+        if (dynClosure->funcReturn != NULL) {
+	    dynType_destroy(dynClosure->funcReturn);
+	}
+	if (dynClosure->ffiClosure != NULL) {
+	    ffi_closure_free(dynClosure->ffiClosure);
+	}
+	free(dynClosure);
+    }
     return result;
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/8eeec9a8/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 c3ea1de..9138fb3 100644
--- a/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp
+++ b/remote_services/dynamic_function_interface/tst/dyn_closure_tests.cpp
@@ -47,7 +47,7 @@ void example2_binding(void *userData, void* args[], void *out) {
     int32_t a = *((int32_t *)args[0]);
     struct example2_arg2 b =  *((struct example2_arg2 *)args[1]);
     int32_t c = *((int32_t *)args[2]);
-    int32_t *ret = (int32_t *)out;
+    double *ret = (double *)out;
     *ret = a + b.val1 + b.val2 + b.val3 + c;
     g_count += 1;
 }
@@ -79,7 +79,7 @@ static void example3_binding(void *userData, void* args[], void *out) {
 
 static void tests() {
     dyn_closure_type *dynClosure = NULL;
-    int rc;
+    int rc = 0;
 
     {
         rc = dynClosure_create(EXAMPLE1_SCHEMA, example1_binding, NULL, &dynClosure);
@@ -88,8 +88,9 @@ static void tests() {
         int rc = dynClosure_getFnPointer(dynClosure, (void(**)(void))&func);
         CHECK_EQUAL(0, rc);
         int32_t ret = func(2,3,4);
-        printf("Return value for example1 is %i\n", ret);
+        //printf("Return value for example1 is %i\n", ret);
         CHECK_EQUAL(1, g_count);
+	CHECK_EQUAL(9, ret);
         dynClosure_destroy(dynClosure);
     }
 
@@ -105,8 +106,9 @@ static void tests() {
         b.val2 = 1.5;
         b.val3 = 2.0;
         double ret = func(2,b,4);
-        printf("Return value for example2 is %f\n", ret);
+        //printf("Return value for example2 is %f\n", ret);
         CHECK_EQUAL(2, g_count);
+	CHECK_EQUAL(10.5, ret);
         dynClosure_destroy(dynClosure);
     }
 
@@ -118,8 +120,9 @@ static void tests() {
         rc = dynClosure_getFnPointer(dynClosure, (void(**)(void))&func);
         CHECK_EQUAL(0, rc);
         struct example3_ret *ret = func(2,8,4);
-        printf("Return value for example3 is {sum:%i, max:%i, min:%i}\n", ret->sum, ret->max, ret->min);
+        //printf("Return value for example3 is {sum:%i, max:%i, min:%i}\n", ret->sum, ret->max, ret->min);
         CHECK_EQUAL(3, g_count);
+	CHECK_EQUAL(14, ret->sum);
         dynClosure_destroy(dynClosure);
         free(ret);
     }