Skip to content
Snippets Groups Projects
Verified Commit bafe246c authored by raphael.bach's avatar raphael.bach
Browse files

Fix variable scope bug with `fmpi_error_handler`

- Change all `fmpi_error_handler` occurrences to non-pointer variables
parent fc6f8efe
No related branches found
No related tags found
No related merge requests found
......@@ -51,7 +51,7 @@ typedef struct fmpi_ctx {
size_t task_cnt;
double timer_start; //!< TODO
double timer_stop; //!< TODO
const struct fmpi_error_handler * err_handler; //!< TODO
struct fmpi_error_handler err_handler; //!< TODO
} fmpi_ctx;
/*==============================================================================
PUBLIC FUNCTION
......
......@@ -194,7 +194,7 @@ typedef struct fmpi_error_handler {
* }
*/
void fmpi_raise_error(
const struct fmpi_error_handler * err_handler,
struct fmpi_error_handler err_handler,
const char * file, size_t line, const char * func, const char * module,
const char * fmt, ...
);
......@@ -271,7 +271,7 @@ const char * fmpi_error_timestamp_str(time_t t, char * buf, size_t size);
* }
*/
#define FMPI_RAISE_ERROR(err_handler, module, ...) \
fmpi_raise_error((err_handler), __FILE__, __LINE__, __func__, (module), __VA_ARGS__)
fmpi_raise_error(err_handler, __FILE__, __LINE__, __func__, (module), __VA_ARGS__)
/*==============================================================================
GUARD
==============================================================================*/
......
......@@ -43,7 +43,7 @@
typedef struct fmpi_futhark_ctx {
struct futhark_context * ctx; //!< TODO
struct futhark_context_config * cfg; //!< TODO
const struct fmpi_error_handler * err_handler; //!< TODO
struct fmpi_error_handler err_handler; //!< TODO
} fmpi_futhark_ctx;
/*==============================================================================
PUBLIC FUNCTION
......@@ -66,7 +66,7 @@ typedef struct fmpi_futhark_ctx {
* TODO
* }
*/
struct fmpi_futhark_ctx * fmpi_futhark_init(const struct fmpi_error_handler * err_handler);
struct fmpi_futhark_ctx * fmpi_futhark_init(struct fmpi_error_handler err_handler);
/*------------------------------------------------------------------------------
fmpi_futhark_exit()
------------------------------------------------------------------------------*/
......
......@@ -52,7 +52,7 @@ typedef struct fmpi_mpi_ctx {
int root; //!< TODO
int futhark_err_class; //!< TODO
int futhark_err_code; //!< TODO
const struct fmpi_error_handler * err_handler; //!< TODO
struct fmpi_error_handler err_handler; //!< TODO
} fmpi_mpi_ctx;
/*==============================================================================
PUBLIC FUNCTION
......@@ -78,7 +78,7 @@ typedef struct fmpi_mpi_ctx {
* }
*/
struct fmpi_mpi_ctx * fmpi_mpi_init(
int * argc, char ** argv[], const struct fmpi_error_handler * err_handler
int * argc, char ** argv[], struct fmpi_error_handler err_handler
);
/*------------------------------------------------------------------------------
fmpi_mpi_exit()
......
......@@ -64,12 +64,12 @@ struct fmpi_ctx * fmpi_ctx_create(int * argc, char ** argv[])
fprintf(stderr, "malloc(fmpi_ctx) failed!\n");
return NULL;
}
ctx->err_handler = &(struct fmpi_error_handler) {
ctx->err_handler = (struct fmpi_error_handler) {
.func = fmpi_error_callback,
.user_data = ctx
};
// MPI initialization
ctx->mpi = fmpi_mpi_init(argc, argv, &(struct fmpi_error_handler) {
ctx->mpi = fmpi_mpi_init(argc, argv, (struct fmpi_error_handler) {
.func = fmpi_error_callback,
.user_data = ctx
});
......@@ -79,7 +79,7 @@ struct fmpi_ctx * fmpi_ctx_create(int * argc, char ** argv[])
return NULL;
}
// Futhark Initialization
ctx->fut = fmpi_futhark_init(&(struct fmpi_error_handler) {
ctx->fut = fmpi_futhark_init((struct fmpi_error_handler) {
.func = fmpi_error_callback,
.user_data = ctx
});
......
......@@ -35,7 +35,7 @@
fmpi_raise_error()
------------------------------------------------------------------------------*/
void fmpi_raise_error(
const struct fmpi_error_handler * const err_handler,
const struct fmpi_error_handler err_handler,
const char * const file, const size_t line, const char * const func,
const char * const module, const char * const fmt, ...
){
......@@ -43,7 +43,7 @@ void fmpi_raise_error(
assert(func != NULL);
assert(module != NULL);
assert(fmt != NULL);
if(err_handler->func == NULL) {
if(err_handler.func == NULL) {
return;
}
const time_t t = time(NULL);
......@@ -60,7 +60,7 @@ void fmpi_raise_error(
}
va_end(args);
}
err_handler->func(&(const struct fmpi_error){
err_handler.func(&(const struct fmpi_error){
.file = file,
.line = line,
.func = func,
......@@ -68,7 +68,7 @@ void fmpi_raise_error(
.module = module,
.msg = msg_str,
},
err_handler->user_data
err_handler.user_data
);
}
/*------------------------------------------------------------------------------
......
......@@ -50,7 +50,7 @@ static const fmpi_futhark_new_data_func fmpi_futhark_new_data_func_list[] = {
==============================================================================*/
#define FMPI_RAISE_FUTHARK_ERROR(ctx, ...) \
do { \
if((ctx)->err_handler != NULL) { \
if((ctx)->err_handler.func != NULL) { \
FMPI_RAISE_ERROR((ctx)->err_handler, "FUTHARK", __VA_ARGS__); \
} \
} while(0)
......@@ -61,16 +61,14 @@ do { \
fmpi_futhark_init()
------------------------------------------------------------------------------*/
struct fmpi_futhark_ctx * fmpi_futhark_init(
const struct fmpi_error_handler * const err_handler
const struct fmpi_error_handler err_handler
){
struct fmpi_futhark_ctx * ctx = malloc(sizeof(*ctx));
if(ctx == NULL) {
if(err_handler != NULL) {
FMPI_RAISE_ERROR(err_handler, "FUTHARK", "malloc(fmpi_futhark_ctx) failed!");
}
return NULL;
}
ctx->err_handler = (err_handler != NULL) ? err_handler : NULL;
ctx->err_handler = err_handler;
ctx->cfg = futhark_context_config_new();
if(ctx->cfg == NULL) {
FMPI_RAISE_FUTHARK_ERROR(ctx, "futhark_context_config_new() failed!");
......
......@@ -41,7 +41,7 @@
==============================================================================*/
#define FMPI_RAISE_MPI_ERROR(ctx, ...) \
do { \
if((ctx)->err_handler != NULL) { \
if((ctx)->err_handler.func != NULL) { \
FMPI_RAISE_ERROR((ctx)->err_handler, "MPI", __VA_ARGS__); \
} \
} while(0)
......@@ -53,17 +53,15 @@ do { \
------------------------------------------------------------------------------*/
struct fmpi_mpi_ctx * fmpi_mpi_init(
int * const argc, char *** const argv,
const struct fmpi_error_handler * const err_handler
const struct fmpi_error_handler err_handler
){
struct fmpi_mpi_ctx * ctx = malloc(sizeof(*ctx));
if(ctx == NULL) {
if(err_handler != NULL) {
FMPI_RAISE_ERROR(err_handler, "MPI", "malloc(fmpi_mpi_ctx) failed!");
}
return NULL;
}
ctx->root = FMPI_MPI_ROOT;
ctx->err_handler = (err_handler != NULL) ? err_handler : NULL;
ctx->err_handler = err_handler;
int err_id = MPI_Init(argc, argv);
if(fmpi_mpi_check_error(ctx, err_id, "MPI_Init") == true) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment