-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
++cWill be eventually fixed, using ++CWill be eventually fixed, using ++C
Description
Some array/strings utility function cannot take a T const** as argument because they need to possibly reallocate and return the new pointer to the array.
For example:
// Appends the given string `string` to the end of the given string array `dest`.
t_char** StringArray_Add(t_char** dest, t_char const* str);This forces T const** type array to be casted to T**.
One should be able to pass a T const** type array because the function does not modify the elements.
I suggest adding another version of these functions and wrapping them like so:
t_char const** StringArray_Add_Const(t_char const** dest, t_char const* str)
{
// The current implementation of `StringArray_Add` which doesn't modify the content of strings anyway
t_char const** result;
t_uint length;
HANDLE_ERROR(NULLPOINTER, (dest == NULL), return (NULL);)
HANDLE_ERROR(NULLPOINTER, (str == NULL), return (NULL);)
length = (StringArray_Length((t_char const**)dest));
result = (t_char const**)Memory_Reallocate(dest, (length + 1) * sizeof(t_char*));
HANDLE_ERROR(ALLOCFAILURE, (result == NULL), return (NULL);)
result[length] = String_Duplicate(str);
return (result);
}
t_char** StringArray_Add(t_char** dest, t_char const* str)
{
return (t_char**)StringArray_Add_Const((t_char const**)dest, str);
}Here is a list of all the functions I think this applies:
- PointerArray_Add
- PointerArray_Insert
- PointerArray_Wedge
- PointerArray_Replace
- PointerArray_ReplaceFirst
- PointerArray_ReplaceLast
- PointerArray_Concat
- PointerArray_Append
- PointerArray_Prepend
- PointerArray_Join
- PointerArray_Find
- PointerArray_Find_F
- PointerArray_Iterate
- PointerArray_Iterate_I
- PointerArray_Map (need to double check if this applies)
- PointerArray_Map_I (need to double check if this applies)
- PointerArray_Filter
- PointerArray_Filter_I
- StringArray_Add
- StringArray_Insert
- StringArray_Wedge
- StringArray_Append (that would imply we free some
t_char const*, does that make sense?) - StringArray_Prepend (same ^^^)
- StringArray_Iterate
- StringArray_Iterate_I
Metadata
Metadata
Assignees
Labels
++cWill be eventually fixed, using ++CWill be eventually fixed, using ++C