typedef struct
{
int count;
char *str[];
} Edje_Message_String_Set;
####
malloc( sizeof(Edje_Message_String_Set) + (count-1)*sizeof(char *) );
##
##
Newx(message,1,EdjeMessageStringSet);
Renewc(message,count+2, char*,EdjeMessageStringSet);
if (message == NULL)
croak("Failed to allocate memory in _new function\n");
##
##
void Newx(void* ptr, int nitems, type)
void* safemalloc(size_t size)
void* Renewc( void *ptr, int size, type, cast )
void Safefree(void* ptr)
Newx(message,1,EdjeMessageStringSet);
// allocate space for 1 EdjeMessageStringSet
// this is enough for just 1 pointer to char
// i.e. ok if count==1
// memory is not initialized.
Renewc(message,count+2, char*, EdjeMessageStringSet);
// Leak some memory from the heap.
// Allocate enough space for count+2 char*
// copy contents of memory from previous Newx() operation
// to this newly allocated memory
// Then throw pointer to this new memory away
// For extra confusion, also calls "free" on the original pointer!!
if (message == NULL)
croak("Failed to allocate memory in _new function\n");
// Of course should have checked this after the Newx().
##
##
EdjeMessageStringSet* m = (EdjeMessageStringSet*) safemalloc( sizeof(Edje_Message_String_Set) + (count-1)*sizeof(char *) );
if (m == NULL)
croak("Failed to allocate memory in _new function\n");