- memory allocation now works with allocator-functions...
authorJan Hutter <jhutter@hsr.ch>
Wed, 9 Nov 2005 09:35:06 +0000 (09:35 -0000)
committerJan Hutter <jhutter@hsr.ch>
Wed, 9 Nov 2005 09:35:06 +0000 (09:35 -0000)
25 files changed:
Source/charon/configuration.c
Source/charon/event_queue.c
Source/charon/generator.c
Source/charon/ike_sa.c
Source/charon/ike_sa_id.c
Source/charon/ike_sa_manager.c
Source/charon/job.c
Source/charon/job_queue.c
Source/charon/linked_list.c
Source/charon/message.c
Source/charon/packet.c
Source/charon/receiver.c
Source/charon/scheduler.c
Source/charon/send_queue.c
Source/charon/sender.c
Source/charon/socket.c
Source/charon/tester.c
Source/charon/tests.c
Source/charon/tests/event_queue_test.c
Source/charon/tests/job_queue_test.c
Source/charon/tests/receiver_test.c
Source/charon/tests/scheduler_test.c
Source/charon/tests/sender_test.c
Source/charon/tests/socket_test.c
Source/charon/tests/thread_pool_test.c

index 0cb9d67..244fe86 100644 (file)
@@ -26,6 +26,7 @@
 #include <pluto/constants.h>
 #include <pluto/defs.h>
 
+#include "allocator.h"
 #include "types.h"
 #include "configuration.h"
 
