You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pe...@apache.org on 2023/08/06 11:00:54 UTC
[celix] branch feature/more-auto-cleanup created (now 7311ec55)
This is an automated email from the ASF dual-hosted git repository.
pengzheng pushed a change to branch feature/more-auto-cleanup
in repository https://gitbox.apache.org/repos/asf/celix.git
at 7311ec55 Add autocleanup for celix_version_range.
This branch includes the following new commits:
new 6dc67486 Add autocleanup for celix_filter.
new 7311ec55 Add autocleanup for celix_version_range.
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[celix] 01/02: Add autocleanup for celix_filter.
Posted by pe...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pengzheng pushed a commit to branch feature/more-auto-cleanup
in repository https://gitbox.apache.org/repos/asf/celix.git
commit 6dc674861a22902f3ab98e95e45eff640e2b99b0
Author: PengZheng <ho...@gmail.com>
AuthorDate: Sun Aug 6 18:34:05 2023 +0800
Add autocleanup for celix_filter.
---
bundles/pubsub/pubsub_utils/src/pubsub_utils.c | 5 +----
.../discovery_common/src/discovery.c | 8 ++------
.../remote_services/topology_manager/src/scope.c | 10 +++-------
.../topology_manager/src/topology_manager.c | 12 +++---------
libs/framework/src/bundle_context.c | 8 ++++----
libs/framework/src/framework.c | 21 +++++++++------------
libs/framework/src/service_registry.c | 3 +--
libs/utils/gtest/src/FilterTestSuite.cc | 4 ++++
libs/utils/include/celix_filter.h | 3 +++
9 files changed, 30 insertions(+), 44 deletions(-)
diff --git a/bundles/pubsub/pubsub_utils/src/pubsub_utils.c b/bundles/pubsub/pubsub_utils/src/pubsub_utils.c
index 2ec9bfb7..e003a218 100644
--- a/bundles/pubsub/pubsub_utils/src/pubsub_utils.c
+++ b/bundles/pubsub/pubsub_utils/src/pubsub_utils.c
@@ -52,7 +52,7 @@ celix_status_t pubsub_getPubSubInfoFromFilter(const char* filterstr, char **scop
const char *scope = NULL;
const char *topic = NULL;
const char *objectClass = NULL;
- celix_filter_t *filter = celix_filter_create(filterstr);
+ celix_autoptr(celix_filter_t) filter = celix_filter_create(filterstr);
scope = celix_filter_findAttribute(filter, PUBSUB_PUBLISHER_SCOPE);
topic = celix_filter_findAttribute(filter, PUBSUB_PUBLISHER_TOPIC);
objectClass = celix_filter_findAttribute(filter, OSGI_FRAMEWORK_OBJECTCLASS);
@@ -75,9 +75,6 @@ celix_status_t pubsub_getPubSubInfoFromFilter(const char* filterstr, char **scop
*scopeOut = NULL;
}
- if (filter != NULL) {
- filter_destroy(filter);
- }
return status;
}
diff --git a/bundles/remote_services/discovery_common/src/discovery.c b/bundles/remote_services/discovery_common/src/discovery.c
index 3e582765..2387cb76 100644
--- a/bundles/remote_services/discovery_common/src/discovery.c
+++ b/bundles/remote_services/discovery_common/src/discovery.c
@@ -91,7 +91,7 @@ celix_status_t discovery_endpointListenerAdded(void* handle, service_reference_p
const char *scope = NULL;
serviceReference_getProperty(reference, OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
- celix_filter_t *filter = celix_filter_create(scope);
+ celix_autoptr(celix_filter_t) filter = celix_filter_create(scope);
if (discoveryListener != NULL && strcmp(discoveryListener, "true") == 0) {
celix_logHelper_info(discovery->loghelper, "EndpointListener Ignored - Discovery listener");
@@ -119,8 +119,6 @@ celix_status_t discovery_endpointListenerAdded(void* handle, service_reference_p
celixThreadMutex_unlock(&discovery->mutex);
}
- celix_filter_destroy(filter);
-
return status;
}
@@ -170,7 +168,7 @@ celix_status_t discovery_informEndpointListeners(discovery_t *discovery, endpoin
const char* scope = NULL;
serviceReference_getProperty(reference, OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
- celix_filter_t *filter = celix_filter_create(scope);
+ celix_autoptr(celix_filter_t) filter = celix_filter_create(scope);
bool matchResult = celix_filter_match(filter, endpoint->properties);
if (matchResult) {
bundleContext_getService(discovery->context, reference, (void **) &listener);
@@ -185,8 +183,6 @@ celix_status_t discovery_informEndpointListeners(discovery_t *discovery, endpoin
}
bundleContext_ungetService(discovery->context, reference, NULL);
}
-
- celix_filter_destroy(filter);
}
hashMapIterator_destroy(iter);
}
diff --git a/bundles/remote_services/topology_manager/src/scope.c b/bundles/remote_services/topology_manager/src/scope.c
index 76e2bcc4..c4ac6b7a 100644
--- a/bundles/remote_services/topology_manager/src/scope.c
+++ b/bundles/remote_services/topology_manager/src/scope.c
@@ -113,11 +113,9 @@ celix_status_t tm_addImportScope(void *handle, char *filter) {
celix_status_t status = CELIX_SUCCESS;
scope_pt scope = (scope_pt) handle;
- filter_pt new;
-
if (handle == NULL)
return CELIX_ILLEGAL_ARGUMENT;
- new = filter_create(filter);
+ celix_autoptr(celix_filter_t) new = celix_filter_create(filter);
if (new == NULL) {
return CELIX_ILLEGAL_ARGUMENT; // filter not parsable
}
@@ -125,9 +123,8 @@ celix_status_t tm_addImportScope(void *handle, char *filter) {
int index = arrayList_indexOf(scope->importScopes, new);
filter_pt present = (filter_pt) arrayList_get(scope->importScopes, index);
if (present == NULL) {
- arrayList_add(scope->importScopes, new);
+ arrayList_add(scope->importScopes, celix_steal_ptr(new));
} else {
- filter_destroy(new);
status = CELIX_ILLEGAL_ARGUMENT;
}
@@ -300,7 +297,7 @@ celix_status_t scope_getExportProperties(scope_pt scope, service_reference_pt re
while ((!found) && hashMapIterator_hasNext(scopedPropIter)) {
hash_map_entry_pt scopedEntry = hashMapIterator_nextEntry(scopedPropIter);
char *filterStr = (char *) hashMapEntry_getKey(scopedEntry);
- filter_pt filter = filter_create(filterStr);
+ celix_autoptr(celix_filter_t) filter = celix_filter_create(filterStr);
if (filter != NULL) {
// test if the scope filter matches the exported service properties
status = filter_match(filter, serviceProperties, &found);
@@ -309,7 +306,6 @@ celix_status_t scope_getExportProperties(scope_pt scope, service_reference_pt re
*props = item->props;
}
}
- filter_destroy(filter);
}
hashMapIterator_destroy(scopedPropIter);
celix_properties_destroy(serviceProperties);
diff --git a/bundles/remote_services/topology_manager/src/topology_manager.c b/bundles/remote_services/topology_manager/src/topology_manager.c
index 2cb24fc1..ad1d3c23 100644
--- a/bundles/remote_services/topology_manager/src/topology_manager.c
+++ b/bundles/remote_services/topology_manager/src/topology_manager.c
@@ -317,7 +317,7 @@ celix_status_t topologyManager_exportScopeChanged(void *handle, char *filterStr)
const char* serviceId = NULL;
bool found;
celix_properties_t *props;
- filter_pt filter = filter_create(filterStr);
+ celix_autoptr(celix_filter_t) filter = celix_filter_create(filterStr);
if (filter == NULL) {
printf("filter creating failed\n");
@@ -382,9 +382,6 @@ celix_status_t topologyManager_exportScopeChanged(void *handle, char *filterStr)
// should unlock until here ?, avoid srvRefs[i] is released during topologyManager_removeExportedService
celixThreadMutex_unlock(&manager->lock);
-
- filter_destroy(filter);
-
return status;
}
@@ -683,7 +680,7 @@ celix_status_t topologyManager_endpointListenerAdded(void* handle, service_refer
serviceReference_getProperty(reference, OSGI_ENDPOINT_LISTENER_SCOPE, &scope);
- filter_pt filter = filter_create(scope);
+ celix_autoptr(celix_filter_t) filter = celix_filter_create(scope);
hash_map_iterator_pt refIter = hashMapIterator_create(manager->exportedServices);
@@ -720,8 +717,6 @@ celix_status_t topologyManager_endpointListenerAdded(void* handle, service_refer
celixThreadMutex_unlock(&manager->lock);
- filter_destroy(filter);
-
return status;
}
@@ -765,7 +760,7 @@ static celix_status_t topologyManager_notifyListenersEndpointAdded(topology_mana
status = bundleContext_getService(manager->context, reference, (void **) &epl);
if (status == CELIX_SUCCESS) {
- filter_pt filter = filter_create(scope);
+ celix_autoptr(celix_filter_t) filter = celix_filter_create(scope);
int regSize = celix_arrayList_size(registrations);
for (int regIt = 0; regIt < regSize; regIt++) {
@@ -782,7 +777,6 @@ static celix_status_t topologyManager_notifyListenersEndpointAdded(topology_mana
status = substatus;
}
}
- filter_destroy(filter);
bundleContext_ungetService(manager->context, reference, NULL);
}
}
diff --git a/libs/framework/src/bundle_context.c b/libs/framework/src/bundle_context.c
index 05541e16..eb970f02 100644
--- a/libs/framework/src/bundle_context.c
+++ b/libs/framework/src/bundle_context.c
@@ -1391,12 +1391,13 @@ static celix_status_t bundleContext_callServicedTrackerTrackerCallback(void *han
celix_bundle_t *bnd = NULL;
bundleContext_getBundle(info->context, &bnd);
+ celix_autoptr(celix_filter_t) filter = celix_filter_create(info->filter);
celix_service_tracker_info_t trkInfo;
memset(&trkInfo, 0, sizeof(trkInfo));
trkInfo.bundleId = celix_bundle_getId(bnd);
- trkInfo.filter = celix_filter_create(info->filter);
- trkInfo.serviceName = celix_filter_findAttribute(trkInfo.filter, OSGI_FRAMEWORK_OBJECTCLASS);
- const char *filterSvcName = celix_filter_findAttribute(trkInfo.filter, OSGI_FRAMEWORK_OBJECTCLASS);
+ trkInfo.filter = filter;
+ trkInfo.serviceName = celix_filter_findAttribute(filter, OSGI_FRAMEWORK_OBJECTCLASS);
+ const char *filterSvcName = celix_filter_findAttribute(filter, OSGI_FRAMEWORK_OBJECTCLASS);
bool match = entry->serviceName == NULL || (filterSvcName != NULL && strncmp(filterSvcName, entry->serviceName, 1024*1024) == 0);
@@ -1405,7 +1406,6 @@ static celix_status_t bundleContext_callServicedTrackerTrackerCallback(void *han
} else if (!add && entry->remove != NULL && match) {
entry->remove(entry->callbackHandle, &trkInfo);
}
- celix_filter_destroy(trkInfo.filter);
}
}
return CELIX_SUCCESS;
diff --git a/libs/framework/src/framework.c b/libs/framework/src/framework.c
index c5fed072..fc61a53b 100644
--- a/libs/framework/src/framework.c
+++ b/libs/framework/src/framework.c
@@ -808,20 +808,17 @@ celix_status_t fw_registerServiceFactory(framework_pt framework, service_registr
celix_status_t fw_getServiceReferences(framework_pt framework, array_list_pt *references, bundle_pt bundle, const char * serviceName, const char * sfilter) {
celix_status_t status = CELIX_SUCCESS;
- filter_pt filter = NULL;
- unsigned int refIdx = 0;
+ celix_autoptr(celix_filter_t) filter = NULL;
+ unsigned int refIdx = 0;
if (sfilter != NULL) {
- filter = filter_create(sfilter);
- }
+ filter = celix_filter_create(sfilter);
+ }
- status = CELIX_DO_IF(status, serviceRegistry_getServiceReferences(framework->registry, bundle, serviceName, filter, references));
+ status = CELIX_DO_IF(status, serviceRegistry_getServiceReferences(framework->registry, bundle, serviceName, filter, references));
- if (filter != NULL) {
- filter_destroy(filter);
- }
- if (status == CELIX_SUCCESS) {
+ if (status == CELIX_SUCCESS) {
for (refIdx = 0; (*references != NULL) && refIdx < arrayList_size(*references); refIdx++) {
service_reference_pt ref = (service_reference_pt) arrayList_get(*references, refIdx);
service_registration_pt reg = NULL;
@@ -838,11 +835,11 @@ celix_status_t fw_getServiceReferences(framework_pt framework, array_list_pt *re
}
}
}
- }
+ }
- framework_logIfError(framework->logger, status, NULL, "Failed to get service references");
+ framework_logIfError(framework->logger, status, NULL, "Failed to get service references");
- return status;
+ return status;
}
celix_status_t fw_getBundleRegisteredServices(framework_pt framework, bundle_pt bundle, array_list_pt *services) {
diff --git a/libs/framework/src/service_registry.c b/libs/framework/src/service_registry.c
index 4de6ee02..c1e5ac3b 100644
--- a/libs/framework/src/service_registry.c
+++ b/libs/framework/src/service_registry.c
@@ -878,7 +878,7 @@ celix_array_list_t* celix_serviceRegisrty_findServices(
celix_service_registry_t* registry,
const char* filterStr) {
- celix_filter_t* filter = celix_filter_create(filterStr);
+ celix_autoptr(celix_filter_t) filter = celix_filter_create(filterStr);
if (filter == NULL) {
celix_framework_log(registry->framework->logger, CELIX_LOG_LEVEL_ERROR, __FUNCTION__, __BASE_FILE__, __LINE__,
"Error incorrect filter.");
@@ -913,7 +913,6 @@ celix_array_list_t* celix_serviceRegisrty_findServices(
}
celixThreadRwlock_unlock(®istry->lock);
- celix_filter_destroy(filter);
celix_arrayList_destroy(matchedRegistrations);
return result;
}
diff --git a/libs/utils/gtest/src/FilterTestSuite.cc b/libs/utils/gtest/src/FilterTestSuite.cc
index fc746c07..3a1b41c0 100644
--- a/libs/utils/gtest/src/FilterTestSuite.cc
+++ b/libs/utils/gtest/src/FilterTestSuite.cc
@@ -414,6 +414,10 @@ TEST_F(FilterTestSuite, filterMatch) {
celix_filter_destroy(f3);
}
+TEST_F(FilterTestSuite, AutoCleanupTest) {
+ celix_autoptr(celix_filter_t) filter = celix_filter_create("(test_attr1=attr1)");
+}
+
#include "filter.h"
TEST_F(FilterTestSuite, deprecatedApi) {
auto* f1 = filter_create("(test_attr1=attr1)");
diff --git a/libs/utils/include/celix_filter.h b/libs/utils/include/celix_filter.h
index 32fbc565..24287a8f 100644
--- a/libs/utils/include/celix_filter.h
+++ b/libs/utils/include/celix_filter.h
@@ -22,6 +22,7 @@
#include "celix_properties.h"
#include "celix_array_list.h"
+#include "celix_cleanup.h"
#include "celix_utils_export.h"
#ifdef __cplusplus
@@ -65,6 +66,8 @@ CELIX_UTILS_EXPORT celix_filter_t* celix_filter_create(const char *filterStr);
CELIX_UTILS_EXPORT void celix_filter_destroy(celix_filter_t *filter);
+CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC(celix_filter_t, celix_filter_destroy)
+
CELIX_UTILS_EXPORT bool celix_filter_match(const celix_filter_t *filter, const celix_properties_t* props);
CELIX_UTILS_EXPORT bool celix_filter_matchFilter(const celix_filter_t *filter1, const celix_filter_t *filter2);
[celix] 02/02: Add autocleanup for celix_version_range.
Posted by pe...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pengzheng pushed a commit to branch feature/more-auto-cleanup
in repository https://gitbox.apache.org/repos/asf/celix.git
commit 7311ec5528e2c16da16aa63cce597fd8de78975f
Author: PengZheng <ho...@gmail.com>
AuthorDate: Sun Aug 6 19:00:18 2023 +0800
Add autocleanup for celix_version_range.
---
libs/framework/src/service_registry.c | 14 +++++---------
libs/utils/gtest/src/VersionRangeTestSuite.cc | 4 ++++
libs/utils/include/celix_version_range.h | 3 +++
3 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/libs/framework/src/service_registry.c b/libs/framework/src/service_registry.c
index c1e5ac3b..ed4e8664 100644
--- a/libs/framework/src/service_registry.c
+++ b/libs/framework/src/service_registry.c
@@ -27,6 +27,8 @@
#include "service_registration_private.h"
#include "listener_hook_service.h"
#include "celix_constants.h"
+#include "celix_stdlib_cleanup.h"
+#include "celix_version_range.h"
#include "service_reference_private.h"
#include "framework_private.h"
@@ -820,17 +822,15 @@ char* celix_serviceRegistry_createFilterFor(celix_service_registry_t* registry,
serviceName = "*";
}
- char* versionRange = NULL;
+ celix_autofree char* versionRange = NULL;
if (versionRangeStr != NULL) {
- version_range_pt range;
- celix_status_t status = versionRange_parse(versionRangeStr, &range);
- if(status != CELIX_SUCCESS) {
+ celix_autoptr(celix_version_range_t) range = celix_versionRange_parse(versionRangeStr);
+ if(range == NULL) {
celix_framework_log(registry->framework->logger, CELIX_LOG_LEVEL_ERROR, __FUNCTION__, __BASE_FILE__, __LINE__,
"Error incorrect version range.");
return NULL;
}
versionRange = versionRange_createLDAPFilter(range, CELIX_FRAMEWORK_SERVICE_VERSION);
- versionRange_destroy(range);
if (versionRange == NULL) {
celix_framework_log(registry->framework->logger, CELIX_LOG_LEVEL_ERROR, __FUNCTION__, __BASE_FILE__, __LINE__,
"Error creating LDAP filter.");
@@ -849,10 +849,6 @@ char* celix_serviceRegistry_createFilterFor(celix_service_registry_t* registry,
asprintf(&filter, "(&(%s=%s))", OSGI_FRAMEWORK_OBJECTCLASS, serviceName);
}
- if (versionRange != NULL){
- free(versionRange);
- }
-
return filter;
}
diff --git a/libs/utils/gtest/src/VersionRangeTestSuite.cc b/libs/utils/gtest/src/VersionRangeTestSuite.cc
index 85fa1a7e..4ae74772 100644
--- a/libs/utils/gtest/src/VersionRangeTestSuite.cc
+++ b/libs/utils/gtest/src/VersionRangeTestSuite.cc
@@ -43,6 +43,10 @@ TEST_F(VersionRangeTestSuite, create) {
versionRange_destroy(range);
}
+TEST_F(VersionRangeTestSuite, cleanup) {
+ celix_autoptr(celix_version_range_t) range = celix_versionRange_createInfiniteVersionRange();
+}
+
TEST_F(VersionRangeTestSuite, createInfinite) {
celix_status_t status = CELIX_SUCCESS;
version_range_pt range = nullptr;
diff --git a/libs/utils/include/celix_version_range.h b/libs/utils/include/celix_version_range.h
index 9f677009..977dc71c 100644
--- a/libs/utils/include/celix_version_range.h
+++ b/libs/utils/include/celix_version_range.h
@@ -23,6 +23,7 @@
#include <stdbool.h>
+#include "celix_cleanup.h"
#include "celix_errno.h"
#include "celix_version.h"
#include "celix_utils_export.h"
@@ -59,6 +60,8 @@ CELIX_UTILS_EXPORT celix_version_range_t* celix_versionRange_createInfiniteVersi
CELIX_UTILS_EXPORT void celix_versionRange_destroy(celix_version_range_t* range);
+CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC(celix_version_range_t, celix_versionRange_destroy)
+
/**
* Determine if the specified version is part of the version range or not.
*