Commit 042a72ba authored by Sergio Costas's avatar Sergio Costas

Now typedef'd enums also work

parent d525bf36
......@@ -7,6 +7,7 @@
*/
#ifndef ENABLE_CRUST_TAGS
#define ENABLE_CRUST_TAGS
#define __crust_t__
#define __crust_borrow__
#define __crust_recycle__
......
......@@ -203,7 +203,7 @@ class crust(object):
datacode += line+"\n"
datacode = datacode.encode("latin-1")
else:
params = ["cpp", filename, "-DENABLE_CRUST_TAGS"]
params = ["cpp", filename, "-DENABLE_CRUST_TAGS -DENABLE_CRUST"]
for p in includes:
params.append("-I{:s}".format(p))
for p in defines:
......@@ -1199,9 +1199,9 @@ class crust(object):
if node.type == "EMPTY_DECLARATOR":
continue
if node.type == "VARIABLE_DEFINITION":
if (node.enum_data is not None):
self._process_enum(node, thread_status)
if not node.t_typedef:
if (node.enum_data is not None):
self._process_enum(node, thread_status)
pointers = node.pointer
if node.arrays is not None:
for element in node.arrays:
......@@ -1460,10 +1460,10 @@ class crust(object):
return self._check_return_block(tree[1:], thread_status)
if node.type == "VARIABLE_DEFINITION":
if node.t_typedef:
return self._check_return_block(tree[1:], thread_status)
if (node.enum_data is not None):
self._process_enum(node, thread_status)
if node.t_typedef:
return self._check_return_block(tree[1:], thread_status)
varname = node.name
var_defined = self._get_variable_properties(thread_status, node, node.pointer, False)
if node.arrays is None:
......
......@@ -901,6 +901,12 @@ class Test(unittest.TestCase):
def test209TestSetNullNonGlobal(self):
lib = self._generic_test("unitest/test209.c", [ (crust.crust.MSG_CRITICAL, "Function definition for '{:s}' at line {:d}, file '{:s}' differs from definition at line {:d}, file '{:s}'", "function", 9, "unitest/test209.c", 6, "unitest/test209.c") ])
def test210UseFreedTypedefNotPointer(self):
self._generic_test("unitest/test210.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "function", 6, 5) ])
def test211CheckTypedefEnums(self):
self._all_fine_test("unitest/test211.c")
if __name__ == '__main__':
try:
os.remove("error_list.txt")
......
typedef __crust_t__ unsigned char crust_t; // define a NON pointer typedef, but the arguments or variables are of pointer type
void function(crust_t *param3) { // here: a pointer
int retval = function(param3);
int retval2 = function(param3); // ERROR: param3 was freed at line 5, when passed to "function"
}
typedef enum {
STATUS1, STATUS2
} status_t = STATUS1;
void main(int b) {
typedef enum {
MORE1, MORE2
} more_t = MORE1;
status_t status = STATUS2;
more_t more = MORE2;
}
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