Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Core Modules
dune-common
Commits
de0592a8
Commit
de0592a8
authored
14 years ago
by
Martin Nolte
Browse files
Options
Downloads
Patches
Plain Diff
don't leak memory (the demangled asciiz string has to be freed!)
[[Imported from SVN: r6402]]
parent
f3cae1c6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dune/common/classname.hh
+24
-12
24 additions, 12 deletions
dune/common/classname.hh
with
24 additions
and
12 deletions
dune/common/classname.hh
+
24
−
12
View file @
de0592a8
...
...
@@ -8,38 +8,50 @@
* of a given object or type as a string
*/
#include
<cstdlib>
#include
<string>
#include
<typeinfo>
#ifdef __GNUC__
#include
<cxxabi.h>
#endif
#endif
// #ifdef __GNUC__
namespace
Dune
{
/** \brief Provide the demangled class name of a given object as a string */
template
<
class
T
>
std
::
string
className
(
T
&
t
)
std
::
string
className
(
T
&
t
)
{
std
::
string
className
=
typeid
(
t
).
name
();
#ifdef __GNUC__
int
status
;
return
abi
::
__cxa_demangle
(
typeid
(
t
).
name
(),
0
,
0
,
&
status
);
#else
return
typeid
(
t
).
name
();
#endif
char
*
demangled
=
abi
::
__cxa_demangle
(
className
.
c_str
(),
0
,
0
,
&
status
);
if
(
demangled
)
{
className
=
demangled
;
std
::
free
(
demangled
);
}
#endif // #ifdef __GNUC__
return
className
;
};
/** \brief Provide the demangled class name of a type T as a string */
template
<
class
T
>
std
::
string
className
()
std
::
string
className
()
{
std
::
string
className
=
typeid
(
T
).
name
();
#ifdef __GNUC__
int
status
;
return
abi
::
__cxa_demangle
(
typeid
(
T
).
name
(),
0
,
0
,
&
status
);
#else
return
typeid
(
T
).
name
();
#endif
char
*
demangled
=
abi
::
__cxa_demangle
(
className
.
c_str
(),
0
,
0
,
&
status
);
if
(
demangled
)
{
className
=
demangled
;
std
::
free
(
demangled
);
}
#endif // #ifdef __GNUC__
return
className
;
};
}
}
// namespace Dune
#endif // DUNE_CLASSNAME_HH
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment