czmq icon indicating copy to clipboard operation
czmq copied to clipboard

Auto free on zlists should use strcmp?

Open sphaero opened this issue 3 years ago • 4 comments

If you are using zlist_autofree (usually for storing strings) is there any situation imaginable where you don't want to use strcmp as a comparator function?

As zlist_autofree duplicates strings you can't use zlist_exists or zlist_remove if you don't set a comparator.

So why not set the comparator automatically?

zlist_comparefn (mylist, (zlist_compare_fn *) strcmp);

sphaero avatar Dec 10 '21 21:12 sphaero

backward compat, probably?

bluca avatar Dec 10 '21 22:12 bluca

I don't that would be an issue. If you use zlist_autofree char pointers are implied:

https://github.com/zeromq/czmq/blob/062aeb3bf346f8806e8d39f7da163a57ebad7543/src/zlist.c#L183-L186

Using it like that renders the zlist_remove and zlist_exists useless as they compare pointers by default which is of no use as the strings are duped.

So if people are using zlist_autofree they need to set a compare function if they want any useful functionality. We can at least set it to a sane default. If people want something different they would already set so.

sphaero avatar Dec 11 '21 19:12 sphaero

This issue has been automatically marked as stale because it has not had recent activity for 90 days. It will be closed if no further activity occurs within 21 days. Thank you for your contributions.

stale[bot] avatar Apr 16 '22 17:04 stale[bot]

I still think this is a proper user friendly suggestion

sphaero avatar May 19 '22 20:05 sphaero