1
0
mirror of https://github.com/meekrosoft/fff synced 2026-01-23 00:15:59 +01:00

Add "FFF_FUNCTION_ATTRIBUTES" definition that can be used to declare attributes for functions. More specifically, allow __weak__ attribute.

This commit is contained in:
susundberg
2018-03-21 13:14:05 +02:00
committed by Pauli Salmenrinne
parent 2c5ecf5495
commit 647737304d
3 changed files with 184 additions and 162 deletions

View File

@@ -603,6 +603,18 @@ DEFINE_FAKE_VALUE_FUNC_VARARG(int, value_function_vargs, const char *, int, ...)
DEFINE_FAKE_VOID_FUNC_VARARG(void_function_vargs, const char *, int, ...);
```
## How simplify test linking
You can define
```
#define FFF_FUNCTION_ATTRIBUTES __attribute__((weak))
#include "fff.h"
```
This will cause all of the fake functions to be declared with weak attribute. This causes that during link time a weak object (fake function) is replaced with non-weak (real function).
You can use this so that you link all the fake objects into single fake-archive (compiled once) and then when a single real_implementation.c you can link with the fake-archive. During the link time the all other functions will be the fake ones, except the ones defined in real_implementation.c (that are non-weak).
## Find out more...

View File

@@ -26,6 +26,13 @@ def output_constants
putd "#define FFF_CALL_HISTORY_LEN (#{$MAX_CALL_HISTORY}u)"
}
putd "#endif"
# If user has defined functions to have some attributes, use those. If not, define as empty so it wont affect others.
putd "#ifndef FFF_FUNCTION_ATTRIBUTES"
indent {
putd "#define FFF_FUNCTION_ATTRIBUTES"
}
putd "#endif"
end
@@ -384,8 +391,8 @@ def function_signature(arg_count, has_varargs, has_calling_conventions, is_value
return_type = is_value_function ? "RETURN_TYPE" : "void"
varargs = has_varargs ? ", ..." : ""
calling_conventions = has_calling_conventions ?
"#{return_type} CALLING_CONVENTION FUNCNAME(#{arg_val_list(arg_count)}#{varargs})" :
"#{return_type} FUNCNAME(#{arg_val_list(arg_count)}#{varargs})"
"#{return_type} FFF_FUNCTION_ATTRIBUTES CALLING_CONVENTION FUNCNAME(#{arg_val_list(arg_count)}#{varargs})" :
"#{return_type} FFF_FUNCTION_ATTRIBUTES FUNCNAME(#{arg_val_list(arg_count)}#{varargs})"
end
def output_function_body(arg_count, has_varargs, is_value_function)

323
fff.h

File diff suppressed because it is too large Load Diff