Author: abroekhuis
Date: Tue May 31 10:02:21 2011
New Revision: 1129596

URL: http://svn.apache.org/viewvc?rev=1129596&view=rev
Log:
Applied patch from CELIX-5

Modified:
    incubator/celix/trunk/framework/private/include/bundle_archive.h
    incubator/celix/trunk/framework/private/src/bundle.c
    incubator/celix/trunk/framework/private/src/bundle_archive.c
    incubator/celix/trunk/framework/private/src/bundle_cache.c
    incubator/celix/trunk/framework/private/src/framework.c
    incubator/celix/trunk/framework/private/src/service_registry.c

Modified: incubator/celix/trunk/framework/private/include/bundle_archive.h
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/bundle_archive.h?rev=1129596&r1=1129595&r2=1129596&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/bundle_archive.h (original)
+++ incubator/celix/trunk/framework/private/include/bundle_archive.h Tue May 31 
10:02:21 2011
@@ -36,7 +36,7 @@ typedef struct bundleArchive * BUNDLE_AR
 
 celix_status_t bundleArchive_create(char * archiveRoot, long id, char * 
location, apr_pool_t *mp, BUNDLE_ARCHIVE *bundle_archive);
 celix_status_t bundleArchive_destroy(BUNDLE_ARCHIVE archive);
-BUNDLE_ARCHIVE bundleArchive_createSystemBundleArchive(apr_pool_t *mp);
+celix_status_t bundleArchive_createSystemBundleArchive(apr_pool_t *mp, 
BUNDLE_ARCHIVE *bundle_archive);
 celix_status_t bundleArchive_recreate(char * archiveRoot, apr_pool_t *mp, 
BUNDLE_ARCHIVE *bundle_archive);
 long bundleArchive_getId(BUNDLE_ARCHIVE archive);
 char * bundleArchive_getLocation(BUNDLE_ARCHIVE archive);

