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

Improve Type safety #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Improve Type safety #14

wants to merge 2 commits into from

Conversation

any1
Copy link
Owner

@any1 any1 commented Sep 27, 2024

No description provided.

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*),

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.

Copy link
Owner Author

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.

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.

Copy link
Owner Author

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.

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.

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

Successfully merging this pull request may close these issues.

2 participants