Arcane  v4.1.1.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ArccoreGlobal.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ArccoreGlobal.cc (C) 2000-2025 */
9/* */
10/* Déclarations générales de Arccore. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
15#include "arccore/base/TraceInfo.h"
16#include "arccore/base/PlatformUtils.h"
17#include "arccore/base/String.h"
18#include "arccore/base/IndexOutOfRangeException.h"
19#include "arccore/base/FatalErrorException.h"
20#include "arccore/base/Ref.h"
21
22// Nécessaire pour les exports de symboles
24#include "arccore/base/Float16.h"
25#include "arccore/base/BFloat16.h"
26#include "arccore/base/Float128.h"
27#include "arccore/base/Int128.h"
28#include "arccore/base/IRangeFunctor.h"
29#include "arccore/base/CheckedConvert.h"
30#include "arccore/base/ForLoopRunInfo.h"
31#include "arccore/base/ForLoopRanges.h"
32#include "arccore/base/ParallelLoopOptions.h"
33#include "arccore/base/internal/IDynamicLibraryLoader.h"
34
35#include <iostream>
36#include <cstring>
37#include <sstream>
38#include <cstdarg>
39
40#ifndef ARCCORE_OS_WIN32
41#include <unistd.h>
42#endif
43
44/*---------------------------------------------------------------------------*/
45/*---------------------------------------------------------------------------*/
59/*---------------------------------------------------------------------------*/
60/*---------------------------------------------------------------------------*/
61
62namespace Arcane
63{
64/*---------------------------------------------------------------------------*/
65/*---------------------------------------------------------------------------*/
66
67namespace
68{
69#ifdef ARCCORE_CHECK
70static bool global_arccore_is_check = true;
71#else
72static bool global_arccore_is_check = false;
73#endif
74}
75
76extern "C++" ARCCORE_BASE_EXPORT
78{
79 return global_arccore_is_check;
80}
81
82extern "C++" ARCCORE_BASE_EXPORT
83void arccoreSetCheck(bool v)
84{
85 global_arccore_is_check = v;
86}
87
88/*---------------------------------------------------------------------------*/
89/*---------------------------------------------------------------------------*/
90
91namespace
92{
93bool global_pause_on_error = false;
94}
95
96extern "C++" ARCCORE_BASE_EXPORT void
98{
99 global_pause_on_error = v;
100}
101
102extern "C++" ARCCORE_BASE_EXPORT void
103arccoreDebugPause(const char* msg)
104{
105 if (global_pause_on_error){
106 std::ostringstream ostr;
107 String host_name(Platform::getHostName());
108 ostr << "** FATAL: Debug mode activated. Execution paused\n"
109 << "** FATAL: message:" << msg << "\n"
110 << "** FATAL: To find the location of the error, start\n"
111 << "** FATAL: start the debugger using the process number\n"
112 << "** FATAL: (pid=" << Platform::getProcessId() << ",host=" << host_name << ").\n";
113 std::cerr << ostr.str();
114#ifndef ARCCORE_OS_WIN32
115 ::pause();
116#endif
117 }
118}
119
120/*---------------------------------------------------------------------------*/
121/*---------------------------------------------------------------------------*/
122
123extern "C++" ARCCORE_BASE_EXPORT void
124arccoreRangeError(Int64 i,Int64 min_value_inclusive,Int64 max_value_exclusive)
125{
126 arccoreDebugPause("arccoreRangeError");
127 throw IndexOutOfRangeException(A_FUNCINFO,String(),i,min_value_inclusive,max_value_exclusive);
128}
129
130/*---------------------------------------------------------------------------*/
131/*---------------------------------------------------------------------------*/
132
133extern "C++" ARCCORE_BASE_EXPORT void
134arccoreRangeError(Int32 i,Int32 max_size)
135{
136 arccoreDebugPause("arccoreRangeError");
137 throw IndexOutOfRangeException(A_FUNCINFO,String(),i,0,max_size);
138}
139
140/*---------------------------------------------------------------------------*/
141/*---------------------------------------------------------------------------*/
142
143extern "C++" ARCCORE_BASE_EXPORT void
145{
146 arccoreDebugPause("arccoreRangeError");
147 throw IndexOutOfRangeException(A_FUNCINFO,String(),i,0,max_size);
148}
149
150/*---------------------------------------------------------------------------*/
151/*---------------------------------------------------------------------------*/
152
153extern "C++" ARCCORE_BASE_EXPORT void
155{
156 std::cerr << "** FATAL: null pointer.\n";
157 std::cerr << "** FATAL: Trying to dereference a null pointer.\n";
158 arccoreDebugPause("arcaneNullPointerPtr");
159 throw FatalErrorException(A_FUNCINFO,"null pointer");
160}
161
162/*---------------------------------------------------------------------------*/
163/*---------------------------------------------------------------------------*/
164
165extern "C++" ARCCORE_BASE_EXPORT void
166arccoreThrowNullPointerError(const char* ptr_name,const char* text)
167{
168 throw FatalErrorException(A_FUNCINFO,text ? text : ptr_name);
169}
170
171/*---------------------------------------------------------------------------*/
172/*---------------------------------------------------------------------------*/
173
174// Cette fonction peut être appelée souvent et certaines fois
175// dans des conditions d'exceptions. Pour cette raison, il ne
176// faut pas qu'elle fasse d'allocations.
177namespace
178{
179void _printFuncName(std::ostream& o,const char* name)
180{
181 const char* par_pos = std::strchr(name,'(');
182 if (!par_pos){
183 o << name;
184 return;
185 }
186
187 // Recherche quelque chose du type namespace::class_name::func_name
188 // et essaye de ne conserver que class_name::func_name
189 ptrdiff_t len = par_pos - name;
190 ptrdiff_t last_scope = 0;
191 ptrdiff_t last_scope2 = 0;
192 for( ptrdiff_t i=0; i<len; ++i ){
193 if (name[i]==':' && name[i+1]==':'){
194 last_scope2 = last_scope;
195 last_scope = i;
196 }
197 }
198 if (last_scope2!=0)
199 last_scope2+=2;
200 ptrdiff_t true_pos = last_scope2;
201 ptrdiff_t true_len = len - true_pos;
202 o.write(&name[true_pos],true_len);
203 o << "()";
204}
205}
206
207/*---------------------------------------------------------------------------*/
208/*---------------------------------------------------------------------------*/
209
210extern "C++" ARCCORE_BASE_EXPORT std::ostream&
211operator<<(std::ostream& o,const TraceInfo& t)
212{
213 if (t.printSignature())
214 o << t.name() << ":" << t.line();
215 else{
216 _printFuncName(o,t.name());
217 }
218 return o;
219}
220
221/*---------------------------------------------------------------------------*/
222/*---------------------------------------------------------------------------*/
223
224/*---------------------------------------------------------------------------*/
225/*---------------------------------------------------------------------------*/
226
227namespace
228{
230typedef void (*fDoAssert)(const char*,const char*,const char*,size_t);
232typedef bool (*fCheckDebug)(unsigned int);
233
234fDoAssert g_do_assert_func = 0;
235}
236
237/*---------------------------------------------------------------------------*/
238/*---------------------------------------------------------------------------*/
242extern "C++" ARCCORE_BASE_EXPORT void
243_doAssert(const char* text,const char* file,const char* func,int line)
244{
245 if (g_do_assert_func)
246 (*g_do_assert_func)(text,file,func,line);
247 else{
248 std::ostringstream ostr;
249 ostr << text << ':' << file << ':' << func << ':' << line << ": ";
250 throw FatalErrorException("Assert",ostr.str());
251 }
252}
253
254/*---------------------------------------------------------------------------*/
255/*---------------------------------------------------------------------------*/
256
257extern "C++" ARCCORE_BASE_EXPORT void
258arccorePrintf(const char* format,...)
259{
260 // \n écrit en meme temps pour éviter des écritures intermédiares parasites
261 char buffer[4096];
262 va_list ap;
263 va_start(ap,format);
264 vsnprintf(buffer,4095,format,ap);
265 va_end(ap);
266 std::cerr << buffer << "\n";
267 std::cout << "*E* " << buffer << "\n";
268}
269
270/*---------------------------------------------------------------------------*/
271/*---------------------------------------------------------------------------*/
272
273} // End namespace Arccore
274
275/*---------------------------------------------------------------------------*/
276/*---------------------------------------------------------------------------*/
Définitions et globaux de Arccore.
Gestion des références à une classe C++.
Exception lorsqu'une erreur fatale est survenue.
Exception lorsqu'une valeur n'est pas dans un intervalle donné.
Chaîne de caractères unicode.
Integer len(const char *s)
Retourne la longueur de la chaîne s.
ARCCORE_BASE_EXPORT String getHostName()
Nom de la machine sur lequel tourne le processus.
ARCCORE_BASE_EXPORT int getProcessId()
Numéro du processus.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
ARCCORE_BASE_EXPORT void arccoreNullPointerError()
Signalue l'utilisation d'un pointeur nul.
std::int64_t Int64
Type entier signé sur 64 bits.
ARCCORE_BASE_EXPORT void arccorePrintf(const char *format,...)
Encapsulation de la fonction C printf.
void(* fDoAssert)(const char *, const char *, const char *, size_t)
Fonction appelée lorsqu'une assertion échoue.
Definition Misc.cc:222
ARCCORE_BASE_EXPORT void arccoreDebugPause(const char *msg)
Passe en mode pause ou lance une erreur fatale.
bool(* fCheckDebug)(unsigned int)
Fonction appelée pour indiquer s'il faut afficher l'information de débug.
Definition Misc.cc:224
ARCCORE_BASE_EXPORT void arccoreRangeError(Int64 i, Int64 min_value_inclusive, Int64 max_value_exclusive)
Signale qu'une valeur n'est pas dans l'intervalle souhaité.
ARCCORE_BASE_EXPORT void arccoreThrowNullPointerError(const char *ptr_name, const char *text)
Signalee l'utilisation d'un pointeur nul en envoyant une exception.
ARCCORE_BASE_EXPORT bool arccoreIsCheck()
Vrai si on est en mode vérification.
void _doAssert(const char *text, const char *file, const char *func, size_t line)
Definition Misc.cc:235
ARCCORE_BASE_EXPORT void arccoreSetPauseOnError(bool v)
Indique si on l'appel à arccoreDebugPause() effectue une pause.
ARCCORE_BASE_EXPORT void arccoreSetCheck(bool v)
Active ou désactive le mode vérification.