Allow user to catch asserts

This commit is contained in:
Shahram Najm 2017-03-30 16:19:50 +01:00
commit 23c7de8958
17 changed files with 88 additions and 58 deletions

1
.gitignore vendored
View File

@ -318,3 +318,4 @@ data/bufr/*test
.idea .idea
build/ build/
*.back

View File

@ -1,18 +1,41 @@
{ {
"folders": [ "build_systems":
[
{ {
"path": ".", "file_regex": "([/\\w\\-\\.]+):(\\d+):(\\d+:)?",
"follow_symlinks": true "name": "eccodes",
"shell_cmd": "make",
"syntax": "Packages/CMakeBuilder/Syntax/Make.sublime-syntax",
"variants":
[
{
"name": "clean",
"shell_cmd": "make clean"
},
],
"working_dir": "${project_path}/../../build/eccodes"
},
{
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"name": "Anaconda Python Builder",
"selector": "source.python",
"shell_cmd": "\"python\" -u \"$file\""
} }
], ],
"build_systems": [ "cmake":
{ {
"working_dir": "${project_path}/../../build/eccodes", "build_folder": "${project_path}/../../build/eccodes",
"cmd": [ "command_line_overrides":
"make" {
], "DEVELOPER_MODE": 1,
"file_regex": "([/\\w\\-\\.]+):(\\d+):(\\d+:)?", "ENABLE_MEMFS": 1
"name": "ecbuild" }
},
"folders":
[
{
"follow_symlinks": true,
"path": "."
} }
] ]
} }

View File

@ -9,7 +9,6 @@
*/ */
#include "eccodes.h" #include "eccodes.h"
#include <assert.h>
/* Generic functions */ /* Generic functions */
/******************************************************************************/ /******************************************************************************/

View File

@ -14,7 +14,7 @@
#include "grib_api_internal.h" #include "grib_api_internal.h"
#include <assert.h>
/* /*
This is used by make_class.pl This is used by make_class.pl
@ -175,7 +175,7 @@ static void init(grib_accessor* a,const long l, grib_arguments* c)
self->scale=grib_arguments_get_double(grib_handle_of_accessor(a),c,n++); self->scale=grib_arguments_get_double(grib_handle_of_accessor(a),c,n++);
} }
assert(self->len <= sizeof(long)*8); Assert(self->len <= sizeof(long)*8);
a->length=0; a->length=0;
} }

View File

@ -9,7 +9,6 @@
*/ */
#include "grib_api_internal.h" #include "grib_api_internal.h"
#include <assert.h>
/* /*
This is used by make_class.pl This is used by make_class.pl

View File

@ -9,7 +9,6 @@
*/ */
#include "grib_api_internal.h" #include "grib_api_internal.h"
#include <assert.h>
/* /*
This is used by make_class.pl This is used by make_class.pl

View File

@ -1536,6 +1536,9 @@ grib_handle *grib_util_set_spec2(grib_handle *h,
/* --------------------------------------- */ /* --------------------------------------- */
typedef void (*codes_assertion_failed_proc)(const char* message);
void codes_set_codes_assertion_failed_proc(codes_assertion_failed_proc proc);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -162,8 +162,7 @@ extern "C" {
#define ftello ftell #define ftello ftell
#endif #endif
#define Assert(a) {if(!(a)) grib_fail(#a,__FILE__,__LINE__,0);} #define Assert(a) do { if(!(a)) codes_assertion_failed(#a, __FILE__, __LINE__); } while(0)
#define AssertSilent(a) {if(!(a)) grib_fail(#a,__FILE__,__LINE__,1);}
#ifndef NDEBUG #ifndef NDEBUG
#define DebugAssert(a) Assert(a) #define DebugAssert(a) Assert(a)
@ -814,6 +813,9 @@ struct codes_condition {
double rightDouble; double rightDouble;
}; };
void codes_assertion_failed(const char* message, const char* file, int line);
#define MAX_SET_VALUES 10 #define MAX_SET_VALUES 10
#define MAX_ACCESSOR_CACHE 100 #define MAX_ACCESSOR_CACHE 100

View File

