michael@0: # *********************************************************************** michael@0: # * COPYRIGHT: michael@0: # * Copyright (c) 2004-2006, International Business Machines Corporation michael@0: # * and others. All Rights Reserved. michael@0: # *********************************************************************** michael@0: # michael@0: # This perl script checks for correct memory function usage in ICU library code. michael@0: # It works with Linux builds of ICU using gcc. michael@0: # michael@0: # To run it, michael@0: # 1. Build ICU michael@0: # 2. cd icu/source michael@0: # 3. perl ICUMemCheck.pl michael@0: # michael@0: # All object files containing direct references to C or C++ runtime library memory michael@0: # functions will be listed in the output. michael@0: # michael@0: # For ICU 3.6, the expected output is michael@0: # common/uniset.o U operator delete(void*) michael@0: # common/unifilt.o U operator delete(void*) michael@0: # common/cmemory.o U malloc michael@0: # common/cmemory.o U free michael@0: # i18n/strrepl.o U operator delete(void*) michael@0: # layout/LEFontInstance.o U operator delete(void*) michael@0: # layout/LEGlyphStorage.o U operator delete(void*) michael@0: # layout/LayoutEngine.o U operator delete(void*) michael@0: # michael@0: # cmemory.c Expected failures from uprv_malloc, uprv_free implementation. michael@0: # uniset.cpp Fails because of SymbolTable::~SymbolTable() michael@0: # unifilt.cpp Fails because of UnicodeMatcher::~UnicodeMatcher() michael@0: # strrepl.cpp Fails because of UnicodeReplacer::~UnicodeReplacer() michael@0: # LayoutEngine.cpp Fails because of LEGlyphFilter::~LEGlyphFilter() michael@0: # LEGlyphStorage.cpp Fails because of LEInsertionCallback::~LEInsertionCallback() michael@0: # LEFontInstance.cpp Fails because of LECharMapper::~LECharMapper michael@0: # michael@0: # To verify that no additional problems exist in the .cpp files, #ifdef out the michael@0: # offending destructors, rebuild icu, and re-run the tool. The problems should michael@0: # be gone. michael@0: # michael@0: # The problem destructors all are for mix-in style interface classes. michael@0: # These classes can not derive from UObject or UMemory because of multiple-inheritance michael@0: # problems, so they don't get the ICU memory functions. The delete code michael@0: # in the destructors will never be called because stand-alone instances of michael@0: # the classes cannot exist. michael@0: # michael@0: $fileNames = `find common i18n layout io -name "*.o" -print`; michael@0: foreach $f (split('\n', $fileNames)) { michael@0: $symbols = `nm -u -C $f`; michael@0: if ($symbols =~ /U +operator delete\(void\*\)/) { michael@0: print "$f $&\n"; michael@0: } michael@0: if ($symbols =~ /U +operator delete\[\]\(void\*\)/) { michael@0: print "$f $&\n"; michael@0: } michael@0: if ($symbols =~ /U +operator new\(unsigned int\)/) { michael@0: print "$f $&\n"; michael@0: } michael@0: if ($symbols =~ /U +operator new\[\]\(unsigned int\)/) { michael@0: print "$f $&\n"; michael@0: } michael@0: if ($symbols =~ /U +malloc.*/) { michael@0: print "$f $&\n"; michael@0: } michael@0: if ($symbols =~ /U +free.*/) { michael@0: print "$f $&\n"; michael@0: } michael@0: michael@0: }