Error messages: Print context

This commit is contained in:
shahramn 2024-02-24 22:21:36 +00:00
parent e7e8e5f9a2
commit f7869adb9c
7 changed files with 15 additions and 27 deletions

View File

@ -379,8 +379,7 @@ bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, i
DEBUG_ASSERT(c); DEBUG_ASSERT(c);
v = (bufr_descriptor*)grib_context_malloc_clear(c, sizeof(bufr_descriptor)); v = (bufr_descriptor*)grib_context_malloc_clear(c, sizeof(bufr_descriptor));
if (!v) { if (!v) {
grib_context_log(c, GRIB_LOG_ERROR, grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(bufr_descriptor));
"accessor_bufr_elements_table_get_descriptor: unable to allocate %ld bytes\n", sizeof(bufr_descriptor));
*err = GRIB_OUT_OF_MEMORY; *err = GRIB_OUT_OF_MEMORY;
return NULL; return NULL;
} }

View File

@ -1772,7 +1772,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
unsigned char* sec7 = reinterpret_cast<unsigned char*>(grib_context_malloc(a->context, size_sec7)); unsigned char* sec7 = reinterpret_cast<unsigned char*>(grib_context_malloc(a->context, size_sec7));
if (sec7 == NULL) { 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; return GRIB_OUT_OF_MEMORY;
} }

View File

@ -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)); v = (bufr_descriptors_array*)grib_context_malloc(c, sizeof(bufr_descriptors_array));
if (!v) { if (!v) {
grib_context_log(c, GRIB_LOG_ERROR, grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(bufr_descriptors_array));
"bufr_descriptors_array_new unable to allocate %ld bytes\n", sizeof(bufr_descriptors_array));
return NULL; return NULL;
} }
v->context = c; 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; v->number_of_pop_front = 0;
if (!v->v) { if (!v->v) {
grib_context_log(c, GRIB_LOG_ERROR, 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 NULL;
} }
return v; 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*)); newv = (bufr_descriptor**)grib_context_malloc_clear(c, newsize * sizeof(bufr_descriptor*));
if (!newv) { if (!newv) {
grib_context_log(c, GRIB_LOG_ERROR, grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(bufr_descriptor*) * newsize);
"grib_bufr_descriptors_array_resize unable to allocate %ld bytes\n", sizeof(bufr_descriptor*) * newsize);
return NULL; return NULL;
} }

View File

@ -45,8 +45,7 @@ grib_darray* grib_darray_new(grib_context* c, size_t size, size_t incsize)
c = grib_context_get_default(); c = grib_context_get_default();
v = (grib_darray*)grib_context_malloc_clear(c, sizeof(grib_darray)); v = (grib_darray*)grib_context_malloc_clear(c, sizeof(grib_darray));
if (!v) { if (!v) {
grib_context_log(c, GRIB_LOG_ERROR, grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(grib_darray));
"grib_darray_new unable to allocate %zu bytes", sizeof(grib_darray));
return NULL; return NULL;
} }
v->size = size; 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->context = c;
v->v = (double*)grib_context_malloc_clear(c, sizeof(double) * size); v->v = (double*)grib_context_malloc_clear(c, sizeof(double) * size);
if (!v->v) { if (!v->v) {
grib_context_log(c, GRIB_LOG_ERROR, grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(double) * size);
"grib_darray_new unable to allocate %zu bytes", sizeof(double) * size);
return NULL; return NULL;
} }
return v; return v;
@ -73,7 +71,7 @@ static grib_darray* grib_darray_resize(grib_darray* v)
v->size = newsize; v->size = newsize;
if (!v->v) { if (!v->v) {
grib_context_log(c, GRIB_LOG_ERROR, 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 NULL;
} }
return v; return v;

View File

@ -458,7 +458,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
* if (size==0) return; * if (size==0) return;
* value=(char*)grib_context_malloc_clear(a->context,size); * value=(char*)grib_context_malloc_clear(a->context,size);
* if (!value) { * 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; * return;
* } * }
*/ */

View File

@ -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)); v = (grib_iarray*)grib_context_malloc(c, sizeof(grib_iarray));
if (!v) { if (!v) {
grib_context_log(c, GRIB_LOG_ERROR, grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(grib_iarray));
"grib_iarray_new unable to allocate %zu bytes", sizeof(grib_iarray));
return NULL; return NULL;
} }
v->context = c; 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->v = (long*)grib_context_malloc(c, sizeof(long) * size);
v->number_of_pop_front = 0; v->number_of_pop_front = 0;
if (!v->v) { if (!v->v) {
grib_context_log(c, GRIB_LOG_ERROR, grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(long) * size);
"grib_iarray_new unable to allocate %zu bytes", sizeof(long) * size);
return NULL; return NULL;
} }
return v; 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)); newv = (long*)grib_context_malloc_clear(c, newsize * sizeof(long));
if (!newv) { if (!newv) {
grib_context_log(c, GRIB_LOG_ERROR, grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(long) * newsize);
"grib_iarray_resize unable to allocate %zu bytes", sizeof(long) * newsize);
return NULL; return NULL;
} }

View File

@ -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)); next = (grib_index_key*)grib_context_malloc_clear(c, sizeof(grib_index_key));
if (!next) { if (!next) {
grib_context_log(c, GRIB_LOG_ERROR, grib_context_log(c, GRIB_LOG_ERROR, "Unable to allocate %zu bytes", sizeof(grib_index_key));
"unable to allocate %ld bytes",
sizeof(grib_index_key));
*err = GRIB_OUT_OF_MEMORY; *err = GRIB_OUT_OF_MEMORY;
return NULL; return NULL;
} }
values = (grib_string_list*)grib_context_malloc_clear(c, sizeof(grib_string_list)); values = (grib_string_list*)grib_context_malloc_clear(c, sizeof(grib_string_list));
if (!values) { if (!values) {
grib_context_log(c, GRIB_LOG_ERROR, grib_context_log(c, GRIB_LOG_ERROR, "Unable to allocate %zu bytes", sizeof(grib_string_list));
"unable to allocate %ld bytes",
sizeof(grib_string_list));
*err = GRIB_OUT_OF_MEMORY; *err = GRIB_OUT_OF_MEMORY;
return NULL; return NULL;
} }
@ -1908,7 +1904,7 @@ grib_handle* codes_new_from_index(grib_index* index, int message_type, int* err)
sizeof(grib_field_list)); sizeof(grib_field_list));
if (!index->fieldset) { if (!index->fieldset) {
grib_context_log(index->context, GRIB_LOG_ERROR, 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; return NULL;
} }
index->current = index->fieldset; index->current = index->fieldset;