]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/memcheck/ICUMemCheck.pl
1 # Copyright (C) 2016 and later: Unicode, Inc. and others.
2 # License & terms of use: http://www.unicode.org/copyright.html
3 # ***********************************************************************
5 # * Copyright (c) 2004-2006, International Business Machines Corporation
6 # * and others. All Rights Reserved.
7 # ***********************************************************************
9 # This perl script checks for correct memory function usage in ICU library code.
10 # It works with Linux builds of ICU using clang or gcc.
15 # 3. perl tools/memcheck/ICUMemCheck.pl
17 # All object files containing direct references to C or C++ runtime library memory
18 # functions will be listed in the output.
20 # For ICU 58, the expected output is
21 # common/uniset.o U operator delete(void*)
22 # common/unifilt.o U operator delete(void*)
23 # common/cmemory.o U malloc
24 # common/cmemory.o U free
25 # i18n/strrepl.o U operator delete(void*)
27 # cmemory.c Expected failures from uprv_malloc, uprv_free implementation.
28 # uniset.cpp Fails because of SymbolTable::~SymbolTable()
29 # unifilt.cpp Fails because of UnicodeMatcher::~UnicodeMatcher()
30 # strrepl.cpp Fails because of UnicodeReplacer::~UnicodeReplacer()
32 # To verify that no additional problems exist in the .cpp files, #ifdef out the
33 # offending destructors, rebuild icu, and re-run the tool. The problems should
36 # The problem destructors all are for mix-in style interface classes.
37 # These classes can not derive from UObject or UMemory because of multiple-inheritance
38 # problems, so they don't get the ICU memory functions. The delete code
39 # in the destructors will never be called because stand-alone instances of
40 # the classes cannot exist.
42 $fileNames = `find common i18n io -name "*.o" -print`;
43 foreach $f (split('\n', $fileNames)) {
44 $symbols = `nm -u -C $f`;
45 if ($symbols =~ /U +operator delete\(void\*\)/) {
48 if ($symbols =~ /U +operator delete\[\]\(void\*\)/) {
51 if ($symbols =~ /U +operator new\(unsigned int\)/) {
54 if ($symbols =~ /U +operator new\[\]\(unsigned int\)/) {
57 if ($symbols =~ /U +malloc.*/) {
60 if ($symbols =~ /(?m:U +free$)/) {