From fff61fc9b0d4cbcde9d4e6d4262f2e8225ec56c1 Mon Sep 17 00:00:00 2001 From: PengZheng Date: Sat, 16 Nov 2024 22:42:15 +0800 Subject: [PATCH] Remove unnecessary memory allocation for getting version string. --- libs/framework/src/bundle_archive.c | 5 +++-- libs/framework/src/celix_bundle_manifest.c | 12 ------------ libs/framework/src/celix_bundle_manifest.h | 12 ++++++++++++ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/libs/framework/src/bundle_archive.c b/libs/framework/src/bundle_archive.c index 5e73f6fff..bc140dd69 100644 --- a/libs/framework/src/bundle_archive.c +++ b/libs/framework/src/bundle_archive.c @@ -75,9 +75,10 @@ static celix_status_t celix_bundleArchive_storeBundleStateProperties(bundle_arch } celix_bundle_manifest_t* man = celix_bundleArchive_getManifest(archive); - celix_autofree char* bndVersion = celix_version_toString(celix_bundleManifest_getBundleVersion(man)); + const char* bndVersion = celix_properties_getAsString(celix_bundleManifest_getAttributes(man), + CELIX_BUNDLE_VERSION, ""); - if (!bundleStateProperties || !bndVersion) { + if (!bundleStateProperties) { return CELIX_ENOMEM; } diff --git a/libs/framework/src/celix_bundle_manifest.c b/libs/framework/src/celix_bundle_manifest.c index 21e43e756..d70e9bf1a 100644 --- a/libs/framework/src/celix_bundle_manifest.c +++ b/libs/framework/src/celix_bundle_manifest.c @@ -33,18 +33,6 @@ #include #include -// Mandatory manifest attributes -#define CELIX_BUNDLE_MANIFEST_VERSION "CELIX_BUNDLE_MANIFEST_VERSION" -#define CELIX_BUNDLE_SYMBOLIC_NAME "CELIX_BUNDLE_SYMBOLIC_NAME" -#define CELIX_BUNDLE_VERSION "CELIX_BUNDLE_VERSION" -#define CELIX_BUNDLE_NAME "CELIX_BUNDLE_NAME" - -// Optional manifest attributes -#define CELIX_BUNDLE_ACTIVATOR_LIBRARY "CELIX_BUNDLE_ACTIVATOR_LIBRARY" -#define CELIX_BUNDLE_PRIVATE_LIBRARIES "CELIX_BUNDLE_PRIVATE_LIBRARIES" -#define CELIX_BUNDLE_DESCRIPTION "CELIX_BUNDLE_DESCRIPTION" -#define CELIX_BUNDLE_GROUP "CELIX_BUNDLE_GROUP" - #define CELIX_BUNDLE_SYMBOLIC_NAME_ALLOWED_SPECIAL_CHARS "-_:." #define CELIX_FRAMEWORK_MANIFEST_VERSION "2.0.0" diff --git a/libs/framework/src/celix_bundle_manifest.h b/libs/framework/src/celix_bundle_manifest.h index d80710bff..adb7aac3d 100644 --- a/libs/framework/src/celix_bundle_manifest.h +++ b/libs/framework/src/celix_bundle_manifest.h @@ -32,6 +32,18 @@ extern "C" { #endif +// Mandatory manifest attributes +#define CELIX_BUNDLE_MANIFEST_VERSION "CELIX_BUNDLE_MANIFEST_VERSION" +#define CELIX_BUNDLE_SYMBOLIC_NAME "CELIX_BUNDLE_SYMBOLIC_NAME" +#define CELIX_BUNDLE_VERSION "CELIX_BUNDLE_VERSION" +#define CELIX_BUNDLE_NAME "CELIX_BUNDLE_NAME" + +// Optional manifest attributes +#define CELIX_BUNDLE_ACTIVATOR_LIBRARY "CELIX_BUNDLE_ACTIVATOR_LIBRARY" +#define CELIX_BUNDLE_PRIVATE_LIBRARIES "CELIX_BUNDLE_PRIVATE_LIBRARIES" +#define CELIX_BUNDLE_DESCRIPTION "CELIX_BUNDLE_DESCRIPTION" +#define CELIX_BUNDLE_GROUP "CELIX_BUNDLE_GROUP" + /** * @file celix_bundle_manifest.h * @brief Header file for celix_bundle_manifest_t.