@@ -64,7 +65,7 @@ static status_t destroy (private_configuration_t *this)
  */
 configuration_t * configuration_create()
 {
-       private_configuration_t *this = allocator_alloc_thing(private_configuration_t, "private_configuration_t");
+       private_configuration_t *this = allocator_alloc_thing(private_configuration_t);
        if (this == NULL)
        {
                return NULL;
index d086bf4..a4dd598 100644 (file)
@@ -26,7 +26,7 @@
 #include <pthread.h>
 #include <stdlib.h>
 
-
+#include "allocator.h"
 #include "types.h"
 #include "event_queue.h"
 #include "linked_list.h"
@@ -85,7 +85,7 @@ static status_t event_destroy(event_t *event)
  */
 static event_t *event_create(timeval_t time, job_t *job)
 {
-       event_t *this = allocator_alloc_thing(event_t, "event_t");
+       event_t *this = allocator_alloc_thing(event_t);
 
        this->destroy = event_destroy;
 
@@ -361,7 +361,7 @@ event_queue_t *event_queue_create()
                return NULL;
        }
 
-       private_event_queue_t *this = allocator_alloc_thing(private_event_queue_t, "private_event_queue_t");
+       private_event_queue_t *this = allocator_alloc_thing(private_event_queue_t);
        if (this == NULL)
        {
                linked_list->destroy(linked_list);
index dd7b1e5..c06cba6 100644 (file)
@@ -25,6 +25,7 @@
 #include <pluto/constants.h>
 #include <pluto/defs.h>
 
+#include "allocator.h"
 #include "types.h"
 #include "generator.h"
 
@@ -106,7 +107,7 @@ static status_t generate_u_int_type (private_generator_t *this,encoding_type_t i
  */
 static status_t generate (private_generator_t *this,void * data_struct,encoding_rule_t *encoding_rules, size_t encoding_rules_count, chunk_t *data)
 {
-       u_int8_t * buffer = allocator_alloc(GENERATOR_DATA_BUFFER_SIZE,  "generator buffer");
+       u_int8_t * buffer = allocator_alloc(GENERATOR_DATA_BUFFER_SIZE);
        u_int8_t * out_position = buffer;
        u_int8_t * roof_position = buffer + GENERATOR_DATA_BUFFER_SIZE;
        size_t current_bit = 0;
@@ -188,7 +189,7 @@ generator_t * generator_create(payload_info_t ** payload_infos)
                return NULL;
        }
 
-       this = allocator_alloc_thing(private_generator_t,"private_generator_t");
+       this = allocator_alloc_thing(private_generator_t);
        if (this == NULL)
        {
                return NULL;
index f5333c6..638b64d 100644 (file)
@@ -21,6 +21,7 @@
  * for more details.
  */
 
+#include "allocator.h"
 #include "types.h"
 #include "linked_list.h"
 #include "ike_sa.h"
@@ -145,7 +146,7 @@ static status_t destroy (private_ike_sa_t *this)
  */
 ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
 {
-       private_ike_sa_t *this = allocator_alloc_thing(private_ike_sa_t, "private_ike_sa_t");
+       private_ike_sa_t *this = allocator_alloc_thing(private_ike_sa_t);
        if (this == NULL)
        {
                return NULL;
index 8ff1fd7..3634c82 100644 (file)
@@ -26,6 +26,7 @@
 #include <pluto/constants.h>
 #include <pluto/defs.h>
 
+#include "allocator.h"
 #include "types.h"
 #include "ike_sa_id.h"
 
@@ -182,7 +183,7 @@ static status_t destroy (private_ike_sa_id_t *this)
  */
 ike_sa_id_t * ike_sa_id_create(spi_t initiator_spi, spi_t responder_spi, ike_sa_role_t role)
 {
-       private_ike_sa_id_t *this = allocator_alloc_thing(private_ike_sa_id_t, "private_ike_sa_id_t");
+       private_ike_sa_id_t *this = allocator_alloc_thing(private_ike_sa_id_t);
        if (this == NULL)
        {
                return NULL;
index 19a7139..267e3b0 100644 (file)
@@ -23,6 +23,7 @@
 #include <pthread.h>
 #include <string.h>
 
+#include "allocator.h"
 #include "ike_sa_manager.h"
 #include "linked_list.h"
 #include "ike_sa_id.h"
@@ -78,7 +79,7 @@ static status_t ike_sa_entry_destroy(ike_sa_entry_t *this)
  */
 ike_sa_entry_t *ike_sa_entry_create(ike_sa_id_t *ike_sa_id)
 {
-       ike_sa_entry_t *this = allocator_alloc_thing(ike_sa_entry_t, "ike_sa_entry_t");
+       ike_sa_entry_t *this = allocator_alloc_thing(ike_sa_entry_t);
 
        this->destroy = ike_sa_entry_destroy;
        this->waiting_threads = 0;
@@ -512,7 +513,7 @@ static status_t destroy(private_ike_sa_manager_t *this)
 
 ike_sa_manager_t *ike_sa_manager_create()
 {
-       private_ike_sa_manager_t *this = allocator_alloc_thing(private_ike_sa_manager_t, "private_ike_sa_manager_t");
+       private_ike_sa_manager_t *this = allocator_alloc_thing(private_ike_sa_manager_t);
 
        /* assign public functions */
        this->public.destroy = (status_t(*)(ike_sa_manager_t*))destroy;
index 4db37be..5332cc8 100644 (file)
@@ -25,6 +25,7 @@
 #include <pluto/constants.h>
 #include <pluto/defs.h>
 
+#include "allocator.h"
  #include "job.h"
 
  /**
@@ -41,7 +42,7 @@ static status_t job_destroy(job_t *job)
  */
 job_t *job_create(job_type_t type, void *assigned_data)
 {
-       job_t *this = allocator_alloc_thing(job_t, "job_t");
+       job_t *this = allocator_alloc_thing(job_t);
 
        this->destroy = job_destroy;
 
index 3c4d74a..b5c21e6 100644 (file)
@@ -26,6 +26,7 @@
 #include <pluto/constants.h>
 #include <pluto/defs.h>
 
+#include "allocator.h"
 #include "job_queue.h"
 #include "linked_list.h"
 
@@ -149,7 +150,7 @@ job_queue_t *job_queue_create()
                return NULL;
        }
 
-       private_job_queue_t *this = allocator_alloc_thing(private_job_queue_t, "private_job_queue_t");
+       private_job_queue_t *this = allocator_alloc_thing(private_job_queue_t);
        if (this == NULL)
        {
                linked_list->destroy(linked_list);
index 9081782..78a2f66 100644 (file)
@@ -25,6 +25,7 @@
 #include <pluto/constants.h>
 #include <pluto/defs.h>
 
+#include "allocator.h"
 #include "linked_list.h"
 
 
@@ -87,7 +88,7 @@ static status_t linked_list_element_destroy(linked_list_element_t *this)
 
 linked_list_element_t *linked_list_element_create(void *value)
 {
-       linked_list_element_t *this = allocator_alloc_thing(linked_list_element_t, "linked_list_element_t");
+       linked_list_element_t *this = allocator_alloc_thing(linked_list_element_t);
 
        if (this == NULL)
        {
@@ -252,7 +253,7 @@ static status_t get_count(private_linked_list_t *this, int *count)
 
 static status_t create_iterator (private_linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward)
 {
-       private_linked_list_iterator_t *this = allocator_alloc_thing(private_linked_list_iterator_t, "private_linked_list_iterator_t");
+       private_linked_list_iterator_t *this = allocator_alloc_thing(private_linked_list_iterator_t);
 
        if (this == NULL)
        {
@@ -682,7 +683,7 @@ static status_t linked_list_destroy(private_linked_list_t *this)
  */
 linked_list_t *linked_list_create()
 {
-       private_linked_list_t *this = allocator_alloc_thing(private_linked_list_t, "private_linked_list_t");
+       private_linked_list_t *this = allocator_alloc_thing(private_linked_list_t);
 
        this->public.get_count = (status_t (*) (linked_list_t *linked_list, int *count)) get_count;
        this->public.create_iterator = (status_t (*) (linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward)) create_iterator;
index 9064004..1651d9d 100644 (file)
@@ -25,6 +25,7 @@
 #include <pluto/constants.h>
 #include <pluto/defs.h>
 
+#include "allocator.h"
 #include "types.h"
 #include "message.h"
 
@@ -63,7 +64,7 @@ static status_t destroy (private_message_t *this)
  */
 message_t * message_create()
 {
-       private_message_t *this = allocator_alloc_thing(private_message_t, "private_message_t");
+       private_message_t *this = allocator_alloc_thing(private_message_t);
        if (this == NULL)
        {
                return NULL;
index 22977bd..94b58e5 100644 (file)
@@ -20,6 +20,7 @@
  * for more details.
  */
 
+#include "allocator.h"
 #include "packet.h"
 
 
@@ -68,7 +69,7 @@ status_t set_source(packet_t *this, char *address, u_int16_t port)
 
 packet_t *packet_create(int family)
 {
-       packet_t *this = allocator_alloc_thing(packet_t, "packet_t");
+       packet_t *this = allocator_alloc_thing(packet_t);
 
        this->destroy = destroy;
        this->set_destination = set_destination;
index 8557607..abbb5cf 100644 (file)
@@ -26,6 +26,7 @@
 #include <pluto/constants.h>
 #include <pluto/defs.h>
 
+#include "allocator.h"
 #include "receiver.h"
 #include "socket.h"
 #include "packet.h"
@@ -105,7 +106,7 @@ static status_t destroy(private_receiver_t *this)
 
 receiver_t * receiver_create()
 {
-       private_receiver_t *this = allocator_alloc_thing(private_receiver_t,"private_receiver_t");
+       private_receiver_t *this = allocator_alloc_thing(private_receiver_t);
 
        this->public.destroy = (status_t(*)(receiver_t*)) destroy;
        if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))receiver_thread_function, this) != 0)
index 05d999b..7a00bc8 100644 (file)
@@ -26,6 +26,7 @@
 #include <pluto/constants.h>
 #include <pluto/defs.h>
 
+#include "allocator.h"
 #include "scheduler.h"
 #include "job_queue.h"
 #include "globals.h"
@@ -85,7 +86,7 @@ static status_t destroy(private_scheduler_t *this)
 
 scheduler_t * scheduler_create()
 {
-       private_scheduler_t *this = allocator_alloc_thing(private_scheduler_t,"private_scheduler_t");
+       private_scheduler_t *this = allocator_alloc_thing(private_scheduler_t);
 
        this->public.destroy = (status_t(*)(scheduler_t*)) destroy;
        if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))scheduler_thread_function, this) != 0)
index 673ba38..3cb61b0 100644 (file)
@@ -22,6 +22,7 @@
 
  #include <pthread.h>
 
+#include "allocator.h"
  #include "send_queue.h"
  #include "linked_list.h"
 
@@ -149,7 +150,7 @@ send_queue_t *send_queue_create()
                return NULL;
        }
 
-       private_send_queue_t *this = allocator_alloc_thing(private_send_queue_t, "private_send_queue_t");
+       private_send_queue_t *this = allocator_alloc_thing(private_send_queue_t);
        if (this == NULL)
        {
                linked_list->destroy(linked_list);
index 5d821b2..20d301f 100644 (file)
@@ -26,6 +26,7 @@
 #include <pluto/constants.h>
 #include <pluto/defs.h>
 
+#include "allocator.h"
 #include "sender.h"
 #include "socket.h"
 #include "packet.h"
@@ -101,7 +102,7 @@ static status_t destroy(private_sender_t *this)
 
 sender_t * sender_create()
 {
-       private_sender_t *this = allocator_alloc_thing(private_sender_t,"private_sender_t");
+       private_sender_t *this = allocator_alloc_thing(private_sender_t);
 
        this->public.destroy = (status_t(*)(sender_t*)) destroy;
        if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))sender_thread_function, this) != 0)
index 782a349..5b6ad2f 100644 (file)
@@ -22,8 +22,6 @@
  * for more details.
  */
 
-#include "socket.h"
-
 #include <pthread.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -34,6 +32,8 @@
 #include <pluto/constants.h>
 #include <pluto/defs.h>
 
+#include "allocator.h"
+#include "socket.h"
 
 typedef struct private_socket_s private_socket_t;
 
@@ -83,7 +83,7 @@ status_t receiver(private_socket_t *this, packet_t **packet)
        }
 
        /* fill in packet */
-       pkt->data.ptr = allocator_alloc(pkt->data.len, "data in packet_t");
+       pkt->data.ptr = allocator_alloc(pkt->data.len);
        memcpy(pkt->data.ptr, buffer, pkt->data.len);
 
        /* return packet */
@@ -124,7 +124,7 @@ status_t destroy(private_socket_t *this)
 
 socket_t *socket_create(u_int16_t port)
 {
-       private_socket_t *this = allocator_alloc_thing(private_socket_t, "private_socket_t");
+       private_socket_t *this = allocator_alloc_thing(private_socket_t);
        struct sockaddr_in addr;
 
        /* public functions */
index 4fe6410..96af2ed 100644 (file)
@@ -29,6 +29,7 @@
 #include <pthread.h>
 #include <sys/time.h>
 
+#include "allocator.h"
 #include "tester.h"
 #include "linked_list.h"
 #include "thread_pool.h"
@@ -179,7 +180,7 @@ static status_t destroy(tester_t *tester)
 
 tester_t *tester_create(FILE *output, bool display_succeeded_asserts)
 {
-       private_tester_t *this = allocator_alloc_thing(private_tester_t, "private_tester_t");
+       private_tester_t *this = allocator_alloc_thing(private_tester_t);
 
        this->public.destroy = destroy;
        this->public.perform_tests = perform_tests;
index 47297dc..565b2e1 100644 (file)
@@ -149,9 +149,9 @@ socket_t *global_socket;
        &job_queue_test1,
        &event_queue_test,
        &send_queue_test,
+       &scheduler_test,
        &socket_test,
        &sender_test,
-       &scheduler_test,
        &receiver_test,
        &ike_sa_id_test,
        &ike_sa_test,
@@ -167,8 +167,8 @@ socket_t *global_socket;
                
        tester_t *tester = tester_create(test_output, FALSE);
 
-/*     tester->perform_tests(tester,all_tests);  */
-       tester->perform_test(tester,&thread_pool_test);  
+       tester->perform_tests(tester,all_tests);
+/*     tester->perform_test(tester,&scheduler_test);   */
        
        tester->destroy(tester);
 
@@ -180,8 +180,7 @@ socket_t *global_socket;
        global_socket->destroy(global_socket);
        
 #ifdef LEAK_DETECTIVE
-       /* Leaks are reported in log file */
-       report_leaks();
+       /* Leaks are reported on stderr */
        report_memory_leaks();
 #endif
        
index de39653..28cdf25 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <pthread.h>
 
+#include "../allocator.h"
 #include "event_queue_test.h"
 #include "../tester.h"
 #include "../event_queue.h"
@@ -76,7 +77,7 @@ static void event_queue_insert_thread(event_queue_test_t * testinfos)
        {
                for (j = 0; j < testinfos->entries_per_time;j++)
                {
-                       int *value = allocator_alloc_thing(int, "value");
+                       int *value = allocator_alloc_thing(int);
                        *value = i;
                        job = job_create(INCOMING_PACKET,value);
                        time.tv_usec = 0;
index 5e1fa81..b42512a 100644 (file)
@@ -28,6 +28,7 @@
 #include <pthread.h>
 #include <unistd.h>
 
+#include "../allocator.h"
 #include "job_queue_test.h"
 #include "../tester.h"
 #include "../job_queue.h"
@@ -63,7 +64,7 @@ static void test_job_queue_sender(job_queue_test_t * testinfo)
        int i;
        for (i = 0; i < testinfo->insert_item_count; i++)
        {
-               int *value = allocator_alloc_thing(int,"int in test_job_queue_sender");
+               int *value = allocator_alloc_thing(int);
                *value = i;
                job_t *job = job_create(INCOMING_PACKET,value);
                testinfo->job_queue->add(testinfo->job_queue,job);
index 59ab540..2c3556d 100644 (file)
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "../allocator.h"
 #include "sender_test.h"
 #include "../globals.h"
 #include "../receiver.h"
@@ -59,7 +60,7 @@ void test_receiver(tester_t *tester)
        {
                packet = packet_create(AF_INET);
                packet->set_destination(packet,DESTINATION_IP,PORT_TO_SEND);
-               packet->data.ptr = allocator_alloc_thing(int, "packet data");
+               packet->data.ptr = allocator_alloc_thing(int);
                packet->data.len = ( sizeof(int));
                *((int *) (packet->data.ptr)) = i;
                global_socket->send(global_socket,packet);
index b6cac6f..ab89fe0 100644 (file)
@@ -71,6 +71,7 @@ void test_scheduler(tester_t *tester)
                usleep(100 * 1000);
                global_event_queue->get_count(global_event_queue, &event_queue_size);
                global_job_queue->get_count(global_job_queue, &job_queue_size);
+
                tester->assert_true(tester, (job_queue_size == current + 1), "job-queue size after event");
                tester->assert_true(tester, (event_queue_size == job_count - current - 1), "event-queue size after event");
        }
index 3f8cfa8..56a5d9c 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <string.h>
 
+#include "../allocator.h"
 #include "sender_test.h"
 #include "../globals.h"
 #include "../sender.h"
@@ -57,7 +58,7 @@ void test_sender(tester_t *tester)
        {
                packet = packet_create(AF_INET);
                packet->set_destination(packet,DESTINATION_IP,PORT_TO_SEND);
-               packet->data.ptr = allocator_alloc_thing(int, "packet data");
+               packet->data.ptr = allocator_alloc_thing(int);
                packet->data.len = ( sizeof(int));
                *((int *) (packet->data.ptr)) = i;
                global_send_queue->add(global_send_queue,packet);
index ea61e5f..1273903 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "../allocator.h"
 #include "socket_test.h"
 #include "../tester.h"
 #include "../socket.h"
@@ -39,7 +40,7 @@ void test_socket(tester_t *tester)
        char *test_string = "Testing functionality of socket_t";
 
 
-       pkt->data.ptr = allocator_alloc(strlen(test_string) + 1,"test_string");
+       pkt->data.ptr = allocator_alloc(strlen(test_string) + 1);
        memcpy(pkt->data.ptr,test_string,strlen(test_string) + 1);
        pkt->data.len = strlen(test_string) + 1;
 
index de2e51d..1e8ac46 100644 (file)
@@ -37,5 +37,5 @@ void test_thread_pool(tester_t *tester)
        thread_pool_t *pool = thread_pool_create(desired_pool_size);
        pool->get_pool_size(pool, &pool_size);
        tester->assert_true(tester, (desired_pool_size == pool_size), "thread creation");
-       //tester->assert_true(tester, (pool->destroy(pool) == SUCCESS), "threadpool destruction");
+       tester->assert_true(tester, (pool->destroy(pool) == SUCCESS), "threadpool destruction");
 }