made wxDELETE[A]() template functions instead of macros; they now also check that their argument is fully declared (#9685)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54940 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -611,15 +611,33 @@ typedef short int WXTYPE;
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* delete pointer if it is not NULL and NULL it afterwards */
|
#ifdef __cplusplus
|
||||||
/* (checking that it's !NULL before passing it to delete is just a */
|
// delete pointer if it is not NULL and NULL it afterwards
|
||||||
/* a question of style, because delete will do it itself anyhow, but it might */
|
template <typename T>
|
||||||
/* be considered as an error by some overzealous debugging implementations of */
|
inline void wxDELETE(T*& ptr)
|
||||||
/* the library, so we do it ourselves) */
|
{
|
||||||
#define wxDELETE(p) if ( (p) != NULL ) { delete p; p = NULL; }
|
typedef char TypeIsCompleteCheck[sizeof(T)];
|
||||||
|
|
||||||
/* delete an array and NULL it (see comments above) */
|
if ( ptr != NULL )
|
||||||
#define wxDELETEA(p) if ( (p) ) { delete [] (p); p = NULL; }
|
{
|
||||||
|
delete ptr;
|
||||||
|
ptr = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete an array and NULL it (see comments above)
|
||||||
|
template <typename T>
|
||||||
|
inline void wxDELETEA(T*& ptr)
|
||||||
|
{
|
||||||
|
typedef char TypeIsCompleteCheck[sizeof(T)];
|
||||||
|
|
||||||
|
if ( ptr != NULL )
|
||||||
|
{
|
||||||
|
delete [] ptr;
|
||||||
|
ptr = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /*__cplusplus*/
|
||||||
|
|
||||||
/* size of statically declared array */
|
/* size of statically declared array */
|
||||||
#define WXSIZEOF(array) (sizeof(array)/sizeof(array[0]))
|
#define WXSIZEOF(array) (sizeof(array)/sizeof(array[0]))
|
||||||
|
@@ -71,6 +71,7 @@ TEST_OBJECTS = \
|
|||||||
test_longlongtest.o \
|
test_longlongtest.o \
|
||||||
test_convautotest.o \
|
test_convautotest.o \
|
||||||
test_mbconvtest.o \
|
test_mbconvtest.o \
|
||||||
|
test_misctests.o \
|
||||||
test_ipc.o \
|
test_ipc.o \
|
||||||
test_regextest.o \
|
test_regextest.o \
|
||||||
test_wxregextest.o \
|
test_wxregextest.o \
|
||||||
@@ -395,6 +396,9 @@ test_convautotest.o: $(srcdir)/mbconv/convautotest.cpp $(TEST_ODEP)
|
|||||||
test_mbconvtest.o: $(srcdir)/mbconv/mbconvtest.cpp $(TEST_ODEP)
|
test_mbconvtest.o: $(srcdir)/mbconv/mbconvtest.cpp $(TEST_ODEP)
|
||||||
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/mbconv/mbconvtest.cpp
|
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/mbconv/mbconvtest.cpp
|
||||||
|
|
||||||
|
test_misctests.o: $(srcdir)/misc/misctests.cpp $(TEST_ODEP)
|
||||||
|
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/misc/misctests.cpp
|
||||||
|
|
||||||
test_ipc.o: $(srcdir)/net/ipc.cpp $(TEST_ODEP)
|
test_ipc.o: $(srcdir)/net/ipc.cpp $(TEST_ODEP)
|
||||||
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/net/ipc.cpp
|
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/net/ipc.cpp
|
||||||
|
|
||||||
|
@@ -57,6 +57,7 @@ TEST_OBJECTS = \
|
|||||||
$(OBJS)\test_longlongtest.obj \
|
$(OBJS)\test_longlongtest.obj \
|
||||||
$(OBJS)\test_convautotest.obj \
|
$(OBJS)\test_convautotest.obj \
|
||||||
$(OBJS)\test_mbconvtest.obj \
|
$(OBJS)\test_mbconvtest.obj \
|
||||||
|
$(OBJS)\test_misctests.obj \
|
||||||
$(OBJS)\test_ipc.obj \
|
$(OBJS)\test_ipc.obj \
|
||||||
$(OBJS)\test_regextest.obj \
|
$(OBJS)\test_regextest.obj \
|
||||||
$(OBJS)\test_wxregextest.obj \
|
$(OBJS)\test_wxregextest.obj \
|
||||||
@@ -424,6 +425,9 @@ $(OBJS)\test_convautotest.obj: .\mbconv\convautotest.cpp
|
|||||||
$(OBJS)\test_mbconvtest.obj: .\mbconv\mbconvtest.cpp
|
$(OBJS)\test_mbconvtest.obj: .\mbconv\mbconvtest.cpp
|
||||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\mbconv\mbconvtest.cpp
|
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\mbconv\mbconvtest.cpp
|
||||||
|
|
||||||
|
$(OBJS)\test_misctests.obj: .\misc\misctests.cpp
|
||||||
|
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\misc\misctests.cpp
|
||||||
|
|
||||||
$(OBJS)\test_ipc.obj: .\net\ipc.cpp
|
$(OBJS)\test_ipc.obj: .\net\ipc.cpp
|
||||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\net\ipc.cpp
|
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\net\ipc.cpp
|
||||||
|
|
||||||
|
@@ -49,6 +49,7 @@ TEST_OBJECTS = \
|
|||||||
$(OBJS)\test_longlongtest.o \
|
$(OBJS)\test_longlongtest.o \
|
||||||
$(OBJS)\test_convautotest.o \
|
$(OBJS)\test_convautotest.o \
|
||||||
$(OBJS)\test_mbconvtest.o \
|
$(OBJS)\test_mbconvtest.o \
|
||||||
|
$(OBJS)\test_misctests.o \
|
||||||
$(OBJS)\test_ipc.o \
|
$(OBJS)\test_ipc.o \
|
||||||
$(OBJS)\test_regextest.o \
|
$(OBJS)\test_regextest.o \
|
||||||
$(OBJS)\test_wxregextest.o \
|
$(OBJS)\test_wxregextest.o \
|
||||||
@@ -402,6 +403,9 @@ $(OBJS)\test_convautotest.o: ./mbconv/convautotest.cpp
|
|||||||
$(OBJS)\test_mbconvtest.o: ./mbconv/mbconvtest.cpp
|
$(OBJS)\test_mbconvtest.o: ./mbconv/mbconvtest.cpp
|
||||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||||
|
|
||||||
|
$(OBJS)\test_misctests.o: ./misc/misctests.cpp
|
||||||
|
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||||
|
|
||||||
$(OBJS)\test_ipc.o: ./net/ipc.cpp
|
$(OBJS)\test_ipc.o: ./net/ipc.cpp
|
||||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||||
|
|
||||||
|
@@ -50,6 +50,7 @@ TEST_OBJECTS = \
|
|||||||
$(OBJS)\test_longlongtest.obj \
|
$(OBJS)\test_longlongtest.obj \
|
||||||
$(OBJS)\test_convautotest.obj \
|
$(OBJS)\test_convautotest.obj \
|
||||||
$(OBJS)\test_mbconvtest.obj \
|
$(OBJS)\test_mbconvtest.obj \
|
||||||
|
$(OBJS)\test_misctests.obj \
|
||||||
$(OBJS)\test_ipc.obj \
|
$(OBJS)\test_ipc.obj \
|
||||||
$(OBJS)\test_regextest.obj \
|
$(OBJS)\test_regextest.obj \
|
||||||
$(OBJS)\test_wxregextest.obj \
|
$(OBJS)\test_wxregextest.obj \
|
||||||
@@ -509,6 +510,9 @@ $(OBJS)\test_convautotest.obj: .\mbconv\convautotest.cpp
|
|||||||
$(OBJS)\test_mbconvtest.obj: .\mbconv\mbconvtest.cpp
|
$(OBJS)\test_mbconvtest.obj: .\mbconv\mbconvtest.cpp
|
||||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\mbconv\mbconvtest.cpp
|
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\mbconv\mbconvtest.cpp
|
||||||
|
|
||||||
|
$(OBJS)\test_misctests.obj: .\misc\misctests.cpp
|
||||||
|
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\misc\misctests.cpp
|
||||||
|
|
||||||
$(OBJS)\test_ipc.obj: .\net\ipc.cpp
|
$(OBJS)\test_ipc.obj: .\net\ipc.cpp
|
||||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\net\ipc.cpp
|
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\net\ipc.cpp
|
||||||
|
|
||||||
|
@@ -262,6 +262,7 @@ TEST_OBJECTS = &
|
|||||||
$(OBJS)\test_longlongtest.obj &
|
$(OBJS)\test_longlongtest.obj &
|
||||||
$(OBJS)\test_convautotest.obj &
|
$(OBJS)\test_convautotest.obj &
|
||||||
$(OBJS)\test_mbconvtest.obj &
|
$(OBJS)\test_mbconvtest.obj &
|
||||||
|
$(OBJS)\test_misctests.obj &
|
||||||
$(OBJS)\test_ipc.obj &
|
$(OBJS)\test_ipc.obj &
|
||||||
$(OBJS)\test_regextest.obj &
|
$(OBJS)\test_regextest.obj &
|
||||||
$(OBJS)\test_wxregextest.obj &
|
$(OBJS)\test_wxregextest.obj &
|
||||||
@@ -455,6 +456,9 @@ $(OBJS)\test_convautotest.obj : .AUTODEPEND .\mbconv\convautotest.cpp
|
|||||||
$(OBJS)\test_mbconvtest.obj : .AUTODEPEND .\mbconv\mbconvtest.cpp
|
$(OBJS)\test_mbconvtest.obj : .AUTODEPEND .\mbconv\mbconvtest.cpp
|
||||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||||
|
|
||||||
|
$(OBJS)\test_misctests.obj : .AUTODEPEND .\misc\misctests.cpp
|
||||||
|
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||||
|
|
||||||
$(OBJS)\test_ipc.obj : .AUTODEPEND .\net\ipc.cpp
|
$(OBJS)\test_ipc.obj : .AUTODEPEND .\net\ipc.cpp
|
||||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||||
|
|
||||||
|
71
tests/misc/misctests.cpp
Normal file
71
tests/misc/misctests.cpp
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: tests/misc/misctests.cpp
|
||||||
|
// Purpose: test miscellaneous stuff
|
||||||
|
// Author: Peter Most
|
||||||
|
// Created: 2008-07-10
|
||||||
|
// RCS-ID: $Id$
|
||||||
|
// Copyright: (c) 2008 Peter Most
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// headers
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "testprec.h"
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// test class
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class MiscTestCase : public CppUnit::TestCase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MiscTestCase() { }
|
||||||
|
|
||||||
|
private:
|
||||||
|
CPPUNIT_TEST_SUITE( MiscTestCase );
|
||||||
|
CPPUNIT_TEST( Delete );
|
||||||
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
|
void Delete();
|
||||||
|
|
||||||
|
DECLARE_NO_COPY_CLASS(MiscTestCase)
|
||||||
|
};
|
||||||
|
|
||||||
|
// register in the unnamed registry so that these tests are run by default
|
||||||
|
CPPUNIT_TEST_SUITE_REGISTRATION( MiscTestCase );
|
||||||
|
|
||||||
|
// also include in it's own registry so that these tests can be run alone
|
||||||
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MiscTestCase, "MiscTestCase" );
|
||||||
|
|
||||||
|
void MiscTestCase::Delete()
|
||||||
|
{
|
||||||
|
// Allocate some arbitrary memory to get a valid pointer:
|
||||||
|
long *pointer = new long;
|
||||||
|
CPPUNIT_ASSERT( pointer != NULL );
|
||||||
|
|
||||||
|
// Check that wxDELETE sets the pointer to NULL:
|
||||||
|
wxDELETE( pointer );
|
||||||
|
CPPUNIT_ASSERT( pointer == NULL );
|
||||||
|
|
||||||
|
// Allocate some arbitrary array to get a valid pointer:
|
||||||
|
long *array = new long[ 3 ];
|
||||||
|
CPPUNIT_ASSERT( array != NULL );
|
||||||
|
|
||||||
|
// Check that wxDELETEA sets the pointer to NULL:
|
||||||
|
wxDELETE( array );
|
||||||
|
CPPUNIT_ASSERT( array == NULL );
|
||||||
|
|
||||||
|
// this results in compilation error, as it should
|
||||||
|
#if 0
|
||||||
|
struct SomeUnknownStruct *p = NULL;
|
||||||
|
wxDELETE(p);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
@@ -43,6 +43,7 @@
|
|||||||
longlong/longlongtest.cpp
|
longlong/longlongtest.cpp
|
||||||
mbconv/convautotest.cpp
|
mbconv/convautotest.cpp
|
||||||
mbconv/mbconvtest.cpp
|
mbconv/mbconvtest.cpp
|
||||||
|
misc/misctests.cpp
|
||||||
net/ipc.cpp
|
net/ipc.cpp
|
||||||
regex/regextest.cpp
|
regex/regextest.cpp
|
||||||
regex/wxregextest.cpp
|
regex/wxregextest.cpp
|
||||||
|
@@ -361,6 +361,10 @@ SOURCE=.\streams\memstream.cpp
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\misc\misctests.cpp
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\thread\queue.cpp
|
SOURCE=.\thread\queue.cpp
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
@@ -760,6 +760,8 @@
|
|||||||
RelativePath=".\mbconv\mbconvtest.cpp"/>
|
RelativePath=".\mbconv\mbconvtest.cpp"/>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\streams\memstream.cpp"/>
|
RelativePath=".\streams\memstream.cpp"/>
|
||||||
|
<File
|
||||||
|
RelativePath=".\misc\misctests.cpp"/>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\thread\queue.cpp"/>
|
RelativePath=".\thread\queue.cpp"/>
|
||||||
<File
|
<File
|
||||||
|
@@ -965,6 +965,9 @@
|
|||||||
<File
|
<File
|
||||||
RelativePath=".\streams\memstream.cpp"
|
RelativePath=".\streams\memstream.cpp"
|
||||||
/>
|
/>
|
||||||
|
<File
|
||||||
|
RelativePath=".\misc\misctests.cpp"
|
||||||
|
/>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\thread\queue.cpp"
|
RelativePath=".\thread\queue.cpp"
|
||||||
/>
|
/>
|
||||||
|
Reference in New Issue
Block a user