From scoder at codespeak.net Sun Feb 5 11:19:50 2006 From: scoder at codespeak.net (scoder@codespeak.net) Date: Sun Feb 5 11:19:52 2006 Subject: [Lxml-checkins] r23033 - lxml/branch/scoder2/src/lxml Message-ID: <20060205101950.8D590100A5@code0.codespeak.net> Author: scoder Date: Sun Feb 5 11:19:46 2006 New Revision: 23033 Modified: lxml/branch/scoder2/src/lxml/etree.pyx Log: fixed memory leak in Element.get() found by Scott Haeger, some clean up of that function Modified: lxml/branch/scoder2/src/lxml/etree.pyx ============================================================================== --- lxml/branch/scoder2/src/lxml/etree.pyx (original) +++ lxml/branch/scoder2/src/lxml/etree.pyx Sun Feb 5 11:19:46 2006 @@ -594,17 +594,20 @@ raise ValueError, "list index(x): x not in list" def get(self, key, default=None): - # XXX more redundancy, but might be slightly faster - cdef char* result + # XXX more redundancy, but might be slightly faster than + # return self.attrib.get(key, default) + cdef char* cresult ns, tag = _getNsTag(key) if ns is None: - result = tree.xmlGetNoNsProp(self._c_node, tag) + cresult = tree.xmlGetNoNsProp(self._c_node, tag) else: - result = tree.xmlGetNsProp(self._c_node, tag, ns) - if result is NULL: - return default - return funicode(result) - #return self.attrib.get(key, default) + cresult = tree.xmlGetNsProp(self._c_node, tag, ns) + if cresult is NULL: + result = default + else: + result = funicode(cresult) + tree.xmlFree(cresult) + return result def keys(self): return self.attrib.keys() From scoder at codespeak.net Sun Feb 5 11:24:19 2006 From: scoder at codespeak.net (scoder@codespeak.net) Date: Sun Feb 5 11:24:21 2006 Subject: [Lxml-checkins] r23034 - in lxml/trunk: . src/lxml Message-ID: <20060205102419.A933D100A5@code0.codespeak.net> Author: scoder Date: Sun Feb 5 11:24:16 2006 New Revision: 23034 Modified: lxml/trunk/Makefile lxml/trunk/src/lxml/etree.pyx Log: fixed memory leak in Element.get() found by Scott Haeger: missing tree.xmlFree(), some clean up of that function Modified: lxml/trunk/Makefile ============================================================================== --- lxml/trunk/Makefile (original) +++ lxml/trunk/Makefile Sun Feb 5 11:24:16 2006 @@ -1,4 +1,4 @@ -PYTHON=python2.3 +PYTHON=python TESTFLAGS=-p -v TESTOPTS= SETUPFLAGS= Modified: lxml/trunk/src/lxml/etree.pyx ============================================================================== --- lxml/trunk/src/lxml/etree.pyx (original) +++ lxml/trunk/src/lxml/etree.pyx Sun Feb 5 11:24:16 2006 @@ -594,17 +594,20 @@ raise ValueError, "list index(x): x not in list" def get(self, key, default=None): - # XXX more redundancy, but might be slightly faster - cdef char* result + # XXX more redundancy, but might be slightly faster than + # return self.attrib.get(key, default) + cdef char* cresult ns, tag = _getNsTag(key) if ns is None: - result = tree.xmlGetNoNsProp(self._c_node, tag) + cresult = tree.xmlGetNoNsProp(self._c_node, tag) else: - result = tree.xmlGetNsProp(self._c_node, tag, ns) - if result is NULL: - return default - return funicode(result) - #return self.attrib.get(key, default) + cresult = tree.xmlGetNsProp(self._c_node, tag, ns) + if cresult is NULL: + result = default + else: + result = funicode(cresult) + tree.xmlFree(cresult) + return result def keys(self): return self.attrib.keys() From scoder at codespeak.net Tue Feb 14 13:01:56 2006 From: scoder at codespeak.net (scoder@codespeak.net) Date: Tue Feb 14 13:01:58 2006 Subject: [Lxml-checkins] r23316 - lxml/trunk/src/lxml Message-ID: <20060214120156.B98A8100A2@code0.codespeak.net> Author: scoder Date: Tue Feb 14 13:01:55 2006 New Revision: 23316 Modified: lxml/trunk/src/lxml/etree.pyx Log: bug fix for memory leak found by Narayan Desai Modified: lxml/trunk/src/lxml/etree.pyx ============================================================================== --- lxml/trunk/src/lxml/etree.pyx (original) +++ lxml/trunk/src/lxml/etree.pyx Tue Feb 14 13:01:55 2006 @@ -855,7 +855,11 @@ result = tree.xmlGetNoNsProp(self._c_node, tag) else: result = tree.xmlGetNsProp(self._c_node, tag, ns) - return result is not NULL + if result is not NULL: + tree.xmlFree(result) + return True + else: + return False def __contains__(self, key): cdef xmlNs* c_ns @@ -865,7 +869,11 @@ result = tree.xmlGetNoNsProp(self._c_node, tag) else: result = tree.xmlGetNsProp(self._c_node, tag, ns) - return result is not NULL + if result is not NULL: + tree.xmlFree(result) + return True + else: + return False cdef _Attrib _attribFactory(_Document doc, xmlNode* c_node): cdef _Attrib result From scoder at codespeak.net Tue Feb 14 13:33:22 2006 From: scoder at codespeak.net (scoder@codespeak.net) Date: Tue Feb 14 13:33:23 2006 Subject: [Lxml-checkins] r23320 - lxml/branch/scoder2/src/lxml Message-ID: <20060214123322.CEDF5100A6@code0.codespeak.net> Author: scoder Date: Tue Feb 14 13:33:21 2006 New Revision: 23320 Modified: lxml/branch/scoder2/src/lxml/etree.pyx Log: bug fix for memory leak found by Narayan Desai Modified: lxml/branch/scoder2/src/lxml/etree.pyx ============================================================================== --- lxml/branch/scoder2/src/lxml/etree.pyx (original) +++ lxml/branch/scoder2/src/lxml/etree.pyx Tue Feb 14 13:33:21 2006 @@ -855,7 +855,11 @@ result = tree.xmlGetNoNsProp(self._c_node, tag) else: result = tree.xmlGetNsProp(self._c_node, tag, ns) - return result is not NULL + if result is not NULL: + tree.xmlFree(result) + return True + else: + return False def __contains__(self, key): cdef xmlNs* c_ns @@ -865,7 +869,11 @@ result = tree.xmlGetNoNsProp(self._c_node, tag) else: result = tree.xmlGetNsProp(self._c_node, tag, ns) - return result is not NULL + if result is not NULL: + tree.xmlFree(result) + return True + else: + return False cdef _Attrib _attribFactory(_Document doc, xmlNode* c_node): cdef _Attrib result From scoder at codespeak.net Fri Feb 17 12:01:34 2006 From: scoder at codespeak.net (scoder@codespeak.net) Date: Fri Feb 17 12:01:36 2006 Subject: [Lxml-checkins] r23450 - in lxml/branch/scoder2: . src/lxml Message-ID: <20060217110134.F2AC310095@code0.codespeak.net> Author: scoder Date: Fri Feb 17 12:01:33 2006 New Revision: 23450 Modified: lxml/branch/scoder2/src/lxml/etree.pyx lxml/branch/scoder2/version.txt Log: another memory leak fix for __getitem__ Modified: lxml/branch/scoder2/src/lxml/etree.pyx ============================================================================== --- lxml/branch/scoder2/src/lxml/etree.pyx (original) +++ lxml/branch/scoder2/src/lxml/etree.pyx Fri Feb 17 12:01:33 2006 @@ -775,16 +775,18 @@ def __getitem__(self, key): cdef xmlNs* c_ns - cdef char* result + cdef char* cresult ns, tag = _getNsTag(key) if ns is None: - result = tree.xmlGetNoNsProp(self._c_node, tag) + cresult = tree.xmlGetNoNsProp(self._c_node, tag) else: - result = tree.xmlGetNsProp(self._c_node, tag, ns) - if result is NULL: + cresult = tree.xmlGetNsProp(self._c_node, tag, ns) + if cresult is NULL: # XXX free namespace that is not in use..? raise KeyError, key - return funicode(result) + result = funicode(cresult) + tree.xmlFree(cresult) + return result def __len__(self): cdef int c Modified: lxml/branch/scoder2/version.txt ============================================================================== --- lxml/branch/scoder2/version.txt (original) +++ lxml/branch/scoder2/version.txt Fri Feb 17 12:01:33 2006 @@ -1 +1 @@ -0.8_s2 +0.8_s3 From scoder at codespeak.net Fri Feb 17 12:01:43 2006 From: scoder at codespeak.net (scoder@codespeak.net) Date: Fri Feb 17 12:01:44 2006 Subject: [Lxml-checkins] r23451 - lxml/trunk/src/lxml Message-ID: <20060217110143.BEF16100C2@code0.codespeak.net> Author: scoder Date: Fri Feb 17 12:01:42 2006 New Revision: 23451 Modified: lxml/trunk/src/lxml/etree.pyx Log: another memory leak fix for __getitem__ Modified: lxml/trunk/src/lxml/etree.pyx ============================================================================== --- lxml/trunk/src/lxml/etree.pyx (original) +++ lxml/trunk/src/lxml/etree.pyx Fri Feb 17 12:01:42 2006 @@ -775,16 +775,18 @@ def __getitem__(self, key): cdef xmlNs* c_ns - cdef char* result + cdef char* cresult ns, tag = _getNsTag(key) if ns is None: - result = tree.xmlGetNoNsProp(self._c_node, tag) + cresult = tree.xmlGetNoNsProp(self._c_node, tag) else: - result = tree.xmlGetNsProp(self._c_node, tag, ns) - if result is NULL: + cresult = tree.xmlGetNsProp(self._c_node, tag, ns) + if cresult is NULL: # XXX free namespace that is not in use..? raise KeyError, key - return funicode(result) + result = funicode(cresult) + tree.xmlFree(cresult) + return result def __len__(self): cdef int c From scoder at codespeak.net Sat Feb 25 09:05:29 2006 From: scoder at codespeak.net (scoder@codespeak.net) Date: Sat Feb 25 17:47:53 2006 Subject: [Lxml-checkins] r23651 - lxml/trunk/doc Message-ID: <20060225080529.C3348100A0@code0.codespeak.net> Author: scoder Date: Sat Feb 25 09:05:28 2006 New Revision: 23651 Added: lxml/trunk/doc/pyrex.txt Log: notes on pyrex and the problems with gcc 4 Added: lxml/trunk/doc/pyrex.txt ============================================================================== --- (empty file) +++ lxml/trunk/doc/pyrex.txt Sat Feb 25 09:05:28 2006 @@ -0,0 +1,25 @@ +Notes on Pyrex +============== + +The lxml wrapper around libxml2 and libxslt is written in Pyrex_. However, +there are known issues with the current version of Pyrex (0.9.3.1) and version +4.x of gcc. Most Linux distributions have the necessary patches applied, but +there is still a certain chance yours hasn't. Also, MacOS-X is known to ship +with GCC 4, so users may run into problems when compiling Pyrex generated code +on this system. If the C compiler fails to compile the file src/lxml/etree.c, +you likely have used an unpatched version of Pyrex to build it. + +There are two ways to get around this problem. First of all, if you are using +a release version of lxml, it should come with the generated C file in the +source distribution. There is no need to regenerate it using Pyrex. + +However, if you want to use more recent SVN versions of lxml or want to work +on the code, you will need Pyrex to regenerate the C-code. If your version of +Pyrex is not patched, you may try to apply the patch that ships with lxml and +is also part of the SVN checkouts. It should fix the remaining problems. +Apply it to the 0.9.3.1 version of Pyrex, rebuild and install it. If the +problems persist, please report to the lxml mailing list. Try to provide a +clear description of what you did to run into the problems and provide the +compiler output that shows the error. + +.. Pyrex_: http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ From scoder at codespeak.net Sat Feb 25 09:37:18 2006 From: scoder at codespeak.net (scoder@codespeak.net) Date: Sat Feb 25 17:47:54 2006 Subject: [Lxml-checkins] r23652 - lxml/branch/scoder2/doc Message-ID: <20060225083718.8B0DD100A0@code0.codespeak.net> Author: scoder Date: Sat Feb 25 09:37:16 2006 New Revision: 23652 Added: lxml/branch/scoder2/doc/pyrex.txt - copied unchanged from r23651, lxml/trunk/doc/pyrex.txt Log: copied from trunk From scoder at codespeak.net Sat Feb 25 10:08:39 2006 From: scoder at codespeak.net (scoder@codespeak.net) Date: Sat Feb 25 17:47:55 2006 Subject: [Lxml-checkins] r23653 - lxml/branch/scoder2/doc Message-ID: <20060225090839.5CDF7100A0@code0.codespeak.net> Author: scoder Date: Sat Feb 25 10:08:38 2006 New Revision: 23653 Modified: lxml/branch/scoder2/doc/namespace_extensions.txt Log: clean up Modified: lxml/branch/scoder2/doc/namespace_extensions.txt ============================================================================== --- lxml/branch/scoder2/doc/namespace_extensions.txt (original) +++ lxml/branch/scoder2/doc/namespace_extensions.txt Sat Feb 25 10:08:38 2006 @@ -164,10 +164,9 @@ XPath extension functions ========================= -The same API is used for extension functions in XPath. If you -associate a name in the Namespace with a callable object (that is not -a subclass of ElementBase), it will be used as extension function in -XPath evaluations. +The same API is used for extension functions in XPath. If you associate a +name in the namespace with a callable object (that is not a subclass of +ElementBase), it will be used as extension function in XPath evaluations. >>> from lxml.etree import Namespace >>> def tag_of(context, elem): From scoder at codespeak.net Sat Feb 25 10:11:12 2006 From: scoder at codespeak.net (scoder@codespeak.net) Date: Sat Feb 25 17:47:56 2006 Subject: [Lxml-checkins] r23654 - lxml/branch/scoder2/src/lxml Message-ID: <20060225091112.5A24F100A0@code0.codespeak.net> Author: scoder Date: Sat Feb 25 10:11:11 2006 New Revision: 23654 Modified: lxml/branch/scoder2/src/lxml/nsclasses.pxi Log: clean up, dummy implementation of FunctionNamespace API (currently commented out) Modified: lxml/branch/scoder2/src/lxml/nsclasses.pxi ============================================================================== --- lxml/branch/scoder2/src/lxml/nsclasses.pxi (original) +++ lxml/branch/scoder2/src/lxml/nsclasses.pxi Sat Feb 25 10:11:11 2006 @@ -4,31 +4,42 @@ pass class ElementBase(_Element): - """All classes in namespace implementations must inherit from this - one. Note that subclasses *must not* override __init__ or __new__ - as there is absolutely undefined when these objects will be - created or destroyed. All state must be kept in the underlying - XML.""" + """All classes in namespace implementations must inherit from this one. + Note that subclasses *must not* override __init__ or __new__ as it is + absolutely undefined when these objects will be created or destroyed. All + persistent state of elements must be stored in the underlying XML.""" pass class XSLTElement(object): "NOT IMPLEMENTED YET!" pass -cdef object __NAMESPACE_CLASSES -__NAMESPACE_CLASSES = {} +cdef object __NAMESPACE_REGISTRIES +__NAMESPACE_REGISTRIES = {} def Namespace(ns_uri): + """Retrieve the namespace object associated with the given URI. Creates a + new one if it does not yet exist.""" if ns_uri: ns_utf = ns_uri.encode('UTF-8') else: ns_utf = None try: - return __NAMESPACE_CLASSES[ns_utf] + return __NAMESPACE_REGISTRIES[ns_utf] except KeyError: - registry = __NAMESPACE_CLASSES[ns_utf] = _NamespaceRegistry(ns_uri) + registry = __NAMESPACE_REGISTRIES[ns_utf] = _NamespaceRegistry(ns_uri) return registry +## just an idea for a different API: +## +## def FunctionNamespace(ns_uri): +## """Retrieve the function namespace object associated with the given +## URI. Creates a new one if it does not yet exist. A function namespace can +## only be used to register extension functions.""" +## # This is a dummy for now. It only defines the correct API. +## return Namespace(ns_uri) +## + cdef class _NamespaceRegistry: "Dictionary-like registry for namespace implementations" cdef object _ns_uri @@ -86,7 +97,7 @@ cdef object _find_all_namespaces(): "Hack to register all extension functions in XSLT" ns_uris = [] - for s in __NAMESPACE_CLASSES.keys(): + for s in __NAMESPACE_REGISTRIES.keys(): ns_uris.append(unicode(s, 'UTF-8')) return ns_uris @@ -95,7 +106,7 @@ ns_utf = ns_uri.encode('UTF-8') else: ns_utf = None - return __NAMESPACE_CLASSES[ns_utf] + return __NAMESPACE_REGISTRIES[ns_utf] cdef _find_extensions(namespaces): extension_dict = {} @@ -121,7 +132,7 @@ namespace_utf = c_namespace_utf try: - registry = __NAMESPACE_CLASSES[namespace_utf] + registry = __NAMESPACE_REGISTRIES[namespace_utf] except KeyError: return _Element classes = registry._classes