File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ struct sPtrArray {
2727 unsigned int max ;
2828 unsigned int count ;
2929 void * * array ;
30+ int refcount ;
3031 ptrArrayDeleteFunc deleteFunc ;
3132};
3233
@@ -40,6 +41,7 @@ extern ptrArray *ptrArrayNew (ptrArrayDeleteFunc deleteFunc)
4041 result -> max = 8 ;
4142 result -> count = 0 ;
4243 result -> array = xMalloc (result -> max , void * );
44+ result -> refcount = 1 ;
4345 result -> deleteFunc = deleteFunc ;
4446 return result ;
4547}
@@ -145,10 +147,20 @@ extern void ptrArrayClear (ptrArray *const current)
145147 current -> count = 0 ;
146148}
147149
148- extern void ptrArrayDelete (ptrArray * const current )
150+ extern void ptrArrayRef (ptrArray * const current )
151+ {
152+ current -> refcount ++ ;
153+ }
154+
155+ extern void ptrArrayUnref (ptrArray * const current )
149156{
150157 if (current != NULL )
151158 {
159+ current -> refcount -- ;
160+ if (current -> refcount > 0 )
161+ return ;
162+ Assert (current -> refcount == 0 );
163+
152164 ptrArrayClear (current );
153165 eFree (current -> array );
154166 eFree (current );
Original file line number Diff line number Diff line change @@ -41,7 +41,9 @@ extern unsigned int ptrArrayCount (const ptrArray *const current);
4141extern void * ptrArrayItem (const ptrArray * const current , const unsigned int indx );
4242extern void * ptrArrayItemFromLast (const ptrArray * const current , const unsigned int indx );
4343#define ptrArrayLast (A ) ptrArrayItemFromLast(A, 0)
44- extern void ptrArrayDelete (ptrArray * const current );
44+ extern void ptrArrayUnref (ptrArray * const current );
45+ #define ptrArrayDelete ptrArrayUnref
46+ extern void ptrArrayRef (ptrArray * const current );
4547extern bool ptrArrayHasTest (const ptrArray * const current ,
4648 bool (* test )(const void * ptr , void * userData ),
4749 void * userData );
You can’t perform that action at this time.
0 commit comments