#10963: More functorial constructions
-------------------------------------+-------------------------------------
Reporter: nthiery | Owner: stumpc5
Type: enhancement | Status: needs_work
Priority: major | Milestone: sage-5.13
Component: categories | Resolution:
Keywords: days54 | Merged in:
Authors: Nicolas M. Thiéry | Reviewers: Simon King, Frédéric
Report Upstream: N/A | Chapoton
Branch: | Work issues:
public/ticket/10963 | Commit:
Dependencies: #11224, #8327, | 362fd5e462adea5860d52fd99db94a2623044d89
#10193, #12895, #14516, #14722, | Stopgaps:
#13589, #14471, #15069, #15094, |
#11688, #13394 |
-------------------------------------+-------------------------------------
Comment (by nbruin):
Replying to [comment:169 vbraun]:
> How about we just create our own trashcan for weakref callbacks?
> {{{
> cdef bool trashcan_closed = True
> cdef object trashcan = []
>
> def remove(wr):
> if trashcan_closed:
> trashcan_closed = False
> trashcan = [] # empty trash, possible call to remove()
> trashcan_closed = False
> trashcan.append(wr.subobject)
> trashcan_close = True
> }}}
> Limits Python and C recursion depth to 2 frames...
It's easier than that. You can take the same approach as in #15367:
{{{
def remove(wr):
key_tmp = [key under which wr occurs in dict]
remove (key:wr) entry from dict
del key_tmp
}}}
Instead of deleting a bare key, we're deleting a list containing the key.
Since python lists participate in the trashcan, we get to borrow the
trashcan count from there.
There's a slight cost to this approach: we're allocating a list only to
delete it, but that is a very small cost indeed (and a cost we'd incur
with our home-rolled trashcan too), and we still get to benefit from all
the other performance tunings that have gone into python's trashcan.
--
Ticket URL: <http://trac.sagemath.org/ticket/10963#comment:171>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.