Skip to content
Snippets Groups Projects
Commit a147f9ee authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Change 'long' to 'int' in link list API

so the sizes of these elements are the same across all our current target
platforms
parent 31c01008
Branches
Tags
No related merge requests found
......@@ -29,7 +29,7 @@
#define free(ptr) HeapFree(GetProcessHeap(), /* flags: */ 0, ptr)
#endif
link_list_t* listInit(link_list_t* list, long flags)
link_list_t* listInit(link_list_t* list, int flags)
{
if (list == NULL)
return NULL;
......@@ -63,7 +63,7 @@ bool listFreeNodeData(list_node_t* node)
return false;
}
long listFreeNodes(link_list_t* list)
int listFreeNodes(link_list_t* list)
{
list_node_t* node;
list_node_t* next;
......@@ -126,7 +126,7 @@ bool listFree(link_list_t* list)
return true;
}
long listAttach(link_list_t* list)
int listAttach(link_list_t* list)
{
if (list == NULL)
return -1;
......@@ -138,7 +138,7 @@ long listAttach(link_list_t* list)
return list->refs;
}
long listDettach(link_list_t* list)
int listDettach(link_list_t* list)
{
int refs;
......@@ -206,7 +206,7 @@ bool listSemTryWait(link_list_t* list)
return sem_trywait(&list->sem) == 0;
}
bool listSemTryWaitBlock(link_list_t* list, unsigned long timeout)
bool listSemTryWaitBlock(link_list_t* list, unsigned int timeout)
{
if (list == NULL || !(list->flags & LINK_LIST_SEMAPHORE))
return false;
......@@ -249,9 +249,9 @@ bool listUnlock(link_list_t* list)
return ret == 0;
}
long listCountNodes(link_list_t* list)
int listCountNodes(link_list_t* list)
{
long count = 0;
int count = 0;
list_node_t* node;
if (list == NULL)
......@@ -295,10 +295,10 @@ list_node_t* listFindNode(link_list_t* list, const void* data, size_t length)
return node;
}
ulong listCountMatches(link_list_t* list, const void* data, size_t length)
uint listCountMatches(link_list_t* list, const void* data, size_t length)
{
list_node_t* node;
ulong matches = 0;
uint matches = 0;
if (list == NULL)
return 0;
......@@ -348,9 +348,9 @@ str_list_t listStringList(link_list_t* list)
return str_list;
}
str_list_t listSubStringList(const list_node_t* node, long max)
str_list_t listSubStringList(const list_node_t* node, int max)
{
long count;
int count;
str_list_t str_list;
link_list_t* list;
......@@ -414,9 +414,9 @@ list_node_t* listLastNode(link_list_t* list)
return last;
}
long listNodeIndex(link_list_t* list, list_node_t* find_node)
int listNodeIndex(link_list_t* list, list_node_t* find_node)
{
long i = 0;
int i = 0;
list_node_t* node;
if (list == NULL)
......@@ -436,9 +436,9 @@ long listNodeIndex(link_list_t* list, list_node_t* find_node)
return i;
}
list_node_t* listNodeAt(link_list_t* list, long index)
list_node_t* listNodeAt(link_list_t* list, int index)
{
long i = 0;
int i = 0;
list_node_t* node;
if (list == NULL || index < 0)
......@@ -569,7 +569,7 @@ static list_node_t* list_add_node(link_list_t* list, list_node_t* node, list_nod
return node;
}
list_node_t* listAddNodeWithFlags(link_list_t* list, void* data, list_node_tag_t tag, long flags, list_node_t* after)
list_node_t* listAddNodeWithFlags(link_list_t* list, void* data, list_node_tag_t tag, int flags, list_node_t* after)
{
list_node_t* node;
......@@ -592,9 +592,9 @@ list_node_t* listAddNode(link_list_t* list, void* data, list_node_tag_t tag, lis
return listAddNodeWithFlags(list, data, tag, 0, after);
}
long listAddNodes(link_list_t* list, void** data, list_node_tag_t* tag, list_node_t* after)
int listAddNodes(link_list_t* list, void** data, list_node_tag_t* tag, list_node_t* after)
{
long i;
int i;
list_node_t* node = NULL;
if (data == NULL)
......@@ -645,9 +645,9 @@ list_node_t* listAddNodeString(link_list_t* list, const char* str, list_node_tag
#ifndef NO_STR_LIST_SUPPORT
long listAddStringList(link_list_t* list, str_list_t str_list, list_node_tag_t* tag, list_node_t* after)
int listAddStringList(link_list_t* list, str_list_t str_list, list_node_tag_t* tag, list_node_t* after)
{
long i;
int i;
list_node_t* node = NULL;
if (str_list == NULL)
......@@ -662,9 +662,9 @@ long listAddStringList(link_list_t* list, str_list_t str_list, list_node_tag_t*
#endif
long listAddNodeList(link_list_t* list, const link_list_t* src, list_node_t* after)
int listAddNodeList(link_list_t* list, const link_list_t* src, list_node_t* after)
{
long count = 0;
int count = 0;
list_node_t* node = NULL;
list_node_t* src_node;
......@@ -679,9 +679,9 @@ long listAddNodeList(link_list_t* list, const link_list_t* src, list_node_t* aft
return count;
}
long listMerge(link_list_t* list, const link_list_t* src, list_node_t* after)
int listMerge(link_list_t* list, const link_list_t* src, list_node_t* after)
{
long count = 0;
int count = 0;
list_node_t* node = NULL;
list_node_t* src_node;
......@@ -695,9 +695,9 @@ long listMerge(link_list_t* list, const link_list_t* src, list_node_t* after)
return count;
}
link_list_t* listExtract(link_list_t* dest_list, const list_node_t* node, long max)
link_list_t* listExtract(link_list_t* dest_list, const list_node_t* node, int max)
{
long count;
int count;
link_list_t* list;
if (node == NULL || node->list == NULL)
......@@ -785,10 +785,10 @@ void* listRemoveTaggedNode(link_list_t* list, list_node_tag_t tag, bool free_dat
return data;
}
long listRemoveNodes(link_list_t* list, list_node_t* node, long max, bool free_data)
int listRemoveNodes(link_list_t* list, list_node_t* node, int max, bool free_data)
{
list_node_t *next_node;
long count;
int count;
if (list == NULL)
return -1;
......@@ -899,11 +899,11 @@ void listReverse(link_list_t* list)
listUnlock(list);
}
long listVerify(link_list_t* list)
int listVerify(link_list_t* list)
{
list_node_t* node;
list_node_t* prev = NULL;
long result = 0;
int result = 0;
if (list == NULL)
return -1;
......@@ -942,7 +942,7 @@ long listVerify(link_list_t* list)
int main(int arg, char** argv)
{
int i;
long result;
int result;
char* p;
char str[32];
link_list_t list;
......
......@@ -49,7 +49,7 @@ extern "C" {
/* in case the default tag type is not sufficient for your needs, you can over-ride */
#if !defined(list_node_tag_t)
typedef long list_node_tag_t;
typedef int list_node_tag_t;
#endif
#if !defined(LIST_NODE_TAG_DEFAULT)
#define LIST_NODE_TAG_DEFAULT 0
......@@ -60,18 +60,18 @@ typedef struct list_node {
struct list_node* next; /* next node in list (or NULL) */
struct list_node* prev; /* previous node in list (or NULL) */
struct link_list* list;
unsigned long flags; /* private use flags (by this library) */
unsigned int flags; /* private use flags (by this library) */
list_node_tag_t tag; /* application use value */
} list_node_t;
typedef struct link_list {
list_node_t* first; /* first node in list (or NULL) */
list_node_t* last; /* last node in list (or NULL) */
unsigned long flags; /* private use flags (by this library) */
long count; /* number of nodes in list */
unsigned int flags; /* private use flags (by this library) */
int count; /* number of nodes in list */
void* private_data; /* for use by the application/caller */
long refs; /* reference counter (attached clients) */
long locks; /* recursive lock counter */
int refs; /* reference counter (attached clients) */
int locks; /* recursive lock counter */
#if defined(LINK_LIST_THREADSAFE)
pthread_mutex_t mutex;
sem_t sem;
......@@ -79,20 +79,20 @@ typedef struct link_list {
} link_list_t;
/* Initialization, Allocation, and Freeing of Lists and Nodes */
DLLEXPORT link_list_t* listInit(link_list_t* /* NULL to auto-allocate */, long flags);
DLLEXPORT link_list_t* listInit(link_list_t* /* NULL to auto-allocate */, int flags);
DLLEXPORT bool listFree(link_list_t*);
DLLEXPORT long listFreeNodes(link_list_t*);
DLLEXPORT int listFreeNodes(link_list_t*);
DLLEXPORT bool listFreeNodeData(list_node_t* node);
/* Increment/decrement reference counter (and auto-free when zero), returns -1 on error */
DLLEXPORT long listAttach(link_list_t*);
DLLEXPORT long listDetach(link_list_t*);
DLLEXPORT int listAttach(link_list_t*);
DLLEXPORT int listDetach(link_list_t*);
#if defined(LINK_LIST_THREADSAFE)
DLLEXPORT bool listSemPost(link_list_t*);
DLLEXPORT bool listSemWait(link_list_t*);
DLLEXPORT bool listSemTryWait(link_list_t*);
DLLEXPORT bool listSemTryWaitBlock(link_list_t*, unsigned long timeout);
DLLEXPORT bool listSemTryWaitBlock(link_list_t*, unsigned int timeout);
#endif
/* Lock/unlock linked lists (works best for mutex-protected lists) */
......@@ -103,8 +103,8 @@ DLLEXPORT bool listIsLocked(const link_list_t*);
#define listForceUnlock(list) while (listUnlock(list) == TRUE)
/* Return count or index of nodes, or -1 on error */
DLLEXPORT long listCountNodes(link_list_t*);
DLLEXPORT long listNodeIndex(link_list_t*, list_node_t*);
DLLEXPORT int listCountNodes(link_list_t*);
DLLEXPORT int listNodeIndex(link_list_t*, list_node_t*);
/* Get/Set list private data */
DLLEXPORT void* listSetPrivateData(link_list_t*, void*);
......@@ -114,24 +114,24 @@ DLLEXPORT void* listGetPrivateData(link_list_t*);
DLLEXPORT str_list_t listStringList(link_list_t*);
/* Return an allocated string list (which must be freed), subset of strings in linked list */
DLLEXPORT str_list_t listSubStringList(const list_node_t*, long max);
DLLEXPORT str_list_t listSubStringList(const list_node_t*, int max);
/* Free a string list returned from either of the above functions */
DLLEXPORT void* listFreeStringList(str_list_t);
/* Extract subset (up to max number of nodes) in linked list (src_node) and place into dest_list */
/* dest_list == NULL, then allocate a return a new linked list */
DLLEXPORT link_list_t* listExtract(link_list_t* dest_list, const list_node_t* src_node, long max);
DLLEXPORT link_list_t* listExtract(link_list_t* dest_list, const list_node_t* src_node, int max);
/* Simple search functions returning found node or NULL on error */
DLLEXPORT list_node_t* listNodeAt(link_list_t*, long index);
DLLEXPORT list_node_t* listNodeAt(link_list_t*, int index);
/* Find a specific node by data or tag */
/* Pass length of 0 to search by data pointer rather than by data content comparison (memcmp) */
DLLEXPORT list_node_t* listFindNode(link_list_t*, const void* data, size_t length);
/* Find a specific node by its tag value */
#define listFindTaggedNode(list, tag) listFindNode(list, NULL, tag)
/* Pass length of 0 to search by data pointer rather than by data content comparison (memcmp) */
DLLEXPORT ulong listCountMatches(link_list_t*, const void* data, size_t length);
DLLEXPORT uint listCountMatches(link_list_t*, const void* data, size_t length);
/* Convenience functions */
DLLEXPORT list_node_t* listFirstNode(link_list_t*);
......@@ -149,11 +149,11 @@ DLLEXPORT bool listNodeIsLocked(const list_node_t*);
DLLEXPORT list_node_t* listAddNode(link_list_t*, void* data, list_node_tag_t, list_node_t * after /* NULL=insert */);
/* Add node to list with flags, returns pointer to new node or NULL on error */
DLLEXPORT list_node_t* listAddNodeWithFlags(link_list_t*, void* data, list_node_tag_t, long flags, list_node_t * after /* NULL=insert */);
DLLEXPORT list_node_t* listAddNodeWithFlags(link_list_t*, void* data, list_node_tag_t, int flags, list_node_t * after /* NULL=insert */);
/* Add array of node data to list, returns number of nodes added (or negative on error) */
/* tag array may be NULL */
DLLEXPORT long listAddNodes(link_list_t*, void** data, list_node_tag_t*, list_node_t* after /* NULL=insert */);
DLLEXPORT int listAddNodes(link_list_t*, void** data, list_node_tag_t*, list_node_t* after /* NULL=insert */);
/* Add node to list, allocating and copying the data for the node */
DLLEXPORT list_node_t* listAddNodeData(link_list_t*, const void* data, size_t length, list_node_tag_t, list_node_t * after);
......@@ -163,17 +163,17 @@ DLLEXPORT list_node_t* listAddNodeString(link_list_t*, const char* str, list_nod
/* Add a list of strings to the linked list, allocating and copying each */
/* tag array may be NULL */
DLLEXPORT long listAddStringList(link_list_t*, str_list_t, list_node_tag_t*, list_node_t * after);
DLLEXPORT int listAddStringList(link_list_t*, str_list_t, list_node_tag_t*, list_node_t * after);
/* Add a list of nodes from a source linked list */
DLLEXPORT long listAddNodeList(link_list_t*, const link_list_t* src, list_node_t* after);
DLLEXPORT int listAddNodeList(link_list_t*, const link_list_t* src, list_node_t* after);
/* Merge a source linked list into the destination linked list */
/* after merging, the nodes in the source linked list should not be modified or freed */
DLLEXPORT long listMerge(link_list_t* dest, const link_list_t* src, list_node_t* after);
DLLEXPORT int listMerge(link_list_t* dest, const link_list_t* src, list_node_t* after);
/* Swap the data pointers and flags for 2 nodes (possibly in separate lists) */
DLLEXPORT bool listSwapNodes(list_node_t* node1, list_node_t* node2);
DLLEXPORT bool listSwapNodes(list_node_t* node1, list_node_t* node2);
/* Convenience macros for pushing, popping, and inserting nodes */
#define listPushNode(list, data) listAddNode(list, data, LIST_NODE_TAG_DEFAULT, LAST_NODE)
......@@ -192,13 +192,13 @@ DLLEXPORT void* listRemoveNode(link_list_t*, list_node_t* /* NULL=first */, bool
DLLEXPORT void* listRemoveTaggedNode(link_list_t*, list_node_tag_t, bool free_data);
/* Remove multiple nodes from list, returning the number of nodes removed */
DLLEXPORT long listRemoveNodes(link_list_t*, list_node_t* /* NULL=first */, long count, bool free_data);
DLLEXPORT int listRemoveNodes(link_list_t*, list_node_t* /* NULL=first */, int count, bool free_data);
/* Reverse the nodes in a list */
DLLEXPORT void listReverse(link_list_t*);
/* Return >= 0 (count of nodes) if list is valid, negative otherwise */
DLLEXPORT long listVerify(link_list_t*);
DLLEXPORT int listVerify(link_list_t*);
#if defined(__cplusplus)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment