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

DRAFT: Callback API #66

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

DRAFT: Callback API #66

wants to merge 2 commits into from

Conversation

Ambrevar
Copy link
Collaborator

Fixes #65.

For some reason Nyxt crashes on my machine when I load my local cl-webkit (unrelated to this change). I'll figure it out next week.

Feel free to test @aartaka

To do:

  • Adapt can-execute-command-checked and message-replied-to.
  • Add a similar macro for the uri-scheme-processed callback and adapt the code.
  • Remove
(defvar callback-counter 0)
(defvar callbacks ())
(defstruct callback
  (id callback-counter :type number)
  web-view
  (function nil :type (or function null))
  (error-function nil :type (or function null)))

@Ambrevar
Copy link
Collaborator Author

On second thought, relying on CFFI to pass any callback, including closures, may have a drawback: it seems that the CFFI callbacks are never freed. Is this a CFFI limitation?

If so, it's problematic for Nyxt because it means that lots and lots of closures would capture data that can never be freed.

The current approach on master has the benefit of calling defcallback only on a some 2-3 hard-coded function, and it's we do clean up after use, thus freeing the closures.

To do:

  • Ask CFFI if their callbacks are ever freed.
  • If yes, then this patch is good.
  • If no, then I suggest we implement an intermediary approach: define 1 hardcoded callback for g-async-result. This hardcoded callback would accept a closure which is stored in callbacks and freed after it's called.

@aartaka
Copy link
Collaborator

aartaka commented May 23, 2022

SBCL callbacks are not freed, as far as I understand by

;;; FIXME: This call assembles a new callback for every closure,
;;; which sucks hugely. ...not that I can think of an obvious
;;; solution. Possibly maybe we could write a generalized closure
;;; callback analogous to closure_tramp, and share the actual wrapper?
;;;
;;; For lambdas that result in simple-funs we get the callback from
;;; the cache on subsequent calls.
(defmacro alien-lambda (result-type typed-lambda-list &body forms)
  (multiple-value-bind (specifier lambda-list)
      (parse-callback-specification result-type typed-lambda-list)
    `(alien-callback ,specifier (lambda ,lambda-list ,@forms))))

@Ambrevar
Copy link
Collaborator Author

Let's go for the intermediary solution then?

@aartaka
Copy link
Collaborator

aartaka commented May 23, 2022

Yes!

@jmercouris
Copy link
Collaborator

Agreed on the intermediary solution.

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.

Leverage with-g-async-ready-callback
3 participants