From f7cf087f083ee74ed93345236ac984c76d84e9f1 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 4 Sep 2023 12:44:59 +0100 Subject: [PATCH] Remove pack_ methods on read-only accessors --- src/grib_accessor_class_to_string.cc | 49 ++++++++-------------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/src/grib_accessor_class_to_string.cc b/src/grib_accessor_class_to_string.cc index 2abfccee1..ce8bf4e74 100644 --- a/src/grib_accessor_class_to_string.cc +++ b/src/grib_accessor_class_to_string.cc @@ -7,9 +7,6 @@ * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/*********************************************************** - * Enrico Fucile - ***********************************************************/ #include "grib_api_internal.h" /* @@ -18,9 +15,9 @@ START_CLASS_DEF CLASS = accessor SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_string;pack_string - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = unpack_double;pack_double + IMPLEMENTS = unpack_string + IMPLEMENTS = unpack_long + IMPLEMENTS = unpack_double IMPLEMENTS = init;dump;string_length IMPLEMENTS = value_count IMPLEMENTS = next_offset @@ -44,9 +41,6 @@ or edit "accessor.class" and rerun ./make_class.pl */ static int get_native_type(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); static int unpack_double(grib_accessor*, double* val, size_t* len); static int unpack_long(grib_accessor*, long* val, size_t* len); static int unpack_string(grib_accessor*, char*, size_t* len); @@ -88,13 +82,13 @@ static grib_accessor_class _grib_accessor_class_to_string = { 0, /* get sub_section */ 0, /* pack_missing */ 0, /* is_missing */ - &pack_long, /* pack_long */ + 0, /* pack_long */ &unpack_long, /* unpack_long */ - &pack_double, /* pack_double */ + 0, /* pack_double */ 0, /* pack_float */ &unpack_double, /* unpack_double */ 0, /* unpack_float */ - &pack_string, /* pack_string */ + 0, /* pack_string */ &unpack_string, /* unpack_string */ 0, /* pack_string_array */ 0, /* unpack_string_array */ @@ -148,11 +142,11 @@ static int value_count(grib_accessor* a, long* count) static size_t string_length(grib_accessor* a) { grib_accessor_to_string* self = (grib_accessor_to_string*)a; - size_t size = 0; if (self->length) return self->length; + size_t size = 0; grib_get_string_length(grib_handle_of_accessor(a), self->key, &size); return size; } @@ -169,21 +163,21 @@ static int get_native_type(grib_accessor* a) static int unpack_string(grib_accessor* a, char* val, size_t* len) { - int err = 0; grib_accessor_to_string* self = (grib_accessor_to_string*)a; - char buff[512] = {0,}; - size_t length; - size_t size = 512; - length = string_length(a); + int err = 0; + char buff[512] = {0,}; + + size_t length = string_length(a); if (len[0] < length + 1) { grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s, it contains %ld values", - len[0], a->name, a->length + 1); + len[0], a->name, a->length + 1); len[0] = 0; return GRIB_ARRAY_TOO_SMALL; } + size_t size = sizeof(buff); err = grib_get_string(grib_handle_of_accessor(a), self->key, buff, &size); if (err) return err; @@ -199,23 +193,6 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) return GRIB_SUCCESS; } -static int pack_string(grib_accessor* a, const char* val, size_t* len) -{ - return GRIB_NOT_IMPLEMENTED; -} - -static int pack_long(grib_accessor* a, const long* v, size_t* len) -{ - grib_context_log(a->context, GRIB_LOG_ERROR, " Should not pack %s as long", a->name); - return GRIB_NOT_IMPLEMENTED; -} - -static int pack_double(grib_accessor* a, const double* v, size_t* len) -{ - grib_context_log(a->context, GRIB_LOG_ERROR, " Should not pack %s as double", a->name); - return GRIB_NOT_IMPLEMENTED; -} - static int unpack_long(grib_accessor* a, long* v, size_t* len) { char val[1024] = {0,};