Permalink
Browse files

Ins before Outs in function parameters.

Testing:
All unit tests passed.
  • Loading branch information...
Jeremiah Martell Jeremiah Martell
Jeremiah Martell authored and Jeremiah Martell committed Nov 19, 2011
1 parent 2eaef20 commit 4a6780f2c1c81433095c83d3a47f7e5328676775
View
@@ -31,6 +31,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef trot_H
#define trot_H
+/******************************************************************************/
+#include <stdlib.h> /* for size_t, in memory hook functions */
+
/******************************************************************************/
typedef enum
{
@@ -78,14 +81,17 @@ typedef enum
/******************************************************************************/
typedef struct trotListRef_STRUCT trotListRef;
-typedef struct trotListNode_STRUCT trotListNode;
-typedef struct trotList_STRUCT trotList;
-typedef struct trotListRefListNode_STRUCT trotListRefListNode;
+
+/******************************************************************************/
+/* trotHooks.c */
+extern void *(*trotCalloc)( size_t nmemb, size_t size );
+extern void *(*trotMalloc)( size_t size );
+extern void (*trotFree)( void *ptr );
/******************************************************************************/
/* trotListPrimary.c */
TROT_RC trotListRefInit( trotListRef **lr_A );
-TROT_RC trotListRefTwin( trotListRef **lr_A, trotListRef *lrToTwin );
+TROT_RC trotListRefTwin( trotListRef *lr, trotListRef **lrTwin_A );
void trotListRefFree( trotListRef **lr_F );
TROT_RC trotListRefGetCount( trotListRef *lr, INT_TYPE *c );
@@ -96,25 +102,25 @@ TROT_RC trotListRefAppendInt( trotListRef *lr, INT_TYPE n );
TROT_RC trotListRefAppendListTwin( trotListRef *lr, trotListRef *lrToAppend );
TROT_RC trotListRefInsertInt( trotListRef *lr, INT_TYPE index, INT_TYPE n );
-TROT_RC trotListRefInsertListTwin( trotListRef *lr, INT_TYPE index, trotListRef *l );
+TROT_RC trotListRefInsertListTwin( trotListRef *lr, INT_TYPE index, trotListRef *lrToInsert );
TROT_RC trotListRefGetInt( trotListRef *lr, INT_TYPE index, INT_TYPE *n );
-TROT_RC trotListRefGetListTwin( trotListRef *lr, INT_TYPE index, trotListRef **l );
+TROT_RC trotListRefGetListTwin( trotListRef *lr, INT_TYPE index, trotListRef **lrTwin_A );
TROT_RC trotListRefRemoveInt( trotListRef *lr, INT_TYPE index, INT_TYPE *n );
-TROT_RC trotListRefRemoveList( trotListRef *lr, INT_TYPE index, trotListRef **l );
+TROT_RC trotListRefRemoveList( trotListRef *lr, INT_TYPE index, trotListRef **lrRemoved_A );
TROT_RC trotListRefRemove( trotListRef *lr, INT_TYPE index );
/******************************************************************************/
/* trotListSecondary.c */
TROT_RC trotListRefCompare( trotListRef *lr, trotListRef *lrCompareTo, TROT_LIST_COMPARE_RESULT *compareResult );
-TROT_RC trotListRefCopy( trotListRef **lrCopy_A, trotListRef *lr );
+TROT_RC trotListRefCopy( trotListRef *lr, trotListRef **lrCopy_A );
TROT_RC trotListRefEnlist( trotListRef *lr, INT_TYPE indexStart, INT_TYPE indexEnd );
TROT_RC trotListRefDelist( trotListRef *lr, INT_TYPE index );
-TROT_RC trotListRefCopySpan( trotListRef **lrCopy_A, trotListRef *lr, INT_TYPE indexStart, INT_TYPE indexEnd );
+TROT_RC trotListRefCopySpan( trotListRef *lr, INT_TYPE indexStart, INT_TYPE indexEnd, trotListRef **lrCopy_A );
TROT_RC trotListRefRemoveSpan( trotListRef *lr, INT_TYPE indexStart, INT_TYPE indexEnd );
/******************************************************************************/
@@ -30,31 +30,40 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/******************************************************************************/
/*!
\file
- Contains our function pointers for:
- Calloc, Malloc, Free
+ Contains hook function pointers for:
+ - Calloc, Malloc, Free
+ - Load
- Used so we can override the standard functions.
+ Used if we're embedded in an app that uses it's own
+ memory functions. We can easily "plug into" their memory management
+ system.
+
+ Used so client can provide a "load" function when we're compiling that
+ we'll use for (include) lists.
Used in our unit tests for testing malloc/calloc failures.
- Also can be useful if we're embedded in an app that uses it's own
- memory functions. We can easily "plug into" their memory management
- system.
*/
/******************************************************************************/
#include <stdlib.h> /* for malloc, calloc, free */
+#include "trot.h"
/******************************************************************************/
/*! This is the function that the library uses for 'calloc'. Used for unit
-testing failed callocs and in case the user of the library has their own memory
-management routines. */
+ testing failed callocs and in case the user of the library has their own
+ memory management routines. */
void *(*trotCalloc)( size_t nmemb, size_t size ) = calloc;
/*! This is the function that the library uses for 'malloc'. Used for unit
-testing failed mallocs and in case the user of the library has their own memory
-management routines. */
+ testing failed mallocs and in case the user of the library has their own
+ memory management routines. */
void *(*trotMalloc)( size_t size ) = malloc;
-/*! This is the function that the library uses for 'free'. Used in case the user
-of the library has their own memory management routines. */
+/*! This is the function that the library uses for 'free'. Used in case the
+ user of the library has their own memory management routines. */
void (*trotFree)( void *ptr ) = free;
+/******************************************************************************/
+/*! This is the function that the library uses to load a (include) when
+ compiling.*/
+TROT_RC (*trotLoad)( trotListRef *lrName, trotListRef **lrCharacters );
+
@@ -35,8 +35,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h> /* for printf in ERR */
#include <stdlib.h> /* for NULL */
-#include "trotMem.h"
-
/******************************************************************************/
#define NODE_SIZE 64
@@ -87,6 +85,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ERR_IF( POINTER == NULL, TROT_LIST_ERROR_MEMORY_ALLOCATION_FAILED );
/******************************************************************************/
+typedef struct trotListNode_STRUCT trotListNode;
+typedef struct trotList_STRUCT trotList;
+typedef struct trotListRefListNode_STRUCT trotListRefListNode;
+
/*! Data in a trotList is stored in a linked list of trotListNodes. */
struct trotListNode_STRUCT
{
@@ -189,12 +189,12 @@ TROT_RC trotListRefInit( trotListRef **lr_A )
/******************************************************************************/
/*!
\brief Twins a trotListRef reference.
- \param lr_A Pointer to a trotListRef pointer that must be NULL. On
+ \param lr Pointer to the trotListRef pointer to be twinned.
+ \param lrTwin_A Pointer to a trotListRef pointer that must be NULL. On
success, this will point to a new trotListRef reverence.
- \param lrToTwin Pointer to the trotListRef pointer to be twinned.
\return TROT_RC
*/
-TROT_RC trotListRefTwin( trotListRef **lr_A, trotListRef *lrToTwin )
+TROT_RC trotListRefTwin( trotListRef *lr, trotListRef **lrTwin_A )
{
/* DATA */
TROT_RC rc = TROT_LIST_SUCCESS;
@@ -203,23 +203,23 @@ TROT_RC trotListRefTwin( trotListRef **lr_A, trotListRef *lrToTwin )
/* PRECOND */
- PRECOND_ERR_IF( lr_A == NULL );
- PRECOND_ERR_IF( (*lr_A) != NULL );
- PRECOND_ERR_IF( lrToTwin == NULL );
+ PRECOND_ERR_IF( lr == NULL );
+ PRECOND_ERR_IF( lrTwin_A == NULL );
+ PRECOND_ERR_IF( (*lrTwin_A) != NULL );
/* CODE */
TROT_MALLOC( newListRef, trotListRef, 1 );
newListRef -> lParent = NULL;
- newListRef -> lPointsTo = lrToTwin -> lPointsTo;
+ newListRef -> lPointsTo = lr -> lPointsTo;
rc = _refListAdd( newListRef -> lPointsTo, newListRef );
ERR_IF_PASSTHROUGH;
/* give back */
- (*lr_A) = newListRef;
+ (*lrTwin_A) = newListRef;
newListRef = NULL;
return TROT_LIST_SUCCESS;
@@ -557,7 +557,7 @@ TROT_RC trotListRefAppendListTwin( trotListRef *lr, trotListRef *lrToAppend )
}
/* append */
- rc = trotListRefTwin( &newLr, lrToAppend );
+ rc = trotListRefTwin( lrToAppend, &newLr );
ERR_IF_PASSTHROUGH;
node -> l[ node -> count ] = newLr;
@@ -747,10 +747,10 @@ TROT_RC trotListRefInsertInt( trotListRef *lr, INT_TYPE index, INT_TYPE n )
\brief Inserts a twin of a list into the list.
\param lr Pointer to a trotListRef pointer.
\param index Where to insert.
- \param lToInsert The listRef to insert.
+ \param lrToInsert The listRef to insert.
\return TROT_RC
*/
-TROT_RC trotListRefInsertListTwin( trotListRef *lr, INT_TYPE index, trotListRef *lToInsert )
+TROT_RC trotListRefInsertListTwin( trotListRef *lr, INT_TYPE index, trotListRef *lrToInsert )
{
/* DATA */
TROT_RC rc = TROT_LIST_SUCCESS;
@@ -771,7 +771,7 @@ TROT_RC trotListRefInsertListTwin( trotListRef *lr, INT_TYPE index, trotListRef
/* PRECOND */
PRECOND_ERR_IF( lr == NULL );
- PRECOND_ERR_IF( lToInsert == NULL );
+ PRECOND_ERR_IF( lrToInsert == NULL );
/* CODE */
@@ -787,7 +787,7 @@ TROT_RC trotListRefInsertListTwin( trotListRef *lr, INT_TYPE index, trotListRef
list. And two, if they want to add to an empty list. */
if ( index == (l -> childrenCount) + 1 )
{
- rc = trotListRefAppendListTwin( lr, lToInsert );
+ rc = trotListRefAppendListTwin( lr, lrToInsert );
ERR_IF_PASSTHROUGH;
return TROT_LIST_SUCCESS;
@@ -835,7 +835,7 @@ TROT_RC trotListRefInsertListTwin( trotListRef *lr, INT_TYPE index, trotListRef
(count + 1) is the beginning index of the node */
/* *** */
- rc = trotListRefTwin( &newL, lToInsert );
+ rc = trotListRefTwin( lrToInsert, &newL );
ERR_IF_PASSTHROUGH;
/* Now let's move any lists over to make room */
@@ -873,7 +873,7 @@ TROT_RC trotListRefInsertListTwin( trotListRef *lr, INT_TYPE index, trotListRef
node = node -> prev;
/* Insert list into node */
- rc = trotListRefTwin( &newL, lToInsert );
+ rc = trotListRefTwin( lrToInsert, &newL );
ERR_IF_PASSTHROUGH;
node -> l[ node -> count ] = newL;
@@ -901,7 +901,7 @@ TROT_RC trotListRefInsertListTwin( trotListRef *lr, INT_TYPE index, trotListRef
ERR_IF_PASSTHROUGH;
/* *** */
- rc = trotListRefTwin( &newL, lToInsert );
+ rc = trotListRefTwin( lrToInsert, &newL );
ERR_IF_PASSTHROUGH;
/* Insert node into list */
@@ -1019,10 +1019,10 @@ TROT_RC trotListGetInt( trotList *l, INT_TYPE index, INT_TYPE *n )
\brief Gets list ref of list in list.
\param lr Pointer to a trotListRef pointer.
\param index Which list to get.
- \param l On success, will point to list ref.
+ \param lrTwin_A On success, will point to list ref.
\return TROT_RC
*/
-TROT_RC trotListRefGetListTwin( trotListRef *lr, INT_TYPE index, trotListRef **l )
+TROT_RC trotListRefGetListTwin( trotListRef *lr, INT_TYPE index, trotListRef **lrTwin_A )
{
/* DATA */
TROT_RC rc = TROT_LIST_SUCCESS;
@@ -1036,8 +1036,8 @@ TROT_RC trotListRefGetListTwin( trotListRef *lr, INT_TYPE index, trotListRef **l
/* PRECOND */
PRECOND_ERR_IF( lr == NULL );
- PRECOND_ERR_IF( l == NULL );
- PRECOND_ERR_IF( (*l) != NULL );
+ PRECOND_ERR_IF( lrTwin_A == NULL );
+ PRECOND_ERR_IF( (*lrTwin_A) != NULL );
/* CODE */
@@ -1068,11 +1068,11 @@ TROT_RC trotListRefGetListTwin( trotListRef *lr, INT_TYPE index, trotListRef **l
ERR_IF( node -> kind != NODE_KIND_LIST, TROT_LIST_ERROR_WRONG_KIND );
- rc = trotListRefTwin( &newL, node -> l[ (node -> count) - 1 - (count - index) ] );
+ rc = trotListRefTwin( node -> l[ (node -> count) - 1 - (count - index) ], &newL );
ERR_IF_PASSTHROUGH;
/* give back */
- (*l) = newL;
+ (*lrTwin_A) = newL;
newL = NULL;
return TROT_LIST_SUCCESS;
@@ -1176,10 +1176,10 @@ TROT_RC trotListRefRemoveInt( trotListRef *lr, INT_TYPE index, INT_TYPE *n )
\brief Gets and removes list ref of list in list.
\param lr Pointer to a trotListRef pointer.
\param index Which list to get.
- \param l On success, will point to list ref.
+ \param lrRemoved_A On success, will point to list ref.
\return TROT_RC
*/
-TROT_RC trotListRefRemoveList( trotListRef *lr, INT_TYPE index, trotListRef **l )
+TROT_RC trotListRefRemoveList( trotListRef *lr, INT_TYPE index, trotListRef **lrRemoved_A )
{
/* DATA */
TROT_RC rc = TROT_LIST_SUCCESS;
@@ -1195,8 +1195,8 @@ TROT_RC trotListRefRemoveList( trotListRef *lr, INT_TYPE index, trotListRef **l
/* PRECOND */
PRECOND_ERR_IF( lr == NULL );
- PRECOND_ERR_IF( l == NULL );
- PRECOND_ERR_IF( (*l) != NULL );
+ PRECOND_ERR_IF( lrRemoved_A == NULL );
+ PRECOND_ERR_IF( (*lrRemoved_A) != NULL );
/* CODE */
@@ -1249,7 +1249,7 @@ TROT_RC trotListRefRemoveList( trotListRef *lr, INT_TYPE index, trotListRef **l
}
/* give back */
- (*l) = giveBackL;
+ (*lrRemoved_A) = giveBackL;
return TROT_LIST_SUCCESS;
@@ -214,21 +214,21 @@ TROT_RC trotListRefCompare( trotListRef *lr, trotListRef *lrCompareTo, TROT_LIST
/******************************************************************************/
/*!
\brief Copies a list.
+ \param lr Pointer to a trotListRef to copy.
\param lrCopy_A Pointer to a trotListRef pointer that must be NULL.
On success, this will be a copy of the list.
- \param lr Pointer to a trotListRef to copy.
\return TROT_RC
*/
-TROT_RC trotListRefCopy( trotListRef **lrCopy_A, trotListRef *lr )
+TROT_RC trotListRefCopy( trotListRef *lr, trotListRef **lrCopy_A )
{
/* DATA */
TROT_RC rc = TROT_LIST_SUCCESS;
/* PRECOND */
+ PRECOND_ERR_IF( lr == NULL );
PRECOND_ERR_IF( lrCopy_A == NULL );
PRECOND_ERR_IF( (*lrCopy_A) != NULL );
- PRECOND_ERR_IF( lr == NULL );
/* CODE */
@@ -241,7 +241,7 @@ TROT_RC trotListRefCopy( trotListRef **lrCopy_A, trotListRef *lr )
/* else, use CopySpan */
else
{
- rc = trotListRefCopySpan( lrCopy_A, lr, 1, -1 );
+ rc = trotListRefCopySpan( lr, 1, -1, lrCopy_A );
ERR_IF_PASSTHROUGH;
}
@@ -525,7 +525,7 @@ TROT_RC trotListRefDelist( trotListRef *lr, INT_TYPE index )
/* copy our delist (only if it contains something) */
if ( delistListRef -> lPointsTo -> childrenCount > 0 )
{
- rc = trotListRefCopySpan( &copiedListRef, delistListRef, 1, -1 );
+ rc = trotListRefCopySpan( delistListRef, 1, -1, &copiedListRef );
ERR_IF_PASSTHROUGH;
}
@@ -616,14 +616,14 @@ TROT_RC trotListRefDelist( trotListRef *lr, INT_TYPE index )
/******************************************************************************/
/*!
\brief Makes a copy of a span in a list.
- \param lrCopy_A Pointer to a trotListRef pointer that must be NULL.
- On success, this will be a copy of the span.
\param lr Pointer to a trotListRef that you want to copy a span in.
\param indexStart index of start of span.
\param indexEnd index of end of span.
+ \param lrCopy_A Pointer to a trotListRef pointer that must be NULL.
+ On success, this will be a copy of the span.
\return TROT_RC
*/
-TROT_RC trotListRefCopySpan( trotListRef **lrCopy_A, trotListRef *lr, INT_TYPE indexStart, INT_TYPE indexEnd )
+TROT_RC trotListRefCopySpan( trotListRef *lr, INT_TYPE indexStart, INT_TYPE indexEnd, trotListRef **lrCopy_A )
{
/* DATA */
TROT_RC rc = TROT_LIST_SUCCESS;
@@ -643,9 +643,9 @@ TROT_RC trotListRefCopySpan( trotListRef **lrCopy_A, trotListRef *lr, INT_TYPE i
/* PRECOND */
+ PRECOND_ERR_IF( lr == NULL );
PRECOND_ERR_IF( lrCopy_A == NULL );
PRECOND_ERR_IF( (*lrCopy_A) != NULL );
- PRECOND_ERR_IF( lr == NULL );
/* CODE */
Oops, something went wrong.

0 comments on commit 4a6780f

Please sign in to comment.