Skip to content

Commit d4e6a94

Browse files
Merge pull request #2131 from arcaneframework/dev/gg-add-macro-for-funcname
Add macro `ARCCORE_MACRO_FUNCTION_NAME` to get the name of the current function.
2 parents 4ec65d4 + 83976a9 commit d4e6a94

File tree

2 files changed

+27
-29
lines changed

2 files changed

+27
-29
lines changed

arccore/src/base/arccore/base/ArccoreGlobal.h

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,8 @@ arccoreCheckAt(Int64 i,Int64 max_size)
570570
/*---------------------------------------------------------------------------*/
571571
/*---------------------------------------------------------------------------*/
572572

573-
/*
574-
* Macros utilisées pour le débug.
575-
*/
576-
#ifdef ARCCORE_DEBUG_ASSERT
577-
extern "C++" ARCCORE_BASE_EXPORT void _doAssert(const char*,const char*,const char*,int);
573+
extern "C++" ARCCORE_BASE_EXPORT void
574+
_doAssert(const char*,const char*,const char*,int);
578575
template<typename T> inline T*
579576
_checkPointer(T* t,const char* file,const char* func,int line)
580577
{
@@ -584,13 +581,27 @@ _checkPointer(T* t,const char* file,const char* func,int line)
584581
}
585582
return t;
586583
}
587-
# ifdef __GNUG__
588-
#define ARCCORE_D_WHERE(a) ::Arcane::_doAssert(a, __FILE__, __PRETTY_FUNCTION__, __LINE__)
589-
#define ARCCORE_DCHECK_POINTER(a) ::Arcane::_checkPointer((a), __FILE__, __PRETTY_FUNCTION__, __LINE__);
590-
# else
591-
# define ARCCORE_D_WHERE(a) Arccore::_doAssert(a,__FILE__,"(NoInfo)",__LINE__)
592-
# define ARCCORE_DCHECK_POINTER(a) Arccore::_checkPointer((a),__FILE__,"(NoInfo"),__LINE__);
593-
# endif
584+
585+
/*---------------------------------------------------------------------------*/
586+
/*---------------------------------------------------------------------------*/
587+
// Macro pour obtenir par le pré-processeur le nom de la fonction actuelle
588+
589+
#if defined(__GNUG__)
590+
# define ARCCORE_MACRO_FUNCTION_NAME __PRETTY_FUNCTION__
591+
#elif defined( _MSC_VER)
592+
# define ARCCORE_MACRO_FUNCTION_NAME __FUNCTION__
593+
#else
594+
# define ARCCORE_MACRO_FUNCTION_NAME __func__
595+
#endif
596+
597+
/*---------------------------------------------------------------------------*/
598+
/*---------------------------------------------------------------------------*/
599+
/*
600+
* Macros utilisées pour le débug.
601+
*/
602+
#ifdef ARCCORE_DEBUG_ASSERT
603+
# define ARCCORE_D_WHERE(a) ::Arcane::_doAssert(a, __FILE__, ARCCORE_MACRO_FUNCTION_NAME, __LINE__)
604+
# define ARCCORE_DCHECK_POINTER(a) ::Arcane::_checkPointer((a), __FILE__, ARCCORE_MACRO_FUNCTION_NAME, __LINE__);
594605
# define ARCCORE_CHECK_PTR(a) \
595606
{ \
596607
if (!(a)) { \
@@ -746,6 +757,8 @@ using Arcane::arccoreThrowNullPointerError;
746757

747758
using Arcane::FalseType;
748759
using Arcane::TrueType;
760+
using Arcane::_doAssert;
761+
using Arcane::_checkPointer;
749762
}
750763

751764
/*---------------------------------------------------------------------------*/

arccore/src/base/arccore/base/TraceInfo.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,10 @@ std::ostream& operator<<(std::ostream& o,const TraceInfo&);
7676
/*---------------------------------------------------------------------------*/
7777
/*---------------------------------------------------------------------------*/
7878

79-
#ifdef __GNUG__
8079
#define A_FUNCINFO \
81-
::Arccore::TraceInfo(__FILE__,__PRETTY_FUNCTION__,__LINE__)
80+
::Arccore::TraceInfo(__FILE__,ARCCORE_MACRO_FUNCTION_NAME,__LINE__)
8281
#define A_FUNCNAME \
83-
::Arccore::TraceInfo(__FILE__,__PRETTY_FUNCTION__,__LINE__,false)
84-
#else
85-
// Normalement valide uniquement avec extension c99
86-
#ifdef ARCCORE_OS_WIN32
87-
#define A_FUNCINFO \
88-
::Arccore::TraceInfo(__FILE__,__FUNCTION__,__LINE__)
89-
#define A_FUNCNAME \
90-
::Arccore::TraceInfo(__FILE__,__FUNCTION__,__LINE__,false)
91-
#else
92-
#define A_FUNCINFO \
93-
::Arccore::TraceInfo(__FILE__,__func__,__LINE__)
94-
#define A_FUNCNAME \
95-
::Arccore::TraceInfo(__FILE__,__func__,__LINE__,false)
96-
#endif
97-
#endif
82+
::Arccore::TraceInfo(__FILE__,ARCCORE_MACRO_FUNCTION_NAME,__LINE__,false)
9883

9984
#define A_FUNCINFO1(name)\
10085
::Arccore::TraceInfo(__FILE__,name,__LINE__)

0 commit comments

Comments
 (0)