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

MISRA-C - Do not use reserved names #9882

Closed
ceolin opened this issue Sep 10, 2018 · 6 comments
Closed

MISRA-C - Do not use reserved names #9882

ceolin opened this issue Sep 10, 2018 · 6 comments
Assignees
Labels
area: MISRA-C Enhancement Changes/Updates/Additions to existing features priority: medium Medium impact/importance bug

Comments

@ceolin
Copy link
Member

ceolin commented Sep 10, 2018

The C standard reserves all identifiers that begin with an underscore for implementation details. Zephyr is using underscore for identifiers and macros all over the project resulting in many violations. Bellow a suggestion to handle this:

  • If a function is static, it is renamed so that the leading underscore is removed
  • If a function isn't static, a rule based on its name is used to rename the function based on its name:
    • _arch_ -> z_arch_
    • _sys_ -> z_sys_
    • _k_ -> z_
    • _impl_ -> z_sys_impl_
    • _handler_ -> z_sys_handl_
    • Otherwise, z_
    • Shortcuts such as "_current", "_ready_q", "_timeout_q" and "_threads" can be changed to their respective values.

According to the C Standard, 7.1.3 [ISO/IEC 9899:2011]

  • All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.
  • All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces.
  • Each macro name in any of the following subclauses (including the future library directions) is reserved for use as specified if any of its associated headers is included, unless explicitly stated otherwise.
  • All identifiers with external linkage (including future library directions) and errno are always reserved for use as identifiers with external linkage.

Part of #9552

@andrewboie
Copy link
Contributor

andrewboie commented Dec 14, 2018

`_impl_` -> `z_sys_impl_`
`_handler_` -> `z_sys_handl_`

What's the semantics of the sys in the middle?
Can we just do:

`_impl_` -> `z_impl_`
`_handler_` -> `z_handl_`

@nashif nashif added bug The issue is a bug, or the PR is fixing a bug and removed Feature A planned feature with a milestone labels Feb 7, 2019
@nashif nashif assigned pfl and unassigned ceolin Feb 7, 2019
@andyross
Copy link
Contributor

andyross commented Feb 13, 2019

I missed the discussion earlier and was pointed here after the @pfl had already submitted.

Regarding conventions, note that both _impl and _handler are only ever applied to syscalls, which are symbols in the public headers that already have (or should have, prior to this patch) well-formed namespaced names like "k_yield()" or whatever. I'd argue we don't need the "z" at all, and it's perfectly acceptable to do a mapping like k_yield -> impl_k_yield (or "k_impl_yield" or "kimpl_yield", ...)

Would also generally prefer to save bytes by not stuffing underscores into the middle of a prefix, so e.g. "zarch_" and "zsys_" make more sense to me.

@pfl
Copy link
Collaborator

pfl commented Feb 13, 2019

The original renaming list was written down by @ceolin so I'd guess it can be discussed and the scripts updated accordingly.

@pfl
Copy link
Collaborator

pfl commented Feb 15, 2019

Shall we go for

`_impl_` -> `z_impl_`
`_handler_` -> `z_handl_`

here?

@andrewboie
Copy link
Contributor

Shall we go for

`_impl_` -> `z_impl_`
`_handler_` -> `z_handl_`

here?

Works for me

@ceolin
Copy link
Member Author

ceolin commented Feb 15, 2019

+1

it seems better go with

_impl_ -> z_impl
_handler_ -> z_handl_

@nashif nashif removed Feature A planned feature with a milestone labels Feb 21, 2019
@nashif nashif modified the milestones: v1.14.0, future Mar 29, 2019
@nashif nashif removed this from the future milestone May 21, 2019
@MaureenHelm MaureenHelm added the Enhancement Changes/Updates/Additions to existing features label Aug 14, 2019
@MaureenHelm MaureenHelm removed the bug The issue is a bug, or the PR is fixing a bug label Aug 14, 2019
@nashif nashif closed this as completed May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: MISRA-C Enhancement Changes/Updates/Additions to existing features priority: medium Medium impact/importance bug
Projects
None yet
Development

No branches or pull requests

6 participants