celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [celix] branch feature/gh-142-rsa-issues updated: gh-142: Fixes some issue with remote calls and string input/output.
Date Tue, 21 Jan 2020 22:38:12 GMT
This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/gh-142-rsa-issues
in repository https://gitbox.apache.org/repos/asf/celix.git


The following commit(s) were added to refs/heads/feature/gh-142-rsa-issues by this push:
     new e1e162d  gh-142: Fixes some issue with remote calls and string input/output.
e1e162d is described below

commit e1e162d64d3eba3478e39282192df33ff4163f4f
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
AuthorDate: Tue Jan 21 23:37:22 2020 +0100

    gh-142: Fixes some issue with remote calls and string input/output.
---
 .../test/src/tst_activator.c                       | 37 +++++++++++-----------
 libs/dfi/src/json_rpc.c                            | 10 ++++--
 libs/dfi/src/json_serializer.c                     |  5 ++-
 3 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/bundles/remote_services/remote_service_admin_dfi/test/src/tst_activator.c b/bundles/remote_services/remote_service_admin_dfi/test/src/tst_activator.c
index a92e277..5e8d0ae 100644
--- a/bundles/remote_services/remote_service_admin_dfi/test/src/tst_activator.c
+++ b/bundles/remote_services/remote_service_admin_dfi/test/src/tst_activator.c
@@ -141,25 +141,24 @@ static int bndTestRemoteExample(void *handle) {
             ok = (f == 3);
         }
 
-        //TODO enable and fix segfault
-//        if (ok) {
-//            //test string call with taking ownership
-//            char *tmp = strndup("test1", 1024);
-//            char *result = NULL;
-//            act->remoteExample->setName1(act->remoteExample->handle, tmp, &result);
-//            free(tmp);
-//            ok = strncmp(tmp, result, 1024) == 0;
-//            free(result);
-//        }
-//
-//        if (ok) {
-//            //test string call with keeping ownership
-//            const char *tmp = "test2";
-//            char *result = NULL;
-//            act->remoteExample->setName2(act->remoteExample->handle, tmp, &result);
-//            ok = strncmp(tmp, result, 1024) == 0;
-//            free(result);
-//        }
+        if (ok) {
+            //test string call with taking ownership
+            char *tmp = strndup("test1", 1024);
+            char *result = NULL;
+            act->remoteExample->setName1(act->remoteExample->handle, tmp, &result);
+            //note setName1 should take ownership of tmp, so no free(tmp) needed.
+            ok = strncmp("test1", result, 1024) == 0;
+            free(result);
+        }
+
+        if (ok) {
+            //test string call with keeping ownership
+            const char *tmp = "test2";
+            char *result = NULL;
+            act->remoteExample->setName2(act->remoteExample->handle, tmp, &result);
+            ok = strncmp("test2", result, 1024) == 0;
+            free(result); //TODO should fail on double free.
+        }
 
     } else {
         fprintf(stderr, "remote example service not available");
diff --git a/libs/dfi/src/json_rpc.c b/libs/dfi/src/json_rpc.c
index 6ff8367..912e23d 100644
--- a/libs/dfi/src/json_rpc.c
+++ b/libs/dfi/src/json_rpc.c
@@ -321,9 +321,13 @@ int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void
*args[]
 				dynType_typedPointer_getTypedType(argType, &subType);
 
 				if (dynType_descriptorType(subType) == 't') {
-					void ***out = (void ***) args[i];
-					status = jsonSerializer_deserializeJson(subType, result, *out);
-				} else {
+				    char ***out = (char ***) args[i];
+                    char **ptrToString = NULL;
+                    status = jsonSerializer_deserializeJson(subType, result, (void**)&ptrToString);
+                    char *s __attribute__((unused)) = *ptrToString; //note for debug
+                    free(ptrToString);
+                    **out = (void*)s;
+                } else {
 					dyn_type *subSubType = NULL;
 					dynType_typedPointer_getTypedType(subType, &subSubType);
 					void ***out = (void ***) args[i];
diff --git a/libs/dfi/src/json_serializer.c b/libs/dfi/src/json_serializer.c
index db3dd3a..78f7e9b 100644
--- a/libs/dfi/src/json_serializer.c
+++ b/libs/dfi/src/json_serializer.c
@@ -77,8 +77,11 @@ static int jsonSerializer_createType(dyn_type *type, json_t *val, void
**result)
 
     if (dynType_descriptorType(type) == 't') {
         if (json_typeof(val) == JSON_STRING) {
+            //note a deserialized C string is a sequence of memory for the actual string
and a
+            //pointer to that sequence. That pointer also needs to reside in the memory (heap).
             const char *s = json_string_value(val);
-            inst = strdup(s);
+            inst = calloc(1, sizeof(char*));
+            *((char**)inst) = strdup(s);
         } else {
             status = ERROR;
             LOG_ERROR("Expected json_string type got %i\n", json_typeof(val));


Mime
View raw message