Modified: incubator/celix/trunk/framework/private/src/bundle.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle.c?rev=1129596&r1=1129595&r2=1129596&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle.c Tue May 31 10:02:21 
2011
@@ -39,32 +39,37 @@ MODULE bundle_createModule(BUNDLE bundle
 celix_status_t bundle_closeRevisions(BUNDLE bundle);
 
 celix_status_t bundle_create(BUNDLE * bundle, apr_pool_t *mp) {
-       *bundle = (BUNDLE) malloc(sizeof(**bundle));
+    celix_status_t status = CELIX_SUCCESS;
+    BUNDLE_ARCHIVE archive = NULL;
+
+       *bundle = (BUNDLE) apr_palloc(mp, sizeof(**bundle));
        if (*bundle == NULL) {
                return CELIX_ENOMEM;
        }
-       BUNDLE_ARCHIVE archive = bundleArchive_createSystemBundleArchive(mp);
-       (*bundle)->memoryPool = mp;
-       (*bundle)->archive = archive;
-       (*bundle)->activator = NULL;
-       (*bundle)->context = NULL;
-       (*bundle)->framework = NULL;
-       (*bundle)->state = BUNDLE_INSTALLED;
-       (*bundle)->modules = arrayList_create();
+       status = bundleArchive_createSystemBundleArchive(mp, &archive);
+       if (status == CELIX_SUCCESS) {
+        (*bundle)->memoryPool = mp;
+        (*bundle)->archive = archive;
+        (*bundle)->activator = NULL;
+        (*bundle)->context = NULL;
+        (*bundle)->framework = NULL;
+        (*bundle)->state = BUNDLE_INSTALLED;
+        (*bundle)->modules = arrayList_create();
 
-       MODULE module = module_createFrameworkModule((*bundle));
-       bundle_addModule(*bundle, module);
-       // (*bundle)->module = module;
-
-       pthread_mutex_init(&(*bundle)->lock, NULL);
-       (*bundle)->lockCount = 0;
-       (*bundle)->lockThread = NULL;
+        MODULE module = module_createFrameworkModule((*bundle));
+        bundle_addModule(*bundle, module);
+        // (*bundle)->module = module;
 
-       resolver_addModule(module);
+        pthread_mutex_init(&(*bundle)->lock, NULL);
+        (*bundle)->lockCount = 0;
+        (*bundle)->lockThread = NULL;
+
+        resolver_addModule(module);
 
-       (*bundle)->manifest = NULL;
+        (*bundle)->manifest = NULL;
+       }
 
-       return CELIX_SUCCESS;
+       return status;
 }
 
 celix_status_t bundle_createFromArchive(BUNDLE * bundle, FRAMEWORK framework, 
BUNDLE_ARCHIVE archive, apr_pool_t *bundlePool) {

Modified: incubator/celix/trunk/framework/private/src/bundle_archive.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle_archive.c?rev=1129596&r1=1129595&r2=1129596&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_archive.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_archive.c Tue May 31 
10:02:21 2011
@@ -49,18 +49,32 @@ struct bundleArchive {
        apr_pool_t *mp;
 };
 
-BUNDLE_ARCHIVE bundleArchive_createSystemBundleArchive(apr_pool_t *mp) {
-       BUNDLE_ARCHIVE archive = (BUNDLE_ARCHIVE) malloc(sizeof(*archive));
-       archive->id = 0l;
-       archive->location = "System Bundle";
-       archive->mp = mp;
-       archive->archiveRoot = NULL;
-       archive->archiveRootDir = NULL;
-       archive->revisions = linkedList_create();
-       archive->refreshCount = -1;
-       time(&archive->lastModified);
+celix_status_t bundleArchive_createSystemBundleArchive(apr_pool_t *mp, 
BUNDLE_ARCHIVE *bundle_archive) {
+    celix_status_t status;
+       BUNDLE_ARCHIVE archive;
+
+       if (!mp || *bundle_archive) {
+           status = CELIX_ILLEGAL_ARGUMENT;
+       } else {
+        archive = (BUNDLE_ARCHIVE) apr_palloc(mp, sizeof(*archive));
+        if (archive == NULL) {
+            status = CELIX_ENOMEM;
+        } else {
+            archive->id = 0l;
+            archive->location = "System Bundle";
+            archive->mp = mp;
+            archive->archiveRoot = NULL;
+            archive->archiveRootDir = NULL;
+            archive->revisions = linkedList_create();
+            archive->refreshCount = -1;
+            time(&archive->lastModified);
+
+            *bundle_archive = archive;
+            status = CELIX_SUCCESS;
+        }
+       }
 
-       return archive;
+    return status;
 }
 
 celix_status_t bundleArchive_getRevisionLocation(BUNDLE_ARCHIVE archive, long 
revNr, char **revision_location);

Modified: incubator/celix/trunk/framework/private/src/bundle_cache.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle_cache.c?rev=1129596&r1=1129595&r2=1129596&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_cache.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_cache.c Tue May 31 
10:02:21 2011
@@ -44,22 +44,28 @@ struct bundleCache {
 static celix_status_t bundleCache_deleteTree(char * directory, apr_pool_t *mp);
 
 celix_status_t bundleCache_create(PROPERTIES configurationMap, apr_pool_t *mp, 
BUNDLE_CACHE *bundle_cache) {
-    celix_status_t status = CELIX_SUCCESS;
-       BUNDLE_CACHE cache = (BUNDLE_CACHE) malloc(sizeof(*cache));
+    celix_status_t status;
+    BUNDLE_CACHE cache;
 
-       if (configurationMap != NULL && mp != NULL && *bundle_cache == NULL) {
-        cache->configurationMap = configurationMap;
-        char * cacheDir = properties_get(configurationMap, (char *) 
FRAMEWORK_STORAGE);
-        if (cacheDir == NULL) {
-            cacheDir = ".cache";
-        }
-        cache->cacheDir = cacheDir;
-        cache->mp = mp;
+       cache = (BUNDLE_CACHE) apr_palloc(mp, (sizeof(*cache)));
+    if (cache == NULL) {
+        status = CELIX_ENOMEM;
+    } else {
+               if (configurationMap != NULL && mp != NULL && *bundle_cache == 
NULL) {
+            cache->configurationMap = configurationMap;
+            char * cacheDir = properties_get(configurationMap, (char *) 
FRAMEWORK_STORAGE);
+            if (cacheDir == NULL) {
+                cacheDir = ".cache";
+            }
+            cache->cacheDir = cacheDir;
+            cache->mp = mp;
 
-        *bundle_cache = cache;
-       } else {
-        status = CELIX_ILLEGAL_ARGUMENT;
-       }
+            *bundle_cache = cache;
+            status = CELIX_SUCCESS;
+        } else {
+            status = CELIX_ILLEGAL_ARGUMENT;
+        }
+    }
 
        return status;
 }

Modified: incubator/celix/trunk/framework/private/src/framework.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/framework.c?rev=1129596&r1=1129595&r2=1129596&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/framework.c (original)
+++ incubator/celix/trunk/framework/private/src/framework.c Tue May 31 10:02:21 
2011
@@ -267,34 +267,38 @@ celix_status_t fw_init(FRAMEWORK framewo
 
         bundle_setHandle(framework->bundle, handle);
 
-        ACTIVATOR activator = (ACTIVATOR) malloc(sizeof(*activator));
-        void * (*create)(BUNDLE_CONTEXT context);
-        void (*start)(void * handle, BUNDLE_CONTEXT context);
-        void (*stop)(void * handle, BUNDLE_CONTEXT context);
-        void (*destroy)(void * handle, BUNDLE_CONTEXT context);
-        create = dlsym(bundle_getHandle(framework->bundle), 
BUNDLE_ACTIVATOR_CREATE);
-        start = dlsym(bundle_getHandle(framework->bundle), 
BUNDLE_ACTIVATOR_START);
-        stop = dlsym(bundle_getHandle(framework->bundle), 
BUNDLE_ACTIVATOR_STOP);
-        destroy = dlsym(bundle_getHandle(framework->bundle), 
BUNDLE_ACTIVATOR_DESTROY);
-        activator->start = start;
-        activator->stop = stop;
-        activator->destroy = destroy;
-        bundle_setActivator(framework->bundle, activator);
-
-        void * userData = NULL;
-        if (create != NULL) {
-            userData = create(bundle_getContext(framework->bundle));
-        }
-        activator->userData = userData;
+        ACTIVATOR activator = (ACTIVATOR) apr_palloc(framework->mp, 
(sizeof(*activator)));
+        if (activator == NULL) {
+            status = CELIX_ENOMEM;
+        }  else {
+            void * (*create)(BUNDLE_CONTEXT context);
+            void (*start)(void * handle, BUNDLE_CONTEXT context);
+            void (*stop)(void * handle, BUNDLE_CONTEXT context);
+            void (*destroy)(void * handle, BUNDLE_CONTEXT context);
+            create = dlsym(bundle_getHandle(framework->bundle), 
BUNDLE_ACTIVATOR_CREATE);
+            start = dlsym(bundle_getHandle(framework->bundle), 
BUNDLE_ACTIVATOR_START);
+            stop = dlsym(bundle_getHandle(framework->bundle), 
BUNDLE_ACTIVATOR_STOP);
+            destroy = dlsym(bundle_getHandle(framework->bundle), 
BUNDLE_ACTIVATOR_DESTROY);
+            activator->start = start;
+            activator->stop = stop;
+            activator->destroy = destroy;
+            bundle_setActivator(framework->bundle, activator);
+
+            void * userData = NULL;
+            if (create != NULL) {
+                userData = create(bundle_getContext(framework->bundle));
+            }
+            activator->userData = userData;
 
-        if (start != NULL) {
-            start(userData, bundle_getContext(framework->bundle));
-        }
+            if (start != NULL) {
+                start(userData, bundle_getContext(framework->bundle));
+            }
 
-        framework->serviceListeners = arrayList_create();
-        framework_releaseBundleLock(framework, framework->bundle);
+            framework->serviceListeners = arrayList_create();
+            framework_releaseBundleLock(framework, framework->bundle);
 
-        status = CELIX_SUCCESS;
+            status = CELIX_SUCCESS;
+        }
        }
        return status;
 }
@@ -491,33 +495,37 @@ celix_status_t fw_startBundle(FRAMEWORK 
 
                        bundle_setHandle(bundle, handle);
 
-                       ACTIVATOR activator = (ACTIVATOR) 
malloc(sizeof(*activator));
-                       void * (*create)(BUNDLE_CONTEXT context, void 
**userData);
-                       void (*start)(void * userData, BUNDLE_CONTEXT context);
-                       void (*stop)(void * userData, BUNDLE_CONTEXT context);
-                       void (*destroy)(void * userData, BUNDLE_CONTEXT 
context);
-                       create = dlsym(bundle_getHandle(bundle), 
BUNDLE_ACTIVATOR_CREATE);
-                       start = dlsym(bundle_getHandle(bundle), 
BUNDLE_ACTIVATOR_START);
-                       stop = dlsym(bundle_getHandle(bundle), 
BUNDLE_ACTIVATOR_STOP);
-                       destroy = dlsym(bundle_getHandle(bundle), 
BUNDLE_ACTIVATOR_DESTROY);
-                       activator->start = start;
-                       activator->stop = stop;
-                       activator->destroy = destroy;
-                       bundle_setActivator(bundle, activator);
-
-                       framework_setBundleStateAndNotify(framework, bundle, 
BUNDLE_STARTING);
-
-                       void * userData = NULL;
-                       if (create != NULL) {
-                               create(bundle_getContext(bundle), &userData);
-                       }
-                       activator->userData = userData;
+                       ACTIVATOR activator = (ACTIVATOR) 
apr_palloc(bundle->memoryPool, (sizeof(*activator)));
+                       if (activator == NULL) {
+                           return CELIX_ENOMEM;
+                       } else {
+                void * (*create)(BUNDLE_CONTEXT context, void **userData);
+                void (*start)(void * userData, BUNDLE_CONTEXT context);
+                void (*stop)(void * userData, BUNDLE_CONTEXT context);
+                void (*destroy)(void * userData, BUNDLE_CONTEXT context);
+                create = dlsym(bundle_getHandle(bundle), 
BUNDLE_ACTIVATOR_CREATE);
+                start = dlsym(bundle_getHandle(bundle), 
BUNDLE_ACTIVATOR_START);
+                stop = dlsym(bundle_getHandle(bundle), BUNDLE_ACTIVATOR_STOP);
+                destroy = dlsym(bundle_getHandle(bundle), 
BUNDLE_ACTIVATOR_DESTROY);
+                activator->start = start;
+                activator->stop = stop;
+                activator->destroy = destroy;
+                bundle_setActivator(bundle, activator);
+
+                framework_setBundleStateAndNotify(framework, bundle, 
BUNDLE_STARTING);
+
+                void * userData = NULL;
+                if (create != NULL) {
+                    create(bundle_getContext(bundle), &userData);
+                }
+                activator->userData = userData;
 
-                       if (start != NULL) {
-                               start(userData, bundle_getContext(bundle));
-                       }
+                if (start != NULL) {
+                    start(userData, bundle_getContext(bundle));
+                }
 
-                       framework_setBundleStateAndNotify(framework, bundle, 
BUNDLE_ACTIVE);
+                framework_setBundleStateAndNotify(framework, bundle, 
BUNDLE_ACTIVE);
+                       }
 
                        break;
        }
@@ -616,7 +624,7 @@ void fw_stopBundle(FRAMEWORK framework, 
                activator->start = NULL;
                activator->stop = NULL;
                activator->userData = NULL;
-               free(activator);
+               //free(activator);
                bundle_setActivator(bundle, NULL);
 
                serviceRegistry_unregisterServices(framework->registry, bundle);

Modified: incubator/celix/trunk/framework/private/src/service_registry.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/service_registry.c?rev=1129596&r1=1129595&r2=1129596&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/service_registry.c (original)
+++ incubator/celix/trunk/framework/private/src/service_registry.c Tue May 31 
10:02:21 2011
@@ -86,17 +86,23 @@ void serviceRegistry_flushUsageCount(SER
 }
 
 SERVICE_REGISTRY serviceRegistry_create(FRAMEWORK framework, void 
(*serviceChanged)(FRAMEWORK, SERVICE_EVENT, PROPERTIES)) {
-       SERVICE_REGISTRY registry = (SERVICE_REGISTRY) 
malloc(sizeof(*registry));
-       registry->serviceChanged = serviceChanged;
-       registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
-       registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL);
-       registry->framework = framework;
-
-       pthread_mutexattr_t mutexattr;
-       pthread_mutexattr_init(&mutexattr);
-       pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
-       pthread_mutex_init(&registry->mutex, &mutexattr);
-       registry->currentServiceId = 1l;
+       SERVICE_REGISTRY registry;
+
+       registry = (SERVICE_REGISTRY) apr_palloc(framework->mp, 
(sizeof(*registry)));
+       if (registry == NULL) {
+           // no memory
+       } else {
+        registry->serviceChanged = serviceChanged;
+        registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
+        registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, 
NULL);
+        registry->framework = framework;
+
+        pthread_mutexattr_t mutexattr;
+        pthread_mutexattr_init(&mutexattr);
+        pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
+        pthread_mutex_init(&registry->mutex, &mutexattr);
+        registry->currentServiceId = 1l;
+       }
        return registry;
 }
 
@@ -105,8 +111,6 @@ celix_status_t serviceRegistry_destroy(S
     hashMap_destroy(registry->serviceRegistrations, false, false);
     pthread_mutex_destroy(&registry->mutex);
 
-    free(registry);
-
     return CELIX_SUCCESS;
 }
 


Reply via email to