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 Neil Graham <ne...@ca.ibm.com> on 2003/06/03 00:05:34 UTC

in search of ideas: how might one write a test that the parser never calls global new directly?

Hi folks,

Now that we've implemented the new memory management framework, it would be
nice to have some confidence that we're using it correctly and
comprehensively.  I'll shortly commit some tests that exercise per-parser
handlers, and ensure that all memory that the handlers allocate is deleted,
and that it's deleted by the right handler.  But it's a little less clear
how we'd write a test to make sure that there aren't any places in the code
that are calling global new directly; i.e., it's not completely obvious (to
me anyway) how one tests that the pluggable mechanism is always used.

Anyone have some thoughts on how one might go about doing this in a
compiler/OS agnostic manner?

Cheers,
Neil
Neil Graham
XML Parser Development
IBM Toronto Lab
Phone:  905-413-3519, T/L 969-3519
E-mail:  neilg@ca.ibm.com



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: in search of ideas: how might one write a test that the parser never calls global new directly?

Posted by da...@us.ibm.com.



Hi Neil,

Since you're allowed to override global new/delete, why not put an empty
implementation within Xerces that calls the panic handler or the default
static MemoryManager, and logs a message?  I tried this on Win32 (with a
little massaging of the code), Linux, and AIX and it seems to work just
fine:

File NewHack.cpp:

   #include <cstdio>
   #include <cstdlib>
   #include <new>

   void*
   operator new( size_t size ) throw(std::bad_alloc)
   {
      fprintf(stderr, "Call to global new!!!!!!!!!!!\n");

      exit(-1);

      return 0;
   }

   void
   operator delete( void* ) throw()
   {
      fprintf(stderr, "Call to global delete!!!!!!!!!!!\n");

      exit(-1);
   }

File TestNew.cpp:

#include <new>

   int
   main(
           int                    argc,
           const char*  argv[])
   {
      int*  i = new int(5);

      delete i;

      return 0;
   }

You wouldn't want to do this in a production environment, since the library
might export the symbols for new and delete, which would affect users'
code, but for testing purposes, I think it will work.

Dave



                                                                                                                                          
                      "Neil Graham"                                                                                                       
                      <neilg@ca.ibm.co         To:      xerces-c-dev@xml.apache.org                                                       
                      m>                       cc:      (bcc: David N Bertoni/Cambridge/IBM)                                              
                                               Subject: in search of ideas:  how might one write a test that the parser never calls       
                      06/02/2003 03:05         global new directly?                                                                       
                      PM                                                                                                                  
                      Please respond                                                                                                      
                      to xerces-c-dev                                                                                                     
                                                                                                                                          



Hi folks,

Now that we've implemented the new memory management framework, it would be
nice to have some confidence that we're using it correctly and
comprehensively.  I'll shortly commit some tests that exercise per-parser
handlers, and ensure that all memory that the handlers allocate is deleted,
and that it's deleted by the right handler.  But it's a little less clear
how we'd write a test to make sure that there aren't any places in the code
that are calling global new directly; i.e., it's not completely obvious (to
me anyway) how one tests that the pluggable mechanism is always used.

Anyone have some thoughts on how one might go about doing this in a
compiler/OS agnostic manner?

Cheers,
Neil
Neil Graham
XML Parser Development
IBM Toronto Lab
Phone:  905-413-3519, T/L 969-3519
E-mail:  neilg@ca.ibm.com



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org