This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch feature/plc4c-memory-cleanup
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/feature/plc4c-memory-cleanup
by this push:
new b15186c Moved the memory allocation to the branch of reading simple
typed optional fields
b15186c is described below
commit b15186c95114bae33dc02f3e2919ff6200a23360
Author: cdutz <[email protected]>
AuthorDate: Mon May 24 13:15:36 2021 +0200
Moved the memory allocation to the branch of reading simple typed optional
fields
---
.../resources/templates/c/pojo-template.c.ftlh | 8 ++++----
code-generation/pom.xml | 5 ++---
.../plc4c/generated-sources/s7/src/cotp_packet.c | 4 ----
.../plc4c/generated-sources/s7/src/s7_message.c | 8 --------
.../s7/src/s7_parameter_user_data_item.c | 24 +++++++++++-----------
5 files changed, 18 insertions(+), 31 deletions(-)
diff --git
a/code-generation/language-c/src/main/resources/templates/c/pojo-template.c.ftlh
b/code-generation/language-c/src/main/resources/templates/c/pojo-template.c.ftlh
index 35d7438..a635ac0 100644
---
a/code-generation/language-c/src/main/resources/templates/c/pojo-template.c.ftlh
+++
b/code-generation/language-c/src/main/resources/templates/c/pojo-template.c.ftlh
@@ -331,11 +331,11 @@ plc4c_return_code
${helper.getCTypeName(type.name)}_parse(plc4c_spi_read_buffer*
</#if>
<#if indentContent> </#if> ${helper.getLanguageTypeNameForField(field)}*
${optionalField.name} = NULL;
<#if indentContent> </#if> if(${helper.toParseExpression(baseType, field,
optionalField.conditionExpression, baseType.parserArguments)}) {
-<#if indentContent> </#if> //${optionalField.name} =
malloc(sizeof(${helper.getLanguageTypeNameForField(field)}));
-<#if indentContent> </#if> //if(${optionalField.name} == NULL) {
-<#if indentContent> </#if> // return NO_MEMORY;
-<#if indentContent> </#if> //}
<#if helper.isSimpleTypeReference(optionalField.type)>
+<#if indentContent> </#if> ${optionalField.name} =
malloc(sizeof(${helper.getLanguageTypeNameForField(field)}));
+<#if indentContent> </#if> if(${optionalField.name} == NULL) {
+<#if indentContent> </#if> return NO_MEMORY;
+<#if indentContent> </#if> }
<#if indentContent> </#if> *${optionalField.name} =
${helper.getNullValueForTypeReference(optionalField.type)};
<#if indentContent> </#if> _res =
${helper.getReadBufferReadMethodCall(optionalField.type, optionalField.name,
field)};
<#else>
diff --git a/code-generation/pom.xml b/code-generation/pom.xml
index 44d98f8..db4e847 100644
--- a/code-generation/pom.xml
+++ b/code-generation/pom.xml
@@ -30,8 +30,8 @@
<artifactId>plc4x-code-generation</artifactId>
<packaging>pom</packaging>
- <name>PLC4X: Build Utils</name>
- <description>Some build related utilities.</description>
+ <name>PLC4X: Code-Generation</name>
+ <description>Home of the PLC4X code-generation framework.</description>
<modules>
<module>language-base-freemarker</module>
@@ -39,7 +39,6 @@
<module>protocol-test</module>
<module>language-java</module>
-
</modules>
<profiles>
diff --git a/sandbox/plc4c/generated-sources/s7/src/cotp_packet.c
b/sandbox/plc4c/generated-sources/s7/src/cotp_packet.c
index b1991f5..fb1e1b0 100644
--- a/sandbox/plc4c/generated-sources/s7/src/cotp_packet.c
+++ b/sandbox/plc4c/generated-sources/s7/src/cotp_packet.c
@@ -273,10 +273,6 @@ plc4c_return_code
plc4c_s7_read_write_cotp_packet_parse(plc4c_spi_read_buffer* r
curPos = plc4c_spi_read_get_pos(readBuffer) - startPos;
plc4c_s7_read_write_s7_message* payload = NULL;
if((curPos) < (cotpLen)) {
- //payload = malloc(sizeof(plc4c_s7_read_write_s7_message));
- //if(payload == NULL) {
- // return NO_MEMORY;
- //}
_res = plc4c_s7_read_write_s7_message_parse(readBuffer, &payload);
if(_res != OK) {
return _res;
diff --git a/sandbox/plc4c/generated-sources/s7/src/s7_message.c
b/sandbox/plc4c/generated-sources/s7/src/s7_message.c
index 63bee7a..da12c76 100644
--- a/sandbox/plc4c/generated-sources/s7/src/s7_message.c
+++ b/sandbox/plc4c/generated-sources/s7/src/s7_message.c
@@ -177,10 +177,6 @@ plc4c_return_code
plc4c_s7_read_write_s7_message_parse(plc4c_spi_read_buffer* re
// Optional Field (parameter) (Can be skipped, if a given expression
evaluates to false)
plc4c_s7_read_write_s7_parameter* parameter = NULL;
if((parameterLength) > (0)) {
- //parameter = malloc(sizeof(plc4c_s7_read_write_s7_parameter));
- //if(parameter == NULL) {
- // return NO_MEMORY;
- //}
_res = plc4c_s7_read_write_s7_parameter_parse(readBuffer, messageType,
¶meter);
if(_res != OK) {
return _res;
@@ -193,10 +189,6 @@ plc4c_return_code
plc4c_s7_read_write_s7_message_parse(plc4c_spi_read_buffer* re
// Optional Field (payload) (Can be skipped, if a given expression evaluates
to false)
plc4c_s7_read_write_s7_payload* payload = NULL;
if((payloadLength) > (0)) {
- //payload = malloc(sizeof(plc4c_s7_read_write_s7_payload));
- //if(payload == NULL) {
- // return NO_MEMORY;
- //}
_res = plc4c_s7_read_write_s7_payload_parse(readBuffer, messageType,
parameter, &payload);
if(_res != OK) {
return _res;
diff --git
a/sandbox/plc4c/generated-sources/s7/src/s7_parameter_user_data_item.c
b/sandbox/plc4c/generated-sources/s7/src/s7_parameter_user_data_item.c
index e74bccc..de5bc98 100644
--- a/sandbox/plc4c/generated-sources/s7/src/s7_parameter_user_data_item.c
+++ b/sandbox/plc4c/generated-sources/s7/src/s7_parameter_user_data_item.c
@@ -131,10 +131,10 @@ plc4c_return_code
plc4c_s7_read_write_s7_parameter_user_data_item_parse(plc4c_sp
// Optional Field (dataUnitReferenceNumber) (Can be skipped, if a given
expression evaluates to false)
uint8_t* dataUnitReferenceNumber = NULL;
if((cpuFunctionType) == (8)) {
- //dataUnitReferenceNumber = malloc(sizeof(uint8_t));
- //if(dataUnitReferenceNumber == NULL) {
- // return NO_MEMORY;
- //}
+ dataUnitReferenceNumber = malloc(sizeof(uint8_t));
+ if(dataUnitReferenceNumber == NULL) {
+ return NO_MEMORY;
+ }
*dataUnitReferenceNumber = 0;
_res = plc4c_spi_read_unsigned_byte(readBuffer, 8, (uint8_t*)
dataUnitReferenceNumber);
if(_res != OK) {
@@ -150,10 +150,10 @@ plc4c_return_code
plc4c_s7_read_write_s7_parameter_user_data_item_parse(plc4c_sp
// Optional Field (lastDataUnit) (Can be skipped, if a given expression
evaluates to false)
uint8_t* lastDataUnit = NULL;
if((cpuFunctionType) == (8)) {
- //lastDataUnit = malloc(sizeof(uint8_t));
- //if(lastDataUnit == NULL) {
- // return NO_MEMORY;
- //}
+ lastDataUnit = malloc(sizeof(uint8_t));
+ if(lastDataUnit == NULL) {
+ return NO_MEMORY;
+ }
*lastDataUnit = 0;
_res = plc4c_spi_read_unsigned_byte(readBuffer, 8, (uint8_t*)
lastDataUnit);
if(_res != OK) {
@@ -169,10 +169,10 @@ plc4c_return_code
plc4c_s7_read_write_s7_parameter_user_data_item_parse(plc4c_sp
// Optional Field (errorCode) (Can be skipped, if a given expression
evaluates to false)
uint16_t* errorCode = NULL;
if((cpuFunctionType) == (8)) {
- //errorCode = malloc(sizeof(uint16_t));
- //if(errorCode == NULL) {
- // return NO_MEMORY;
- //}
+ errorCode = malloc(sizeof(uint16_t));
+ if(errorCode == NULL) {
+ return NO_MEMORY;
+ }
*errorCode = 0;
_res = plc4c_spi_read_unsigned_short(readBuffer, 16, (uint16_t*)
errorCode);
if(_res != OK) {