Skip to content

Commit dc09972

Browse files
(feature+WIP) Correct copying of struct data (WIP).
1 parent 354434b commit dc09972

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

languages/c/templates/datastructures/constructors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ module.exports = {
99
constructorAssign: (node) => {
1010
const fields = node.inputs.map((p, idx) => t('Datastructures.fieldAssign')({
1111
name: variable(p.port),
12+
fieldType: p.type,
1213
index: idx,
1314
type: node.type,
1415
output: '____TMP____'
1516
}))
1617
return `
17-
/* ${JSON.stringify(node, null, 2)} */
1818
${sanitize(node.type.name)}* ____TMP____ = new ${sanitize(node.type.name)}();
1919
${variable(node.output.port)} = ${t('defType')(node.output.type, '____TMP____')};
2020
${fields.join('\n')}`
@@ -29,6 +29,6 @@ ${fields.join('\n')}`
2929

3030
destructorAssign: (assign) => `${variable(assign.output.port)} = ((${t('dataType')(assign.type.name)}*)${variable(assign.input.port)}->data)->get()->arg${assign.parameter};`,
3131

32-
fieldAssign: (assign) => ` ${assign.output}->argp_${assign.index} = ${assign.name};`
32+
fieldAssign: (assign) => ` ${assign.output}->argp_${assign.index} = __copy_${t('Types.typeName')(assign.fieldType)}(${assign.name});`
3333
}
3434
}

languages/c/templates/datastructures/typeclass.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ struct ${sanitize(typeName)} {
3030
std::string subType;
3131
void* data;
3232
${orTypes.map((type, idx) => '\n ' + sanitize(typeName) + '(' + sanitize(type.name) + '* ptr) {\n' +
33-
' this->data = (void*)(new ' + t('dataType')(type.name) + '(ptr));\n' +
33+
' this->data = (void*)(new ' + t('Types.typeName')(type.name) + '(ptr));\n' +
3434
' this->subType = "' + type.name + '";\n' +
3535
' }').join('\n')}
3636
3737
~${typeName}() {
3838
if (false) {}
39-
${orTypes.map((type, idx) => 'else if (this->subType == "' + type.name + '") { delete ((' + t('dataType')(type.name) + '*)(this->data))->get(); }').join('\n')}
39+
${orTypes.map((type, idx) => 'else if (this->subType == "' + type.name + '") { delete ((' + t('Types.typeName')(type.name) + '*)(this->data)); }').join('\n')}
4040
}
4141
};
4242
@@ -59,7 +59,7 @@ std::string ${t('Types.toStringName')(struct.metaInformation.type.type.type)} (c
5959
return `
6060
std::string ${t('Types.toStringName')(struct.metaInformation.type.type.type)} (const ${sanitize(struct.metaInformation.type.type.type)}& obj) {
6161
if (false) {}
62-
${orTypes.map((type, idx) => 'else if (obj.subType == "' + type.name + '") { return __' + sanitize(type.name) + '_to_std__string(*((' + t('dataType')(type.name) + '*)(obj.data))->get()); }').join('\n')}
62+
${orTypes.map((type, idx) => 'else if (obj.subType == "' + type.name + '") { return __' + sanitize(type.name) + '_to_std__string(*((' + t('Types.typeName')(type.name) + '*)(obj.data))); }').join('\n')}
6363
}
6464
`
6565
} else {

0 commit comments

Comments
 (0)