Issue 802310: tkFont may reuse font names (original) (raw)

(sent to me instead of to the bug manager; note that the tkFont naming approach is also used for widgets and callbacks /F)

The class tkFont has a problem name it chooses if no name is given. The choosen method 'name = "font" + str(id (self))' isn't safe because the name may exists longer than the Font object and so another Font object may be created with a different font but the same id() and so the same name. id() says

Return the identity of an object.  This is guaranteed 

to be unique among simultaneously existing objects. ^^^^^^^^^^^^^^^^^^^^^^^

Note that this bug doesn't strike if you hold a reference to the Font object and so the GC can't reclaim the space.

To reproduce run the attached program. It produces something like:

previously: ('Times', 15, 'bold') now: ('Times', 18, 'bold') iterations: 8 mapping: {'font136494612': ('Times', 14, 'bold'), 'font136499772': ('Times', 15, 'bold'), 'font136545468': ('Times', 17, 'bold'), 'font136483156': ('Times', 11, 'bold'), 'font136502700': ('Times', 12, 'bold'), 'font136510460': ('Times', 13, 'bold'), 'font136515228': ('Times', 16, 'bold'), 'font136365348': ('Times', 10, 'bold')} Traceback (most recent call last): File "tkfont_bug.py", line 20, in ? assert 0 AssertionError

Raimar

This still happens, but around 2000 iterations here on newer Python versions (trunk, 3alpha, 2.5.x, 2.4.x). Using Python 1.6 I've got it at 2 iterations (min), but.. is this going to be fixed or given the amount of iterations needed nowadays this is no longer a problem ? If it should be fixed, are there any suggestions on how to proceed ?