changeset 36:82b36ebdc648 PR_univ_lib

new branch -- PR_univ_lib -- is a static library, copied to /usr/lib/PR__lib
author Sean Halle <seanhalle@yahoo.com>
date Sat, 27 Jul 2013 15:22:09 -0700
parents 59eaf81a9cc7
children 962fe26aca16
files DynArray.c DynArray.h __brch__PR_univ __brch__PR_univ_lib prdynarray.h
diffstat 5 files changed, 97 insertions(+), 97 deletions(-) [+]
line diff
     1.1 --- a/DynArray.c	Tue Jul 23 07:41:03 2013 -0700
     1.2 +++ b/DynArray.c	Sat Jul 27 15:22:09 2013 -0700
     1.3 @@ -9,8 +9,8 @@
     1.4  #include <stdio.h>
     1.5  #include <malloc.h>
     1.6  
     1.7 -#include "DynArray.h"
     1.8 -#include "PR__common_includes/Services_offered_by_PR/Memory_Handling/vmalloc__wrapper_library.h"
     1.9 +#include <PR__include/prdynarray.h>
    1.10 +#include <PR__include/prmalloc.h>
    1.11  
    1.12  //== declarations
    1.13  void
     2.1 --- a/DynArray.h	Tue Jul 23 07:41:03 2013 -0700
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,91 +0,0 @@
     2.4 -/* 
     2.5 - * File:   Vector.h
     2.6 - * Author: Me
     2.7 - *
     2.8 - * Created on May 14, 2010, 3:08 PM
     2.9 - */
    2.10 -
    2.11 -#ifndef _DYNARRAY_H
    2.12 -#define	_DYNARRAY_H
    2.13 -
    2.14 -#include "PR__common_includes/PR__primitive_data_types.h"
    2.15 -
    2.16 -
    2.17 -
    2.18 -/*WARNING: Passing a DynArray as a param is dangerous if add to the DynArray
    2.19 - * inside the function called!   After adding or other operation that might
    2.20 - * change the size, must re-read the addr of the chunk of memory that is the
    2.21 - * array, via the DynArrayInfo.
    2.22 - *Here's why: An array variable is a location, either on the stack
    2.23 - * or in a field of a struct, whose contents is an addr.  That addr is of the
    2.24 - * first location of a chunk of locations.  The DynArray works by changing
    2.25 - * the chunk of locations, then modifying the contents of the original 
    2.26 - * array variable.  It overwrites the addr of the old chunk of locations
    2.27 - * with the addr of the new chunk.
    2.28 - *But when the array variable is passed as a parameter, such as 
    2.29 - * in this: "foo( myDynArray )", then there are now two locations that hold
    2.30 - * the addr of the same chunk of locations.  So when a call is made that
    2.31 - * adds to the DynArray, and inside the DynArray expands, it only updates
    2.32 - * the original location with  the new addr.  Hence, the function will begin
    2.33 - * overwriting memory past the end of the old chunk, because it still has 
    2.34 - * the pointer to the old chunk of locations.
    2.35 - *
    2.36 - *A dynamic array is accessed same as any other array.  However, must use
    2.37 - * dyn array calls, defined in here, in order to add or increase the size.
    2.38 - * Must re-read the original array variable after any size-changing calls.
    2.39 - *To pass a DynArray as a parameter to a function, can only pass the 
    2.40 - * DynArrayInfo, then inside the function, to read the addr of the first 
    2.41 - * location in the chunk of locations that is the array, do this:
    2.42 - * "localArrayCopy = *(myDynArrayInfo->addrOfPtrToArray).  After that, can 
    2.43 - * treat localArrayCopy as a normal array, as long as don't make any calls
    2.44 - * that add or otherwise could increase the size of the array.  If do make
    2.45 - * such a call, then re-copy the array via the above.  Can then use the
    2.46 - * copy up until another add to the array.
    2.47 - * 
    2.48 - */
    2.49 -typedef struct
    2.50 - {
    2.51 -   void ***addrOfPtrToArray; //addr of var that is array of ptrs == triple *
    2.52 -   int32   numInArray;  //num entries added
    2.53 -   int32   sizeOfArray; //num elems alloc'd
    2.54 -   int32   sizeOfElem;  //num bytes in one elem of array -- used in 2nd version
    2.55 - }
    2.56 -PrivDynArrayInfo;
    2.57 -
    2.58 -PrivDynArrayInfo *
    2.59 -makePrivDynArrayInfoFrom( void ***addrOfPtrToArray, int32 sizeOfArray );
    2.60 -
    2.61 -PrivDynArrayInfo *
    2.62 -makePrivDynArrayOfSize( void ***addrOfPtrToArray, int32 sizeOfArray );
    2.63 -
    2.64 -PrivDynArrayInfo *
    2.65 -makePrivDynArrayOfSize_Ext( void ***addrOfPtrToArray, int32 sizeOfArray );
    2.66 -
    2.67 -int32
    2.68 -addToDynArray( void *value, PrivDynArrayInfo *info );
    2.69 -
    2.70 -void
    2.71 -makeHighestDynArrayIndexBe( PrivDynArrayInfo *info, int32 highestIndex );
    2.72 -
    2.73 -void
    2.74 -makeHighestDynArrayIndexBeAtLeast(PrivDynArrayInfo *info,int32 highestIndex);
    2.75 -
    2.76 -void
    2.77 -increaseSizeOfDynArrayTo( PrivDynArrayInfo *info, int32 newSize );
    2.78 -
    2.79 -typedef void  (*FreeFnPtr)  ( void * ); //fn has to cast void * to whatever
    2.80 -
    2.81 -void
    2.82 -freeDynArrayDeep( PrivDynArrayInfo *info, FreeFnPtr freeFnPtr );
    2.83 -
    2.84 -void
    2.85 -freeDynArrayFlat( PrivDynArrayInfo *info );
    2.86 -
    2.87 -
    2.88 -typedef void  (*DynArrayFnPtr)  ( void * );  //fn has to cast void *
    2.89 -
    2.90 -void
    2.91 -forAllInDynArrayDo( PrivDynArrayInfo *info, DynArrayFnPtr fnPtr );
    2.92 -
    2.93 -#endif	/* _DYNARRAY_H */
    2.94 -
     3.1 --- a/__brch__PR_univ	Tue Jul 23 07:41:03 2013 -0700
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,4 +0,0 @@
     3.4 -This branch is for the project structure defined Jan 2012..  the #includes reflect this directory structure.
     3.5 -
     3.6 -More importantly, the MC_shared  version of PR requires a separat malloc implemeted by PR code..  so this branch has modified the library to use the PR-specific malloc.
     3.7 -
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/__brch__PR_univ_lib	Sat Jul 27 15:22:09 2013 -0700
     4.3 @@ -0,0 +1,4 @@
     4.4 +This branch is for the project structure defined Jan 2012..  the #includes reflect this directory structure.
     4.5 +
     4.6 +More importantly, the MC_shared  version of PR requires a separat malloc implemeted by PR code..  so this branch has modified the library to use the PR-specific malloc.
     4.7 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/prdynarray.h	Sat Jul 27 15:22:09 2013 -0700
     5.3 @@ -0,0 +1,91 @@
     5.4 +/* 
     5.5 + * File:   Vector.h
     5.6 + * Author: Me
     5.7 + *
     5.8 + * Created on May 14, 2010, 3:08 PM
     5.9 + */
    5.10 +
    5.11 +#ifndef _DYNARRAY_H
    5.12 +#define	_DYNARRAY_H
    5.13 +
    5.14 +#include <PR__include/PR__primitive_data_types.h>
    5.15 +
    5.16 +
    5.17 +
    5.18 +/*WARNING: Passing a DynArray as a param is dangerous if add to the DynArray
    5.19 + * inside the function called!   After adding or other operation that might
    5.20 + * change the size, must re-read the addr of the chunk of memory that is the
    5.21 + * array, via the DynArrayInfo.
    5.22 + *Here's why: An array variable is a location, either on the stack
    5.23 + * or in a field of a struct, whose contents is an addr.  That addr is of the
    5.24 + * first location of a chunk of locations.  The DynArray works by changing
    5.25 + * the chunk of locations, then modifying the contents of the original 
    5.26 + * array variable.  It overwrites the addr of the old chunk of locations
    5.27 + * with the addr of the new chunk.
    5.28 + *But when the array variable is passed as a parameter, such as 
    5.29 + * in this: "foo( myDynArray )", then there are now two locations that hold
    5.30 + * the addr of the same chunk of locations.  So when a call is made that
    5.31 + * adds to the DynArray, and inside the DynArray expands, it only updates
    5.32 + * the original location with  the new addr.  Hence, the function will begin
    5.33 + * overwriting memory past the end of the old chunk, because it still has 
    5.34 + * the pointer to the old chunk of locations.
    5.35 + *
    5.36 + *A dynamic array is accessed same as any other array.  However, must use
    5.37 + * dyn array calls, defined in here, in order to add or increase the size.
    5.38 + * Must re-read the original array variable after any size-changing calls.
    5.39 + *To pass a DynArray as a parameter to a function, can only pass the 
    5.40 + * DynArrayInfo, then inside the function, to read the addr of the first 
    5.41 + * location in the chunk of locations that is the array, do this:
    5.42 + * "localArrayCopy = *(myDynArrayInfo->addrOfPtrToArray).  After that, can 
    5.43 + * treat localArrayCopy as a normal array, as long as don't make any calls
    5.44 + * that add or otherwise could increase the size of the array.  If do make
    5.45 + * such a call, then re-copy the array via the above.  Can then use the
    5.46 + * copy up until another add to the array.
    5.47 + * 
    5.48 + */
    5.49 +typedef struct
    5.50 + {
    5.51 +   void ***addrOfPtrToArray; //addr of var that is array of ptrs == triple *
    5.52 +   int32   numInArray;  //num entries added
    5.53 +   int32   sizeOfArray; //num elems alloc'd
    5.54 +   int32   sizeOfElem;  //num bytes in one elem of array -- used in 2nd version
    5.55 + }
    5.56 +PrivDynArrayInfo;
    5.57 +
    5.58 +PrivDynArrayInfo *
    5.59 +makePrivDynArrayInfoFrom( void ***addrOfPtrToArray, int32 sizeOfArray );
    5.60 +
    5.61 +PrivDynArrayInfo *
    5.62 +makePrivDynArrayOfSize( void ***addrOfPtrToArray, int32 sizeOfArray );
    5.63 +
    5.64 +PrivDynArrayInfo *
    5.65 +makePrivDynArrayOfSize_Ext( void ***addrOfPtrToArray, int32 sizeOfArray );
    5.66 +
    5.67 +int32
    5.68 +addToDynArray( void *value, PrivDynArrayInfo *info );
    5.69 +
    5.70 +void
    5.71 +makeHighestDynArrayIndexBe( PrivDynArrayInfo *info, int32 highestIndex );
    5.72 +
    5.73 +void
    5.74 +makeHighestDynArrayIndexBeAtLeast(PrivDynArrayInfo *info,int32 highestIndex);
    5.75 +
    5.76 +void
    5.77 +increaseSizeOfDynArrayTo( PrivDynArrayInfo *info, int32 newSize );
    5.78 +
    5.79 +typedef void  (*FreeFnPtr)  ( void * ); //fn has to cast void * to whatever
    5.80 +
    5.81 +void
    5.82 +freeDynArrayDeep( PrivDynArrayInfo *info, FreeFnPtr freeFnPtr );
    5.83 +
    5.84 +void
    5.85 +freeDynArrayFlat( PrivDynArrayInfo *info );
    5.86 +
    5.87 +
    5.88 +typedef void  (*DynArrayFnPtr)  ( void * );  //fn has to cast void *
    5.89 +
    5.90 +void
    5.91 +forAllInDynArrayDo( PrivDynArrayInfo *info, DynArrayFnPtr fnPtr );
    5.92 +
    5.93 +#endif	/* _DYNARRAY_H */
    5.94 +