Commit 147d3788 authored by Sergio Costas's avatar Sergio Costas

Now assigning a borrowed variable to another borrowed variable doesn't...

Now assigning a borrowed variable to another borrowed variable doesn't invalidate the origin variable
parent 7be9f5e7
......@@ -126,6 +126,10 @@ class crust_helpers(crust_open):
variable = self._find_variable(thread_status, var_name, line_number)
if variable["value"] == self.VALUE_GLOBAL:
return
if variable["borrowed"]:
return
if variable["function"]:
self._add_error(thread_status, self.MSG_CRITICAL, "Trying to free a function name '{:s}' at line {:d}", str(var_name), line_number)
return
......
......@@ -1007,6 +1007,9 @@ class Test(unittest.TestCase):
def test244ReturnVoidPointer2(self):
self._generic_test("unitest/test244.c", [ (crust.crust.MSG_ERROR, "Function '{:s}' expects a return value, but the code exited without it", 'function_name') ])
def test245AssignBorrowedToBorrowed(self):
self._all_fine_test("unitest/test245.c")
if __name__ == '__main__':
try:
os.remove("error_list.txt")
......
typedef __crust__ unsigned char *crust_t;
#define NULL ((void *)0)
crust_t __crust_borrow__ function1();
void function2(crust_t __crust_borrow__);
void main() {
__crust_borrow__ crust_t var1;
__crust_borrow__ crust_t var2;
var1 = function1(); // Valid
var2 = var1; // since both are borrowed, this assignment doesn't invalidates var1
function2(var1);
function2(var1);
function2(var2);
function2(var2);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment