ECC-1675: C internals: Add error argument to grib_nearest_factory function

This commit is contained in:
Shahram Najm 2023-08-30 10:00:44 +01:00 committed by shahramn
parent 2e5b0bc69a
commit 33cd475fe0
4 changed files with 16 additions and 14 deletions

View File

@ -1284,7 +1284,7 @@ int grib_nearest_find_generic(grib_nearest* nearest, grib_handle* h, double inla
double* outlats, double* outlons, double* values, double* distances, int* indexes, size_t* len);
/* grib_nearest_class.cc*/
grib_nearest* grib_nearest_factory(grib_handle* h, grib_arguments* args);
grib_nearest* grib_nearest_factory(grib_handle* h, grib_arguments* args, int* error);
/* grib_nearest_class_gen.cc*/

View File

@ -122,7 +122,7 @@ grib_nearest* grib_nearest_new(const grib_handle* ch, int* error)
if (!a)
return NULL;
n = grib_nearest_factory(h, na->args);
n = grib_nearest_factory(h, na->args, error);
if (n)
*error = GRIB_SUCCESS;

View File

@ -31,26 +31,27 @@ static const struct table_entry table[] = {
#include "grib_iterator_factory.h"
};
grib_iterator* grib_iterator_factory(grib_handle* h, grib_arguments* args, unsigned long flags, int* ret)
grib_iterator* grib_iterator_factory(grib_handle* h, grib_arguments* args, unsigned long flags, int* error)
{
size_t i = 0;
const char* type = (char*)grib_arguments_get_name(h, args, 0);
*error = GRIB_NOT_IMPLEMENTED;
for (i = 0; i < NUMBER(table); i++)
for (i = 0; i < NUMBER(table); i++) {
if (strcmp(type, table[i].type) == 0) {
grib_iterator_class* c = *(table[i].cclass);
grib_iterator* it = (grib_iterator*)grib_context_malloc_clear(h->context, c->size);
it->cclass = c;
it->flags = flags;
*ret = GRIB_SUCCESS;
*ret = grib_iterator_init(it, h, args);
if (*ret == GRIB_SUCCESS)
*error = grib_iterator_init(it, h, args);
if (*error == GRIB_SUCCESS)
return it;
grib_context_log(h->context, GRIB_LOG_ERROR, "Geoiterator factory: Error instantiating iterator %s (%s)",
table[i].type, grib_get_error_message(*ret));
table[i].type, grib_get_error_message(*error));
grib_iterator_delete(it);
return NULL;
}
}
grib_context_log(h->context, GRIB_LOG_ERROR, "Geoiterator factory: Unknown type: %s", type);

View File

@ -26,25 +26,26 @@ static const struct table_entry table[] = {
#include "grib_nearest_factory.h"
};
grib_nearest* grib_nearest_factory(grib_handle* h, grib_arguments* args)
grib_nearest* grib_nearest_factory(grib_handle* h, grib_arguments* args, int* error)
{
size_t i = 0;
int ret = GRIB_SUCCESS;
*error = GRIB_NOT_IMPLEMENTED;
char* type = (char*)grib_arguments_get_name(h, args, 0);
for (i = 0; i < NUMBER(table); i++)
for (i = 0; i < NUMBER(table); i++) {
if (strcmp(type, table[i].type) == 0) {
grib_nearest_class* c = *(table[i].cclass);
grib_nearest* it = (grib_nearest*)grib_context_malloc_clear(h->context, c->size);
it->cclass = c;
ret = grib_nearest_init(it, h, args);
if (ret == GRIB_SUCCESS)
*error = grib_nearest_init(it, h, args);
if (*error == GRIB_SUCCESS)
return it;
grib_context_log(h->context, GRIB_LOG_ERROR, "grib_nearest_factory: Error instantiating nearest %s (%s)",
table[i].type, grib_get_error_message(ret));
table[i].type, grib_get_error_message(*error));
grib_nearest_delete(it);
return NULL;
}
}
grib_context_log(h->context, GRIB_LOG_ERROR, "grib_nearest_factory: Unknown type: %s", type);