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

Proposal: have webview_unbind return the arg #730

Open
silversquirl opened this issue May 9, 2022 · 6 comments · May be fixed by #867
Open

Proposal: have webview_unbind return the arg #730

silversquirl opened this issue May 9, 2022 · 6 comments · May be fixed by #867
Milestone

Comments

@silversquirl
Copy link
Contributor

Currently, if a wrapper library needs to allocate extra memory for a bound function argument (eg. to store the function closure, or to store extra arguments), it has three options for handing unbinding:

  • Keep track of arguments itself, using a dictionary. This duplicates the data tracked internally by webview
  • Leak memory
  • Don't allow unbinding (this appears to be what most of the existing wrappers do)

Instead of these, it would be nice to be able to use webview's internal datastructures to track this instead, by having webview_unbind return the stored argument.

I'm not sure of webview's policy on API compatibility, so perhaps a more backwards-compatible approach would be preferable - in that case, a webview_get_binding or similar could be added that returns the bound arg and/or function for a name.

@justjosias justjosias added this to the v0.11.0 milestone May 9, 2022
@justjosias
Copy link
Member

I'm not sure of webview's policy on API compatibility, so perhaps a more backwards-compatible approach would be preferable - in that case, a webview_get_binding or similar could be added that returns the bound arg and/or function for a name.

We are trying to preserve maximum backwards compatibility, but I think we can consider changing unbind slightly before releasing v0.11.0, since it has been recently introduced.

@justjosias
Copy link
Member

I think there is a vague idea that the webview API functions shouldn't return anything in most cases (besides webview_create). It just seems to be a recent convention. This also applies to #735. I'd rather have the ability to return values, but maybe that should be in a more specific function like webview_get_binding or similar ones that provide a peek within webview itself from the outside.

@dandeto
Copy link
Collaborator

dandeto commented Jul 15, 2022

@justjosias In this case, I think it should return the argument. For example, if a programmer mallocs a variable and passes it to bind, then upon unbind, they can conveniently free it. Otherwise, they would need to remember to call another function, free, and then unbind. It seems more natural to unbind and free, to me.

@justjosias
Copy link
Member

@dandeto I agree. That behavior does seem more intuitive. I'm just thinking about API consistency and backwards compatibility. Do you have any thoughts there?

@dandeto
Copy link
Collaborator

dandeto commented Jul 15, 2022

@justjosias In this case, I think changing from void to void* is backwards-compatible. Before, the user needed to keep track of a mallocd variable some other way, or opt to allow a little memory to leak. Changing the return type won't break that pre-existing code, it just gives the programmer a way to improve it.

@dandeto
Copy link
Collaborator

dandeto commented Jul 15, 2022

Oh, as far as consistency goes, I think the void pattern emerged because most methods aren't really storing anything (except bind in this case) - they are just wrapper functions that cause different behaviors in a webview window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants