[lxml-dev] segfault when using etree.CustomElementClassLookup
Stefan Behnel
stefan_ml at behnel.de
Wed Jun 4 14:38:30 CEST 2008
Hi Martijn,
Martijn Faassen wrote:
> I just ran into a segfault with lxml (2.0.6). The problem is as follows:
>
> from lxml import etree
>
> class Lookup(etree.CustomElementClassLookup):
> def __init__(self):
> pass
Yep, you didn't call the __init__() method of the super class here, so the
internal lookup function call isn't set up. I replaced that with a __cinit__()
now that always sets it to the default lookup scheme, so that it won't
segfault anymore even if people forget the obvious. ;)
A patch is attached and it's generally easy to work around this by writing
correct code, so there won't be a 2.0.7 right away.
BTW, this:
> parser.setElementClassLookup(lookup)
is correctly spelled
> parser.set_element_class_lookup(lookup)
since lxml 2.0, following PEP 8 naming conventions. However, I didn't dare to
remove the original method, since I figured that it would break tons of code
for no major reason. At least the examples should reflect the new name
everywhere now, so maybe I can remove it in lxml 3.0. ;)
Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: class-lookup-crash-fix.patch
Type: text/x-patch
Size: 3033 bytes
Desc: not available
Url : http://codespeak.net/pipermail/lxml-dev/attachments/20080604/81a340c2/attachment.bin
More information about the lxml-dev
mailing list