-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Improve Type safety #14
base: master
Are you sure you want to change the base?
Conversation
This enforces type-safety.
This improves upon type-safety.
|
||
/* The following calls create event handler objects. | ||
* | ||
* An object will have a reference count of 1 upon creation and must be freed | ||
* using aml_unref(). | ||
*/ | ||
struct aml_handler* aml_handler_new(int fd, aml_callback_fn, void* userdata, | ||
aml_free_fn); | ||
struct aml_handler* aml_handler_new(int fd, void (*cb)(struct aml_handler*), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, this is a breaking API change, because a callback taking a void *
is (sadly) not compatible with one taking a struct pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I've never declared the API to be stable for this, so that's fine. Besides, this library doesn't have many users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, just wanted to double-check that it's known.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might declare it stable soon after these changes though.
I'm also considering whether I should remove the free_fn. It is a bit of a foot-gun, but it's not particularly bad because if you know not to use it unless you really know what you're doing, you can't shoot yourself in the foot with it by mistake. Whereas the type-safety stuff was possible to mess up by mistake even if you knew about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be in favor of dropping free_fn
because I don't use it and don't think it's particularly useful, but yeah, it's not a big deal since I can just ignore it.
No description provided.