Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
libcdi
Commits
b01623a3
Commit
b01623a3
authored
Jun 13, 2013
by
Thomas Jahns
🤸
Browse files
Move abort/assert wrappers to error.h/error.c.
parent
c0efd87f
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/error.c
View file @
b01623a3
...
...
@@ -7,6 +7,10 @@
#include
<stdarg.h>
#include
<errno.h>
#ifdef USE_MPI
#include
"pio_util.h"
#include
<mpi.h>
#endif
int
_ExitOnError
=
1
;
/* If set to 1, exit on error */
int
_Verbose
=
1
;
/* If set to 1, errors are reported */
...
...
@@ -49,6 +53,38 @@ void Error_(const char *caller, const char *fmt, ...)
if
(
_ExitOnError
)
exit
(
EXIT_FAILURE
);
}
void
cdiAbortC
(
const
char
*
caller
,
const
char
*
filename
,
const
char
*
functionname
,
int
line
,
const
char
*
errorString
,
...
)
{
va_list
ap
;
va_start
(
ap
,
errorString
);
#ifdef USE_MPI
{
int
rank
=
getMPICommWorldRank
();
fprintf
(
stderr
,
"ERROR, pe%d in %s, %s, line %d%s"
"%s
\n
errorString:
\"
"
,
rank
,
functionname
,
filename
,
line
,
caller
?
", called from "
:
""
,
caller
?
caller
:
""
);
}
vfprintf
(
stderr
,
errorString
,
ap
);
fputs
(
"
\"\n
"
,
stderr
);
if
(
callsToMPIAreAllowed
())
MPI_Abort
(
MPI_COMM_WORLD
,
1
);
else
abort
();
#else
fprintf
(
stderr
,
"ERROR, %s, %s, line %d%s%s
\n
errorString:
\"
"
,
functionname
,
filename
,
line
,
caller
?
", called from "
:
""
,
caller
?
caller
:
""
);
vfprintf
(
stderr
,
errorString
,
ap
);
fputs
(
"
\"\n
"
,
stderr
);
#endif
exit
(
EXIT_FAILURE
);
va_end
(
ap
);
}
void
Warning_
(
const
char
*
caller
,
const
char
*
fmt
,
...)
{
...
...
src/error.h
View file @
b01623a3
...
...
@@ -34,6 +34,27 @@ void Message_(const char *caller, const char *fmt, ...);
# define Message(...) Message_((void *), __VA_ARGS__)
#endif
/* If we're not using GNU C, elide __attribute__ */
#ifndef __GNUC__
# define __attribute__(x)
/*NOTHING*/
#endif
void
cdiAbortC
(
const
char
*
caller
,
const
char
*
filename
,
const
char
*
functionname
,
int
line
,
const
char
*
errorString
,
...
)
__attribute__
((
noreturn
));
#define xabortC(caller, ...) \
cdiAbortC(caller, __FILE__, __func__, __LINE__, __VA_ARGS__ )
#define xabort(...) \
cdiAbortC(NULL, __FILE__, __func__, __LINE__, __VA_ARGS__ )
#define cdiAbort(file, func, line, ...) \
cdiAbortC(NULL, (file), (func), (line), __VA_ARGS__)
#define xassert(arg) do { \
if ((arg)) { } else { \
xabort("assertion failed");} \
} while(0)
#endif
/* _ERROR_H */
/*
* Local Variables:
...
...
src/pio_util.c
View file @
b01623a3
...
...
@@ -19,82 +19,6 @@ char commands[][13] = { "FINALIZE\0",
"WRITETS
\0
"
};
#endif
void
pcdiAssert
(
bool
assumption
,
const
char
*
filename
,
const
char
*
functionname
,
int
line
)
{
if
(
!
assumption
)
{
#ifdef USE_MPI
int
rank
=
getMPICommWorldRank
();
fprintf
(
stderr
,
"ERROR, FALSE ASSUMPTION: PE%d in %s, %s, line %d
\n
"
,
rank
,
functionname
,
filename
,
line
);
fflush
(
stderr
);
if
(
callsToMPIAreAllowed
())
MPI_Abort
(
MPI_COMM_WORLD
,
1
);
else
abort
();
#else
fprintf
(
stderr
,
"ERROR, FALSE ASSUMPTION, %s, %s, line %d
\n
"
,
functionname
,
filename
,
line
);
fflush
(
stderr
);
abort
();
#endif
}
}
/****************************************************/
void
pcdiAbortC
(
const
char
*
caller
,
const
char
*
filename
,
const
char
*
functionname
,
int
line
,
const
char
*
errorString
,
...
)
{
va_list
ap
;
va_start
(
ap
,
errorString
);
#ifdef USE_MPI
{
int
rank
=
getMPICommWorldRank
();
fprintf
(
stderr
,
"ERROR, pe%d in %s, %s, line %d, called from"
" %s
\n
errorString:
\"
"
,
rank
,
functionname
,
filename
,
line
,
caller
);
}
vfprintf
(
stderr
,
errorString
,
ap
);
fputs
(
"
\"\n
"
,
stderr
);
if
(
callsToMPIAreAllowed
())
MPI_Abort
(
MPI_COMM_WORLD
,
1
);
else
abort
();
#else
fprintf
(
stderr
,
"ERROR, %s, %s, line %d, called from %s
\n
errorString:
\"
"
,
functionname
,
filename
,
line
,
caller
);
vfprintf
(
stderr
,
errorString
,
ap
);
fputs
(
"
\"\n
"
,
stderr
);
#endif
exit
(
EXIT_FAILURE
);
va_end
(
ap
);
}
void
pcdiAbort
(
const
char
*
filename
,
const
char
*
functionname
,
int
line
,
const
char
*
errorString
,
...
)
{
va_list
ap
;
va_start
(
ap
,
errorString
);
#ifdef USE_MPI
{
int
rank
=
getMPICommWorldRank
();
fprintf
(
stderr
,
"ERROR, pe%d in %s, %s, line %d, errorString:
\"
"
,
rank
,
functionname
,
filename
,
line
);
}
vfprintf
(
stderr
,
errorString
,
ap
);
fputs
(
"
\"\n
"
,
stderr
);
MPI_Abort
(
MPI_COMM_WORLD
,
1
);
#else
fprintf
(
stderr
,
"ERROR, %s, %s, line %d, errorString:
\"
"
,
functionname
,
filename
,
line
);
vfprintf
(
stderr
,
errorString
,
ap
);
fputs
(
"
\"\n
"
,
stderr
);
#endif
exit
(
EXIT_FAILURE
);
va_end
(
ap
);
}
/*****************************************************************************/
...
...
@@ -102,11 +26,9 @@ void * pcdiXmalloc ( size_t size, const char *filename, const char *functionname
int
line
)
{
void
*
value
=
calloc
(
1
,
size
);
if
(
value
==
NULL
)
pcdiAbort
(
filename
,
functionname
,
line
,
"malloc failed: %s"
,
strerror
(
errno
));
cdiAbort
(
filename
,
functionname
,
line
,
"malloc failed: %s"
,
strerror
(
errno
));
return
value
;
}
...
...
@@ -114,11 +36,9 @@ void * pcdiXcalloc ( size_t nmemb, size_t size, const char *filename,
const
char
*
functionname
,
int
line
)
{
void
*
value
=
calloc
(
nmemb
,
size
);
if
(
value
==
NULL
)
pcdiAbort
(
filename
,
functionname
,
line
,
"calloc failed: %s"
,
strerror
(
errno
)
);
cdiAbort
(
filename
,
functionname
,
line
,
"calloc failed: %s"
,
strerror
(
errno
)
);
return
value
;
}
...
...
@@ -126,11 +46,9 @@ void * pcdiXrealloc ( void *p, size_t size, const char *functionname,
const
char
*
filename
,
int
line
)
{
void
*
value
=
realloc
(
p
,
size
);
if
(
value
==
NULL
)
pcdiAbort
(
filename
,
functionname
,
line
,
"realloc failed: %s"
,
strerror
(
errno
));
cdiAbort
(
filename
,
functionname
,
line
,
"realloc failed: %s"
,
strerror
(
errno
));
return
value
;
}
...
...
src/pio_util.h
View file @
b01623a3
#ifndef PIO_UTIL_
#define PIO_UTIL_
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
<stdbool.h>
#include
<stdlib.h>
#include
<stdio.h>
...
...
@@ -14,6 +10,8 @@
#include
"mpi.h"
#endif
#include
"error.h"
#define MAXDEBUG 3
...
...
@@ -21,10 +19,6 @@
#define debugString "#####"
/* If we're not using GNU C, elide __attribute__ */
#ifndef __GNUC__
# define __attribute__(x)
/*NOTHING*/
#endif
#ifdef USE_MPI
static
inline
int
...
...
@@ -45,14 +39,6 @@ getMPICommWorldRank()
}
#endif
void
pcdiAssert
(
bool
,
const
char
*
,
const
char
*
,
int
);
#define xassert(arg) do { \
if ((arg)) { \
} else { \
pcdiAssert(0, __FILE__, __func__, __LINE__ ); \
} \
} while(0)
#ifdef USE_MPI
#define xdebug(fmt, ...) \
if ( ddebug ){ \
...
...
@@ -107,14 +93,6 @@ void pcdiAssert( bool, const char *, const char *, int );
}
#endif
void
pcdiAbortC
(
const
char
*
,
const
char
*
,
const
char
*
,
int
,
const
char
*
,
...
)
__attribute__
((
noreturn
));
#define xabortC(caller, ...) pcdiAbortC(caller, __FILE__, __func__, __LINE__, __VA_ARGS__ )
void
pcdiAbort
(
const
char
*
,
const
char
*
,
int
,
const
char
*
,
...
)
__attribute__
((
noreturn
));
#define xabort(...) pcdiAbort(__FILE__, __func__, __LINE__, __VA_ARGS__ )
void
*
pcdiXmalloc
(
size_t
,
const
char
*
,
const
char
*
,
int
);
#define xmalloc(size) pcdiXmalloc ( size, __FILE__, __func__, __LINE__ )
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment