Skip to content

Commit

Permalink
Stop adding frames to backtrace once a buttercup wrap func is found
Browse files Browse the repository at this point in the history
Buttercup wrapped functions are the only thing containing the
buttercup--mark-stackframe marker anyway.

The assert in `buttercup--enclosed-expr' had to be removed, since that
function is also used to verify if the argument is a wrapper function.
Once it is used to test objects that are not wrapped functions, the
assert became a liability.
  • Loading branch information
snogge committed Jul 18, 2024
1 parent 4b1682e commit 145c69f
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ forms:
and the return value will be EXPR, unevaluated. The quoted EXPR
is useful if EXPR is a macro call, in which case the `quote'
ensures access to the un-expanded form."
(cl-assert (functionp fun) t "Expected FUN to be a function")
(if (buttercup--thunk-p fun)
(buttercup--thunk--expr fun)
(pcase fun
Expand Down Expand Up @@ -2122,30 +2121,12 @@ ARGS according to `debugger'."
(backtrace-frame n #'buttercup--debugger))
(frame-list nil))
((not frame) frame-list)
(push frame frame-list)
;; keep frames until one of the known functions are found, after
;; this is just the buttercup framework and not interesting for
;; users (incorrect for testing buttercup). Some frames before the
;; function also have to be discarded
(cl-labels ((tree-find (key tree)
(cl-block tree-find
(while (consp tree)
(let ((elem (pop tree)))
(when (or (and (consp elem)
(tree-find key elem))
(and (buttercup--thunk-p elem)
(tree-find key (aref elem 1)))
(eql key elem))
(cl-return-from tree-find t))))
(cl-return-from tree-find
(and tree (eql tree key))))))
;; TODO: Only check the cadr of frame, that is where the function is.
;; The buttercup--mark-stackframe should only be in wrapped expressions,
;; optimize by checking if it is a wrapped expression?
;; Will we even need the marker if we can check that?
(when (tree-find 'buttercup--mark-stackframe frame)
(pop frame-list)
(cl-return frame-list)))))
;; keep frames until it is a buttercup wrapped function, after
;; this is just the buttercup framework and not interesting for
;; users - except for testing buttercup
(when (buttercup--wrapper-fun-p (cadr frame))
(cl-return frame-list))
(push frame frame-list)))

(defun buttercup--format-stack-frame (frame &optional style)
"Format stack FRAME according to STYLE.
Expand Down

0 comments on commit 145c69f

Please sign in to comment.