Re: [xml] Few Casts



On Thu, 2003-08-28 at 06:32, Igor Zlatkovic wrote:

I added few casts. MS compiler won't convert a const object to a non-const
one without displaying a warning. I'm tired of those warnings :-)

Is that okay with everyone?

xmlRealloc is a macro wrapper around xmlReallocLoc, which takes 'void *"
as its first parameter, right?  wouldn't casting to 'void *' be clearer
(the other looks like "casting away const", which would normally be ab
Bad Thing).  Since realloc operations really do treat the target of the
pointer as opaque, and therefore immutable, another option would be to
change the signature of xmlReallocLoc to:

  void* xmlReallocLoc(const void *ptr,size_t size, const char *file,
                      int line);

but then, that looks silly. Does MSWin have the extra 'const' in the
signature of its 'realloc'?  Or is the MS compiler parsing the const as
applying to the outer pointer, instead of the inmost primitive?  In that
case, we could create a typedef which forced the compiler to assign the
constness to the correct spot:

  typedef const xmlChar* xmlCharConstPtr;

and then declare 'nameTab' with that typedef.  Or we could move the
'const' to between 'xmlChar' and '*', which should disambiguate to
constness for VC++.  I think that this is actually more "correct", by
the language definition, but it always looks odd to me:

  xmlChar const* * nameTab;


Index: DOCBparser.c
===================================================================
RCS file: /cvs/gnome/libxml2/DOCBparser.c,v
retrieving revision 1.40
diff -c -r1.40 DOCBparser.c
*** DOCBparser.c 18 Aug 2003 12:15:32 -0000 1.40
--- DOCBparser.c 28 Aug 2003 10:28:08 -0000
***************
*** 118,124 ****
      if (ctxt->nameNr >= ctxt->nameMax) {
          ctxt->nameMax *= 2;
          ctxt->nameTab = (const xmlChar * *)
!                          xmlRealloc(ctxt->nameTab,
                                      ctxt->nameMax *
                                      sizeof(ctxt->nameTab[0]));
          if (ctxt->nameTab == NULL) {
--- 118,124 ----
      if (ctxt->nameNr >= ctxt->nameMax) {
          ctxt->nameMax *= 2;
          ctxt->nameTab = (const xmlChar * *)
!                          xmlRealloc((xmlChar * *)ctxt->nameTab,
                                      ctxt->nameMax *
                                      sizeof(ctxt->nameTab[0]));
          if (ctxt->nameTab == NULL) {
Index: HTMLparser.c
===================================================================
RCS file: /cvs/gnome/libxml2/HTMLparser.c,v
retrieving revision 1.155
diff -c -r1.155 HTMLparser.c
*** HTMLparser.c 18 Aug 2003 12:15:32 -0000 1.155
--- HTMLparser.c 28 Aug 2003 10:28:10 -0000
***************
*** 78,84 ****
      if (ctxt->nameNr >= ctxt->nameMax) {
          ctxt->nameMax *= 2;
          ctxt->nameTab = (const xmlChar * *)
!                          xmlRealloc(ctxt->nameTab,
                                      ctxt->nameMax *
                                      sizeof(ctxt->nameTab[0]));
          if (ctxt->nameTab == NULL) {
--- 78,84 ----
      if (ctxt->nameNr >= ctxt->nameMax) {
          ctxt->nameMax *= 2;
          ctxt->nameTab = (const xmlChar * *)
!                          xmlRealloc((xmlChar * *)ctxt->nameTab,
                                      ctxt->nameMax *
                                      sizeof(ctxt->nameTab[0]));
          if (ctxt->nameTab == NULL) {
Index: parser.c
===================================================================
RCS file: /cvs/gnome/libxml2/parser.c,v
retrieving revision 1.283
diff -c -r1.283 parser.c
*** parser.c 20 Aug 2003 22:54:38 -0000 1.283
--- parser.c 28 Aug 2003 10:28:13 -0000
***************
*** 254,260 ****
      if (ctxt->nameNr >= ctxt->nameMax) {
          ctxt->nameMax *= 2;
          ctxt->nameTab = (const xmlChar * *)
!                   xmlRealloc(ctxt->nameTab,
                                      ctxt->nameMax *
                                      sizeof(ctxt->nameTab[0]));
          if (ctxt->nameTab == NULL) {
--- 254,260 ----
      if (ctxt->nameNr >= ctxt->nameMax) {
          ctxt->nameMax *= 2;
          ctxt->nameTab = (const xmlChar * *)
!                   xmlRealloc((xmlChar * *)ctxt->nameTab,
                                      ctxt->nameMax *
                                      sizeof(ctxt->nameTab[0]));
          if (ctxt->nameTab == NULL) {
Index: parserInternals.c
===================================================================
RCS file: /cvs/gnome/libxml2/parserInternals.c,v
retrieving revision 1.78
diff -c -r1.78 parserInternals.c
*** parserInternals.c 19 Aug 2003 15:01:26 -0000 1.78
--- parserInternals.c 28 Aug 2003 10:28:14 -0000
***************
*** 2360,2366 ****
          xmlFreeInputStream(input);
      }
      if (ctxt->spaceTab != NULL) xmlFree(ctxt->spaceTab);
!     if (ctxt->nameTab != NULL) xmlFree(ctxt->nameTab);
      if (ctxt->nodeTab != NULL) xmlFree(ctxt->nodeTab);
      if (ctxt->inputTab != NULL) xmlFree(ctxt->inputTab);
      if (ctxt->version != NULL) xmlFree((char *) ctxt->version);
--- 2360,2366 ----
          xmlFreeInputStream(input);
      }
      if (ctxt->spaceTab != NULL) xmlFree(ctxt->spaceTab);
!     if (ctxt->nameTab != NULL) xmlFree((xmlChar * *)ctxt->nameTab);
      if (ctxt->nodeTab != NULL) xmlFree(ctxt->nodeTab);
      if (ctxt->inputTab != NULL) xmlFree(ctxt->inputTab);
      if (ctxt->version != NULL) xmlFree((char *) ctxt->version);
***************
*** 2371,2377 ****
          xmlFree(ctxt->sax);
      if (ctxt->directory != NULL) xmlFree((char *) ctxt->directory);
      if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab);
!     if (ctxt->atts != NULL) xmlFree(ctxt->atts);
      if (ctxt->dict != NULL) xmlDictFree(ctxt->dict);
  #ifdef LIBXML_CATALOG_ENABLED
      if (ctxt->catalogs != NULL)
--- 2371,2377 ----
          xmlFree(ctxt->sax);
      if (ctxt->directory != NULL) xmlFree((char *) ctxt->directory);
      if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab);
!     if (ctxt->atts != NULL) xmlFree((xmlChar * *)ctxt->atts);
      if (ctxt->dict != NULL) xmlDictFree(ctxt->dict);
  #ifdef LIBXML_CATALOG_ENABLED
      if (ctxt->catalogs != NULL)

Tres.
-- 
===============================================================
Tres Seaver                                tseaver zope com
Zope Corporation      "Zope Dealers"       http://www.zope.com




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]