diff --git a/definitions/bufr/section.3.def b/definitions/bufr/section.3.def index 5d20c60c9..7bbe1c486 100644 --- a/definitions/bufr/section.3.def +++ b/definitions/bufr/section.3.def @@ -82,9 +82,8 @@ if (section2Present && bufrHeaderCentre==98 && section2Length==52) { } else { meta ls.localLatitude bits(keyData,72,25,-9000000,100000) : dump,no_copy; meta ls.localLongitude bits(keyData,40,26,-18000000,100000) : dump,no_copy; - meta identTrimmed trim(keyMore,1,1): no_copy, hidden; - meta mars.ident sprintf("%s", identTrimmed) : string_type, no_copy; - alias ls.ident=identTrimmed : dump,string_type,no_copy; + meta ident trim(keyMore,1,1): dump, no_copy; # remove whitespaces left and right + alias mars.ident = ident : string_type, no_copy; } } diff --git a/src/grib_accessor_class_trim.c b/src/grib_accessor_class_trim.c index 7aaec91c8..6f97593db 100644 --- a/src/grib_accessor_class_trim.c +++ b/src/grib_accessor_class_trim.c @@ -16,7 +16,7 @@ CLASS = accessor SUPER = grib_accessor_class_ascii IMPLEMENTS = unpack_string;pack_string - IMPLEMENTS = init + IMPLEMENTS = init; string_length MEMBERS= const char* input MEMBERS= int trim_left MEMBERS= int trim_right @@ -36,6 +36,7 @@ or edit "accessor.class" and rerun ./make_class.pl static int pack_string(grib_accessor*, const char*, size_t* len); static int unpack_string(grib_accessor*, char*, size_t* len); +static size_t string_length(grib_accessor*); static void init(grib_accessor*, const long, grib_arguments*); static void init_class(grib_accessor_class*); @@ -63,7 +64,7 @@ static grib_accessor_class _grib_accessor_class_trim = { 0, /* free mem */ 0, /* describes himself */ 0, /* get length of section */ - 0, /* get length of string */ + &string_length, /* get length of string */ 0, /* get number of values */ 0, /* get number of bytes */ 0, /* get offset to bytes */ @@ -103,7 +104,6 @@ static void init_class(grib_accessor_class* c) { c->dump = (*(c->super))->dump; c->next_offset = (*(c->super))->next_offset; - c->string_length = (*(c->super))->string_length; c->value_count = (*(c->super))->value_count; c->byte_count = (*(c->super))->byte_count; c->byte_offset = (*(c->super))->byte_offset; @@ -193,3 +193,8 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) return grib_pack_string(inputAccesstor, pBuf, len); } + +static size_t string_length(grib_accessor* a) +{ + return 1024; +} diff --git a/src/grib_dumper_class_bufr_decode_C.c b/src/grib_dumper_class_bufr_decode_C.c index b9c6954a8..c289a0c57 100644 --- a/src/grib_dumper_class_bufr_decode_C.c +++ b/src/grib_dumper_class_bufr_decode_C.c @@ -547,12 +547,13 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm (void)err; /* TODO */ } +#define MAX_STRING_SIZE 4096 static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) { grib_dumper_bufr_decode_C* self = (grib_dumper_bufr_decode_C*)d; - char* value = NULL; + char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */ + size_t size = MAX_STRING_SIZE; char* p = NULL; - size_t size = 0; grib_context* c = a->context; int r = 0, err = 0; grib_handle* h = grib_handle_of_accessor(a); @@ -560,16 +561,6 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - _grib_get_string_length(a, &size); - if (size == 0) - return; - - value = (char*)grib_context_malloc_clear(c, size); - if (!value) { - grib_context_log(c, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size); - return; - } - self->empty = 0; err = grib_unpack_string(a, value, &size); @@ -613,7 +604,6 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) depth -= 2; } - grib_context_free(c, value); (void)err; /* TODO */ } diff --git a/src/grib_dumper_class_bufr_decode_filter.c b/src/grib_dumper_class_bufr_decode_filter.c index 4841a13e2..1434efc23 100644 --- a/src/grib_dumper_class_bufr_decode_filter.c +++ b/src/grib_dumper_class_bufr_decode_filter.c @@ -460,31 +460,21 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm (void)err; /* TODO */ } +#define MAX_STRING_SIZE 4096 static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) { grib_dumper_bufr_decode_filter* self = (grib_dumper_bufr_decode_filter*)d; - char* value = NULL; - char* p = NULL; - size_t size = 0; - grib_context* c = a->context; + char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */ + size_t size = MAX_STRING_SIZE; + char* p = NULL; + grib_context* c = a->context; int r =0, err = 0; grib_handle* h = grib_handle_of_accessor(a); if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - _grib_get_string_length(a, &size); - if (size == 0) - return; - - value = (char*)grib_context_malloc_clear(c, size); - if (!value) { - grib_context_log(c, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size); - return; - } - - else - self->begin = 0; + self->begin = 0; self->empty = 0; @@ -492,7 +482,6 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) p = value; r = compute_bufr_key_rank(h, self->keys, a->name); if (grib_is_missing_string(a, (unsigned char*)value, size)) { - grib_context_free(c, value); return; } @@ -528,7 +517,6 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) depth -= 2; } - grib_context_free(c, value); (void)err; /* TODO */ } diff --git a/src/grib_dumper_class_bufr_decode_fortran.c b/src/grib_dumper_class_bufr_decode_fortran.c index 8b9d1e10a..d01e1e083 100644 --- a/src/grib_dumper_class_bufr_decode_fortran.c +++ b/src/grib_dumper_class_bufr_decode_fortran.c @@ -489,29 +489,20 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm (void)err; /* TODO */ } +#define MAX_STRING_SIZE 4096 static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) { grib_dumper_bufr_decode_fortran* self = (grib_dumper_bufr_decode_fortran*)d; - char* value = NULL; - char* p = NULL; - size_t size = 0; - grib_context* c = a->context; + char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */ + size_t size = MAX_STRING_SIZE; + char* p = NULL; + grib_context* c = a->context; int r = 0, err = 0; grib_handle* h = grib_handle_of_accessor(a); if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - _grib_get_string_length(a, &size); - if (size == 0) - return; - - value = (char*)grib_context_malloc_clear(c, size); - if (!value) { - grib_context_log(c, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size); - return; - } - self->empty = 0; err = grib_unpack_string(a, value, &size); @@ -556,7 +547,6 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) depth -= 2; } - grib_context_free(c, value); (void)err; /* TODO */ } diff --git a/src/grib_dumper_class_bufr_decode_python.c b/src/grib_dumper_class_bufr_decode_python.c index 2d2dc7a0f..4ebd9cf73 100644 --- a/src/grib_dumper_class_bufr_decode_python.c +++ b/src/grib_dumper_class_bufr_decode_python.c @@ -502,12 +502,13 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm (void)err; /* TODO */ } +#define MAX_STRING_SIZE 4096 static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) { grib_dumper_bufr_decode_python* self = (grib_dumper_bufr_decode_python*)d; - char* value = NULL; + char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */ char* p = NULL; - size_t size = 0; + size_t size = MAX_STRING_SIZE; grib_context* c = a->context; int r = 0, err = 0; grib_handle* h = grib_handle_of_accessor(a); @@ -515,16 +516,6 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - _grib_get_string_length(a, &size); - if (size == 0) - return; - - value = (char*)grib_context_malloc_clear(c, size); - if (!value) { - grib_context_log(c, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size); - return; - } - self->empty = 0; err = grib_unpack_string(a, value, &size); @@ -567,7 +558,6 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) depth -= 2; } - grib_context_free(c, value); (void)err; /* TODO */ } diff --git a/src/grib_dumper_class_bufr_simple.c b/src/grib_dumper_class_bufr_simple.c index eecf302d1..db7db99b7 100644 --- a/src/grib_dumper_class_bufr_simple.c +++ b/src/grib_dumper_class_bufr_simple.c @@ -628,49 +628,31 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm (void)err; /* TODO */ } +#define MAX_STRING_SIZE 4096 static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) { grib_dumper_bufr_simple* self = (grib_dumper_bufr_simple*)d; - char* value = NULL; + char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */ char* p = NULL; - size_t size = 0; + size_t size = MAX_STRING_SIZE; grib_context* c = a->context; int r = 0; int is_missing = 0; int err = 0; grib_handle* h = grib_handle_of_accessor(a); const char* acc_name = a->name; - - _grib_get_string_length(a, &size); - if (size == 0) - return; + + if ( strcmp(acc_name,"ident")==0 ) + puts(""); if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { - /* ECC-356: Solution for the special local section key 'keyMore' and its alias 'ident' */ - int skip = 1; - if ((a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) { - /* We've come across a key which is hidden */ - if (strcmp(a->name, "keyMore") == 0 && grib_is_defined(h, "ls.ident")) { - grib_accessor* acc = NULL; - skip = 0; - acc_name = "ident"; - acc = grib_find_accessor(h, "identTrimmed"); - if (acc) a = acc; - } - } - if (skip) - return; - } - - value = (char*)grib_context_malloc_clear(c, size); - if (!value) { - grib_context_log(c, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size); return; } self->empty = 0; err = grib_unpack_string(a, value, &size); + Assert(size < MAX_STRING_SIZE); p = value; r = compute_bufr_key_rank(h, self->keys, acc_name); if (grib_is_missing_string(a, (unsigned char*)value, size)) { @@ -711,7 +693,6 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) grib_context_free(c, prefix); } - grib_context_free(c, value); (void)err; /* TODO */ } diff --git a/src/grib_dumper_class_json.c b/src/grib_dumper_class_json.c index 61d828fc5..8a526005c 100644 --- a/src/grib_dumper_class_json.c +++ b/src/grib_dumper_class_json.c @@ -450,23 +450,14 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) { grib_dumper_json* self = (grib_dumper_json*)d; char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */ + size_t size = MAX_STRING_SIZE; char* p = NULL; - size_t size = MAX_STRING_SIZE; int is_missing = 0; int err = 0; const char* acc_name = a->name; if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { - /* ECC-356: Solution for the special local section key 'keyMore' and its alias 'ident' */ - int skip = 1; - if ((a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) { - if (strcmp(a->name, "identTrimmed") == 0) { - skip = 0; - acc_name = "ident"; - } - } - if (skip) - return; + return; } /* ECC-710: It is MUCH slower determining the string length here