From f7869adb9c2f67334b715d00346bcfae2c7ffb34 Mon Sep 17 00:00:00 2001 From: shahramn Date: Sat, 24 Feb 2024 22:21:36 +0000 Subject: [PATCH] Error messages: Print context --- src/grib_accessor_class_bufr_elements_table.cc | 3 +-- src/grib_accessor_class_data_g22order_packing.cc | 2 +- src/grib_bufr_descriptors_array.cc | 8 +++----- src/grib_darray.cc | 8 +++----- src/grib_dumper_class_json.cc | 2 +- src/grib_iarray.cc | 9 +++------ src/grib_index.cc | 10 +++------- 7 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/grib_accessor_class_bufr_elements_table.cc b/src/grib_accessor_class_bufr_elements_table.cc index cee7049aa..4858ff63d 100644 --- a/src/grib_accessor_class_bufr_elements_table.cc +++ b/src/grib_accessor_class_bufr_elements_table.cc @@ -379,8 +379,7 @@ bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, i DEBUG_ASSERT(c); v = (bufr_descriptor*)grib_context_malloc_clear(c, sizeof(bufr_descriptor)); if (!v) { - grib_context_log(c, GRIB_LOG_ERROR, - "accessor_bufr_elements_table_get_descriptor: unable to allocate %ld bytes\n", sizeof(bufr_descriptor)); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(bufr_descriptor)); *err = GRIB_OUT_OF_MEMORY; return NULL; } diff --git a/src/grib_accessor_class_data_g22order_packing.cc b/src/grib_accessor_class_data_g22order_packing.cc index f45d9f722..4ed535d29 100644 --- a/src/grib_accessor_class_data_g22order_packing.cc +++ b/src/grib_accessor_class_data_g22order_packing.cc @@ -1772,7 +1772,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) unsigned char* sec7 = reinterpret_cast(grib_context_malloc(a->context, size_sec7)); if (sec7 == NULL) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: unable to allocate %d bytes", cclass_name, size_sec7); + grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Unable to allocate %d bytes", cclass_name, size_sec7); return GRIB_OUT_OF_MEMORY; } diff --git a/src/grib_bufr_descriptors_array.cc b/src/grib_bufr_descriptors_array.cc index 0134048a2..637cf14eb 100644 --- a/src/grib_bufr_descriptors_array.cc +++ b/src/grib_bufr_descriptors_array.cc @@ -22,8 +22,7 @@ bufr_descriptors_array* grib_bufr_descriptors_array_new(grib_context* c, size_t v = (bufr_descriptors_array*)grib_context_malloc(c, sizeof(bufr_descriptors_array)); if (!v) { - grib_context_log(c, GRIB_LOG_ERROR, - "bufr_descriptors_array_new unable to allocate %ld bytes\n", sizeof(bufr_descriptors_array)); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(bufr_descriptors_array)); return NULL; } v->context = c; @@ -34,7 +33,7 @@ bufr_descriptors_array* grib_bufr_descriptors_array_new(grib_context* c, size_t v->number_of_pop_front = 0; if (!v->v) { grib_context_log(c, GRIB_LOG_ERROR, - "grib_bufr_descriptors_array_new unable to allocate %ld bytes\n", sizeof(bufr_descriptor) * size); + "%s: Unable to allocate %zu bytes", __func__, sizeof(bufr_descriptor) * size); return NULL; } return v; @@ -73,8 +72,7 @@ static bufr_descriptors_array* grib_bufr_descriptors_array_resize_to(bufr_descri newv = (bufr_descriptor**)grib_context_malloc_clear(c, newsize * sizeof(bufr_descriptor*)); if (!newv) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_bufr_descriptors_array_resize unable to allocate %ld bytes\n", sizeof(bufr_descriptor*) * newsize); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(bufr_descriptor*) * newsize); return NULL; } diff --git a/src/grib_darray.cc b/src/grib_darray.cc index f2250862d..5aac8265a 100644 --- a/src/grib_darray.cc +++ b/src/grib_darray.cc @@ -45,8 +45,7 @@ grib_darray* grib_darray_new(grib_context* c, size_t size, size_t incsize) c = grib_context_get_default(); v = (grib_darray*)grib_context_malloc_clear(c, sizeof(grib_darray)); if (!v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_darray_new unable to allocate %zu bytes", sizeof(grib_darray)); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(grib_darray)); return NULL; } v->size = size; @@ -55,8 +54,7 @@ grib_darray* grib_darray_new(grib_context* c, size_t size, size_t incsize) v->context = c; v->v = (double*)grib_context_malloc_clear(c, sizeof(double) * size); if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_darray_new unable to allocate %zu bytes", sizeof(double) * size); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(double) * size); return NULL; } return v; @@ -73,7 +71,7 @@ static grib_darray* grib_darray_resize(grib_darray* v) v->size = newsize; if (!v->v) { grib_context_log(c, GRIB_LOG_ERROR, - "grib_darray_resize unable to allocate %zu bytes", sizeof(double) * newsize); + "%s: Unable to allocate %zu bytes", __func__, sizeof(double) * newsize); return NULL; } return v; diff --git a/src/grib_dumper_class_json.cc b/src/grib_dumper_class_json.cc index be1b5bcc4..a3b052844 100644 --- a/src/grib_dumper_class_json.cc +++ b/src/grib_dumper_class_json.cc @@ -458,7 +458,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) * if (size==0) return; * value=(char*)grib_context_malloc_clear(a->context,size); * if (!value) { - * grib_context_log(a->context,GRIB_LOG_ERROR,"unable to allocate %d bytes",(int)size); + * grib_context_log(a->context,GRIB_LOG_ERROR,"Unable to allocate %zu bytes",size); * return; * } */ diff --git a/src/grib_iarray.cc b/src/grib_iarray.cc index 50d16bcaa..f69adfffd 100644 --- a/src/grib_iarray.cc +++ b/src/grib_iarray.cc @@ -46,8 +46,7 @@ grib_iarray* grib_iarray_new(grib_context* c, size_t size, size_t incsize) v = (grib_iarray*)grib_context_malloc(c, sizeof(grib_iarray)); if (!v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_iarray_new unable to allocate %zu bytes", sizeof(grib_iarray)); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(grib_iarray)); return NULL; } v->context = c; @@ -57,8 +56,7 @@ grib_iarray* grib_iarray_new(grib_context* c, size_t size, size_t incsize) v->v = (long*)grib_context_malloc(c, sizeof(long) * size); v->number_of_pop_front = 0; if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_iarray_new unable to allocate %zu bytes", sizeof(long) * size); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(long) * size); return NULL; } return v; @@ -98,8 +96,7 @@ static grib_iarray* grib_iarray_resize_to(grib_iarray* v, size_t newsize) newv = (long*)grib_context_malloc_clear(c, newsize * sizeof(long)); if (!newv) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_iarray_resize unable to allocate %zu bytes", sizeof(long) * newsize); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(long) * newsize); return NULL; } diff --git a/src/grib_index.cc b/src/grib_index.cc index 225e502eb..15e9de083 100644 --- a/src/grib_index.cc +++ b/src/grib_index.cc @@ -242,17 +242,13 @@ static grib_index_key* grib_index_new_key(grib_context* c, grib_index_key* keys, next = (grib_index_key*)grib_context_malloc_clear(c, sizeof(grib_index_key)); if (!next) { - grib_context_log(c, GRIB_LOG_ERROR, - "unable to allocate %ld bytes", - sizeof(grib_index_key)); + grib_context_log(c, GRIB_LOG_ERROR, "Unable to allocate %zu bytes", sizeof(grib_index_key)); *err = GRIB_OUT_OF_MEMORY; return NULL; } values = (grib_string_list*)grib_context_malloc_clear(c, sizeof(grib_string_list)); if (!values) { - grib_context_log(c, GRIB_LOG_ERROR, - "unable to allocate %ld bytes", - sizeof(grib_string_list)); + grib_context_log(c, GRIB_LOG_ERROR, "Unable to allocate %zu bytes", sizeof(grib_string_list)); *err = GRIB_OUT_OF_MEMORY; return NULL; } @@ -1908,7 +1904,7 @@ grib_handle* codes_new_from_index(grib_index* index, int message_type, int* err) sizeof(grib_field_list)); if (!index->fieldset) { grib_context_log(index->context, GRIB_LOG_ERROR, - "unable to allocate %lu bytes", sizeof(grib_field_list)); + "Unable to allocate %zu bytes", sizeof(grib_field_list)); return NULL; } index->current = index->fieldset;