# HG changeset patch # User Paul Boddie # Date 1477774583 -7200 # Node ID 8c1bebfcd574c0c092d5f09c16dbb3cd8ce19157 # Parent cb7d59250434575f659157af2c811721c1080de8 Fixed the __COPY implementation and usage to be more realistic. diff -r cb7d59250434 -r 8c1bebfcd574 templates/ops.c --- a/templates/ops.c Sat Oct 29 22:46:20 2016 +0200 +++ b/templates/ops.c Sat Oct 29 22:56:23 2016 +0200 @@ -1,5 +1,6 @@ /* Common operations. */ +#include #include "ops.h" #include "progconsts.h" #include "progtypes.h" @@ -218,3 +219,12 @@ { return obj->pos; } + +/* Copying of structures. */ + +__ref __COPY(__ref obj, int size) +{ + __ref copy = calloc(1, size); + memcpy(copy, obj, size); + return copy; +} diff -r cb7d59250434 -r 8c1bebfcd574 templates/ops.h --- a/templates/ops.h Sat Oct 29 22:46:20 2016 +0200 +++ b/templates/ops.h Sat Oct 29 22:56:23 2016 +0200 @@ -89,6 +89,6 @@ /* Copying of structures. */ -#define __COPY(__SOURCE, __TARGET) (memcpy(__TARGET, __SOURCE, sizeof(__SOURCE))) +__ref __COPY(__ref obj, int size); #endif /* __OPS_H__ */ diff -r cb7d59250434 -r 8c1bebfcd574 translator.py --- a/translator.py Sat Oct 29 22:46:20 2016 +0200 +++ b/translator.py Sat Oct 29 22:56:23 2016 +0200 @@ -967,7 +967,10 @@ # copy. else: - return make_expression("(__COPY(%s, __tmp), %s)" % (encode_path(function_name), ", ".join(defaults))) + return make_expression("(__tmp_result = __COPY(&%s, sizeof(%s)), %s)" % ( + encode_path(function_name), + encode_symbol("obj", function_name), + ", ".join(defaults))) def process_logical_node(self, n):