Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log_backend.h missing include for UTIL_CAT in LOG_BACKEND_DEFINE macro #21045

Closed
JeffLangballe opened this issue Nov 27, 2019 · 1 comment · Fixed by #21150
Closed

log_backend.h missing include for UTIL_CAT in LOG_BACKEND_DEFINE macro #21045

JeffLangballe opened this issue Nov 27, 2019 · 1 comment · Fixed by #21150
Assignees
Labels
bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@JeffLangballe
Copy link

Describe the bug
When trying to define a logging backend with LOG_BACKEND_DEFINE, I get errors relating to the macro expansion of LOG_BACKEND_DEFINE even though all of the arguments for the macro are correct.

To Reproduce
Create and compile a source file to create a logging backend as such

#include <logging/log_backend.h>// Include only this

... function declarations ...

static struct log_backend_api my_api = {
	.put = put,
	.put_sync_string = put_sync_string,
	.put_sync_hexdump = put_sync_hexdump,
	.dropped = dropped,
	.panic = panic,
	.init = init,
};

LOG_BACKEND_DEFINE(my_log, my_api, true);

Yields many errors and warnings upon compilation. It looks like the UTIL_CAT macro is not defined so the compiler thinks we're doing a function declaration.

Expected behavior
The LOG_BACKEND_DEFINE macro should compile and behave if all of its arguments are correct. log_backend.h should include the necessary headers (in this case, sys/util.h) for its implementation.

Impact
To fix I can include the missing sys/util.h header in log_backend.h so that UTIL_CAT is defined. Alternatively, I can include that same header in my logger backend source or include another log_*.h file which includes it like log_core.h.

Screenshots or console output

/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:77:16: warning: parameter names (without types) in function declaration
  static struct log_backend_control_block UTIL_CAT(backend_cb_, _name) = \
                ^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
 LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
 ^~~~~~~~~~~~~~~~~~
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:77:16: error: function 'UTIL_CAT' is initialized like a variable
  static struct log_backend_control_block UTIL_CAT(backend_cb_, _name) = \
                ^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
 LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
 ^~~~~~~~~~~~~~~~~~
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:79:3: error: field name not in record or union initializer
   .active = false,            \
   ^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
 LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
 ^~~~~~~~~~~~~~~~~~
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:79:3: note: (near initialization for 'UTIL_CAT')
   .active = false,            \
   ^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
 LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
 ^~~~~~~~~~~~~~~~~~
In file included from /mnt/c/Dev/ncs/zephyr/include/sys/atomic.h:12:0,
                 from /mnt/c/Dev/ncs/zephyr/include/logging/log_msg.h:9,
                 from /mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:9,
                 from /mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:1:
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:79:13: error: invalid initializer
   .active = false,            \
             ^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
 LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
 ^~~~~~~~~~~~~~~~~~
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:79:13: note: (near initialization for 'UTIL_CAT')
   .active = false,            \
             ^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
 LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
 ^~~~~~~~~~~~~~~~~~
In file included from /mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:1:0:
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:80:3: error: field name not in record or union initializer
   .id = 0,             \
   ^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
 LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
 ^~~~~~~~~~~~~~~~~~
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:80:3: note: (near initialization for 'UTIL_CAT')
   .id = 0,             \
   ^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
 LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
 ^~~~~~~~~~~~~~~~~~
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:80:9: warning: excess elements in scalar initializer
   .id = 0,             \
         ^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
 LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
 ^~~~~~~~~~~~~~~~~~
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:80:9: note: (near initialization for 'UTIL_CAT')
   .id = 0,             \
         ^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
 LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
 ^~~~~~~~~~~~~~~~~~
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:85:19: error: 'backend_cb_' undeclared here (not in a function); did you mean 'log_backend_get'?
   .cb = &UTIL_CAT(backend_cb_, _name),          \
                   ^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
 LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
 ^~~~~~~~~~~~~~~~~~
```


@JeffLangballe JeffLangballe added the bug The issue is a bug, or the PR is fixing a bug label Nov 27, 2019
@dleach02 dleach02 added the priority: low Low impact/importance bug label Dec 3, 2019
@carlescufi
Copy link
Member

@JeffLangballe does it work if you add:
#include <sys/util.h>
as the first line?

carlescufi added a commit to carlescufi/zephyr that referenced this issue Dec 3, 2019
The UTIL_CAT macro which is used in log_backend.h is implemented in
sys/util.h.

Fixes zephyrproject-rtos#21045.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
carlescufi added a commit that referenced this issue Dec 4, 2019
The UTIL_CAT macro which is used in log_backend.h is implemented in
sys/util.h.

Fixes #21045.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants