Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit df946cd4 authored by rswindell's avatar rswindell

Elimianted LINK_LIST_DONT_FREE flag (now unnecessary)

listRemoveNode() now accepts BOOL free_data argument to specify whether or not
to free the node's data pointer (list and node flags not used in determination)
Renamed listPopFirstNode() macro to listShiftNode().
listPopNode() and listShiftNode() macros now never free the node data pointer.
parent 2825417c
......@@ -619,7 +619,7 @@ link_list_t* listExtract(link_list_t* dest_list, const list_node_t* node, long m
return(list);
}
void* listRemoveNode(link_list_t* list, list_node_t* node)
void* listRemoveNode(link_list_t* list, list_node_t* node, BOOL free_data)
{
void* data;
......@@ -645,8 +645,7 @@ void* listRemoveNode(link_list_t* list, list_node_t* node)
if(list->last==node)
list->last = node->prev;
if((list->flags&LINK_LIST_ALWAYS_FREE || node->flags&LINK_LIST_MALLOC)
&& !(list->flags&LINK_LIST_DONT_FREE))
if(free_data)
listFreeNodeData(node);
data = node->data;
......@@ -661,7 +660,7 @@ void* listRemoveNode(link_list_t* list, list_node_t* node)
return(data);
}
long listRemoveNodes(link_list_t* list, list_node_t* node, long max)
long listRemoveNodes(link_list_t* list, list_node_t* node, long max, BOOL free_data)
{
long count;
......@@ -674,7 +673,7 @@ long listRemoveNodes(link_list_t* list, list_node_t* node, long max)
node=list->first;
for(count=0; node!=NULL && count<max; node=node->next, count++)
if(listRemoveNode(list, node)==NULL)
if(listRemoveNode(list, node, free_data)==NULL)
break;
MUTEX_UNLOCK(list);
......@@ -727,13 +726,13 @@ int main(int arg, char** argv)
char str[32];
link_list_t list;
listInit(&list,LINK_LIST_NEVER_FREE);
listInit(&list,0);
for(i=0; i<100; i++) {
sprintf(str,"%u",i);
listPushNodeString(&list,str);
}
while((p=listRemoveNode(&list,NULL))!=NULL)
while((p=listShiftNode(&list))!=NULL)
printf("%d %s\n",listCountNodes(&list),p), free(p);
/* Yes, this test code leaks heap memory. :-) */
......
......@@ -54,13 +54,12 @@ extern "C" {
/* Valid link_list_t.flags bits */
#define LINK_LIST_MALLOC (1<<0) /* List/node allocated with malloc() */
#define LINK_LIST_DONT_FREE (1<<1) /* Don't free node data when removing */
#define LINK_LIST_ALWAYS_FREE (1<<2) /* ALWAYS free node data when removing */
#define LINK_LIST_NEVER_FREE (1<<3) /* NEVER free node data (careful of memory leaks!) */
#define LINK_LIST_MUTEX (1<<4) /* Mutex-protected linked-list */
#define LINK_LIST_SEMAPHORE (1<<5) /* Semaphore attached to linked-list */
#define LINK_LIST_NODE_LOCKED (1<<6) /* Node is locked */
#define LINK_LIST_ATTACH (1<<7) /* Attach during init */
#define LINK_LIST_ALWAYS_FREE (1<<1) /* ALWAYS free node data in listFreeNodes() */
#define LINK_LIST_NEVER_FREE (1<<2) /* NEVER free node data (careful of memory leaks!) */
#define LINK_LIST_MUTEX (1<<3) /* Mutex-protected linked-list */
#define LINK_LIST_SEMAPHORE (1<<4) /* Semaphore attached to linked-list */
#define LINK_LIST_NODE_LOCKED (1<<5) /* Node is locked */
#define LINK_LIST_ATTACH (1<<6) /* Attach during init */
typedef struct list_node {
void* data; /* pointer to some kind of data */
......@@ -172,14 +171,14 @@ BOOL listSwapNodes(list_node_t* node1, list_node_t* node2);
#define listInsertNodeString(list, str) listAddNodeString(list, str, FIRST_NODE)
#define listPushStringList(list, str_list) listAddStringList(list, str_list, listLastNode(list))
#define listInsertStringList(list, str_list) listAddStringList(list, str_list, FIRST_NODE)
#define listPopNode(list) listRemoveNode(list, listLastNode(list))
#define listPopFirstNode(list) listRemoveNode(list, FIRST_NODE)
#define listPopNode(list) listRemoveNode(list, listLastNode(list), FALSE)
#define listShiftNode(list) listRemoveNode(list, FIRST_NODE, FALSE)
/* Remove node from list, returning the node's data (if not free'd) */
void* listRemoveNode(link_list_t*, list_node_t* /* NULL=first */);
void* listRemoveNode(link_list_t*, list_node_t* /* NULL=first */, BOOL free_data);
/* Remove multiple nodes from list, returning the number of nodes removed */
long listRemoveNodes(link_list_t*, list_node_t* /* NULL=first */, long count);
long listRemoveNodes(link_list_t*, list_node_t* /* NULL=first */, long count, BOOL free_data);
#if defined(__cplusplus)
}
......
......@@ -57,8 +57,8 @@ msg_queue_t* msgQueueInit(msg_queue_t* q, long flags)
q->owner_thread_id = GetCurrentThreadId();
if(q->flags&MSG_QUEUE_BIDIR)
listInit(&q->in,LINK_LIST_DONT_FREE|LINK_LIST_SEMAPHORE);
listInit(&q->out,LINK_LIST_DONT_FREE|LINK_LIST_SEMAPHORE);
listInit(&q->in,LINK_LIST_SEMAPHORE);
listInit(&q->out,LINK_LIST_SEMAPHORE);
return(q);
}
......@@ -181,7 +181,7 @@ void* msgQueueRead(msg_queue_t* q, long timeout)
if(!list_wait(msgQueueReadList(q),timeout))
return(NULL);
return listPopFirstNode(msgQueueReadList(q));
return listShiftNode(msgQueueReadList(q));
}
void* msgQueuePeek(msg_queue_t* q, long timeout)
......@@ -199,7 +199,7 @@ void* msgQueueFind(msg_queue_t* q, const void* data, size_t length)
if((node=listFindNode(list,data,length))==NULL)
return(NULL);
return listRemoveNode(list,node);
return listRemoveNode(list,node,/* Free Data? */FALSE);
}
list_node_t* msgQueueFirstNode(msg_queue_t* q)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment