diff --git a/include/util.h b/include/util.h index 590ecce85daa637d83bf2e88060238183c8c1143..a4af6071b209831747c0c83f732198570ce614f6 100644 --- a/include/util.h +++ b/include/util.h @@ -4,6 +4,7 @@ #include <string.h> #include <stdio.h> #include <stdlib.h> +#include <unistd.h> #ifdef HAVE_STDINT_H #include <stdint.h> #endif @@ -19,12 +20,6 @@ #ifdef HAVE_SYS_RESOURCE_H #include <sys/resource.h> #endif -#ifdef _WIN32 -#include <windows.h> -#endif -#ifdef HAVE_MACH_MACH_TIME_H -#include <mach/mach_time.h> -#endif #include <ctype.h> #include <limits.h> #include <float.h> @@ -35,60 +30,14 @@ struct mpf_hmat_create_compression_args_t { const void * output; }; -#if !(defined (_WIN32)) /* It's a UNIX system, I know this ! */ -/* Try to detect a debugger. This relies on the fact that GDB and IDB - (on Linux at least) catches the signal SIGTRAP and does not deliver - it to the application. - - When no debugger is attached, the SIGTRAP raised by raise(SIGTRAP) - will go to my_sigtrap_handler() which will swallow it, and continue - the program execution as if nothing happened. Otherwise, SIGTRAP - will stop the program inside the debugger, as if a breakpoint had - been reached. - - Thus, debug_break() will break into the debugger if present, and do - nothing otherwise. -*/ -#include <signal.h> - -static int is_debugger_present = -1; -static void my_sigtrap_handler(int signum) { - (void)signum; // silent unused parameter warnings - is_debugger_present = 0; - signal(SIGTRAP, SIG_DFL); -} - -inline static void debug_break() { - if (is_debugger_present == -1) { - is_debugger_present = 1; - signal(SIGTRAP, my_sigtrap_handler); - raise(SIGTRAP); - } -} -#else -inline static void debug_break() {}; -#endif - -#if !(defined (_WIN32)) /* It's a UNIX system, I know this ! */ -#include <execinfo.h> -#include <unistd.h> -inline static void mpf_backtrace(){ - void * stack[32]; - int n = backtrace(stack, 32); - backtrace_symbols_fd(stack, n, STDERR_FILENO); -} -#else -inline static void mpf_backtrace(){} -#endif - /*! \brief Displays a warning message and that's all. */ #define SETWARN(n,s, ...) {MpfWarning(__LINE__,PACKAGE_NAME,__FILE__,__func__,n,s, ## __VA_ARGS__);} /*! \brief Displays an error message. */ #define SHWERRM(n,s, ...) {MpfError(__LINE__,PACKAGE_NAME,__FILE__,__func__,n,s, ## __VA_ARGS__);} /*! \brief Displays an error message and quits the current routine. */ -#define SETERRQ(n,s, ...) {int _ierr = MpfError(__LINE__,PACKAGE_NAME,__FILE__,__func__,n,s, ## __VA_ARGS__); debug_break(); return _ierr;} +#define SETERRQ(n,s, ...) {int _ierr = MpfError(__LINE__,PACKAGE_NAME,__FILE__,__func__,n,s, ## __VA_ARGS__); return _ierr;} /*! \brief Displays an error message and aborts the code. */ -#define SETERRA(n,s, ...) {int _ierr = MpfError(__LINE__,PACKAGE_NAME,__FILE__,__func__,n,s, ## __VA_ARGS__);mpf_backtrace();debug_break();exit(_ierr);} +#define SETERRA(n,s, ...) {int _ierr = MpfError(__LINE__,PACKAGE_NAME,__FILE__,__func__,n,s, ## __VA_ARGS__); exit(_ierr); } /*! \brief Checks the integer n, if not zero then it displays an error message and quits the current routine. */ #define CHKERRQ(n) {if (n) SETERRQ(n,(char *)0);} /*! \brief Checks the integer n, if not zero then it displays an error message and aborts the code. */ @@ -102,27 +51,7 @@ inline static void mpf_backtrace(){} /*! \brief Evaluates the expression x, if it is false then it displays an error message and aborts the code. */ #define ASSERTA(x) { if (!(x)) { SETERRA(1, "Assert failure %s", #x); }} -#if !defined (MIN) - /*! \brief Minimum value of two elements. */ -#define MIN(a,b) ( ((a)<(b)) ? (a) : (b) ) -#endif - -#define MpfCalloc(a,b) calloc(a,b) -#define MpfMalloc(a,b) malloc(a) -#define MpfRealloc(a,b) realloc(a,b) -#define MpfFree(a) free(a) -#define enter_context(a) -#define leave_context() - -#if defined(_WIN32) && \ - !(defined (__MINGW64__) || defined(__MINGW32__)) -typedef struct my_timespec { - int64_t tv_sec; - int64_t tv_nsec; -} Time; -#else typedef struct timespec Time; -#endif int MpfError(int line,char *package,char *file,const char *function, int number, ...) ; int MpfWarning(int line,char *package,char *file,const char *function,int number, ...) ; diff --git a/src/classic.c b/src/classic.c index 116de1a95259cf3e519caf4de8052a83436eca30..c1efa3a8b2b3bb4ec4bf16598f3d8d962de72bf6 100644 --- a/src/classic.c +++ b/src/classic.c @@ -46,7 +46,7 @@ int produitClassique(void **sol) { int ierr; double temps_initial, temps_final, temps_cpu; - void *solCLA = MpfCalloc((size_t)nbPts*nbRHS, sizeof(double)) ; CHKPTRQ(solCLA) ; + void *solCLA = calloc((size_t)nbPts*nbRHS, sizeof(double)) ; CHKPTRQ(solCLA) ; temps_initial = getTime (); ierr = produitClassiqueBEM(2, solCLA) ; CHKERRQ(ierr); diff --git a/src/cylinder.c b/src/cylinder.c index 3be9a2cd08bb0b2df79aa97efbec9d263437547f..ad2f893f020d4870bc4830ffdbba5dcc905f4fec 100644 --- a/src/cylinder.c +++ b/src/cylinder.c @@ -49,7 +49,7 @@ int computeCoordCylinder(int i, double *coord) { } double* createCylinder(void) { - double* result = MpfCalloc((size_t)3 * nbPts, sizeof(double)); + double* result = calloc((size_t)3 * nbPts, sizeof(double)); int i, ierr; for (i = 0; i < nbPts; i++) { ierr=computeCoordCylinder(i, &(result[(size_t)3*i]) ) ; CHKERRA(ierr) ; diff --git a/src/hmat.c b/src/hmat.c index b3e5981ac5d9840013f07232de643148272bd9ad..ca12a4553a5f910f12dc9325bf1fe05963f48dc5 100644 --- a/src/hmat.c +++ b/src/hmat.c @@ -20,11 +20,11 @@ typedef struct { static void free_block_data(void *v) { block_data_t* p = (block_data_t*) v; - if (p->col_points) MpfFree(p->col_points); - if (p->row_points) MpfFree(p->row_points); - if (p->dof_col_used) MpfFree(p->dof_col_used); - if (p->dof_row_used) MpfFree(p->dof_row_used); - if (p) MpfFree(p); + if (p->col_points) free(p->col_points); + if (p->row_points) free(p->row_points); + if (p->dof_col_used) free(p->dof_col_used); + if (p->dof_row_used) free(p->dof_row_used); + if (p) free(p); } /** Callback for hmat block info */ @@ -70,7 +70,7 @@ prepare_hmat(int row_start, ASSERTA(user_context); contextTestFEMBEM *myCtx = (contextTestFEMBEM *)user_context; - info->user_data = MpfCalloc(1, sizeof(block_data_t)); + info->user_data = calloc(1, sizeof(block_data_t)); block_data_t* bdata = (block_data_t*) info->user_data; bdata->row_start = row_start; @@ -84,14 +84,14 @@ prepare_hmat(int row_start, info->release_user_data = free_block_data; /* Arrays to store non-null rows and columns */ - bdata->dof_row_used = MpfCalloc(row_count, sizeof(int)); CHKPTRA(bdata->dof_row_used); - bdata->dof_col_used = MpfCalloc(col_count, sizeof(int)); CHKPTRA(bdata->dof_col_used); + bdata->dof_row_used = calloc(row_count, sizeof(int)); CHKPTRA(bdata->dof_row_used); + bdata->dof_col_used = calloc(col_count, sizeof(int)); CHKPTRA(bdata->dof_col_used); /* precompute and store the coordinates of the points (rows and columns) and tag BEM rows and columns as non-null */ int i, j, col, row, ierr; - bdata->row_points=(double(*)[3])MpfCalloc(row_count, 3*sizeof(double)); CHKPTRA(bdata->row_points); + bdata->row_points=(double(*)[3])calloc(row_count, 3*sizeof(double)); CHKPTRA(bdata->row_points); for (i = 0; i < row_count; ++i) { row = bdata->row_hmat2client ? bdata->row_hmat2client[i + bdata->row_start] : i + bdata->row_start; int row_g = row + myCtx->rowOffset; @@ -100,7 +100,7 @@ prepare_hmat(int row_start, bdata->dof_row_used[i]=1; // tag this row as non-null } } - bdata->col_points=(double(*)[3])MpfCalloc(col_count, 3*sizeof(double)); CHKPTRA(bdata->col_points); + bdata->col_points=(double(*)[3])calloc(col_count, 3*sizeof(double)); CHKPTRA(bdata->col_points); for (j = 0; j < col_count; ++j) { col = bdata->col_hmat2client ? bdata->col_hmat2client[j + bdata->col_start] : j + bdata->col_start; int col_g = col + myCtx->colOffset; @@ -163,7 +163,7 @@ advanced_compute_hmat(struct hmat_block_compute_context_t *b) { HMAT_desc_t *HMAT_generate_matrix( hmat_interface_t *hi ) { - HMAT_desc_t *hdesc = MpfCalloc( 1, sizeof(HMAT_desc_t) ); + HMAT_desc_t *hdesc = calloc( 1, sizeof(HMAT_desc_t) ); /* Create a cluster tree with a clustering algorithm */ hmat_clustering_algorithm_t *clustering = NULL; @@ -176,7 +176,7 @@ HMAT_desc_t *HMAT_generate_matrix( hmat_interface_t *hi ) { double *points = createCylinder(); hmat_cluster_tree_t *cluster_tree = hmat_create_cluster_tree_from_builder( points, 3, nbPts, ct_builder ); - MpfFree(points); points=NULL; + free(points); points=NULL; hmat_delete_cluster_tree_builder( ct_builder ); /* Create the H-matrix with this cluster tree and an admissibility criteria */ @@ -207,7 +207,7 @@ HMAT_desc_t *HMAT_generate_matrix( hmat_interface_t *hi ) { ctx.compression = (hmat_compression_algorithm_t*) compression_ctx.output; ctx.prepare = prepare_hmat; ctx.advanced_compute = advanced_compute_hmat; - contextTestFEMBEM *myCtx = MpfCalloc(1, sizeof(contextTestFEMBEM)) ; CHKPTRA(myCtx); + contextTestFEMBEM *myCtx = calloc(1, sizeof(contextTestFEMBEM)) ; CHKPTRA(myCtx); myCtx->colDim = nbPts; ctx.user_context = myCtx; hi->assemble_generic(hmatrix, &ctx); @@ -232,7 +232,7 @@ void HMAT_destroy_matrix( hmat_interface_t *hi, hmat_delete_admissibility(hdesc->admissibilityCondition); hmat_delete_cluster_tree(hdesc->cluster_tree); hmat_delete_clustering(hdesc->clustering); - if (hdesc->myCtx) MpfFree(hdesc->myCtx); - MpfFree(hdesc); + if (hdesc->myCtx) free(hdesc->myCtx); + free(hdesc); } } diff --git a/src/main.c b/src/main.c index d0759161076271a3a826e9937a89cc86d9a76532..953309452af18ab591c4a1addaea1e35946e12a2 100644 --- a/src/main.c +++ b/src/main.c @@ -178,7 +178,7 @@ int run_one() { printf("[minisolver] cleaning ... "); if (rhs) { - MpfFree(rhs); + free(rhs); rhs = NULL; } printf("done\n"); diff --git a/src/testHMAT.c b/src/testHMAT.c index 9c8019da0611ea6abdb9f6e07763884b2d64a8f1..40e13a119a089e90315884eb87c551623792e501 100644 --- a/src/testHMAT.c +++ b/src/testHMAT.c @@ -69,7 +69,7 @@ int testHMAT(double * relative_error) { printf("[minisolver] test-specific cleaning ... "); HMAT_destroy_matrix( interface, hdesc ); - MpfFree(solCLA); + free(solCLA); printf("done\n"); return 0;