Mercurial > ecos
changeset 2080:a5ff5a2c3e53
* 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.
* src/simple.cxx (cyg_check_func_ptr): match the implementation to
the prototype. This got forgotten in the last patch.
| author | asl |
|---|---|
| date | Sun, 16 Oct 2005 10:37:16 +0000 |
| parents | 2ae48600be8b |
| children | c9aa7b9d7e41 |
| files | packages/infra/current/ChangeLog packages/infra/current/cdl/infra.cdl packages/infra/current/src/delete.cxx packages/infra/current/src/simple.cxx |
| diffstat | 4 files changed, 45 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/infra/current/ChangeLog +++ b/packages/infra/current/ChangeLog @@ -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
--- a/packages/infra/current/cdl/infra.cdl +++ b/packages/infra/current/cdl/infra.cdl @@ -177,6 +177,20 @@ cdl_package CYGPKG_INFRA { 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 {
--- a/packages/infra/current/src/delete.cxx +++ b/packages/infra/current/src/delete.cxx @@ -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
--- a/packages/infra/current/src/simple.cxx +++ b/packages/infra/current/src/simple.cxx @@ -544,7 +544,7 @@ externC cyg_bool cyg_check_data_ptr(cons 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;
