Dead code removal: Unused functions

This commit is contained in:
Shahram Najm 2023-08-21 22:02:03 +01:00
parent e81ce8098f
commit 988e817ef1
4 changed files with 79 additions and 50 deletions

View File

@ -228,8 +228,6 @@ grib_iarray* grib_iarray_new(grib_context* c, size_t size, size_t incsize);
long grib_iarray_pop(grib_iarray* a);
long grib_iarray_pop_front(grib_iarray* a);
grib_iarray* grib_iarray_push(grib_iarray* v, long val);
grib_iarray* grib_iarray_push_front(grib_iarray* v, long val);
grib_iarray* grib_iarray_push_array(grib_iarray* v, long* val, size_t size);
void grib_iarray_delete(grib_iarray* v);
void grib_iarray_delete_array(grib_iarray* v);
long* grib_iarray_get_array(grib_iarray* v);

View File

@ -356,10 +356,12 @@ static int unpack_float(grib_accessor* a, float* v, size_t* len)
static int unpack_string(grib_accessor* a, char* v, size_t* len)
{
int err = 0;
if (a->cclass->unpack_double && a->cclass->unpack_double != &unpack_double) {
double val = 0.0;
size_t l = 1;
grib_unpack_double(a, &val, &l);
err = grib_unpack_double(a, &val, &l);
if (err) return err;
snprintf(v, 64, "%g", val);
*len = strlen(v);
grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting double %s to string", a->name);
@ -369,7 +371,8 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
if (a->cclass->unpack_long && a->cclass->unpack_long != &unpack_long) {
long val = 0;
size_t l = 1;
grib_unpack_long(a, &val, &l);
err = grib_unpack_long(a, &val, &l);
if (err) return err;
snprintf(v, 64, "%ld", val);
*len = strlen(v);
grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting long %s to string\n", a->name);
@ -388,7 +391,8 @@ static int unpack_string_array(grib_accessor* a, char** v, size_t* len)
if (err)
return err;
v[0] = (char*)grib_context_malloc_clear(a->context, length);
grib_unpack_string(a, v[0], &length);
err = grib_unpack_string(a, v[0], &length);
if (err) return err;
*len = 1;
return GRIB_SUCCESS;

View File

@ -8,10 +8,6 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
/***************************************************************************
* Enrico Fucile
***************************************************************************/
#include "grib_api_internal.h"
/* For debugging purposes */
@ -142,48 +138,45 @@ grib_iarray* grib_iarray_push(grib_iarray* v, long val)
return v;
}
grib_iarray* grib_iarray_push_front(grib_iarray* v, long val)
{
size_t start_size = 100;
size_t start_incsize = 100;
size_t i;
if (!v)
v = grib_iarray_new(0, start_size, start_incsize);
// grib_iarray* grib_iarray_push_front(grib_iarray* v, long val)
// {
// size_t start_size = 100;
// size_t start_incsize = 100;
// size_t i;
// if (!v)
// v = grib_iarray_new(0, start_size, start_incsize);
// if (v->number_of_pop_front) {
// v->v--;
// v->number_of_pop_front--;
// }
// else {
// if (v->n >= v->size)
// v = grib_iarray_resize(v);
// for (i = v->n; i > 0; i--)
// v[i] = v[i - 1];
// }
// v->v[0] = val;
// v->n++;
// return v;
// }
if (v->number_of_pop_front) {
v->v--;
v->number_of_pop_front--;
}
else {
if (v->n >= v->size)
v = grib_iarray_resize(v);
for (i = v->n; i > 0; i--)
v[i] = v[i - 1];
}
v->v[0] = val;
v->n++;
return v;
}
grib_iarray* grib_iarray_push_array(grib_iarray* v, long* val, size_t size)
{
size_t start_size = size;
size_t start_incsize = 100;
long* vp = 0;
long* valp = val;
if (!v)
v = grib_iarray_new(0, start_size, start_incsize);
v = grib_iarray_resize_to(v, size + v->n);
vp = v->v + v->n + v->number_of_pop_front;
v->n += size;
while (size) {
*(vp++) = *(valp++);
size--;
}
return v;
}
// grib_iarray* grib_iarray_push_array(grib_iarray* v, long* val, size_t size)
// {
// size_t start_size = size;
// size_t start_incsize = 100;
// long* vp = 0;
// long* valp = val;
// if (!v)
// v = grib_iarray_new(0, start_size, start_incsize);
// v = grib_iarray_resize_to(v, size + v->n);
// vp = v->v + v->n + v->number_of_pop_front;
// v->n += size;
// while (size) {
// *(vp++) = *(valp++);
// size--;
// }
// return v;
// }
void grib_iarray_delete(grib_iarray* v)
{

View File

@ -543,10 +543,44 @@ void test_scale_factor_scaled_values()
Assert(factor == 5);
}
void test_iarray()
{
grib_context* c = grib_context_get_default();
grib_iarray* a = grib_iarray_new(c, 10, 10);
grib_iarray_push(a, 42);
grib_iarray_print("test_iarray", a);
grib_iarray_delete(a);
}
void test_darray()
{
grib_context* c = grib_context_get_default();
grib_darray* a = grib_darray_new(c, 10, 10);
grib_darray_push(c, a, 42.009);
grib_darray_push(c, a, -1.11);
grib_darray_push(c, a, 5099);
grib_darray_print("test_darray", a);
grib_darray_delete(c, a);
}
void test_sarray()
{
grib_context* c = grib_context_get_default();
grib_sarray* a = grib_sarray_new(c, 10, 10);
grib_sarray_push(c, a, "ants");
grib_sarray_push(c, a, "bugs");
grib_sarray_print("test_sarray", a);
grib_sarray_delete(c, a);
}
int main(int argc, char** argv)
{
printf("Doing unit tests. ecCodes version = %ld\n", grib_get_api_version());
test_iarray();
test_darray();
test_sarray();
test_scale_factor_scaled_values();
test_dates();
test_logging_proc();