You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Kirk Wylie <ki...@kidar.org> on 2000/09/09 00:41:14 UTC

Patch: Virtual Destructors patch

There are three classes (NameIdPoolEnumerator, DOM_Entity, and
HashXMLCh) which compiling with g++ (2.95.2) discovered had:
1) Virtual methods,
but
2) No virtual destructors.
I've looked at the actual destructors in question, and they don't seem
to actually DO anything. But without an entry in the virtual table in
the destructor, there's a very high likelihood that things won't
properly be destroyed further up the chain.

In any case, It's a warning which is easy to avoid.

The attached patch, applied to the .../xml-xerces/c/src directory on the
current HEAD revision, will resolve these issues and compile cleanly
using g++.

Also, as a note, in looking at NameIdPoolEnumerator<>, the class has
concrete instantiations of pure virtual methods from XMLEnumerator<>. I
believe that the C++ standard is to make these virtual, but it might
make sense for someone more familiar with the code to examine these
methods (hasMoreElements() and nextElement()) to make sure that the code
is properly written.

Kirk Wylie
-- 
Kirk Wylie  |  mailto:kirk@radik.com  |  http://www.radik.com

Re: Patch: Virtual Destructors patch

Posted by Andy Heninger <an...@jtcsv.com>.
The patches to classes NameIdPoolEnumerator and HashXMLCh are in (or will
be momentarily).  DOM_Entity is a different case, though.  The problem
here is that the other methods of the class should not have been virtual
in the first place.  DOM_* classes are supposed to all just be a single
pointer in size (to the impl class), with no virutal functions at all.

Andy Heninger
IBM XML Technology Group, Cupertino, CA
heninger@us.ibm.com


----- Original Message -----
From: "Kirk Wylie" <ki...@kidar.org>
To: <xe...@xml.apache.org>
Sent: Friday, September 08, 2000 3:41 PM
Subject: Patch: Virtual Destructors patch


> There are three classes (NameIdPoolEnumerator, DOM_Entity, and
> HashXMLCh) which compiling with g++ (2.95.2) discovered had:
> 1) Virtual methods,
> but
> 2) No virtual destructors.
> I've looked at the actual destructors in question, and they don't seem
> to actually DO anything. But without an entry in the virtual table in
> the destructor, there's a very high likelihood that things won't
> properly be destroyed further up the chain.
>
> In any case, It's a warning which is easy to avoid.
>
> The attached patch, applied to the .../xml-xerces/c/src directory on the
> current HEAD revision, will resolve these issues and compile cleanly
> using g++.
>
> Also, as a note, in looking at NameIdPoolEnumerator<>, the class has
> concrete instantiations of pure virtual methods from XMLEnumerator<>. I
> believe that the C++ standard is to make these virtual, but it might
> make sense for someone more familiar with the code to examine these
> methods (hasMoreElements() and nextElement()) to make sure that the code
> is properly written.
>
> Kirk Wylie
> --
> Kirk Wylie  |  mailto:kirk@radik.com  |  http://www.radik.com


--------------------------------------------------------------------------
------


> Index: dom/DOM_Entity.hpp
> ===================================================================
> RCS file: /home/cvspublic/xml-xerces/c/src/dom/DOM_Entity.hpp,v
> retrieving revision 1.7
> diff -u -r1.7 DOM_Entity.hpp
> --- dom/DOM_Entity.hpp 2000/04/19 02:26:16 1.7
> +++ dom/DOM_Entity.hpp 2000/09/08 16:27:22
> @@ -155,7 +155,7 @@
>     * Destructor for DOM_Entity.
>     *
>     */
> -    ~DOM_Entity();
> +    virtual ~DOM_Entity();
>
>      //@}
>      /** @name Get functions. */
> Index: util/HashXMLCh.hpp
> ===================================================================
> RCS file: /home/cvspublic/xml-xerces/c/src/util/HashXMLCh.hpp,v
> retrieving revision 1.1
> diff -u -r1.1 HashXMLCh.hpp
> --- util/HashXMLCh.hpp 2000/06/27 22:06:17 1.1
> +++ util/HashXMLCh.hpp 2000/09/08 16:27:23
> @@ -72,7 +72,7 @@
>  {
>  public:
>   HashXMLCh();
> - ~HashXMLCh();
> + virtual ~HashXMLCh();
>   virtual unsigned int getHashVal(const void *const key, unsigned int
mod);
>   virtual bool equals(const void *const key1, const void *const key2);
>
> Index: util/NameIdPool.hpp
> ===================================================================
> RCS file: /home/cvspublic/xml-xerces/c/src/util/NameIdPool.hpp,v
> retrieving revision 1.5
> diff -u -r1.5 NameIdPool.hpp
> --- util/NameIdPool.hpp 2000/07/19 18:47:26 1.5
> +++ util/NameIdPool.hpp 2000/09/08 16:27:24
> @@ -259,7 +259,7 @@
>          const   NameIdPoolEnumerator<TElem>& toCopy
>      );
>
> -    ~NameIdPoolEnumerator();
> +    virtual ~NameIdPoolEnumerator();
>
>





// -----------------------------------------------------------------------
>      //  Public operators
>