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

at_c: add _init and _free convention 8 to CONTRIBUTING.md #390

Open
JeremyTubongbanua opened this issue Aug 29, 2024 · 0 comments
Open

at_c: add _init and _free convention 8 to CONTRIBUTING.md #390

JeremyTubongbanua opened this issue Aug 29, 2024 · 0 comments
Assignees

Comments

@JeremyTubongbanua
Copy link
Member

Using this as a note to self to do this

We follow MbedTLS' OOP approach in C.

Our modified convention of this approach will state that:

  1. for every _init function, a _free function should be called at the end of the struct's lifetime for future proofing and clean memory management.
  2. _init and _free functions should of type void (this raises the question of "what happens if an error happens in the function" and this is answered in the next rule)
  3. _init and _free function bodies should be immune to run-time errors and any error that is of no fault of the caller. Preconditions should be defined in the function docs and if the caller of the function does not follow those preconditions, then it is of no fault of the function itself, and it is not the function's responsibility to return an error code, hence why we allow ourselves to set the function type to void. This also means that malloc cannot be used in _init because malloc is prone to memory full run-time error, for example.
@JeremyTubongbanua JeremyTubongbanua self-assigned this Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant