# HG changeset patch # User asl # Date 1129459036 0 # Node ID a5ff5a2c3e53379c53c1b07e744a01d5bb34371c # Parent 2ae48600be8b20e6facd889ef7536610af89688f * 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. diff --git a/packages/infra/current/ChangeLog b/packages/infra/current/ChangeLog --- a/packages/infra/current/ChangeLog +++ b/packages/infra/current/ChangeLog @@ -1,3 +1,15 @@ +2005-10-16 Andrew Lunn + + * 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 + + * 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 * include/cyg_ass.h: Fixed a function prototype so that diff --git a/packages/infra/current/cdl/infra.cdl b/packages/infra/current/cdl/infra.cdl --- 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 { diff --git a/packages/infra/current/src/delete.cxx b/packages/infra/current/src/delete.cxx --- 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 #include +#include // 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 diff --git a/packages/infra/current/src/simple.cxx b/packages/infra/current/src/simple.cxx --- 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;