make plist arrays unlimited in size

This commit is contained in:
Bill Currie 2003-04-07 19:29:52 +00:00
parent 55eb6c3ab1
commit d5003f363d
2 changed files with 12 additions and 6 deletions

View file

@ -37,9 +37,6 @@
inrange((ch), '0', '9') ? ((ch) - 0x30) \ inrange((ch), '0', '9') ? ((ch) - 0x30) \
: (inrange((ch), 'a', 'f') ? ((ch) - 0x57) : ((ch) - 0x37)) : (inrange((ch), 'a', 'f') ? ((ch) - 0x57) : ((ch) - 0x37))
// Maximum number of items in an array
#define MAX_ARRAY_INDEX 128
typedef enum {QFDictionary, QFArray, QFBinary, QFString} pltype_t; // possible types typedef enum {QFDictionary, QFArray, QFBinary, QFString} pltype_t; // possible types
/* /*
@ -65,7 +62,8 @@ typedef struct dictkey_s dictkey_t;
*/ */
struct plarray_s { struct plarray_s {
int numvals; // Number of items in array int numvals; // Number of items in array
struct plitem_s *values[MAX_ARRAY_INDEX+1]; // Array data int maxvals;
struct plitem_s **values; // Array data
}; };
typedef struct plarray_s plarray_t; typedef struct plarray_s plarray_t;

View file

@ -120,6 +120,7 @@ PL_FreeItem (plitem_t *item)
while (i-- > 0) { while (i-- > 0) {
PL_FreeItem (((plarray_t *) item->data)->values[i]); PL_FreeItem (((plarray_t *) item->data)->values[i]);
} }
free (((plarray_t *) item->data)->values);
free (item->data); free (item->data);
} }
break; break;
@ -193,8 +194,15 @@ PL_A_InsertObjectAtIndex (plitem_t *array_item, plitem_t *item, int index)
array = (plarray_t *)array_item->data; array = (plarray_t *)array_item->data;
if (array->numvals == MAX_ARRAY_INDEX) if (array->numvals == array->maxvals) {
return NULL; plitem_t **tmp = realloc (array->values, array->maxvals + 128);
if (!tmp)
return NULL;
array->maxvals += 128;
array->values = tmp;
memset (array->values + array->numvals, 0,
(array->maxvals - array->numvals) * sizeof (plitem_t *));
}
if (index == -1) if (index == -1)
index = array->numvals; index = array->numvals;