Modified list setter of C Generator 65/189365/4
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 17 Sep 2018 08:16:34 +0000 (17:16 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Wed, 19 Sep 2018 02:47:34 +0000 (02:47 +0000)
Before adding the value on list, the value is cloned.

Change-Id: I5c81f5ec58c310a50e8bd258cecddd4ef1fbbb8e
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
idlc/c_gen/c_body_gen_base.cc
idlc/c_gen/c_body_gen_base_cb.h

index 13b48968470b019a50bbf2dc12a4d894aa066109..d311a9731fce13ed3a4e1cfdbac3c307625b8c05 100644 (file)
@@ -779,27 +779,31 @@ std::string CBodyGeneratorBase::GetSetterString(const std::string& id,
         });
     str += NLine(1);
   } else if (type.ToString() == "list") {
-    if (type.GetMetaType()->IsUserDefinedType() ||
-        type.GetMetaType()->ToString() == "string" ||
-        type.GetMetaType()->ToString() == "bundle" ||
-        type.GetMetaType()->ToString() == "list" ||
-        type.GetMetaType()->ToString() == "array") {
-      str += GenTemplateString(setter,
-          [&]()->std::string {
-            return "h->" + id;
-          },
-          [&]()->std::string {
-            if (type.GetMetaType()->ToString() == "string")
-              return "g_list_append(h->" + id + ", strdup(" + id + "))";
-            return "g_list_append(h->" + id + ", " + id + ")";
-          });
-    } else {
-      str += GenTemplateString(CB_SETTER_LIST_BLOCK,
-          [&]()->std::string {
-            return GetParcelParamTypeString(*type.GetMetaType());
-          },
-          [&]()->std::string {
-            std::string s;
+    str += GenTemplateString(CB_SETTER_LIST_BLOCK,
+        [&]()->std::string {
+          return GetParcelParamTypeString(*type.GetMetaType());
+        },
+        [&]()->std::string {
+          std::string s;
+          if (type.GetMetaType()->IsUserDefinedType() ||
+              type.GetMetaType()->ToString() == "string" ||
+              type.GetMetaType()->ToString() == "bundle" ||
+              type.GetMetaType()->ToString() == "list" ||
+              type.GetMetaType()->ToString() == "array") {
+            s += GetSetterString(*type.GetMetaType(), "value", id);
+            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+                [&]()->std::string {
+                  return "!value";
+                },
+                [&]()->std::string {
+                  std::string s;
+                  s += "_E(\"Out of memory\");" + NLine(1);
+                  s += "return -1;";
+                  return s;
+                });
+            s += NLine(1);
+          } else {
+            s += "value = calloc(1, sizeof(*value));" + NLine(1);
             s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
                 [&]()->std::string {
                   return "!value";
@@ -812,15 +816,15 @@ std::string CBodyGeneratorBase::GetSetterString(const std::string& id,
                 });
             s += NLine(1);
             s += GetSetterString("*value", id);
-            return s;
-          },
-          [&]()->std::string {
-            return "h->" + id;
-          },
-          [&]()->std::string {
-              return "h->" + id;
-          });
-    }
+          }
+          return s;
+        },
+        [&]()->std::string {
+          return "h->" + id;
+        },
+        [&]()->std::string {
+          return "h->" + id;
+        });
   } else if (type.ToString() == "array") {
     str += GetFinalizeString(id, type, "h->") + NLine(1);
     str += GetSetterString("h->" + id, "NULL");
index db0aa52ca52e26d34f490757831b6d20fd9e94b1..a27cc54820f8f5a77fab857209a334f23de4c37a 100644 (file)
@@ -285,9 +285,8 @@ do {
 const char CB_SETTER_LIST_BLOCK[] =
 R"__c_cb(
 do {
-    $$value;
+    $$value = NULL;
 
-    value = calloc(1, sizeof(*value));
     $$
     $$ = g_list_append($$, value);
 } while (0);