C-Macro-Collections icon indicating copy to clipboard operation
C-Macro-Collections copied to clipboard

Function tables shouldn't be required

Open LeoVen opened this issue 2 years ago • 3 comments
trafficstars

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

LeoVen avatar Feb 22 '23 15:02 LeoVen

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

duarm avatar Nov 02 '23 23:11 duarm

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

LeoVen avatar Dec 11 '23 01:12 LeoVen

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

duarm avatar Dec 11 '23 01:12 duarm