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
build/
*.back

View File

@ -1,18 +1,41 @@
{
"folders": [
{
"path": ".",
"follow_symlinks": true
}
],
"build_systems": [
{
"working_dir": "${project_path}/../../build/eccodes",
"cmd": [
"make"
],
"file_regex": "([/\\w\\-\\.]+):(\\d+):(\\d+:)?",
"name": "ecbuild"
}
]
"build_systems":
[
{
"file_regex": "([/\\w\\-\\.]+):(\\d+):(\\d+:)?",
"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\""
}
],
"cmake":
{
"build_folder": "${project_path}/../../build/eccodes",
"command_line_overrides":
{
"DEVELOPER_MODE": 1,
"ENABLE_MEMFS": 1
}
},
"folders":
[
{
"follow_symlinks": true,
"path": "."
}
]
}

View File

@ -45,7 +45,7 @@ static int execute(grib_action* a,grib_handle* h);
typedef struct grib_action_assert {
grib_action act;
grib_action act;
/* Members defined in assert */
grib_expression *expression;
} grib_action_assert;
@ -101,7 +101,7 @@ static int create_accessor(grib_section* p, grib_action* act,grib_loader *h)
grib_push_accessor(as,p->block);
return GRIB_SUCCESS;
}

View File

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

View File

@ -14,7 +14,7 @@
#include "grib_api_internal.h"
/*
/*
This is used by make_class.pl
START_CLASS_DEF

View File

@ -14,7 +14,7 @@
#include "grib_api_internal.h"
#include <assert.h>
/*
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++);
}
assert(self->len <= sizeof(long)*8);
Assert(self->len <= sizeof(long)*8);
a->length=0;
}
@ -298,7 +298,7 @@ static int get_native_type(grib_accessor* a)
int type=GRIB_TYPE_BYTES;
grib_accessor_bits* self = (grib_accessor_bits*)a;
if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE)
if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE)
type=GRIB_TYPE_STRING;
if (a->flags & GRIB_ACCESSOR_FLAG_LONG_TYPE)

View File

@ -9,9 +9,8 @@
*/
#include "grib_api_internal.h"
#include <assert.h>
/*
/*
This is used by make_class.pl
START_CLASS_DEF
@ -198,7 +197,7 @@ static void dump(grib_accessor* a, grib_dumper* dumper)
}
static int unpack_long(grib_accessor* a, long* val, size_t *len)
{
{
grib_accessor_validity_date* self = (grib_accessor_validity_date*)a;
int ret=0;
long date = 0;

View File

@ -9,9 +9,8 @@
*/
#include "grib_api_internal.h"
#include <assert.h>
/*
/*
This is used by make_class.pl
START_CLASS_DEF
@ -195,7 +194,7 @@ static void dump(grib_accessor* a, grib_dumper* dumper)
}
static int unpack_long(grib_accessor* a, long* val, size_t *len)
{
{
grib_accessor_validity_time* self = (grib_accessor_validity_time*)a;
int ret=0;
long date = 0;

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
}
#endif

View File

@ -22,7 +22,7 @@ extern "C" {
#endif
/* cmake config header */
#ifdef HAVE_ECCODES_CONFIG_H
#ifdef HAVE_ECCODES_CONFIG_H
#include "eccodes_config.h"
#endif
@ -125,11 +125,11 @@ extern "C" {
#if GRIB_PTHREADS
#include <pthread.h>
#define GRIB_MUTEX_INIT_ONCE(a,b) pthread_once(a,b);
#define GRIB_MUTEX_LOCK(a) pthread_mutex_lock(a);
#define GRIB_MUTEX_LOCK(a) pthread_mutex_lock(a);
#define GRIB_MUTEX_UNLOCK(a) pthread_mutex_unlock(a);
/*
#define GRIB_MUTEX_LOCK(a) {pthread_mutex_lock(a); printf("MUTEX LOCK %p %s line %d\n",(void*)a,__FILE__,__LINE__);}
#define GRIB_MUTEX_UNLOCK(a) {pthread_mutex_unlock(a);printf("MUTEX UNLOCK %p %s line %d\n",(void*)a,__FILE__,__LINE__);}
#define GRIB_MUTEX_UNLOCK(a) {pthread_mutex_unlock(a);printf("MUTEX UNLOCK %p %s line %d\n",(void*)a,__FILE__,__LINE__);}
*/
#elif GRIB_OMP_THREADS
#include <omp.h>
@ -162,8 +162,7 @@ extern "C" {
#define ftello ftell
#endif
#define Assert(a) {if(!(a)) grib_fail(#a,__FILE__,__LINE__,0);}
#define AssertSilent(a) {if(!(a)) grib_fail(#a,__FILE__,__LINE__,1);}
#define Assert(a) do { if(!(a)) codes_assertion_failed(#a, __FILE__, __LINE__); } while(0)
#ifndef NDEBUG
#define DebugAssert(a) Assert(a)
@ -504,9 +503,9 @@ struct grib_buffer
typedef struct grib_virtual_value grib_virtual_value;
struct grib_virtual_value {
long lval;
double dval;
char* cval;
long lval;
double dval;
char* cval;
int missing;
int length;
int type;
@ -814,6 +813,9 @@ struct codes_condition {
double rightDouble;
};
void codes_assertion_failed(const char* message, const char* file, int line);
#define MAX_SET_VALUES 10
#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 */
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_fail(const char *expr, const char *file, int line, int silent);
/* 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);

View File

@ -978,3 +978,24 @@ void grib_context_increment_handle_total_count(grib_context *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);
}
}
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.
*/
#include "grib_api_internal.h"
#include <assert.h>
/*
* 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
printf("-- pl=%ld npoints=%ld range=%.10e ilon_first=%ld ilon_last=%ld irange=%ld\n",
pl,*npoints,range,*ilon_first,*ilon_last,irange);

View File

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

View File

@ -9,10 +9,10 @@
*/
#include "md5.h"
#include "grib_api_internal.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
/* On CRAY, disable all automatic optimisations for this module */
#if _CRAYC
@ -215,7 +215,7 @@ static void grib_md5_flush(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));
s->h0 = 0x67452301;
s->h1 = 0xefcdab89;