empty delete warning and fixed simple cyg_check_func_ptr
Andrew Lunn
andrew@lunn.ch
Sun Oct 16 10:44:00 GMT 2005
Hi Folks
Attached is a patch which does two things....
It includes the patch from Laurent Gonzalez for src/simple.cxx
cyg_check_func_ptr(). The implementation and prototype did not match.
As mentioned in eCos discuss i adding a little bit of debug code to
the empty delete() functions. Some people don't realise that by
default delete simply does nothing. If INFRA_DEBUG is enabled i keep
account of how often delete is called. If this exceeds a threshold it
will now throw an assertion failure. This should point heavy users of
delete in the right direction while not affecting people who do want
an empty delete function.
Andrew
-------------- next part --------------
Index: infra/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/infra/current/ChangeLog,v
retrieving revision 1.51
diff -u -r1.51 ChangeLog
--- infra/current/ChangeLog 30 Jul 2005 11:48:54 -0000 1.51
+++ infra/current/ChangeLog 16 Oct 2005 10:36:35 -0000
@@ -1,3 +1,15 @@
+2005-10-16 Andrew Lunn <andrew.lunn@ascom.ch>
+
+ * src/delete.cxx:
+ * cdl/infra.cdl: Count the number of calls to delete when
+ INFRA_DEBUG is enabled. If the threshold is exceeded it probably
+ means the user expects a real delete function, not the empty one.
+
+2005-10-12 Laurent Gonzalez <laurent.gonzalez@trango-systems.com>
+
+ * src/simple.cxx (cyg_check_func_ptr): match the implementation to
+ the prototype. This got forgotten in the last patch.
+
2005-07-29 Andrew Lunn <andrew.lunn@ascom.ch>
* include/cyg_ass.h: Fixed a function prototype so that
Index: infra/current/cdl/infra.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/infra/current/cdl/infra.cdl,v
retrieving revision 1.12
diff -u -r1.12 infra.cdl
--- infra/current/cdl/infra.cdl 9 Feb 2005 10:19:56 -0000 1.12
+++ infra/current/cdl/infra.cdl 16 Oct 2005 10:36:36 -0000
@@ -177,6 +177,20 @@
so that new and delete can be used, if that is what is required."
}
+ cdl_option CYGNUM_INFRA_EMPTY_DELETE_THRESHOLD {
+ display "Threshold for valid number of delete calls"
+ default_value 100
+ active_if CYGPKG_INFRA_DEBUG
+ description "
+ Some users don't know about the empty delete function and then
+ wonder why there C++ classes are leaking memory. If
+ INFRA_DEBUG is enabled we keep a counter for the number of
+ times delete is called. If it goes above this threshold we throw
+ an assertion failure. This should point heavy users of
+ delete in the right direction without upsetting those who want
+ an empty delete function. "
+ }
+
# ========================================================================
cdl_option CYGFUN_INFRA_DUMMY_ABORT {
Index: infra/current/src/delete.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/infra/current/src/delete.cxx,v
retrieving revision 1.7
diff -u -r1.7 delete.cxx
--- infra/current/src/delete.cxx 23 May 2002 23:05:51 -0000 1.7
+++ infra/current/src/delete.cxx 16 Oct 2005 10:36:36 -0000
@@ -9,6 +9,7 @@
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2005 Andrew Lunn
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
@@ -57,6 +58,7 @@
#include <pkgconf/infra.h>
#include <cyg/infra/cyg_type.h>
+#include <cyg/infra/cyg_ass.h>
// see the description comment in infra.cdl for
// CYGFUN_INFRA_EMPTY_DELETE_FUNCTIONS
@@ -64,14 +66,30 @@
#ifdef CYGFUN_INFRA_EMPTY_DELETE_FUNCTIONS
// then define these empty functions:
+#ifdef CYGPKG_INFRA_DEBUG
+static cyg_uint32 counter;
+#endif
+
void operator delete(void *x) throw()
{
+#ifndef CYGPKG_INFRA_DEBUG
CYG_EMPTY_STATEMENT;
+#else
+ counter++;
+ CYG_ASSERT(counter < CYGNUM_INFRA_EMPTY_DELETE_THRESHOLD,
+ "Do you want an empty delete function?");
+#endif
}
void operator delete[](void *x) throw()
{
+#ifndef CYGPKG_INFRA_DEBUG
CYG_EMPTY_STATEMENT;
+#else
+ counter++;
+ CYG_ASSERT(counter < CYGNUM_INFRA_EMPTY_DELETE_THRESHOLD,
+ "Do you want an empty delete function?");
+#endif
}
#endif // CYGFUN_INFRA_EMPTY_DELETE_FUNCTIONS
Index: infra/current/src/simple.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/infra/current/src/simple.cxx,v
retrieving revision 1.12
diff -u -r1.12 simple.cxx
--- infra/current/src/simple.cxx 18 Jan 2003 04:18:27 -0000 1.12
+++ infra/current/src/simple.cxx 16 Oct 2005 10:36:37 -0000
@@ -544,7 +544,7 @@
return true;
}
-externC cyg_bool cyg_check_func_ptr(const void (*ptr)(void))
+externC cyg_bool cyg_check_func_ptr(void (*ptr)(void))
{
unsigned long p = (unsigned long)ptr;
More information about the Ecos-patches
mailing list