~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/debug/demangle.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Inkscape::Debug::demangle - demangle C++ symbol names
 
3
 *
 
4
 * Authors:
 
5
 *   MenTaLguY <mental@rydia.net>
 
6
 *
 
7
 * Copyright (C) 2006 MenTaLguY
 
8
 *
 
9
 * Released under GNU GPL, read the file 'COPYING' for more information
 
10
 */
 
11
 
 
12
#include <stdio.h>
 
13
#include <string.h>
 
14
#include <map>
 
15
#include "debug/demangle.h"
 
16
#include "util/format.h"
 
17
#include "gc-alloc.h"
 
18
 
 
19
namespace Inkscape {
 
20
 
 
21
namespace Debug {
 
22
 
 
23
namespace {
 
24
 
 
25
char const *demangle_helper(char const *name) {
 
26
    char buffer[1024];
 
27
    char const *result;
 
28
    FILE *stream=popen(Util::format("c++filt %s", name), "r");
 
29
    if (fgets(buffer, sizeof(buffer), stream)) {
 
30
        size_t len=strlen(buffer);
 
31
        if ( buffer[len-1] == '\n' ) {
 
32
            buffer[len-1] = '\000';
 
33
        }
 
34
        result = strdup(buffer);
 
35
    } else {
 
36
        result = name;
 
37
    }
 
38
    pclose(stream);
 
39
    return result;
 
40
}
 
41
 
 
42
struct string_less_than {
 
43
    bool operator()(char const *a, char const *b) const {
 
44
        return ( strcmp(a, b) < 0 );
 
45
    }
 
46
};
 
47
 
 
48
typedef std::map<char const *, char const *, string_less_than> MangleCache;
 
49
MangleCache mangle_cache;
 
50
 
 
51
}
 
52
 
 
53
Util::ptr_shared<char> demangle(char const *name) {
 
54
    MangleCache::iterator found=mangle_cache.find(name);
 
55
 
 
56
    char const *result;
 
57
    if ( found != mangle_cache.end() ) {
 
58
        result = (*found).second;
 
59
    } else {
 
60
        result = demangle_helper(name);
 
61
        mangle_cache[name] = result;
 
62
    }
 
63
 
 
64
    return Util::share_unsafe(result);
 
65
}
 
66
 
 
67
}
 
68
 
 
69
}
 
70
 
 
71
/*
 
72
  Local Variables:
 
73
  mode:c++
 
74
  c-file-style:"stroustrup"
 
75
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
76
  indent-tabs-mode:nil
 
77
  fill-column:99
 
78
  End:
 
79
*/
 
80
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :