/*
 * Arrays.  Almost all the array support is in fact in psArray.h,
 * but we directly support arrays of (void *) here, so as to be
 * able to free each element properly
 */
#include "psLib.h"
#include "psArray.h"

typedef void *psVoidPtr;

P_PS_CREATE_ARRAY_TYPE(static, my_, psVoidPtr);

psVoidPtrArray *psVoidPtrArrayAlloc(int n)
{
    return my_psVoidPtrArrayAlloc(n);
}

psVoidPtrArray *psVoidPtrArrayRealloc(psVoidPtrArray *arr, int n)
{
    return my_psVoidPtrArrayRealloc(arr, n);
}

void psVoidPtrArrayFree(psVoidPtrArray *arr,
			void (*elemFree)(void *)) // destructor for data on array
{
    if (arr == NULL) {
	return;
    }
	
    for (int i = 0; i < arr->n; i++) {
	if (elemFree == NULL) {
	    psMemDecrRefCounter(arr->arr[i]);
	} else {
	    elemFree(psMemDecrRefCounter(arr->arr[i]));
	}
    }
    my_psVoidPtrArrayFree(arr);
}
