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

Status code extension #76

Open
mochaaP opened this issue Sep 18, 2024 · 5 comments
Open

Status code extension #76

mochaaP opened this issue Sep 18, 2024 · 5 comments

Comments

@mochaaP
Copy link
Contributor

mochaaP commented Sep 18, 2024

I propose two status code extensions:

/* ---------------------------------------------------------------------------------------------- */
/* Status codes (general purpose) - extensions                                                    */
/* ---------------------------------------------------------------------------------------------- */

/**
 * The operation failed with an unexpected error.
 */
#define ZYAN_STATUS_UNEXPECTED ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0xFFFFu)

/**
 * The operation was not implemented.
 */
#define ZYAN_STATUS_NOT_IMPLEMENTED ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x78u)

p.s. there was also a typo in the comments of Zycore/Status.h:

 /**
- * The operation failed with an generic error.
+ * The operation failed with a generic error.
  */
 #define ZYAN_STATUS_FAILED \
     ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x01u)
@athre0z
Copy link
Member

athre0z commented Sep 18, 2024

Where in Zycore would you like to use this?

@flobernd
Copy link
Member

UNEXPECTED seems to be the same as the existing FAILED status. Both are used to signal generic failures.

Contrary to exceptions, unexpected errors should not exist with status codes as per design every return value MUST be checked. Not doing that is a bug.

NOT_IMPLEMENTED would be ok to add for me, but is not as useful as a NotImplementedException IMO. It's probably better to call printf() and halt(), abort(), etc in the corpus of an unimplemented function. There is no meaningful runtime action to handle a NOT_IMPLEMENTED code. For the exception case, this is different as it at acts as a shortcut for 1) crashing the program and 2) signaling that the function never returns. In the end, using NOT_IMPLEMENTED or NotImplementedException is always a bug in the code.

@mochaaP
Copy link
Contributor Author

mochaaP commented Sep 19, 2024

UNEXPECTED is more like a guard (e.g. __builtin_unreachable) but with a defined behavior instead. NOT_IMPLEMENTED is for platform-dependent support. I hope this clears the confusion.

@flobernd
Copy link
Member

Mhh, what would be the benefit of using UNEXPECTED stats code vs the ZYAN_UNREACHABLE macro? IMO unreachable code should really be unreachable. If it is executed, this is clearly a bug and I don't see a valid runtime strategy that a caller should use to handle this status code (besides terminating the application; but then it can as will be done at the root).

Regarding NOT_IMPLEMENTED: I think we have NOT_SUPPORTED for the mentioned use-case.

@mochaaP
Copy link
Contributor Author

mochaaP commented Sep 19, 2024

Regarding NOT_IMPLEMENTED: I think we have NOT_SUPPORTED for the mentioned use-case.

Not in Zycore:

image

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

3 participants