From 4bde57afdbd768f1c63fffe454b6e5efec29f18a Mon Sep 17 00:00:00 2001 From: Baudouin Raoult Date: Wed, 15 Mar 2017 19:04:21 +0000 Subject: [PATCH 1/3] Catch assertions --- .gitignore | 1 + src/action_class_assert.c | 4 ++-- src/eccodes.c | 1 - src/grib_accessor_class_assert.c | 6 +++--- src/grib_accessor_class_bits.c | 6 +++--- src/grib_accessor_class_validity_date.c | 5 ++--- src/grib_accessor_class_validity_time.c | 5 ++--- src/grib_api.h | 3 +++ src/grib_api_internal.h | 17 +++++++++++------ src/grib_context.c | 18 ++++++++++++++++++ src/grib_gaussian_reduced.c | 3 +-- src/grib_io.c | 2 +- src/md5.c | 4 ++-- 13 files changed, 49 insertions(+), 26 deletions(-) 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/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..18eae827d 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 @@ -44,7 +44,7 @@ static int notify_change(grib_accessor*,grib_accessor*); typedef struct grib_accessor_assert { grib_accessor att; /* Members defined in gen */ -/* Members defined in assert */ +/* Members defined in ASSERT */ } grib_accessor_assert; extern grib_accessor_class* grib_accessor_class_gen; @@ -71,7 +71,7 @@ static grib_accessor_class _grib_accessor_class_assert = { 0, /* grib_pack procedures long */ 0, /* grib_unpack procedures long */ 0, /* grib_pack procedures double */ - 0, /* grib_unpack procedures double */ + 0, /* grib_unpa™ck procedures double */ 0, /* grib_pack procedures string */ 0, /* grib_unpack procedures string */ 0, /* grib_pack array procedures string */ diff --git a/src/grib_accessor_class_bits.c b/src/grib_accessor_class_bits.c index 06f37fd76..c7571ac15 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 400317212..d147d2b92 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 @@ -504,9 +504,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 +814,11 @@ struct codes_condition { double rightDouble; }; + +void codes_assertion_failed(const char* message, const char* file, int line, const char* function); + +#define ASSERT(a) do { if(!(a)) codes_assertion_failed(#a, __FILE__, __LINE__, __FUNCTION__); } while(0) + #define MAX_SET_VALUES 10 #define MAX_ACCESSOR_CACHE 100 diff --git a/src/grib_context.c b/src/grib_context.c index 420293395..75c2e2cf1 100644 --- a/src/grib_context.c +++ b/src/grib_context.c @@ -8,6 +8,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_api.h" #include "grib_api_internal.h" #include #include @@ -982,3 +983,20 @@ void grib_context_increment_handle_total_count(grib_context *c) GRIB_MUTEX_UNLOCK(&mutex_c); } +static codes_assertion_failed_proc assertion = NULL; + +void code_set_codes_assertion_failed_proc(codes_assertion_failed_proc proc) { + assertion = proc; +} + +void codes_assertion_failed(const char* message, const char* file, int line, const char* function) { + if(assertion == NULL) { + fprintf(stderr, "eccodes assertion failed: %s in %s, %s:%d\n", message, function, file, line); + abort(); + } + else { + char buffer[10240]; + sprintf(buffer, "eccodes assertion failed: %s in %s, %s:%d", message, function, file, line); + assertion(buffer); + } +} diff --git a/src/grib_gaussian_reduced.c b/src/grib_gaussian_reduced.c index 12b978c2c..783246b1d 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..144653bf5 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..2f127c915 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; From f3ff058a6e3486d132f24d04df8f5f9172d1ccd8 Mon Sep 17 00:00:00 2001 From: Baudouin Raoult Date: Wed, 15 Mar 2017 19:17:07 +0000 Subject: [PATCH 2/3] Typo --- src/grib_context.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/grib_context.c b/src/grib_context.c index 75c2e2cf1..7c9288890 100644 --- a/src/grib_context.c +++ b/src/grib_context.c @@ -985,7 +985,7 @@ void grib_context_increment_handle_total_count(grib_context *c) static codes_assertion_failed_proc assertion = NULL; -void code_set_codes_assertion_failed_proc(codes_assertion_failed_proc proc) { +void codes_set_codes_assertion_failed_proc(codes_assertion_failed_proc proc) { assertion = proc; } From 6ad6e64b441bc3160f9bcf6c9578d2e93aa59124 Mon Sep 17 00:00:00 2001 From: Baudouin Raoult Date: Fri, 17 Mar 2017 18:46:27 +0000 Subject: [PATCH 3/3] Update sublime text project --- eccodes.sublime-project | 55 +++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 16 deletions(-) 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": "." + } + ] }