1.1 --- a/templates/ops.c Sat Oct 29 22:46:20 2016 +0200
1.2 +++ b/templates/ops.c Sat Oct 29 22:56:23 2016 +0200
1.3 @@ -1,5 +1,6 @@
1.4 /* Common operations. */
1.5
1.6 +#include <stdlib.h>
1.7 #include "ops.h"
1.8 #include "progconsts.h"
1.9 #include "progtypes.h"
1.10 @@ -218,3 +219,12 @@
1.11 {
1.12 return obj->pos;
1.13 }
1.14 +
1.15 +/* Copying of structures. */
1.16 +
1.17 +__ref __COPY(__ref obj, int size)
1.18 +{
1.19 + __ref copy = calloc(1, size);
1.20 + memcpy(copy, obj, size);
1.21 + return copy;
1.22 +}
2.1 --- a/templates/ops.h Sat Oct 29 22:46:20 2016 +0200
2.2 +++ b/templates/ops.h Sat Oct 29 22:56:23 2016 +0200
2.3 @@ -89,6 +89,6 @@
2.4
2.5 /* Copying of structures. */
2.6
2.7 -#define __COPY(__SOURCE, __TARGET) (memcpy(__TARGET, __SOURCE, sizeof(__SOURCE)))
2.8 +__ref __COPY(__ref obj, int size);
2.9
2.10 #endif /* __OPS_H__ */
3.1 --- a/translator.py Sat Oct 29 22:46:20 2016 +0200
3.2 +++ b/translator.py Sat Oct 29 22:56:23 2016 +0200
3.3 @@ -967,7 +967,10 @@
3.4 # copy.
3.5
3.6 else:
3.7 - return make_expression("(__COPY(%s, __tmp), %s)" % (encode_path(function_name), ", ".join(defaults)))
3.8 + return make_expression("(__tmp_result = __COPY(&%s, sizeof(%s)), %s)" % (
3.9 + encode_path(function_name),
3.10 + encode_symbol("obj", function_name),
3.11 + ", ".join(defaults)))
3.12
3.13 def process_logical_node(self, n):
3.14