diff --git a/src/dumper/grib_dumper.h b/src/dumper/grib_dumper.h index 79dd83697..5970954a0 100644 --- a/src/dumper/grib_dumper.h +++ b/src/dumper/grib_dumper.h @@ -33,7 +33,7 @@ class Dumper virtual void header(const grib_handle*) const {}; virtual void footer(const grib_handle*) const {}; - long count() { return count_; } + long count() const { return count_; } void count(long count) { count_ = count; } int depth_ = 0; @@ -41,7 +41,6 @@ class Dumper unsigned long option_flags_ = 0; grib_context* context_ = nullptr; FILE* out_ = nullptr; - int inited_ = 0; protected: const char* class_name_ = nullptr; diff --git a/src/dumper/grib_dumper_class_bufr_decode_C.cc b/src/dumper/grib_dumper_class_bufr_decode_C.cc index ac163a6eb..790e83b07 100644 --- a/src/dumper/grib_dumper_class_bufr_decode_C.cc +++ b/src/dumper/grib_dumper_class_bufr_decode_C.cc @@ -494,7 +494,7 @@ void BufrDecodeC::dump_string(grib_accessor* a, const char* comment) (void)err; /* TODO */ } -void BufrDecodeC::dump_bytes(grib_accessor* a, const char* comment) +void BufrDecodeC::dump_bytes(grib_accessor* a, const char* comment) { } @@ -547,7 +547,7 @@ void BufrDecodeC::dump_section(grib_accessor* a, grib_block_of_accessors* block) } } -void BufrDecodeC::dump_attributes(grib_accessor* a, const char* prefix) +void BufrDecodeC::dump_attributes(grib_accessor* a, const char* prefix) { int i = 0; unsigned long flags; diff --git a/src/geo/iterator/grib_iterator_class_gaussian_reduced.cc b/src/geo/iterator/grib_iterator_class_gaussian_reduced.cc index c7881a7f2..82f996a18 100644 --- a/src/geo/iterator/grib_iterator_class_gaussian_reduced.cc +++ b/src/geo/iterator/grib_iterator_class_gaussian_reduced.cc @@ -303,10 +303,10 @@ int GaussianReduced::init(grib_handle* h, grib_arguments* args) grib_get_long_array_internal(h, spl, pl, &plsize); - lats_ = (double*)grib_context_malloc(h->context, nv_ * sizeof(double)); + lats_ = (double*)grib_context_malloc_clear(h->context, nv_ * sizeof(double)); if (!lats_) return GRIB_OUT_OF_MEMORY; - lons_ = (double*)grib_context_malloc(h->context, nv_ * sizeof(double)); + lons_ = (double*)grib_context_malloc_clear(h->context, nv_ * sizeof(double)); if (!lons_) return GRIB_OUT_OF_MEMORY; diff --git a/src/grib_dumper_factory.cc b/src/grib_dumper_factory.cc index eb0a33595..5671d284c 100644 --- a/src/grib_dumper_factory.cc +++ b/src/grib_dumper_factory.cc @@ -32,7 +32,7 @@ static omp_nest_lock_t mutex; static void init_mutex() { - GRIB_OMP_CRITICAL(lock_dumper_c) + GRIB_OMP_CRITICAL(lock_grib_dumper_factory_c) { if (once == 0) { omp_init_nest_lock(&mutex); @@ -50,51 +50,47 @@ struct table_entry }; static struct table_entry table[] = { - {"bufr_decode_C",&grib_dumper_bufr_decode_c,}, - {"bufr_decode_filter",&grib_dumper_bufr_decode_filter,}, - {"bufr_decode_fortran",&grib_dumper_bufr_decode_fortran,}, - {"bufr_decode_python",&grib_dumper_bufr_decode_python,}, - {"bufr_encode_C",&grib_dumper_bufr_encode_c,}, - {"bufr_encode_filter",&grib_dumper_bufr_encode_filter,}, - {"bufr_encode_fortran",&grib_dumper_bufr_encode_fortran,}, - {"bufr_encode_python",&grib_dumper_bufr_encode_python,}, - {"bufr_simple",&grib_dumper_bufr_simple,}, - {"debug",&grib_dumper_debug,}, - {"default",&grib_dumper_default,}, - {"grib_encode_c",&grib_dumper_grib_encode_c,}, - {"json",&grib_dumper_json,}, - {"serialize",&grib_dumper_serialize,}, - {"wmo",&grib_dumper_wmo,}, + {"bufr_decode_C",&grib_dumper_bufr_decode_c,}, + {"bufr_decode_filter",&grib_dumper_bufr_decode_filter,}, + {"bufr_decode_fortran",&grib_dumper_bufr_decode_fortran,}, + {"bufr_decode_python",&grib_dumper_bufr_decode_python,}, + {"bufr_encode_C",&grib_dumper_bufr_encode_c,}, + {"bufr_encode_filter",&grib_dumper_bufr_encode_filter,}, + {"bufr_encode_fortran",&grib_dumper_bufr_encode_fortran,}, + {"bufr_encode_python",&grib_dumper_bufr_encode_python,}, + {"bufr_simple",&grib_dumper_bufr_simple,}, + {"debug",&grib_dumper_debug,}, + {"default",&grib_dumper_default,}, + {"grib_encode_c",&grib_dumper_grib_encode_c,}, + {"json",&grib_dumper_json,}, + {"serialize",&grib_dumper_serialize,}, + {"wmo",&grib_dumper_wmo,}, }; eccodes::Dumper* grib_dumper_factory(const char* op, const grib_handle* h, FILE* out, unsigned long option_flags, void* arg) { constexpr size_t num_table_entries = sizeof(table) / sizeof(table[0]); - for (size_t i = 0; i < num_table_entries; i++) + for (size_t i = 0; i < num_table_entries; i++) { if (strcmp(op, table[i].type) == 0) { eccodes::Dumper* d = *(table[i].dumper); GRIB_MUTEX_INIT_ONCE(&once, &init_mutex); GRIB_MUTEX_LOCK(&mutex); - if (!d->inited_) { - d->depth_ = 0; - d->context_ = h->context; - d->option_flags_ = option_flags; - d->arg_ = arg; - d->out_ = out; - d->init(); - d->inited_ = 1; - } + d->depth_ = 0; + d->context_ = h->context; + d->option_flags_ = option_flags; + d->arg_ = arg; + d->out_ = out; + d->init(); GRIB_MUTEX_UNLOCK(&mutex); grib_context_log( h->context, GRIB_LOG_DEBUG, "Creating dumper of type : %s ", op); return d; } - grib_context_log( - h->context, GRIB_LOG_ERROR, "Unknown type : '%s' for dumper", op); + } + grib_context_log(h->context, GRIB_LOG_ERROR, "Unknown type : '%s' for dumper", op); return NULL; } - void grib_dump_content(const grib_handle* h, FILE* f, const char* mode, unsigned long flags, void* data) { eccodes::Dumper* dumper = grib_dumper_factory(mode ? mode : "serialize", h, f, flags, data); @@ -115,7 +111,6 @@ void grib_dump_content(const grib_handle* h, FILE* f, const char* mode, unsigned dumper->destroy(); } - void grib_dump_accessors_block(eccodes::Dumper* dumper, grib_block_of_accessors* block) { grib_accessor* a = block->first; @@ -160,15 +155,15 @@ void grib_dump_keys(grib_handle* h, FILE* f, const char* mode, unsigned long fla eccodes::Dumper* dumper = grib_dumper_factory(mode ? mode : "serialize", h, f, flags, data); if (!dumper) return; + GRIB_MUTEX_INIT_ONCE(&once, &init_mutex); + GRIB_MUTEX_LOCK(&mutex); for (size_t i = 0; i < num_keys; ++i) { acc = grib_find_accessor(h, keys[i]); if (acc) { - GRIB_MUTEX_INIT_ONCE(&once, &init_mutex); - GRIB_MUTEX_LOCK(&mutex); acc->dump(dumper); - GRIB_MUTEX_UNLOCK(&mutex); } } + GRIB_MUTEX_UNLOCK(&mutex); dumper->destroy(); } diff --git a/src/grib_iterator_factory.cc b/src/grib_iterator_factory.cc index 15026358f..defb2891c 100644 --- a/src/grib_iterator_factory.cc +++ b/src/grib_iterator_factory.cc @@ -29,7 +29,7 @@ static omp_nest_lock_t mutex; static void init_mutex() { - GRIB_OMP_CRITICAL(lock_grib_accessor_class_c) + GRIB_OMP_CRITICAL(lock_grib_iterator_factory_c) { if (once == 0) { omp_init_nest_lock(&mutex); diff --git a/src/grib_value.cc b/src/grib_value.cc index 7da9bd030..0f07e69dc 100644 --- a/src/grib_value.cc +++ b/src/grib_value.cc @@ -136,15 +136,12 @@ int grib_set_long(grib_handle* h, const char* name, long val) fprintf(stderr, "ECCODES DEBUG grib_set_long h=%p %s=%ld\n", (void*)h, name, val); } - if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) { + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) return GRIB_READ_ONLY; - } ret = a->pack_long(&val, &l); - if (ret == GRIB_SUCCESS) { - auto ret = grib_dependency_notify_change(a); - return ret; - } + if (ret == GRIB_SUCCESS) + return grib_dependency_notify_change(a); return ret; }