intl/icu/source/tools/memcheck/ICUMemCheck.pl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/tools/memcheck/ICUMemCheck.pl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     1.4 +#  ***********************************************************************
     1.5 +#  * COPYRIGHT:
     1.6 +#  * Copyright (c) 2004-2006, International Business Machines Corporation
     1.7 +#  * and others. All Rights Reserved.
     1.8 +#  ***********************************************************************
     1.9 +#
    1.10 +# This perl script checks for correct memory function usage in ICU library code.
    1.11 +# It works with Linux builds of ICU using gcc.
    1.12 +#
    1.13 +#  To run it,
    1.14 +#    1.  Build ICU
    1.15 +#    2.  cd  icu/source
    1.16 +#    3.  perl ICUMemCheck.pl
    1.17 +#
    1.18 +#  All object files containing direct references to C or C++ runtime library memory
    1.19 +#    functions will be listed in the output.
    1.20 +#
    1.21 +#  For ICU 3.6, the expected output is
    1.22 +#    common/uniset.o          U operator delete(void*)
    1.23 +#    common/unifilt.o         U operator delete(void*)
    1.24 +#    common/cmemory.o         U malloc
    1.25 +#    common/cmemory.o         U free
    1.26 +#    i18n/strrepl.o           U operator delete(void*)
    1.27 +#    layout/LEFontInstance.o         U operator delete(void*)
    1.28 +#    layout/LEGlyphStorage.o         U operator delete(void*)
    1.29 +#    layout/LayoutEngine.o    U operator delete(void*)
    1.30 +#
    1.31 +#  cmemory.c          Expected failures from uprv_malloc, uprv_free implementation.
    1.32 +#  uniset.cpp         Fails because of SymbolTable::~SymbolTable()
    1.33 +#  unifilt.cpp        Fails because of UnicodeMatcher::~UnicodeMatcher()
    1.34 +#  strrepl.cpp        Fails because of UnicodeReplacer::~UnicodeReplacer()
    1.35 +#  LayoutEngine.cpp   Fails because of LEGlyphFilter::~LEGlyphFilter()
    1.36 +#  LEGlyphStorage.cpp Fails because of LEInsertionCallback::~LEInsertionCallback()
    1.37 +#  LEFontInstance.cpp Fails because of LECharMapper::~LECharMapper
    1.38 +#
    1.39 +#  To verify that no additional problems exist in the .cpp files, #ifdef out the
    1.40 +#  offending destructors, rebuild icu, and re-run the tool.  The problems should
    1.41 +#  be gone.
    1.42 +#
    1.43 +#  The problem destructors all are for mix-in style interface classes.
    1.44 +#  These classes can not derive from UObject or UMemory because of multiple-inheritance
    1.45 +#  problems, so they don't get the ICU memory functions.  The delete code
    1.46 +#  in the destructors will never be called because stand-alone instances of
    1.47 +#  the classes cannot exist.
    1.48 +#
    1.49 +$fileNames = `find common i18n layout io -name "*.o" -print`;
    1.50 +foreach $f (split('\n', $fileNames)) {
    1.51 +   $symbols = `nm -u -C $f`;
    1.52 +   if ($symbols =~ /U +operator delete\(void\*\)/) {
    1.53 +      print "$f 	$&\n";
    1.54 +   }
    1.55 +   if ($symbols =~ /U +operator delete\[\]\(void\*\)/) {
    1.56 +      print "$f 	$&\n";
    1.57 +   }
    1.58 +   if ($symbols =~ /U +operator new\(unsigned int\)/) {
    1.59 +      print "$f 	$&\n";
    1.60 +   }
    1.61 +   if ($symbols =~ /U +operator new\[\]\(unsigned int\)/) {
    1.62 +      print "$f 	$&\n";
    1.63 +   }
    1.64 +   if ($symbols =~ /U +malloc.*/) {
    1.65 +      print "$f 	$&\n";
    1.66 +   }
    1.67 +   if ($symbols =~ /U +free.*/) {
    1.68 +      print "$f 	$&\n";
    1.69 +   }
    1.70 +
    1.71 +}

mercurial