~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/VMCore/LeaksContext.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===- LeaksContext.h - LeadDetector Implementation ------------*- C++ -*--===//
 
2
//
 
3
//                     The LLVM Compiler Infrastructure
 
4
//
 
5
// This file is distributed under the University of Illinois Open Source
 
6
// License. See LICENSE.TXT for details.
 
7
//
 
8
//===----------------------------------------------------------------------===//
 
9
//
 
10
//  This file defines various helper methods and classes used by
 
11
// LLVMContextImpl for leaks detectors.
 
12
//
 
13
//===----------------------------------------------------------------------===//
 
14
 
 
15
#include "llvm/Value.h"
 
16
#include "llvm/ADT/SmallPtrSet.h"
 
17
using namespace llvm;
 
18
 
 
19
template <class T>
 
20
struct PrinterTrait {
 
21
  static void print(const T* P) { errs() << P; }
 
22
};
 
23
 
 
24
template<>
 
25
struct PrinterTrait<Value> {
 
26
  static void print(const Value* P) { errs() << *P; }
 
27
};
 
28
 
 
29
template <typename T>
 
30
struct LeakDetectorImpl {
 
31
  explicit LeakDetectorImpl(const char* const name = "") : 
 
32
    Cache(0), Name(name) { }
 
33
 
 
34
  void clear() {
 
35
    Cache = 0;
 
36
    Ts.clear();
 
37
  }
 
38
    
 
39
  void setName(const char* n) { 
 
40
    Name = n;
 
41
  }
 
42
    
 
43
  // Because the most common usage pattern, by far, is to add a
 
44
  // garbage object, then remove it immediately, we optimize this
 
45
  // case.  When an object is added, it is not added to the set
 
46
  // immediately, it is added to the CachedValue Value.  If it is
 
47
  // immediately removed, no set search need be performed.
 
48
  void addGarbage(const T* o) {
 
49
    assert(Ts.count(o) == 0 && "Object already in set!");
 
50
    if (Cache) {
 
51
      assert(Cache != o && "Object already in set!");
 
52
      Ts.insert(Cache);
 
53
    }
 
54
    Cache = o;
 
55
  }
 
56
 
 
57
  void removeGarbage(const T* o) {
 
58
    if (o == Cache)
 
59
      Cache = 0; // Cache hit
 
60
    else
 
61
      Ts.erase(o);
 
62
  }
 
63
 
 
64
  bool hasGarbage(const std::string& Message) {
 
65
    addGarbage(0); // Flush the Cache
 
66
 
 
67
    assert(Cache == 0 && "No value should be cached anymore!");
 
68
 
 
69
    if (!Ts.empty()) {
 
70
      errs() << "Leaked " << Name << " objects found: " << Message << ":\n";
 
71
      for (typename SmallPtrSet<const T*, 8>::iterator I = Ts.begin(),
 
72
           E = Ts.end(); I != E; ++I) {
 
73
        errs() << '\t';
 
74
        PrinterTrait<T>::print(*I);
 
75
        errs() << '\n';
 
76
      }
 
77
      errs() << '\n';
 
78
 
 
79
      return true;
 
80
    }
 
81
    
 
82
    return false;
 
83
  }
 
84
 
 
85
private:
 
86
  SmallPtrSet<const T*, 8> Ts;
 
87
  const T* Cache;
 
88
  const char* Name;
 
89
};