Error messages

This commit is contained in:
shahramn 2024-02-24 22:07:55 +00:00
parent 18edad5b52
commit e7e8e5f9a2
4 changed files with 44 additions and 48 deletions

View File

@ -165,9 +165,9 @@ static int grib_load_smart_table(grib_context* c, const char* filename, const ch
static void init(grib_accessor* a, const long len, grib_arguments* params) static void init(grib_accessor* a, const long len, grib_arguments* params)
{ {
int n = 0; int n = 0;
grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; grib_accessor_smart_table* self = (grib_accessor_smart_table*)a;
grib_handle* hand = grib_handle_of_accessor(a); grib_handle* hand = grib_handle_of_accessor(a);
self->values = grib_arguments_get_name(hand, params, n++); self->values = grib_arguments_get_name(hand, params, n++);
self->tablename = grib_arguments_get_string(hand, params, n++); self->tablename = grib_arguments_get_string(hand, params, n++);
@ -179,25 +179,25 @@ static void init(grib_accessor* a, const long len, grib_arguments* params)
a->length = 0; a->length = 0;
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
self->dirty = 1; self->dirty = 1;
self->tableCodesSize = 0; self->tableCodesSize = 0;
self->tableCodes = 0; self->tableCodes = 0;
} }
static grib_smart_table* load_table(grib_accessor* a) static grib_smart_table* load_table(grib_accessor* a)
{ {
grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; grib_accessor_smart_table* self = (grib_accessor_smart_table*)a;
size_t size = 0; size_t size = 0;
grib_handle* h = ((grib_accessor*)self)->parent->h; grib_handle* h = ((grib_accessor*)self)->parent->h;
grib_context* c = h->context; grib_context* c = h->context;
grib_smart_table* t = NULL; grib_smart_table* t = NULL;
grib_smart_table* next = NULL; grib_smart_table* next = NULL;
char* filename = 0; char* filename = 0;
char recomposed[1024] = {0,}; char recomposed[1024] = {0,};
char localRecomposed[1024] = {0,}; char localRecomposed[1024] = {0,};
char* localFilename = 0; char* localFilename = 0;
char extraRecomposed[1024] = {0,}; char extraRecomposed[1024] = {0,};
char* extraFilename = 0; char* extraFilename = 0;
char masterDir[1024] = {0,}; char masterDir[1024] = {0,};
char localDir[1024] = {0,}; char localDir[1024] = {0,};
char extraDir[1024] = {0,}; char extraDir[1024] = {0,};
@ -258,8 +258,8 @@ static grib_smart_table* load_table(grib_accessor* a)
*/ */
size = (1ULL << self->widthOfCode); /* = 2^self->widthOfCode (as a 64 bit number) */ size = (1ULL << self->widthOfCode); /* = 2^self->widthOfCode (as a 64 bit number) */
t = (grib_smart_table*)grib_context_malloc_clear_persistent(c, sizeof(grib_smart_table)); t = (grib_smart_table*)grib_context_malloc_clear_persistent(c, sizeof(grib_smart_table));
t->entries = (grib_smart_table_entry*)grib_context_malloc_clear_persistent(c, size * sizeof(grib_smart_table_entry)); t->entries = (grib_smart_table_entry*)grib_context_malloc_clear_persistent(c, size * sizeof(grib_smart_table_entry));
t->numberOfEntries = size; t->numberOfEntries = size;
if (filename != 0) if (filename != 0)
@ -296,21 +296,21 @@ static int grib_load_smart_table(grib_context* c, const char* filename,
Assert(t != NULL); Assert(t != NULL);
if (t->filename[0] == NULL) { if (t->filename[0] == NULL) {
t->filename[0] = grib_context_strdup_persistent(c, filename); t->filename[0] = grib_context_strdup_persistent(c, filename);
t->recomposed_name[0] = grib_context_strdup_persistent(c, recomposed_name); t->recomposed_name[0] = grib_context_strdup_persistent(c, recomposed_name);
t->next = c->smart_table; t->next = c->smart_table;
t->numberOfEntries = size; t->numberOfEntries = size;
GRIB_MUTEX_INIT_ONCE(&once, &thread_init); GRIB_MUTEX_INIT_ONCE(&once, &thread_init);
GRIB_MUTEX_LOCK(&mutex); GRIB_MUTEX_LOCK(&mutex);
c->smart_table = t; c->smart_table = t;
GRIB_MUTEX_UNLOCK(&mutex); GRIB_MUTEX_UNLOCK(&mutex);
} }
else if (t->filename[1] == NULL) { else if (t->filename[1] == NULL) {
t->filename[1] = grib_context_strdup_persistent(c, filename); t->filename[1] = grib_context_strdup_persistent(c, filename);
t->recomposed_name[1] = grib_context_strdup_persistent(c, recomposed_name); t->recomposed_name[1] = grib_context_strdup_persistent(c, recomposed_name);
} }
else { else {
t->filename[2] = grib_context_strdup_persistent(c, filename); t->filename[2] = grib_context_strdup_persistent(c, filename);
t->recomposed_name[2] = grib_context_strdup_persistent(c, recomposed_name); t->recomposed_name[2] = grib_context_strdup_persistent(c, recomposed_name);
} }
@ -405,7 +405,7 @@ static void dump(grib_accessor* a, grib_dumper* dumper)
static int unpack_string(grib_accessor* a, char* buffer, size_t* len) static int unpack_string(grib_accessor* a, char* buffer, size_t* len)
{ {
grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; grib_accessor_smart_table* self = (grib_accessor_smart_table*)a;
grib_smart_table* table = NULL; grib_smart_table* table = NULL;
size_t size = 1; size_t size = 1;
long value; long value;
@ -435,7 +435,7 @@ static int unpack_string(grib_accessor* a, char* buffer, size_t* len)
} }
strcpy(buffer, tmp); strcpy(buffer, tmp);
*len = l; *len = l;
self->dirty = 0; self->dirty = 0;
return GRIB_SUCCESS; return GRIB_SUCCESS;
@ -444,9 +444,9 @@ static int unpack_string(grib_accessor* a, char* buffer, size_t* len)
static int get_table_codes(grib_accessor* a) static int get_table_codes(grib_accessor* a)
{ {
grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; grib_accessor_smart_table* self = (grib_accessor_smart_table*)a;
size_t size = 0; size_t size = 0;
long* v = 0; long* v = 0;
int err = 0; int err = 0;
int count, j; int count, j;
size_t i; size_t i;
@ -479,7 +479,7 @@ static int get_table_codes(grib_accessor* a)
if (self->tableCodes) if (self->tableCodes)
grib_context_free(a->context, self->tableCodes); grib_context_free(a->context, self->tableCodes);
self->tableCodes = (long*)grib_context_malloc_clear(a->context, count * sizeof(long)); self->tableCodes = (long*)grib_context_malloc_clear(a->context, count * sizeof(long));
j = 0; j = 0;
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
if (v[i] < table_size) if (v[i] < table_size)
self->tableCodes[j++] = v[i]; self->tableCodes[j++] = v[i];
@ -488,16 +488,16 @@ static int get_table_codes(grib_accessor* a)
grib_context_free(a->context, v); grib_context_free(a->context, v);
self->tableCodesSize = count; self->tableCodesSize = count;
self->dirty = 0; self->dirty = 0;
return 0; return 0;
} }
static int value_count(grib_accessor* a, long* count) static int value_count(grib_accessor* a, long* count)
{ {
int err = 0; int err = 0;
grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; grib_accessor_smart_table* self = (grib_accessor_smart_table*)a;
*count = 0; *count = 0;
if (!self->values) if (!self->values)
return 0; return 0;
@ -532,7 +532,7 @@ static int get_native_type(grib_accessor* a)
static int unpack_long(grib_accessor* a, long* val, size_t* len) static int unpack_long(grib_accessor* a, long* val, size_t* len)
{ {
int err = 0; int err = 0;
grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; grib_accessor_smart_table* self = (grib_accessor_smart_table*)a;
size_t i; size_t i;

View File

@ -130,11 +130,11 @@ typedef struct grib_accessor_smart_table
static void init(grib_accessor* a, const long len, grib_arguments* params) static void init(grib_accessor* a, const long len, grib_arguments* params)
{ {
int n = 0; int n = 0;
grib_accessor_smart_table_column* self = (grib_accessor_smart_table_column*)a; grib_accessor_smart_table_column* self = (grib_accessor_smart_table_column*)a;
self->smartTable = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); self->smartTable = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++);
self->index = grib_arguments_get_long(grib_handle_of_accessor(a), params, n++); self->index = grib_arguments_get_long(grib_handle_of_accessor(a), params, n++);
a->length = 0; a->length = 0;
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
@ -158,18 +158,18 @@ static int unpack_string_array(grib_accessor* a, char** buffer, size_t* len)
{ {
grib_accessor_smart_table_column* self = (grib_accessor_smart_table_column*)a; grib_accessor_smart_table_column* self = (grib_accessor_smart_table_column*)a;
grib_accessor_smart_table* tableAccessor = NULL; grib_accessor_smart_table* tableAccessor = NULL;
grib_smart_table* table = NULL; grib_smart_table* table = NULL;
size_t size = 1; size_t size = 1;
long* code; long* code;
int err = GRIB_SUCCESS; int err = GRIB_SUCCESS;
char tmp[1024] = {0,}; char tmp[1024] = {0,};
int i = 0; int i = 0;
tableAccessor = (grib_accessor_smart_table*)grib_find_accessor(grib_handle_of_accessor(a), self->smartTable); tableAccessor = (grib_accessor_smart_table*)grib_find_accessor(grib_handle_of_accessor(a), self->smartTable);
if (!tableAccessor) { if (!tableAccessor) {
grib_context_log(a->context, GRIB_LOG_ERROR, grib_context_log(a->context, GRIB_LOG_ERROR,
"unable to find accessor %s", self->smartTable); "Unable to find accessor %s", self->smartTable);
return GRIB_NOT_FOUND; return GRIB_NOT_FOUND;
} }
@ -213,7 +213,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
{ {
grib_accessor_smart_table_column* self = (grib_accessor_smart_table_column*)a; grib_accessor_smart_table_column* self = (grib_accessor_smart_table_column*)a;
grib_accessor_smart_table* tableAccessor = NULL; grib_accessor_smart_table* tableAccessor = NULL;
grib_smart_table* table = NULL; grib_smart_table* table = NULL;
size_t size = 1; size_t size = 1;
long* code; long* code;
@ -226,7 +226,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
tableAccessor = (grib_accessor_smart_table*)grib_find_accessor(grib_handle_of_accessor(a), self->smartTable); tableAccessor = (grib_accessor_smart_table*)grib_find_accessor(grib_handle_of_accessor(a), self->smartTable);
if (!tableAccessor) { if (!tableAccessor) {
grib_context_log(a->context, GRIB_LOG_ERROR, grib_context_log(a->context, GRIB_LOG_ERROR,
"unable to find accessor %s", self->smartTable); "Unable to find accessor %s", self->smartTable);
return GRIB_NOT_FOUND; return GRIB_NOT_FOUND;
} }
@ -263,14 +263,14 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
static int value_count(grib_accessor* a, long* count) static int value_count(grib_accessor* a, long* count)
{ {
grib_accessor_smart_table_column* self = (grib_accessor_smart_table_column*)a; grib_accessor_smart_table_column* self = (grib_accessor_smart_table_column*)a;
size_t size = 0; size_t size = 0;
int err = 0; int err = 0;
*count = 0; *count = 0;
if (!self->smartTable) if (!self->smartTable)
return 0; return 0;
err = grib_get_size(grib_handle_of_accessor(a), self->smartTable, &size); err = grib_get_size(grib_handle_of_accessor(a), self->smartTable, &size);
*count = size; *count = size;
return err; return err;
} }

View File

@ -17,8 +17,6 @@ grib_oarray* grib_oarray_new(grib_context* c, size_t size, size_t incsize)
c = grib_context_get_default(); c = grib_context_get_default();
v = (grib_oarray*)grib_context_malloc_clear(c, sizeof(grib_oarray)); v = (grib_oarray*)grib_context_malloc_clear(c, sizeof(grib_oarray));
if (!v) { if (!v) {
grib_context_log(c, GRIB_LOG_ERROR,
"grib_oarray_new unable to allocate %zu bytes", sizeof(grib_oarray));
return NULL; return NULL;
} }
v->size = size; v->size = size;
@ -27,8 +25,7 @@ grib_oarray* grib_oarray_new(grib_context* c, size_t size, size_t incsize)
v->v = (void**)grib_context_malloc_clear(c, sizeof(char*) * size); v->v = (void**)grib_context_malloc_clear(c, sizeof(char*) * size);
v->context = c; v->context = c;
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(char*) * size);
"grib_oarray_new unable to allocate %zu bytes", sizeof(char*) * size);
return NULL; return NULL;
} }
return v; return v;
@ -44,8 +41,7 @@ static grib_oarray* grib_oarray_resize(grib_oarray* v)
v->v = (void**)grib_context_realloc(c, v->v, newsize * sizeof(char*)); v->v = (void**)grib_context_realloc(c, v->v, newsize * sizeof(char*));
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, "%s: Unable to allocate %zu bytes", __func__, sizeof(char*) * newsize);
"grib_oarray_resize unable to allocate %zu bytes", sizeof(char*) * newsize);
return NULL; return NULL;
} }
return v; return v;

View File

@ -30,7 +30,7 @@ grib_sarray* grib_sarray_new(grib_context* c, size_t size, size_t incsize)
v = (grib_sarray*)grib_context_malloc_clear(c, sizeof(grib_sarray)); v = (grib_sarray*)grib_context_malloc_clear(c, sizeof(grib_sarray));
if (!v) { if (!v) {
grib_context_log(c, GRIB_LOG_ERROR, grib_context_log(c, GRIB_LOG_ERROR,
"grib_sarray_new unable to allocate %lu bytes\n", sizeof(grib_sarray)); "%s: Unable to allocate %zu bytes", __func__, sizeof(grib_sarray));
return NULL; return NULL;
} }
v->size = size; v->size = size;
@ -40,7 +40,7 @@ grib_sarray* grib_sarray_new(grib_context* c, size_t size, size_t incsize)
v->v = (char**)grib_context_malloc_clear(c, sizeof(char*) * size); v->v = (char**)grib_context_malloc_clear(c, sizeof(char*) * size);
if (!v->v) { if (!v->v) {
grib_context_log(c, GRIB_LOG_ERROR, grib_context_log(c, GRIB_LOG_ERROR,
"grib_sarray_new unable to allocate %lu bytes\n", sizeof(char*) * size); "%s: Unable to allocate %zu bytes", __func__, sizeof(char*) * size);
return NULL; return NULL;
} }
return v; return v;
@ -57,7 +57,7 @@ static grib_sarray* grib_sarray_resize(grib_sarray* 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_sarray_resize unable to allocate %lu bytes\n", sizeof(char*) * newsize); "%s: Unable to allocate %zu bytes", __func__, sizeof(char*) * newsize);
return NULL; return NULL;
} }
return v; return v;