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

Leverage with-g-async-ready-callback #65

Open
Ambrevar opened this issue May 17, 2022 · 2 comments · May be fixed by #66
Open

Leverage with-g-async-ready-callback #65

Ambrevar opened this issue May 17, 2022 · 2 comments · May be fixed by #66

Comments

@Ambrevar
Copy link
Collaborator

We've got a bunch of poorly written, hard-coded callbacks in our codebase.
Today I discovered that cl-webkit has a generic way to handle callbacks. It's in the (unused!) callback.lisp file.

I was thus able to do this (atlas-engineer/nyxt@4e2ecdf#diff-9df864619800a42d41380418e1c5af907bdcc9c453e5ae1ce003951a86c0aed6R1824):

(let ((result-channel (make-channel 1)))
        (run-thread "WebKitGTK cookie-policy"
          (within-gtk-thread
            (let* ((context (webkit:webkit-web-view-web-context (gtk-object buffer)))
                   (cookie-manager (webkit:webkit-web-context-get-cookie-manager context)))
              ;; TODO: Update upstream to export and fix `with-g-async-ready-callback'.
              (webkit::with-g-async-ready-callback (callback
                                                     (declare (ignorable webkit::user-data webkit::source-object))
                                                     (calispel:! result-channel
                                                                 (webkit:webkit-cookie-manager-get-accept-policy-finish
                                                                  cookie-manager
                                                                  webkit::result)))
                (webkit:webkit-cookie-manager-get-accept-policy
                 cookie-manager
                 (cffi:null-pointer)
                 callback
                 (cffi:null-pointer))))))
        (calispel:? result-channel))

Benefits:

  • No more need for a top-level callback definition.
  • No more need to push / pop into a global *callbacks* list.

(By the way, did you know that this strategy is used by CFFI under the hood to implement defcallback? So here with cl-webkit we reinvent the wheel, but poorly.)

To do:

  • Export with-g-async-ready-callback
  • Fix define-g-async-ready-callback to declare all arguments as ignorable, otherwise we quickly get warnings.
  • Find a way to pass the result symbol as parameter to with-g-async-ready-callback, otherwise the only way to get the result from the callback is to refer to the hard-coded webkit::result name, which ain't pretty.

Thoughts?

@aartaka

@aartaka
Copy link
Collaborator

aartaka commented May 17, 2022

Wow, that looks so cool! And it saves a lot of threading hacks everywhere, I suppose!

@Ambrevar
Copy link
Collaborator Author

I'll send a pull request later.

@Ambrevar Ambrevar linked a pull request May 20, 2022 that will close this issue
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 a pull request may close this issue.

2 participants