From d69cc8174e3268b464c7a251c3051c3b5d40f4ab Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Thu, 1 Jul 2004 09:36:26 +0000 Subject: [PATCH] do not provide functions used as destructor of classes as public methods * python/generator.py: do not provide functions used as destructor of classes as public methods to avoid double-free problem like in bug #145185 Daniel --- ChangeLog | 6 + config.h.in | 5 +- python/generator.py | 8 + python/libxml2class.txt | 474 ++++++++++++++++++++-------------------- 4 files changed, 252 insertions(+), 241 deletions(-) diff --git a/ChangeLog b/ChangeLog index 470d95c6..74b35d5e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Jul 1 11:34:10 CEST 2004 Daniel Veillard + + * python/generator.py: do not provide functions used as destructor + of classes as public methods to avoid double-free problem like + in bug #145185 + Wed Jun 30 19:45:23 HKT 2004 William Brack * xmlschemas.c, xmlschemastypes.c: warning message cleanup. diff --git a/config.h.in b/config.h.in index 915ef0c8..f54d0bf7 100644 --- a/config.h.in +++ b/config.h.in @@ -256,7 +256,7 @@ /* Define to the version of this package. */ #undef PACKAGE_VERSION -/* Define if compiler has function prototypes */ +/* Define to 1 if the C compiler supports function prototypes. */ #undef PROTOTYPES /* Determine what socket length (socklen_t) data type is */ @@ -274,6 +274,9 @@ /* Using the Win32 Socket implementation */ #undef _WINSOCKAPI_ +/* Define like PROTOTYPES; this can be used by system headers. */ +#undef __PROTOTYPES + /* Win32 Std C name mangling work-around */ #undef snprintf diff --git a/python/generator.py b/python/generator.py index 4c6c8ab5..e0f10969 100755 --- a/python/generator.py +++ b/python/generator.py @@ -1037,17 +1037,25 @@ def buildWrappers(): classes.write(" self.%s = None\n" % ref[1]) classes.write(" if _obj != None:self._o = _obj;return\n") classes.write(" self._o = None\n\n"); + destruct=None if classes_destructors.has_key(classname): classes.write(" def __del__(self):\n") classes.write(" if self._o != None:\n") classes.write(" libxml2mod.%s(self._o)\n" % classes_destructors[classname]); classes.write(" self._o = None\n\n"); + destruct=classes_destructors[classname] flist = function_classes[classname] flist.sort(functionCompare) oldfile = "" for info in flist: (index, func, name, ret, args, file) = info + # + # Do not provide as method the destructors for the class + # to avoid double free + # + if name == destruct: + continue; if file != oldfile: if file == "python_accessor": classes.write(" # accessors for %s\n" % (classname)) diff --git a/python/libxml2class.txt b/python/libxml2class.txt index 3f29a8ee..74798436 100644 --- a/python/libxml2class.txt +++ b/python/libxml2class.txt @@ -635,6 +635,56 @@ Class xmlDoc(xmlNode) # functions from module xpointer xpointerNewContext() +Class xpathContext() + # accessors + contextDoc() + contextNode() + contextPosition() + contextSize() + function() + functionURI() + setContextDoc() + setContextNode() + + # functions from module python + registerXPathFunction() + + # functions from module xpath + xpathEval() + xpathEvalExpression() + xpathFreeContext() + + # functions from module xpathInternals + xpathNewParserContext() + xpathNsLookup() + xpathRegisterAllFunctions() + xpathRegisterNs() + xpathRegisteredFuncsCleanup() + xpathRegisteredNsCleanup() + xpathRegisteredVariablesCleanup() + xpathVariableLookup() + xpathVariableLookupNS() + + # functions from module xpointer + xpointerEval() + + +Class xmlAttribute(xmlNode) +Class catalog() + + # functions from module catalog + add() + catalogIsEmpty() + convertSGMLCatalog() + dump() + remove() + resolve() + resolvePublic() + resolveSystem() + resolveURI() + + +Class xmlElement(xmlNode) Class xmlAttr(xmlNode) @@ -653,13 +703,95 @@ Class xmlAttr(xmlNode) # functions from module valid removeID() removeRef() + + +Class xmlTextReader(xmlTextReaderCore) + + # functions from module xmlreader + AttributeCount() + BaseUri() + Close() + CurrentDoc() + CurrentNode() + Depth() + Expand() + GetAttribute() + GetAttributeNo() + GetAttributeNs() + GetParserProp() + GetRemainder() + HasAttributes() + HasValue() + IsDefault() + IsEmptyElement() + IsValid() + LocalName() + LookupNamespace() + MoveToAttribute() + MoveToAttributeNo() + MoveToAttributeNs() + MoveToElement() + MoveToFirstAttribute() + MoveToNextAttribute() + Name() + NamespaceUri() + NewDoc() + NewFd() + NewFile() + NewMemory() + NewWalker() + Next() + NextSibling() + NodeType() + Normalization() + Prefix() + Preserve() + QuoteChar() + Read() + ReadAttributeValue() + ReadInnerXml() + ReadOuterXml() + ReadState() + ReadString() + RelaxNGSetSchema() + RelaxNGValidate() + SetParserProp() + String() + Value() + XmlLang() Class xmlReg() # functions from module xmlregexp regexpExec() - regexpFreeRegexp() regexpIsDeterminist() regexpPrint() + + +Class xmlEntity(xmlNode) + + # functions from module parserInternals + handleEntity() +Class relaxNgSchema() + + # functions from module relaxng + relaxNGDump() + relaxNGDumpTree() + relaxNGNewValidCtxt() + + # functions from module xmlreader + RelaxNGSetSchema() +Class Error() + # accessors + code() + domain() + file() + level() + line() + message() + + # functions from module xmlerror + copyError() + resetError() Class relaxNgValidCtxt() # functions from module relaxng @@ -668,6 +800,73 @@ Class relaxNgValidCtxt() relaxNGValidatePopElement() relaxNGValidatePushCData() relaxNGValidatePushElement() +Class xpathParserContext() + # accessors + context() + + # functions from module xpathInternals + xpathAddValues() + xpathBooleanFunction() + xpathCeilingFunction() + xpathCompareValues() + xpathConcatFunction() + xpathContainsFunction() + xpathCountFunction() + xpathDivValues() + xpathEqualValues() + xpathErr() + xpathEvalExpr() + xpathFalseFunction() + xpathFloorFunction() + xpathFreeParserContext() + xpathIdFunction() + xpathLangFunction() + xpathLastFunction() + xpathLocalNameFunction() + xpathModValues() + xpathMultValues() + xpathNamespaceURIFunction() + xpathNextAncestor() + xpathNextAncestorOrSelf() + xpathNextAttribute() + xpathNextChild() + xpathNextDescendant() + xpathNextDescendantOrSelf() + xpathNextFollowing() + xpathNextFollowingSibling() + xpathNextNamespace() + xpathNextParent() + xpathNextPreceding() + xpathNextPrecedingSibling() + xpathNextSelf() + xpathNormalizeFunction() + xpathNotEqualValues() + xpathNotFunction() + xpathNumberFunction() + xpathParseNCName() + xpathParseName() + xpathPopBoolean() + xpathPopNumber() + xpathPopString() + xpathPositionFunction() + xpathRoot() + xpathRoundFunction() + xpathStartsWithFunction() + xpathStringFunction() + xpathStringLengthFunction() + xpathSubValues() + xpathSubstringAfterFunction() + xpathSubstringBeforeFunction() + xpathSubstringFunction() + xpathSumFunction() + xpathTranslateFunction() + xpathTrueFunction() + xpathValueFlipSign() + xpatherror() + + # functions from module xpointer + xpointerEvalRangePredicate() + xpointerRangeToFunction() Class parserCtxt(parserCtxtCore) @@ -775,92 +974,6 @@ Class xmlDtd(xmlNode) dtdElementDesc() dtdQAttrDesc() dtdQElementDesc() -Class relaxNgParserCtxt() - - # functions from module relaxng - relaxNGFreeParserCtxt() - relaxNGParse() - relaxParserSetFlag() -Class xpathParserContext() - # accessors - context() - - # functions from module xpathInternals - xpathAddValues() - xpathBooleanFunction() - xpathCeilingFunction() - xpathCompareValues() - xpathConcatFunction() - xpathContainsFunction() - xpathCountFunction() - xpathDivValues() - xpathEqualValues() - xpathErr() - xpathEvalExpr() - xpathFalseFunction() - xpathFloorFunction() - xpathFreeParserContext() - xpathIdFunction() - xpathLangFunction() - xpathLastFunction() - xpathLocalNameFunction() - xpathModValues() - xpathMultValues() - xpathNamespaceURIFunction() - xpathNextAncestor() - xpathNextAncestorOrSelf() - xpathNextAttribute() - xpathNextChild() - xpathNextDescendant() - xpathNextDescendantOrSelf() - xpathNextFollowing() - xpathNextFollowingSibling() - xpathNextNamespace() - xpathNextParent() - xpathNextPreceding() - xpathNextPrecedingSibling() - xpathNextSelf() - xpathNormalizeFunction() - xpathNotEqualValues() - xpathNotFunction() - xpathNumberFunction() - xpathParseNCName() - xpathParseName() - xpathPopBoolean() - xpathPopNumber() - xpathPopString() - xpathPositionFunction() - xpathRoot() - xpathRoundFunction() - xpathStartsWithFunction() - xpathStringFunction() - xpathStringLengthFunction() - xpathSubValues() - xpathSubstringAfterFunction() - xpathSubstringBeforeFunction() - xpathSubstringFunction() - xpathSumFunction() - xpathTranslateFunction() - xpathTrueFunction() - xpathValueFlipSign() - xpatherror() - - # functions from module xpointer - xpointerEvalRangePredicate() - xpointerRangeToFunction() -Class catalog() - - # functions from module catalog - add() - catalogIsEmpty() - convertSGMLCatalog() - dump() - freeCatalog() - remove() - resolve() - resolvePublic() - resolveSystem() - resolveURI() Class xmlNs(xmlNode) @@ -884,6 +997,40 @@ Class xmlNs(xmlNode) # functions from module xpathInternals xpathNodeSetFreeNs() + + +Class inputBuffer(ioReadWrapper) + + # functions from module xmlIO + grow() + push() + read() + + # functions from module xmlreader + newTextReader() +Class relaxNgParserCtxt() + + # functions from module relaxng + relaxNGParse() + relaxParserSetFlag() + + +Class outputBuffer(ioWriteWrapper) + + # functions from module HTMLtree + htmlDocContentDumpFormatOutput() + htmlDocContentDumpOutput() + htmlNodeDumpFormatOutput() + htmlNodeDumpOutput() + + # functions from module tree + nodeDumpOutput() + saveFileTo() + saveFormatFileTo() + + # functions from module xmlIO + write() + writeString() Class xmlTextReaderLocator() # functions from module xmlreader @@ -911,159 +1058,6 @@ Class URI() user() # functions from module uri - freeURI() parseURIReference() printURI() saveUri() - - -Class xmlAttribute(xmlNode) -Class xpathContext() - # accessors - contextDoc() - contextNode() - contextPosition() - contextSize() - function() - functionURI() - setContextDoc() - setContextNode() - - # functions from module python - registerXPathFunction() - - # functions from module xpath - xpathEval() - xpathEvalExpression() - xpathFreeContext() - - # functions from module xpathInternals - xpathNewParserContext() - xpathNsLookup() - xpathRegisterAllFunctions() - xpathRegisterNs() - xpathRegisteredFuncsCleanup() - xpathRegisteredNsCleanup() - xpathRegisteredVariablesCleanup() - xpathVariableLookup() - xpathVariableLookupNS() - - # functions from module xpointer - xpointerEval() - - -Class xmlElement(xmlNode) - - -Class xmlTextReader(xmlTextReaderCore) - - # functions from module xmlreader - AttributeCount() - BaseUri() - Close() - CurrentDoc() - CurrentNode() - Depth() - Expand() - GetAttribute() - GetAttributeNo() - GetAttributeNs() - GetParserProp() - GetRemainder() - HasAttributes() - HasValue() - IsDefault() - IsEmptyElement() - IsValid() - LocalName() - LookupNamespace() - MoveToAttribute() - MoveToAttributeNo() - MoveToAttributeNs() - MoveToElement() - MoveToFirstAttribute() - MoveToNextAttribute() - Name() - NamespaceUri() - NewDoc() - NewFd() - NewFile() - NewMemory() - NewWalker() - Next() - NextSibling() - NodeType() - Normalization() - Prefix() - Preserve() - QuoteChar() - Read() - ReadAttributeValue() - ReadInnerXml() - ReadOuterXml() - ReadState() - ReadString() - RelaxNGSetSchema() - RelaxNGValidate() - SetParserProp() - String() - Value() - XmlLang() - - -Class xmlEntity(xmlNode) - - # functions from module parserInternals - handleEntity() -Class Error() - # accessors - code() - domain() - file() - level() - line() - message() - - # functions from module xmlerror - copyError() - resetError() -Class relaxNgSchema() - - # functions from module relaxng - relaxNGDump() - relaxNGDumpTree() - relaxNGFree() - relaxNGNewValidCtxt() - - # functions from module xmlreader - RelaxNGSetSchema() - - -Class inputBuffer(ioReadWrapper) - - # functions from module xmlIO - freeParserInputBuffer() - grow() - push() - read() - - # functions from module xmlreader - newTextReader() - - -Class outputBuffer(ioWriteWrapper) - - # functions from module HTMLtree - htmlDocContentDumpFormatOutput() - htmlDocContentDumpOutput() - htmlNodeDumpFormatOutput() - htmlNodeDumpOutput() - - # functions from module tree - nodeDumpOutput() - saveFileTo() - saveFormatFileTo() - - # functions from module xmlIO - write() - writeString()