Home | History | Annotate | Download | only in memcheck
      1 #  ***********************************************************************
      2 #  * COPYRIGHT:
      3 #  * Copyright (c) 2004-2006, International Business Machines Corporation
      4 #  * and others. All Rights Reserved.
      5 #  ***********************************************************************
      6 #
      7 # This perl script checks for correct memory function usage in ICU library code.
      8 # It works with Linux builds of ICU using gcc.
      9 #
     10 #  To run it,
     11 #    1.  Build ICU
     12 #    2.  cd  icu/source
     13 #    3.  perl ICUMemCheck.pl
     14 #
     15 #  All object files containing direct references to C or C++ runtime library memory
     16 #    functions will be listed in the output.
     17 #
     18 #  For ICU 3.6, the expected output is
     19 #    common/uniset.o          U operator delete(void*)
     20 #    common/unifilt.o         U operator delete(void*)
     21 #    common/cmemory.o         U malloc
     22 #    common/cmemory.o         U free
     23 #    i18n/strrepl.o           U operator delete(void*)
     24 #    layout/LEFontInstance.o         U operator delete(void*)
     25 #    layout/LEGlyphStorage.o         U operator delete(void*)
     26 #    layout/LayoutEngine.o    U operator delete(void*)
     27 #
     28 #  cmemory.c          Expected failures from uprv_malloc, uprv_free implementation.
     29 #  uniset.cpp         Fails because of SymbolTable::~SymbolTable()
     30 #  unifilt.cpp        Fails because of UnicodeMatcher::~UnicodeMatcher()
     31 #  strrepl.cpp        Fails because of UnicodeReplacer::~UnicodeReplacer()
     32 #  LayoutEngine.cpp   Fails because of LEGlyphFilter::~LEGlyphFilter()
     33 #  LEGlyphStorage.cpp Fails because of LEInsertionCallback::~LEInsertionCallback()
     34 #  LEFontInstance.cpp Fails because of LECharMapper::~LECharMapper
     35 #
     36 #  To verify that no additional problems exist in the .cpp files, #ifdef out the
     37 #  offending destructors, rebuild icu, and re-run the tool.  The problems should
     38 #  be gone.
     39 #
     40 #  The problem destructors all are for mix-in style interface classes.
     41 #  These classes can not derive from UObject or UMemory because of multiple-inheritance
     42 #  problems, so they don't get the ICU memory functions.  The delete code
     43 #  in the destructors will never be called because stand-alone instances of
     44 #  the classes cannot exist.
     45 #
     46 $fileNames = `find common i18n layout io -name "*.o" -print`;
     47 foreach $f (split('\n', $fileNames)) {
     48    $symbols = `nm -u -C $f`;
     49    if ($symbols =~ /U +operator delete\(void\*\)/) {
     50       print "$f 	$&\n";
     51    }
     52    if ($symbols =~ /U +operator delete\[\]\(void\*\)/) {
     53       print "$f 	$&\n";
     54    }
     55    if ($symbols =~ /U +operator new\(unsigned int\)/) {
     56       print "$f 	$&\n";
     57    }
     58    if ($symbols =~ /U +operator new\[\]\(unsigned int\)/) {
     59       print "$f 	$&\n";
     60    }
     61    if ($symbols =~ /U +malloc.*/) {
     62       print "$f 	$&\n";
     63    }
     64    if ($symbols =~ /U +free.*/) {
     65       print "$f 	$&\n";
     66    }
     67 
     68 }
     69