From 258269101647a0bb75f9a9e70c48ea72db92bb4f Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Mon, 20 May 2024 11:14:54 -0500 Subject: [PATCH] Factor user data serialization. --- src/cconfigspace_deserialize.h | 19 ++++++++++++++---- src/configuration_deserialize.h | 3 --- src/configuration_space_deserialize.h | 3 --- src/context_deserialize.h | 5 +++-- src/distribution_deserialize.h | 28 ++++++++++----------------- src/distribution_space_deserialize.h | 3 --- src/evaluation_deserialize.h | 3 --- src/expression_deserialize.h | 26 ++++--------------------- src/feature_space_deserialize.h | 3 --- src/features_deserialize.h | 3 --- src/map_deserialize.h | 3 --- src/objective_space_deserialize.h | 3 --- src/parameter_deserialize.h | 3 --- src/rng_deserialize.h | 3 --- src/tree_configuration_deserialize.h | 3 --- src/tree_deserialize.h | 24 ++++++++--------------- src/tree_space_deserialize.h | 3 --- src/tuner_deserialize.h | 3 --- 18 files changed, 40 insertions(+), 101 deletions(-) diff --git a/src/cconfigspace_deserialize.h b/src/cconfigspace_deserialize.h index 0840adc1..56c3803b 100644 --- a/src/cconfigspace_deserialize.h +++ b/src/cconfigspace_deserialize.h @@ -201,9 +201,9 @@ _ccs_object_deserialize_with_opts_check( &otype, buffer_size, buffer)); CCS_REFUTE( otype != expected_type, CCS_RESULT_ERROR_INVALID_TYPE); - CCS_VALIDATE(_ccs_object_deserialize_with_opts_type( - object_ret, expected_type, format, version, buffer_size, - buffer, opts)); + CCS_VALIDATE(_ccs_object_deserialize_with_opts( + object_ret, format, version, buffer_size, buffer, + opts)); } break; default: CCS_RAISE( @@ -222,13 +222,15 @@ _ccs_object_deserialize_with_opts( const char **buffer, _ccs_object_deserialize_options_t *opts) { + ccs_result_t err = CCS_RESULT_SUCCESS; + ccs_object_t obj; switch (format) { case CCS_SERIALIZE_FORMAT_BINARY: { ccs_object_type_t otype; CCS_VALIDATE(_ccs_peek_bin_ccs_object_type( &otype, buffer_size, buffer)); CCS_VALIDATE(_ccs_object_deserialize_with_opts_type( - object_ret, otype, format, version, buffer_size, buffer, + &obj, otype, format, version, buffer_size, buffer, opts)); } break; default: @@ -236,7 +238,16 @@ _ccs_object_deserialize_with_opts( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } + CCS_VALIDATE_ERR_GOTO( + err, + _ccs_object_deserialize_user_data( + obj, format, version, buffer_size, buffer, opts), + errobj); + *object_ret = obj; return CCS_RESULT_SUCCESS; +errobj: + ccs_release_object(obj); + return err; } #endif //_CCONFIG_SPACE_SPACE_DESERIALIZE_H diff --git a/src/configuration_deserialize.h b/src/configuration_deserialize.h index 8556b6e5..47bb5627 100644 --- a/src/configuration_deserialize.h +++ b/src/configuration_deserialize.h @@ -115,9 +115,6 @@ _ccs_configuration_deserialize( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*configuration_ret, format, version, buffer_size, - buffer, opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/configuration_space_deserialize.h b/src/configuration_space_deserialize.h index b06a941c..aa434b7c 100644 --- a/src/configuration_space_deserialize.h +++ b/src/configuration_space_deserialize.h @@ -190,9 +190,6 @@ _ccs_configuration_space_deserialize( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*configuration_space_ret, format, version, - buffer_size, buffer, opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/context_deserialize.h b/src/context_deserialize.h index 25b73796..b84eee85 100644 --- a/src/context_deserialize.h +++ b/src/context_deserialize.h @@ -27,8 +27,9 @@ _ccs_deserialize_bin_ccs_context_data( data->num_parameters, sizeof(ccs_parameter_t)); CCS_REFUTE(!data->parameters, CCS_RESULT_ERROR_OUT_OF_MEMORY); for (size_t i = 0; i < data->num_parameters; i++) - CCS_VALIDATE(_ccs_parameter_deserialize( - data->parameters + i, + CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( + (ccs_object_t *)data->parameters + i, + CCS_OBJECT_TYPE_PARAMETER, CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, buffer, opts)); } diff --git a/src/distribution_deserialize.h b/src/distribution_deserialize.h index 5d1880f1..313cf7ba 100644 --- a/src/distribution_deserialize.h +++ b/src/distribution_deserialize.h @@ -167,15 +167,6 @@ _ccs_deserialize_bin_distribution_roulette( return res; } -static inline ccs_result_t -_ccs_distribution_deserialize( - ccs_distribution_t *distribution_ret, - ccs_serialize_format_t format, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts); - struct _ccs_distribution_mixture_data_mock_s { _ccs_distribution_common_data_t common_data; size_t num_distributions; @@ -208,9 +199,11 @@ _ccs_deserialize_bin_ccs_distribution_mixture_data( for (size_t i = 0; i < data->num_distributions; i++) { CCS_VALIDATE(_ccs_deserialize_bin_ccs_float( data->weights + i, buffer_size, buffer)); - CCS_VALIDATE(_ccs_distribution_deserialize( - data->distributions + i, CCS_SERIALIZE_FORMAT_BINARY, - version, buffer_size, buffer, &new_opts)); + CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( + (ccs_object_t *)data->distributions + i, + CCS_OBJECT_TYPE_DISTRIBUTION, + CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, + buffer, &new_opts)); } return CCS_RESULT_SUCCESS; } @@ -276,9 +269,11 @@ _ccs_deserialize_bin_ccs_distribution_multivariate_data( data->num_distributions, sizeof(ccs_distribution_t)); CCS_REFUTE(!data->distributions, CCS_RESULT_ERROR_OUT_OF_MEMORY); for (size_t i = 0; i < data->num_distributions; i++) - CCS_VALIDATE(_ccs_distribution_deserialize( - data->distributions + i, CCS_SERIALIZE_FORMAT_BINARY, - version, buffer_size, buffer, &new_opts)); + CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( + (ccs_object_t *)data->distributions + i, + CCS_OBJECT_TYPE_DISTRIBUTION, + CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, + buffer, &new_opts)); return CCS_RESULT_SUCCESS; } @@ -394,9 +389,6 @@ _ccs_distribution_deserialize( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*distribution_ret, format, version, buffer_size, - buffer, opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/distribution_space_deserialize.h b/src/distribution_space_deserialize.h index b46b6933..b6b123c7 100644 --- a/src/distribution_space_deserialize.h +++ b/src/distribution_space_deserialize.h @@ -165,9 +165,6 @@ _ccs_distribution_space_deserialize( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*distribution_space_ret, format, version, - buffer_size, buffer, opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/evaluation_deserialize.h b/src/evaluation_deserialize.h index 1a89a248..44e15b71 100644 --- a/src/evaluation_deserialize.h +++ b/src/evaluation_deserialize.h @@ -116,9 +116,6 @@ _ccs_evaluation_deserialize( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*evaluation_ret, format, version, buffer_size, - buffer, opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/expression_deserialize.h b/src/expression_deserialize.h index e423e4eb..6c89d7bc 100644 --- a/src/expression_deserialize.h +++ b/src/expression_deserialize.h @@ -10,23 +10,6 @@ struct _ccs_expression_data_mock_s { }; typedef struct _ccs_expression_data_mock_s _ccs_expression_data_mock_t; -static inline ccs_result_t -_ccs_deserialize_bin_expression( - ccs_expression_t *expression_ret, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts); - -static ccs_result_t -_ccs_expression_deserialize( - ccs_expression_t *expression_ret, - ccs_serialize_format_t format, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts); - static inline ccs_result_t _ccs_deserialize_bin_ccs_expression_data( _ccs_expression_data_mock_t *data, @@ -46,8 +29,10 @@ _ccs_deserialize_bin_ccs_expression_data( CCS_REFUTE(!data->nodes, CCS_RESULT_ERROR_OUT_OF_MEMORY); for (size_t i = 0; i < data->num_nodes; i++) { ccs_expression_t expr; - CCS_VALIDATE(_ccs_expression_deserialize( - &expr, CCS_SERIALIZE_FORMAT_BINARY, version, + CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( + (ccs_object_t *)&expr, + CCS_OBJECT_TYPE_EXPRESSION, + CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, buffer, opts)); data->nodes[i].type = CCS_DATA_TYPE_OBJECT; data->nodes[i].value.o = expr; @@ -241,9 +226,6 @@ _ccs_expression_deserialize( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*expression_ret, format, version, buffer_size, - buffer, opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/feature_space_deserialize.h b/src/feature_space_deserialize.h index dbfb2b0a..760016e1 100644 --- a/src/feature_space_deserialize.h +++ b/src/feature_space_deserialize.h @@ -74,9 +74,6 @@ _ccs_feature_space_deserialize( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*feature_space_ret, format, version, buffer_size, - buffer, opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/features_deserialize.h b/src/features_deserialize.h index 271334fe..0ca3732f 100644 --- a/src/features_deserialize.h +++ b/src/features_deserialize.h @@ -82,9 +82,6 @@ _ccs_features_deserialize( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*features_ret, format, version, buffer_size, - buffer, opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/map_deserialize.h b/src/map_deserialize.h index bf5d9b71..9e24e4f5 100644 --- a/src/map_deserialize.h +++ b/src/map_deserialize.h @@ -100,9 +100,6 @@ _ccs_map_deserialize( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*map_ret, format, version, buffer_size, buffer, - opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/objective_space_deserialize.h b/src/objective_space_deserialize.h index 81492a04..8e648d49 100644 --- a/src/objective_space_deserialize.h +++ b/src/objective_space_deserialize.h @@ -189,9 +189,6 @@ _ccs_objective_space_deserialize( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*objective_space_ret, format, version, - buffer_size, buffer, opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/parameter_deserialize.h b/src/parameter_deserialize.h index 4d228eeb..c3b4c9ce 100644 --- a/src/parameter_deserialize.h +++ b/src/parameter_deserialize.h @@ -227,9 +227,6 @@ _ccs_parameter_deserialize( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*parameter_ret, format, version, buffer_size, - buffer, opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/rng_deserialize.h b/src/rng_deserialize.h index dc733550..bd37c557 100644 --- a/src/rng_deserialize.h +++ b/src/rng_deserialize.h @@ -80,9 +80,6 @@ _ccs_rng_deserialize( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*rng_ret, format, version, buffer_size, buffer, - opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/tree_configuration_deserialize.h b/src/tree_configuration_deserialize.h index d6bca5b1..704b1940 100644 --- a/src/tree_configuration_deserialize.h +++ b/src/tree_configuration_deserialize.h @@ -129,9 +129,6 @@ _ccs_tree_configuration_deserialize( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*configuration_ret, format, version, buffer_size, - buffer, opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/tree_deserialize.h b/src/tree_deserialize.h index 1133a6a6..ab46f5db 100644 --- a/src/tree_deserialize.h +++ b/src/tree_deserialize.h @@ -12,15 +12,6 @@ struct _ccs_tree_data_mock_s { }; typedef struct _ccs_tree_data_mock_s _ccs_tree_data_mock_t; -static inline ccs_result_t -_ccs_tree_deserialize( - ccs_tree_t *tree_ret, - ccs_serialize_format_t format, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts); - static inline ccs_result_t _ccs_deserialize_bin_ccs_tree_data( _ccs_tree_data_mock_t *data, @@ -45,10 +36,14 @@ _ccs_deserialize_bin_ccs_tree_data( CCS_VALIDATE(_ccs_deserialize_bin_ccs_bool( &present, buffer_size, buffer)); if (present) - CCS_VALIDATE(_ccs_tree_deserialize( - data->children + i, - CCS_SERIALIZE_FORMAT_BINARY, version, - buffer_size, buffer, &new_opts)); + CCS_VALIDATE( + _ccs_object_deserialize_with_opts_check( + (ccs_object_t *)data->children + + i, + CCS_OBJECT_TYPE_TREE, + CCS_SERIALIZE_FORMAT_BINARY, + version, buffer_size, buffer, + &new_opts)); } } CCS_VALIDATE(_ccs_deserialize_bin_ccs_float( @@ -135,9 +130,6 @@ _ccs_tree_deserialize( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*tree_ret, format, version, buffer_size, buffer, - opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/tree_space_deserialize.h b/src/tree_space_deserialize.h index a41886db..bd8e22f2 100644 --- a/src/tree_space_deserialize.h +++ b/src/tree_space_deserialize.h @@ -206,9 +206,6 @@ _ccs_tree_space_deserialize( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*tree_space_ret, format, version, buffer_size, - buffer, opts)); return CCS_RESULT_SUCCESS; } diff --git a/src/tuner_deserialize.h b/src/tuner_deserialize.h index d6616483..c4ae16b3 100644 --- a/src/tuner_deserialize.h +++ b/src/tuner_deserialize.h @@ -312,9 +312,6 @@ _ccs_tuner_deserialize( CCS_RESULT_ERROR_INVALID_VALUE, "Unsupported serialization format: %d", format); } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*tuner_ret, format, version, buffer_size, buffer, - opts)); return CCS_RESULT_SUCCESS; }