Reviewed by Eric.
Fixes: http://bugzilla.opendarwin.org/show_bug.cgi?id=10835
Fix svg memory leaks.
Reworked SVGList to deal with RefPtr's for ptr types
which makes manual refcounting unnecessary, and is much safer.
Removing all virtual functions (nullItem) from SVGList, and
also remove SVGListBase. Switch to a similar concept like
Vector/VectorTraits (see new file SVGListTraits.h).
Credits go to Eric/Maciej for the inspiration.
* CMakeLists.txt: Add SVGListTraits.cpp to build
* WebCore.xcodeproj/project.pbxproj: Ditto.
* bindings/scripts/CodeGeneratorJS.pm: Generator changes for SVGTransform/PathSeg/LengthList (now RefPtr based)
* kcanvas/RenderSVGText.cpp: Add some get() methods, as SVGLengthList is RefPtr based now.
(WebCore::RenderSVGText::translationForAttributes):
* ksvg2/svg/SVGAnimateTransformElement.cpp: Add some get() methods, as SVGTransformList is RefPtr based now.
(WebCore::SVGAnimateTransformElement::handleTimerEvent):
* ksvg2/svg/SVGElementInstanceList.cpp: Be RefPtr based.
(WebCore::SVGElementInstanceList::SVGElementInstanceList):
* ksvg2/svg/SVGElementInstanceList.h:
* ksvg2/svg/SVGLengthList.cpp: Ditto.
(WebCore::SVGLengthList::SVGLengthList):
* ksvg2/svg/SVGLengthList.h: Ditto.
* ksvg2/svg/SVGList.h: Rewrote, as described above.
(WebCore::SVGListTypeOperations::nullItem):
(WebCore::SVGList::SVGList):
(WebCore::SVGList::~SVGList):
(WebCore::SVGList::clear):
(WebCore::SVGList::getFirst):
(WebCore::SVGList::getLast):
(WebCore::SVGList::getItem):
(WebCore::SVGList::replaceItem):
(WebCore::SVGList::removeItem):
* ksvg2/svg/SVGListTraits.cpp: Added.
* ksvg2/svg/SVGListTraits.h: Added.
(WebCore::):
* ksvg2/svg/SVGPathElement.cpp: Add some get() methods, as SVGPathSegList is RefPtr based now.
(WebCore::SVGPathElement::toPathData):
* ksvg2/svg/SVGPathSegList.cpp: Be RefPtr based.
(WebCore::SVGPathSegList::SVGPathSegList):
* ksvg2/svg/SVGPathSegList.h: Ditto.
* ksvg2/svg/SVGTransform.cpp: Style cleanup.
(SVGTransform::SVGTransform):
* ksvg2/svg/SVGTransformList.cpp: Be RefPtr based.
(SVGTransformList::SVGTransformList):
(SVGTransformList::createSVGTransformFromMatrix):
(SVGTransformList::consolidate):
* ksvg2/svg/SVGTransformList.h: Ditto.
* ksvg2/svg/SVGTransformable.cpp: Fix RefPtr usage of SVGTransform.
(SVGTransformable::parseTransformAttribute):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16378
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2006-09-15 Nikolas Zimmermann <zimmermann@kde.org>
+
+ Reviewed by Eric.
+
+ Fixes: http://bugzilla.opendarwin.org/show_bug.cgi?id=10835
+ Fix svg memory leaks.
+
+ Reworked SVGList to deal with RefPtr's for ptr types
+ which makes manual refcounting unnecessary, and is much safer.
+
+ Removing all virtual functions (nullItem) from SVGList, and
+ also remove SVGListBase. Switch to a similar concept like
+ Vector/VectorTraits (see new file SVGListTraits.h).
+
+ Credits go to Eric/Maciej for the inspiration.
+
+ * CMakeLists.txt: Add SVGListTraits.cpp to build
+ * WebCore.xcodeproj/project.pbxproj: Ditto.
+ * bindings/scripts/CodeGeneratorJS.pm: Generator changes for SVGTransform/PathSeg/LengthList (now RefPtr based)
+ * kcanvas/RenderSVGText.cpp: Add some get() methods, as SVGLengthList is RefPtr based now.
+ (WebCore::RenderSVGText::translationForAttributes):
+ * ksvg2/svg/SVGAnimateTransformElement.cpp: Add some get() methods, as SVGTransformList is RefPtr based now.
+ (WebCore::SVGAnimateTransformElement::handleTimerEvent):
+ * ksvg2/svg/SVGElementInstanceList.cpp: Be RefPtr based.
+ (WebCore::SVGElementInstanceList::SVGElementInstanceList):
+ * ksvg2/svg/SVGElementInstanceList.h:
+ * ksvg2/svg/SVGLengthList.cpp: Ditto.
+ (WebCore::SVGLengthList::SVGLengthList):
+ * ksvg2/svg/SVGLengthList.h: Ditto.
+ * ksvg2/svg/SVGList.h: Rewrote, as described above.
+ (WebCore::SVGListTypeOperations::nullItem):
+ (WebCore::SVGList::SVGList):
+ (WebCore::SVGList::~SVGList):
+ (WebCore::SVGList::clear):
+ (WebCore::SVGList::getFirst):
+ (WebCore::SVGList::getLast):
+ (WebCore::SVGList::getItem):
+ (WebCore::SVGList::replaceItem):
+ (WebCore::SVGList::removeItem):
+ * ksvg2/svg/SVGListTraits.cpp: Added.
+ * ksvg2/svg/SVGListTraits.h: Added.
+ (WebCore::):
+ * ksvg2/svg/SVGPathElement.cpp: Add some get() methods, as SVGPathSegList is RefPtr based now.
+ (WebCore::SVGPathElement::toPathData):
+ * ksvg2/svg/SVGPathSegList.cpp: Be RefPtr based.
+ (WebCore::SVGPathSegList::SVGPathSegList):
+ * ksvg2/svg/SVGPathSegList.h: Ditto.
+ * ksvg2/svg/SVGTransform.cpp: Style cleanup.
+ (SVGTransform::SVGTransform):
+ * ksvg2/svg/SVGTransformList.cpp: Be RefPtr based.
+ (SVGTransformList::SVGTransformList):
+ (SVGTransformList::createSVGTransformFromMatrix):
+ (SVGTransformList::consolidate):
+ * ksvg2/svg/SVGTransformList.h: Ditto.
+ * ksvg2/svg/SVGTransformable.cpp: Fix RefPtr usage of SVGTransform.
+ (SVGTransformable::parseTransformAttribute):
+
2006-09-15 Nikolas Zimmermann <zimmermann@kde.org>
Reviewed by eseidel. Landed by eseidel.
my $numParameters = @{$function->parameters};
my $hasOptionalArguments = 0;
+ # Special case for SVGLengthList / SVGTransformList / SVGPathSegList.
+ # These lists still use RefPtr objects, which will be changed in future.
+ # For now they need special treatment in the generation.
+ my $isRefPtr = 0;
+ if ($interfaceName eq "SVGLengthList" or
+ $interfaceName eq "SVGTransformList" or
+ $interfaceName eq "SVGPathSegList") {
+ $isRefPtr = 1;
+ }
+
foreach my $parameter (@{$function->parameters}) {
if (!$hasOptionalArguments && $parameter->extendedAttributes->{"Optional"}) {
push(@implContent, "\n int argsCount = args.size();\n");
if ($hasOptionalArguments) {
push(@implContent, " if (argsCount < " . ($paramIndex + 1) . ") {\n");
- GenerateImplementationFunctionCall($function, $functionString, $paramIndex, " " x 3);
+ GenerateImplementationFunctionCall($function, $functionString, $paramIndex, " " x 3, $isRefPtr);
push(@implContent, " }\n\n");
}
}
push(@implContent, "\n");
- GenerateImplementationFunctionCall($function, $functionString, $paramIndex, " " x 2);
+ GenerateImplementationFunctionCall($function, $functionString, $paramIndex, " " x 2, $isRefPtr);
push(@implContent, " }\n"); # end case
}
my $functionString = shift;
my $paramIndex = shift;
my $indent = shift;
+ my $isRefPtr = shift;
if (@{$function->raisesExceptions}) {
$functionString .= ", " if $paramIndex;
push(@implContent, $indent . "setDOMException(exec, ec);\n") if @{$function->raisesExceptions};
push(@implContent, $indent . "return jsUndefined();\n");
} else {
- push(@implContent, "\n" . $indent . "KJS::JSValue* result = " . NativeToJSValue($function->signature, $functionString) . ";\n");
+ push(@implContent, "\n" . $indent . "KJS::JSValue* result = " . NativeToJSValue($function->signature, $functionString, $isRefPtr) . ";\n");
push(@implContent, $indent . "setDOMException(exec, ec);\n") if @{$function->raisesExceptions};
push(@implContent, $indent . "return result;\n");
}
{
my $signature = shift;
my $value = shift;
-
+ my $isRefPtr = shift;
+
my $type = $codeGenerator->StripModule($signature->type);
if ($type eq "boolean") {
$implIncludes{"kjs_html.h"} = 1;
$implIncludes{"HTMLCollection.h"} = 1;
return "getHTMLCollection(exec, $value.get())";
+ } elsif (($type eq "SVGLength" or
+ $type eq "SVGTransform") and $isRefPtr eq 1) {
+ $implIncludes{"JS$type.h"} = 1;
+ $implIncludes{"$type.h"} = 1;
+ return "toJS(exec, $value.get())";
} elsif ($type eq "SVGRect" or
$type eq "SVGPoint" or
$type eq "SVGNumber") {
$joinedName = $type;
$joinedName =~ s/Abs|Rel//;
$implIncludes{"$joinedName.h"} = 1;
- return "toJS(exec, $value)";
+
+ if ($isRefPtr eq 1) {
+ return "toJS(exec, $value.get())";
+ } else {
+ return "toJS(exec, $value)";
+ }
} elsif ($codeGenerator->IsSVGAnimatedType($type)) {
$implIncludes{"JS$type.h"} = 1;
$implIncludes{"$type.h"} = 1;
{
SVGTextElement *text = static_cast<SVGTextElement *>(element());
- SVGLength* xOffset = text->x()->getFirst();
- SVGLength* yOffset = text->y()->getFirst();
+ SVGLength* xOffset = text->x()->getFirst().get();
+ SVGLength* yOffset = text->y()->getFirst().get();
return AffineTransform().translate(xOffset ? xOffset->value() : 0,
yOffset ? yOffset->value() : 0);
if (transformList) {
ExceptionCode ec = 0;
for (unsigned long i = 0; i < transformList->numberOfItems(); i++) {
- SVGTransform *value = transformList->getItem(i, ec);
+ SVGTransform *value = transformList->getItem(i, ec).get();;
if (!value)
continue;
namespace WebCore {
SVGElementInstanceList::SVGElementInstanceList()
- : SVGList<SVGElementInstance*>()
+ : SVGList<RefPtr<SVGElementInstance> >()
{
}
namespace WebCore
{
- class SVGElementInstanceList : public SVGList<SVGElementInstance*>
+ class SVGElementInstanceList : public SVGList<RefPtr<SVGElementInstance> >
{
public:
SVGElementInstanceList();
namespace WebCore {
SVGLengthList::SVGLengthList()
- : SVGList<SVGLength*>()
+ : SVGList<RefPtr<SVGLength> >()
{
}
namespace WebCore
{
- class SVGLengthList : public SVGList<SVGLength*>
+ class SVGLengthList : public SVGList<RefPtr<SVGLength> >
{
public:
SVGLengthList();
/*
- Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
+ Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
2004, 2005 Rob Buis <buis@kde.org>
This file is part of the KDE project
Boston, MA 02111-1307, USA.
*/
-#ifndef KSVG_SVGList_H
-#define KSVG_SVGList_H
+#ifndef SVGList_H
+#define SVGList_H
#ifdef SVG_SUPPORT
#include <wtf/Vector.h>
#include "Shared.h"
-#include "FloatPoint.h"
+#include "SVGListTraits.h"
#include "ExceptionCode.h"
-#include "PlatformString.h"
namespace WebCore {
- template<class Item>
- class SVGListBase : public Shared<SVGListBase<Item> >
+ template<typename Item>
+ struct SVGListTypeOperations
{
- public:
- SVGListBase() { }
- virtual ~SVGListBase() { clearVector(m_vector); }
+ static Item nullItem()
+ {
+ return SVGListTraits<UsesDefaultInitializer<Item>::value, Item>::nullItem();
+ }
+ };
- // To be implemented by the SVGList specializations!
- virtual Item nullItem() const = 0;
- virtual void clearVector(Vector<Item>& vector) const { vector.clear(); }
+ template<typename Item>
+ class SVGList : public Shared<SVGList<Item> >
+ {
+ private:
+ typedef SVGListTypeOperations<Item> TypeOperations;
+
+ public:
+ SVGList() { }
+ virtual ~SVGList() { m_vector.clear(); }
unsigned int numberOfItems() const { return m_vector.size(); }
- void clear(ExceptionCode &) { clearVector(m_vector); }
+ void clear(ExceptionCode &) { m_vector.clear(); }
Item initialize(Item newItem, ExceptionCode& ec)
{
Item getFirst() const
{
if (m_vector.isEmpty())
- return nullItem();
+ return TypeOperations::nullItem();
return m_vector.first();
}
Item getLast() const
{
if (m_vector.isEmpty())
- return nullItem();
+ return TypeOperations::nullItem();
return m_vector.last();
}
{
if (m_vector.size() < index) {
ec = INDEX_SIZE_ERR;
- return nullItem();
+ return TypeOperations::nullItem();
}
return m_vector.at(index);
{
if (m_vector.size() < index) {
ec = INDEX_SIZE_ERR;
- return nullItem();
+ return TypeOperations::nullItem();
}
- return m_vector.at(index);
+ return m_vector[index];
}
Item insertItemBefore(Item newItem, unsigned int index, ExceptionCode&)
{
if (m_vector.size() < index) {
ec = INDEX_SIZE_ERR;
- return nullItem();
+ return TypeOperations::nullItem();
}
- m_vector.at(index) = newItem;
+ m_vector[index] = newItem;
return newItem;
}
{
if (m_vector.size() < index) {
ec = INDEX_SIZE_ERR;
- return nullItem();
+ return TypeOperations::nullItem();
}
- Item item = m_vector.at(index);
+ Item item = m_vector[index];
removeItem(index, ec);
return item;
}
Vector<Item> m_vector;
};
- template<class Item>
- class SVGList : public SVGListBase<Item>
- {
- public:
- virtual Item nullItem() const { return 0; }
-
- virtual void clearVector(Vector<Item>& vector) const
- {
- typedef typename Vector<Item>::const_iterator iterator;
-
- iterator end = vector.end();
- for (iterator it = vector.begin(); it != end; ++it)
- (*it)->deref();
-
- vector.clear();
- }
- };
-
- // Specialization for double
- template<>
- class SVGList<double> : public SVGListBase<double>
- {
- public:
- virtual double nullItem() const { return 0.0; }
- };
-
- // Specialization for String
- template<>
- class SVGList<String> : public SVGListBase<String>
- {
- public:
- virtual String nullItem() const { return String(); }
- };
-
- // Specialization for FloatPoint
- template<>
- class SVGList<FloatPoint> : public SVGListBase<FloatPoint>
- {
- public:
- virtual FloatPoint nullItem() const { return FloatPoint(); }
- };
-
} // namespace WebCore
#endif // SVG_SUPPORT
-#endif // KSVG_SVGList_H
+#endif // SVGList_H
// vim:ts=4:noet
--- /dev/null
+/*
+ Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org>
+ 2006 Apple Computer Inc.
+
+ This file is part of the KDE project
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef SVGListTraits_H
+#define SVGListTraits_H
+
+#ifdef SVG_SUPPORT
+
+namespace WebCore {
+
+ template<typename Item> struct UsesDefaultInitializer { static const bool value = true; };
+ template<> struct UsesDefaultInitializer<double> { static const bool value = false; };
+
+ template<bool usesDefaultInitializer, typename Item>
+ struct SVGListTraits { };
+
+ template<typename Item>
+ struct SVGListTraits<true, Item>
+ {
+ static Item nullItem() { return Item(); }
+ };
+
+ template<>
+ struct SVGListTraits<false, double>
+ {
+ static double nullItem() { return 0.0; }
+ };
+
+} // namespace WebCore
+
+#endif // SVG_SUPPORT
+#endif // SVGListTraits_H
+
+// vim:ts=4:noet
#include "config.h"
#ifdef SVG_SUPPORT
+
+#include "DeprecatedString.h"
#include "DeprecatedStringList.h"
#include "SVGMatrix.h"
namespace WebCore
{
+ class DeprecatedString;
+
class SVGNumberList : public SVGList<double>
{
public:
ExceptionCode ec = 0;
for(int i = 0; i < len; ++i)
{
- SVGPathSeg *p = pathSegList()->getItem(i, ec);
+ SVGPathSeg *p = pathSegList()->getItem(i, ec).get();;
switch(p->pathSegType())
{
case SVGPathSeg::PATHSEG_MOVETO_ABS:
namespace WebCore {
SVGPathSegList::SVGPathSegList()
- : SVGList<SVGPathSeg*>()
+ : SVGList<RefPtr<SVGPathSeg> >()
{
}
namespace WebCore
{
- class SVGPathSegList : public SVGList<SVGPathSeg*>
+ class SVGPathSegList : public SVGList<RefPtr<SVGPathSeg> >
{
public:
SVGPathSegList();
using namespace WebCore;
-SVGTransform::SVGTransform() : Shared<SVGTransform>()
+SVGTransform::SVGTransform()
+ : Shared<SVGTransform>()
+ , m_matrix(SVGSVGElement::createSVGMatrix())
{
- m_matrix = SVGSVGElement::createSVGMatrix();
-
m_type = SVG_TRANSFORM_UNKNOWN;
m_angle = 0;
}
using namespace WebCore;
SVGTransformList::SVGTransformList()
- : SVGList<SVGTransform*>()
+ : SVGList<RefPtr<SVGTransform> >()
{
}
{
}
-SVGTransform* SVGTransformList::createSVGTransformFromMatrix(SVGMatrix* matrix) const
+RefPtr<SVGTransform> SVGTransformList::createSVGTransformFromMatrix(SVGMatrix* matrix) const
{
return SVGSVGElement::createSVGTransformFromMatrix(matrix);
}
-SVGTransform* SVGTransformList::consolidate()
+RefPtr<SVGTransform> SVGTransformList::consolidate()
{
SVGTransform* obj = concatenate();
if (!obj)
namespace WebCore {
- class SVGTransformList : public SVGList<SVGTransform*>
+ class SVGTransformList : public SVGList<RefPtr<SVGTransform> >
{
public:
SVGTransformList();
virtual ~SVGTransformList();
- SVGTransform* createSVGTransformFromMatrix(SVGMatrix*) const;
- SVGTransform* consolidate();
+ RefPtr<SVGTransform> createSVGTransformFromMatrix(SVGMatrix*) const;
+ RefPtr<SVGTransform> consolidate();
// Internal use only
SVGTransform* concatenate() const;
if (subtransform[0].startsWith(";") || subtransform[0].startsWith(","))
subtransform[0] = subtransform[0].mid(1).stripWhiteSpace();
- RefPtr<SVGTransform> t(new SVGTransform());
+ SVGTransform* t = new SVGTransform();
if (subtransform[0] == "rotate") {
if (params.count() == 3)
break; // failed to parse a valid transform, abort.
ExceptionCode ec = 0;
- list->appendItem(t.release().release(), ec);
+ list->appendItem(t, ec);
}
}