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

feature: debug/state-check lib #66

Open
nopeslide opened this issue Apr 8, 2020 · 0 comments
Open

feature: debug/state-check lib #66

nopeslide opened this issue Apr 8, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@nopeslide
Copy link
Contributor

nopeslide commented Apr 8, 2020

Related Issues & PRs

none

Description

Objects that need initialization are not checked before use weither they got initialized or not.

Solution

Add a macro lib providing:

  • optional compilation of provided features
  • annotation-like constructs
  • checks if object is usable
  • function macros setting the initialization status
  • function macros resetting the initialization status

Alternative solutions

  • Non-macro lib
    • overhead if disabled
    • no annotation style
  • Solve set/reset status via linker
    • wrap init/reset functions via linker
    • will always apply, can't be forgotten
    • no overhead if disabled (in combination with annotation macro)
    • solution is not directly visible in code

Context

#define CANARY 0xc0ffee
#define NEEDS_INIT uint _initialized;
#define SET_INIT(p) { (p)->_initialized = CANARY;  } //needs further checks
#define RESET_INIT(p) { (p)_initialized = 0x0; } //needs further checks
#define CHECK_INIT(p) { if ( (p)->initialized != CANARY ) { /*throw error*/ }  }

struct object {
  NEEDS_INIT;
  int foo;
};

void using_object( struct object *o) {
  CHECK_INIT(o);
  ...
}

void object_init( struct object *o ) {
  ...
  SET_INIT(o);
}

void object_reset( struct object *o) {
  RESET_INIT(o);
  ...
}
@nopeslide nopeslide added the enhancement New feature or request label Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant