Modular C
+ Collaboration diagram for C◼mod◼demangle:

Modules

 Specific macros to deal with the structure of module C◼mod◼demangle.
 

Macros

#define C◼mod◼demangle◼demangle—4(SOUR, SEP, COM, ...)   C◼mod◼demangle◼demangle—5(256, (char[256]){ 0 }, (SOUR), (SEP), (COM))
 
#define C◼mod◼demangle(...)   C◼mod◼demangle◼demangle—4(__VA_ARGS__, 0, 0, )
 Demangle a mangled composed identifier into its components. More...
 
#define C◼mod◼demangle◼FUNC   C◼mod◼demangle◼demangle—5(2*sizeof(__func__)+10, (char[2*sizeof(__func__)+10]){ 0 }, __func__, 0, 0)
 The pretty printed name of the current function. More...
 
#define C◼mod◼demangle◼set(...)   _Intern◼_B9myt7JS◼C◼mod◼demangle◼set—3(__VA_ARGS__, 0, 0)
 

Functions

char const *() C◼mod◼demangle◼set (char const *rep, char const *com)
 Set an execution wide separator for demangling composed identifiers. More...
 
void C◼mod◼demangle◼init (void)
 An initialization function for the module. More...
 
void C◼mod◼demangle◼atexit (void)
 A function called at exit. More...
 
static char * demangle—7 (C◼size tlen, char target[tlen], char const source[], char const sep[], char const com[], char const suff[], C◼size skip)
 
char const * C◼mod◼demangle◼demangle—5 (C◼size tlen, char target[tlen], char const source[], char const sep0[], char const com0[])
 Demangle a mangled composed identifier into its components. More...
 

Variables

static C◼atomic◼rwlock readers = C◼atomic◼rwlock◼INIT
 
static char * separator = 0
 
static char * composer = 0
 
static char const defs [] = "◼"
 
static char const defc [] = "—"
 

Detailed Description

Macro Definition Documentation

§ C◼mod◼demangle

#define C◼mod◼demangle (   ...)    C◼mod◼demangle◼demangle—4(__VA_ARGS__, 0, 0, )

Demangle a mangled composed identifier into its components.

This returns a string that has the components of its first argument separated by a separator. This separator can either be given as the second argument, or, if that is 0 or omitted, is chosen from a per process default value that can be set with ◼C¯mod¯set.

To ensure that setting the separator doesn't result in a race condition, this function uses a lock to protect that separator. If this lock can't be acquired, this function returns the source argument.

If all goes well, this returns the string in a temporary buffer that is valid in the scope where the call to this macro is found.

See also
demangle—5 if you need finer control of the target buffer

Definition at line 331 of file C-mod-demangle.c.

Referenced by C◼mod◼stats◼print().

§ C◼mod◼demangle◼demangle—4

#define C◼mod◼demangle◼demangle—4 (   SOUR,
  SEP,
  COM,
  ... 
)    C◼mod◼demangle◼demangle—5(256, (char[256]){ 0 }, (SOUR), (SEP), (COM))

Definition at line 310 of file C-mod-demangle.c.

§ C◼mod◼demangle◼FUNC

#define C◼mod◼demangle◼FUNC   C◼mod◼demangle◼demangle—5(2*sizeof(__func__)+10, (char[2*sizeof(__func__)+10]){ 0 }, __func__, 0, 0)

The pretty printed name of the current function.

Definition at line 336 of file C-mod-demangle.c.

§ C◼mod◼demangle◼set

#define C◼mod◼demangle◼set (   ...)    _Intern◼_B9myt7JS◼C◼mod◼demangle◼set—3(__VA_ARGS__, 0, 0)

Definition at line 341 of file C-mod-demangle.c.

Referenced by C◼mod◼demangle◼init().

Function Documentation

§ C◼mod◼demangle◼atexit()

void C◼mod◼demangle◼atexit ( void  )

A function called at exit.

A function called at quick_exit.

Definition at line 168 of file C-mod-demangle.c.

References composer, C◼atomic◼rwlock◼unwrlock(), C◼atomic◼rwlock◼wrlock(), C◼lib◼free(), demangle—7(), and separator.

168  {
169 #line 75 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
170 #ifndef C◼atomic◼NO_ATOMICS
172 #endif
173  // doit
175  separator = 0;
177  composer = 0;
178 #ifndef C◼atomic◼NO_ATOMICS
180 #endif
181 }
static char * composer
static char * separator
static C◼atomic◼rwlock readers
void C◼atomic◼rwlock◼unwrlock(C◼atomic◼rwlock *lck)
void C◼lib◼free(void *)
void C◼atomic◼rwlock◼wrlock(C◼atomic◼rwlock *lck)
+ Here is the call graph for this function:

§ C◼mod◼demangle◼demangle—5()

char const* C◼mod◼demangle◼demangle—5 ( C◼size  tlen,
char  target[tlen],
char const  source[],
char const  sep0[],
char const  com0[] 
)

Demangle a mangled composed identifier into its components.

Similar to ◼demangle but with finer control of the buffer to which the demangled string is written.

Returns
If all goes well returns target, otherwise source.

Definition at line 196 of file C-mod-demangle.c.

References composer, C◼atomic◼rwlock◼unrdlock(), C◼mod◼undump8◼id, C◼str◼len(), demangle—7(), and separator.

196  {
197 #line 102 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
198  static char const pref[] = "_ZN2_C";
199  static char const suff[] = "E";
200  char const* ret = source;
201  char const* sep = sep0;
202  char const* com = com0;
203  /* If no separator is provided, use the default. Therefore we must
204  place a read-lock on the default separator, such nobody frees it
205  while we are working with it. */
206  if (¬sep ∨ ¬com) {
207 #line 111 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
208  // take a read lock
209 #ifndef C◼atomic◼NO_ATOMICS
210  if (¬C◼atomic◼rwlock◼tryrdlock(&readers)) {
211 #line 114 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
212  return ret;
213  } else
214 #endif
215  {
216 #line 118 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
217  if (¬sep) {
218 #line 119 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
219  if (separator) {
220 #line 120 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
221  sep = separator;
222  } else {
223 #line 122 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
224  goto CLEANUP;
225  }
226  }
227  if (¬com) {
228 #line 126 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
229  if (composer) {
230 #line 127 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
231  com = composer;
232  } else {
233 #line 129 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
234  goto CLEANUP;
235  }
236  }
237  }
238  }
239  if (C◼str◼len(source) > (sizeof pref) ∧ ¬C◼mem◼cmp(source, pref, (sizeof pref)-1)) {
240 #line 135 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
241  char tbuf[tlen];
242  demangle—7(tlen, tbuf, source - 1 + sizeof pref, sep, com, suff, 0);
243  C◼mod◼undump8◼id(tlen, target, tbuf);
244  ret = target;
245  }
246  CLEANUP:
247  // release the read lock if we had taken it
248 #ifndef C◼atomic◼NO_ATOMICS
249  if (¬sep0 ∨ ¬com0) C◼atomic◼rwlock◼unrdlock(&readers);
250 #endif
251  return ret;
252 }
void C◼atomic◼rwlock◼unrdlock(C◼atomic◼rwlock *lck)
static char * composer
static char * separator
static char * demangle—7(C◼size tlen, char target[tlen], char const source[], char const sep[], char const com[], char const suff[], C◼size skip)
static C◼atomic◼rwlock readers
#define C◼mod◼undump8◼id(SIZE, B, S)
Convert a string s possibly containing Unicode code point given as UTF-16 or UTF-32 character sequenc...
Definition: C-mod-undump8.c:83
C◼size() C◼str◼len(char const *)
+ Here is the call graph for this function:

§ C◼mod◼demangle◼init()

void C◼mod◼demangle◼init ( void  )

An initialization function for the module.

Definition at line 163 of file C-mod-demangle.c.

References C◼mod◼demangle◼set.

163  {
164 #line 71 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
166 }
#define C◼mod◼demangle◼set(...)

§ C◼mod◼demangle◼set()

char const*() C◼mod◼demangle◼set ( char const *  rep,
char const *  com 
)

Set an execution wide separator for demangling composed identifiers.

Although this changes global state this procedure is thread safe if the platform supports atomics. It is asynchronous signal safe, if in addition atomic int is lock-free.

Returns
rep, if successful. Otherwise, if there are too many active calls for demangling, the global state is not changed, and 0 is returned.

This function never promulgates its global state.

Parameters
repis a pointer to a string. The function copies the value of that string, rep can safely be overwritten or freed afterwards.
comsets the composer string that is to be used in addition. It is optional.

Definition at line 133 of file C-mod-demangle.c.

References composer, C◼atomic◼rwlock◼unwrlock(), C◼lib◼free(), C◼lib◼malloc(), C◼mem◼cpy(), C◼str◼len(), defc, defs, and separator.

133  {
134 #line 44 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
135 #ifndef C◼atomic◼NO_ATOMICS
136  if (¬C◼atomic◼rwlock◼trywrlock(&readers)) return 0;
137 #endif
138  // replace the contents
139  if (¬rep) rep = defs;
140  if (¬com) com = defc;
141  C◼size const lens = C◼str◼len(rep);
142  char* rets = C◼lib◼malloc(lens + 1);
143  if (rets) {
144 #line 53 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
145  C◼mem◼cpy(rets, rep, lens+1);
147  separator = rets;
148  }
149  C◼size const lenc = C◼str◼len(com);
150  char* retc = C◼lib◼malloc(lenc + 1);
151  if (retc) {
152 #line 60 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
153  C◼mem◼cpy(retc, com, lenc+1);
155  composer = retc;
156  }
157 #ifndef C◼atomic◼NO_ATOMICS
159 #endif
160  return rets ? rep : 0;
161 }
void * C◼mem◼cpy(void *restrict, const void *restrict, C◼size)
static char const defc[]
static char * composer
static char * separator
static C◼atomic◼rwlock readers
void * C◼lib◼malloc(C◼lib◼size)
void C◼atomic◼rwlock◼unwrlock(C◼atomic◼rwlock *lck)
void C◼lib◼free(void *)
C◼size C◼size
Definition: C-sizeptr.c:94
static char const defs[]
C◼size() C◼str◼len(char const *)
+ Here is the call graph for this function:

§ demangle—7()

static char * demangle—7 ( C◼size  tlen,
char  target[tlen],
char const  source[],
char const  sep[],
char const  com[],
char const  suff[],
C◼size  skip 
)
static

Definition at line 255 of file C-mod-demangle.c.

References C◼mem◼cpy(), C◼str◼len(), and C◼str◼toull().

Referenced by C◼mod◼demangle◼atexit(), and C◼mod◼demangle◼demangle—5().

257  {
258 #line 152 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
259  static char const pref2[] = "I";
260  static char const suff2[] = "E";
261  C◼size suff—len = C◼str◼len(suff);
262  char* stop = target+tlen-1;
263  char* t = target;
264  for (char const*p = source; t < stop; ) {
265 #line 158 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
266  char* q = 0;
267  C◼size len = C◼str◼toull(p, &q, 10);
268  if (q) p = q;
269  else break;
270  p += skip;
271  len -= skip;
272  if (t+len ≥ stop)
273  len = stop-t;
274  C◼mem◼cpy(t, p, len);
275  t += len;
276  p += len;
277  if (t ≥ stop)
278  break;
279  if (¬C◼mem◼cmp(p, suff, suff—len)) {
280 #line 172 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
281  t[0] = 0;
282  break;
283  } else if (¬C◼mem◼cmp(p, pref2, (sizeof pref2)-1)) {
284 #line 175 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
285  for (char const*s = com; t < stop ∧ *s; ++s, ++t)
286  t[0] = s[0];
287  t[0] = 0;
288  t = demangle—7(stop-t+1, t, p-1+sizeof pref2, com, com, suff2, 1);
289  t[0] = 0;
290  break;
291  } else {
292 #line 182 "/home/gustedt/build/cmod/C/C-mod-demangle.X"
293  for (char const*s = sep; t < stop ∧ *s; ++s, ++t)
294  t[0] = s[0];
295  t[0] = 0;
296  }
297  }
298  t[0] = 0;
299  return t;
300 }
void * C◼mem◼cpy(void *restrict, const void *restrict, C◼size)
unsigned long long int() C◼str◼toull(char const *restrict, char **restrict, int)
static char * demangle—7(C◼size tlen, char target[tlen], char const source[], char const sep[], char const com[], char const suff[], C◼size skip)
C◼size C◼size
Definition: C-sizeptr.c:94
C◼size() C◼str◼len(char const *)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

§ composer

char* composer = 0
static

§ defc

char const defc[] = "—"
static

Definition at line 110 of file C-mod-demangle.c.

Referenced by C◼mod◼demangle◼set().

§ defs

char const defs[] = "◼"
static

Definition at line 109 of file C-mod-demangle.c.

Referenced by C◼mod◼demangle◼set().

§ readers

Definition at line 104 of file C-mod-demangle.c.

§ separator

char* separator = 0
static