]> git.saurik.com Git - apple/icu.git/blame - icuSources/tools/memcheck/ICUMemCheck.pl
ICU-66108.tar.gz
[apple/icu.git] / icuSources / tools / memcheck / ICUMemCheck.pl
CommitLineData
f3c0d7a5
A
1# Copyright (C) 2016 and later: Unicode, Inc. and others.
2# License & terms of use: http://www.unicode.org/copyright.html
73c04bcf
A
3# ***********************************************************************
4# * COPYRIGHT:
5# * Copyright (c) 2004-2006, International Business Machines Corporation
6# * and others. All Rights Reserved.
7# ***********************************************************************
8#
9# This perl script checks for correct memory function usage in ICU library code.
f3c0d7a5 10# It works with Linux builds of ICU using clang or gcc.
73c04bcf
A
11#
12# To run it,
13# 1. Build ICU
14# 2. cd icu/source
f3c0d7a5 15# 3. perl tools/memcheck/ICUMemCheck.pl
73c04bcf
A
16#
17# All object files containing direct references to C or C++ runtime library memory
18# functions will be listed in the output.
19#
f3c0d7a5 20# For ICU 58, the expected output is
73c04bcf
A
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*)
73c04bcf
A
26#
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()
73c04bcf
A
31#
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
34# be gone.
35#
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.
41#
f3c0d7a5 42$fileNames = `find common i18n io -name "*.o" -print`;
73c04bcf
A
43foreach $f (split('\n', $fileNames)) {
44 $symbols = `nm -u -C $f`;
45 if ($symbols =~ /U +operator delete\(void\*\)/) {
46 print "$f $&\n";
47 }
48 if ($symbols =~ /U +operator delete\[\]\(void\*\)/) {
49 print "$f $&\n";
50 }
51 if ($symbols =~ /U +operator new\(unsigned int\)/) {
52 print "$f $&\n";
53 }
54 if ($symbols =~ /U +operator new\[\]\(unsigned int\)/) {
55 print "$f $&\n";
56 }
57 if ($symbols =~ /U +malloc.*/) {
58 print "$f $&\n";
59 }
f3c0d7a5 60 if ($symbols =~ /(?m:U +free$)/) {
73c04bcf
A
61 print "$f $&\n";
62 }
63
64}