C-Macro-Collections
C-Macro-Collections copied to clipboard
Function tables shouldn't be required
The library should:
- [ ] Allow fkey and fval parameters to be null
- [ ] Check in _new() for required functions
- [ ] Check if the struct and if the functions are null before every usage and report errors instead of crashing
Fell for this one, I thought f_val was copied into the list, not kept as a reference, so I did something like this
element_new_custom(50, &((struct tile_effects_list_fval){ .cmp = compare_element }), NULL, NULL);
and you can guess what happened
Fell for this one, I thought f_val was copied into the list, not kept as a reference, so I did something like this
element_new_custom(50, &((struct tile_effects_list_fval){ .cmp = compare_element }), NULL, NULL);and you can guess what happened
Now I'm really starting to think if the function tables should be kept as a copy for each ds instead of a pointer
Not sure about the memory / indirect call tradeoff, it seems worth it to just copy the table since it will be most likely on the cache.
on my own modified version, I removed the default allocation table and made it required to be consistent with fval, and one of the problems I noticed is that most libs expect a different table e.g. some expect { .free, .malloc }, while others expect { .realloc, .malloc }, keeping a table for all of them around is annoying. So you might consider copying the allocation table too for consistency