@ -1271,7 +1271,6 @@ int codes_copy_key(grib_handle *h1, grib_handle *h2, const char *key, int type);
/* grib_errors.c */ /* grib_errors.c */
const char *grib_get_error_message(int code); const char *grib_get_error_message(int code);
void grib_check(const char *call, const char *file, int line, int e, const char *msg); void grib_check(const char *call, const char *file, int line, int e, const char *msg);
void grib_fail(const char *expr, const char *file, int line, int silent);
/* grib_expression_class_binop.c */ /* grib_expression_class_binop.c */
grib_expression *new_binop_expression(grib_context *c, grib_binop_long_proc long_func, grib_binop_double_proc double_func, grib_expression *left, grib_expression *right); grib_expression *new_binop_expression(grib_context *c, grib_binop_long_proc long_func, grib_binop_double_proc double_func, grib_expression *left, grib_expression *right);

View File

@ -978,3 +978,24 @@ void grib_context_increment_handle_total_count(grib_context *c)
GRIB_MUTEX_UNLOCK(&mutex_c); GRIB_MUTEX_UNLOCK(&mutex_c);
} }
static codes_assertion_failed_proc assertion = NULL;
void codes_set_codes_assertion_failed_proc(codes_assertion_failed_proc proc)
{
assertion = proc;
}
void codes_assertion_failed(const char* message, const char* file, int line)
{
/* Default behaviour is to abort
* unless user has supplied his own assertion routine */
if (assertion == NULL) {
fprintf(stderr, "ecCodes assertion failed: `%s' in %s:%d\n", message, file, line);
abort();
}
else {
char buffer[10240];
sprintf(buffer, "ecCodes assertion failed: `%s' in %s:%d", message, file, line);
assertion(buffer);
}
}

View File

@ -113,11 +113,3 @@ void grib_check(const char* call,const char* file,int line,int e,const char* ms
exit(e); exit(e);
} }
} }
void grib_fail(const char* expr,const char* file,int line,int silent) {
if (!silent)
fprintf(stderr,"%s at line %d: assertion failure Assert(%s)\n",file,line,expr);
abort();
}

View File

@ -35,10 +35,3 @@ void grib_check(const char* call,const char* file,int line,int e,const char* ms
} }
} }
void grib_fail(const char* expr,const char* file,int line,int silent) {
if (!silent)
fprintf(stderr,"%s at line %d: assertion failure Assert(%s)\n",file,line,expr);
abort();
}

View File

@ -8,7 +8,6 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/ */
#include "grib_api_internal.h" #include "grib_api_internal.h"
#include <assert.h>
/* /*
* C Implementation: gaussian_reduced * C Implementation: gaussian_reduced
@ -87,7 +86,7 @@ void grib_get_reduced_row(long pl, double lon_first, double lon_last, long* npoi
} }
} }
assert(*npoints==irange); Assert(*npoints==irange);
#if EFDEBUG #if EFDEBUG
printf("-- pl=%ld npoints=%ld range=%.10e ilon_first=%ld ilon_last=%ld irange=%ld\n", printf("-- pl=%ld npoints=%ld range=%.10e ilon_first=%ld ilon_last=%ld irange=%ld\n",
pl,*npoints,range,*ilon_first,*ilon_last,irange); pl,*npoints,range,*ilon_first,*ilon_last,irange);

View File

@ -617,7 +617,7 @@ static int read_BUFR(reader *r)
edition = tmp[i++]; edition = tmp[i++];
/* assert(edition != 1); */ /* Assert(edition != 1); */
switch (edition) { switch (edition) {
case 0: case 0:

View File

@ -9,10 +9,10 @@
*/ */
#include "md5.h" #include "md5.h"
#include "grib_api_internal.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <assert.h>
/* On CRAY, disable all automatic optimisations for this module */ /* On CRAY, disable all automatic optimisations for this module */
#if _CRAYC #if _CRAYC
@ -215,7 +215,7 @@ static void grib_md5_flush(grib_md5_state* s)
void grib_md5_init(grib_md5_state* s) void grib_md5_init(grib_md5_state* s)
{ {
assert( sizeof(UnsignedInt64) == 8 ); Assert( sizeof(UnsignedInt64) == 8 );
memset(s,0,sizeof(grib_md5_state)); memset(s,0,sizeof(grib_md5_state));
s->h0 = 0x67452301; s->h0 = 0x67452301;
s->h1 = 0xefcdab89; s->h1 = 0xefcdab89;