diff --git a/.gitignore b/.gitignore index 29223c823..99a9b7768 100644 --- a/.gitignore +++ b/.gitignore @@ -318,3 +318,4 @@ data/bufr/*test .idea build/ +*.back diff --git a/eccodes.sublime-project b/eccodes.sublime-project index e3f210b60..8d5cd6bf6 100644 --- a/eccodes.sublime-project +++ b/eccodes.sublime-project @@ -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": "." + } + ] } diff --git a/src/action_class_assert.c b/src/action_class_assert.c index c10d0700e..8c868aadc 100644 --- a/src/action_class_assert.c +++ b/src/action_class_assert.c @@ -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; } diff --git a/src/eccodes.c b/src/eccodes.c index 6b7394b3f..0f67c590c 100644 --- a/src/eccodes.c +++ b/src/eccodes.c @@ -9,7 +9,6 @@ */ #include "eccodes.h" -#include /* Generic functions */ /******************************************************************************/ diff --git a/src/grib_accessor_class_assert.c b/src/grib_accessor_class_assert.c index 3f6c74898..acbeea0cb 100644 --- a/src/grib_accessor_class_assert.c +++ b/src/grib_accessor_class_assert.c @@ -14,7 +14,7 @@ #include "grib_api_internal.h" -/* +/* This is used by make_class.pl START_CLASS_DEF diff --git a/src/grib_accessor_class_bits.c b/src/grib_accessor_class_bits.c index 06f37fd76..ebfc52e60 100644 --- a/src/grib_accessor_class_bits.c +++ b/src/grib_accessor_class_bits.c @@ -14,7 +14,7 @@ #include "grib_api_internal.h" -#include + /* 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) diff --git a/src/grib_accessor_class_validity_date.c b/src/grib_accessor_class_validity_date.c index 3bcb3c5c2..a47f05e36 100644 --- a/src/grib_accessor_class_validity_date.c +++ b/src/grib_accessor_class_validity_date.c @@ -9,9 +9,8 @@ */ #include "grib_api_internal.h" -#include -/* +/* 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; diff --git a/src/grib_accessor_class_validity_time.c b/src/grib_accessor_class_validity_time.c index ae36ccc60..23f2d4428 100644 --- a/src/grib_accessor_class_validity_time.c +++ b/src/grib_accessor_class_validity_time.c @@ -9,9 +9,8 @@ */ #include "grib_api_internal.h" -#include -/* +/* 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; diff --git a/src/grib_api.h b/src/grib_api.h index eedbdb44d..c3c810a51 100644 --- a/src/grib_api.h +++ b/src/grib_api.h @@ -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 diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index 65bb4ba24..3829cbca4 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -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 #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 @@ -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 diff --git a/src/grib_api_prototypes.h b/src/grib_api_prototypes.h index be3e1e99d..64548e0e2 100644 --- a/src/grib_api_prototypes.h +++ b/src/grib_api_prototypes.h @@ -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); diff --git a/src/grib_context.c b/src/grib_context.c index 80f75471d..7f6f544e2 100644 --- a/src/grib_context.c +++ b/src/grib_context.c @@ -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); + } +} diff --git a/src/grib_errors.c b/src/grib_errors.c index 41010c45a..1719797d8 100644 --- a/src/grib_errors.c +++ b/src/grib_errors.c @@ -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(); -} - diff --git a/src/grib_errors.c.in b/src/grib_errors.c.in index 3e2f96329..7def1bb56 100644 --- a/src/grib_errors.c.in +++ b/src/grib_errors.c.in @@ -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(); -} - diff --git a/src/grib_gaussian_reduced.c b/src/grib_gaussian_reduced.c index 12b978c2c..d46c32a49 100644 --- a/src/grib_gaussian_reduced.c +++ b/src/grib_gaussian_reduced.c @@ -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 /* * 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); diff --git a/src/grib_io.c b/src/grib_io.c index ff8497063..7994b9fd1 100644 --- a/src/grib_io.c +++ b/src/grib_io.c @@ -617,7 +617,7 @@ static int read_BUFR(reader *r) edition = tmp[i++]; - /* assert(edition != 1); */ + /* Assert(edition != 1); */ switch (edition) { case 0: diff --git a/src/md5.c b/src/md5.c index e28ca1d9e..877a08b85 100644 --- a/src/md5.c +++ b/src/md5.c @@ -9,10 +9,10 @@ */ #include "md5.h" +#include "grib_api_internal.h" #include #include -#include /* 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;