zeromq / czmq

High-level C binding for ØMQ
czmq.zeromq.org
Mozilla Public License 2.0
1.18k stars 525 forks source link

Auto free on zlists should use strcmp? #2204

Open sphaero opened 2 years ago

sphaero commented 2 years ago

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);

bluca commented 2 years ago

backward compat, probably?

sphaero commented 2 years ago

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.

stale[bot] commented 2 years ago

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.

sphaero commented 2 years ago

I still think this is a proper user friendly suggestion