diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2018-09-17 17:16:34 +0900 |
---|---|---|
committer | HwanKyu Jhun <h.jhun@samsung.com> | 2018-09-19 02:47:34 +0000 |
commit | 3e8b76f9eecb7c81007f32e60da101cbc9e7dd38 (patch) | |
tree | b675bda8433b3448e3def0b4cd2f646d1362bfcd | |
parent | 6c11c6bac25b99727552c6c3a61ca3cdbca77e42 (diff) | |
download | tidl-3e8b76f9eecb7c81007f32e60da101cbc9e7dd38.tar.gz tidl-3e8b76f9eecb7c81007f32e60da101cbc9e7dd38.tar.bz2 tidl-3e8b76f9eecb7c81007f32e60da101cbc9e7dd38.zip |
Modified list setter of C Generator
Before adding the value on list, the value is cloned.
Change-Id: I5c81f5ec58c310a50e8bd258cecddd4ef1fbbb8e
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r-- | idlc/c_gen/c_body_gen_base.cc | 64 | ||||
-rw-r--r-- | idlc/c_gen/c_body_gen_base_cb.h | 3 |
2 files changed, 35 insertions, 32 deletions
diff --git a/idlc/c_gen/c_body_gen_base.cc b/idlc/c_gen/c_body_gen_base.cc index 13b4896..d311a97 100644 --- a/idlc/c_gen/c_body_gen_base.cc +++ b/idlc/c_gen/c_body_gen_base.cc @@ -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"); diff --git a/idlc/c_gen/c_body_gen_base_cb.h b/idlc/c_gen/c_body_gen_base_cb.h index db0aa52..a27cc54 100644 --- a/idlc/c_gen/c_body_gen_base_cb.h +++ b/idlc/c_gen/c_body_gen_base_cb.h @@ -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); |