Current implementation is macro-based and sometimes it is hard to identify issues during build stage or debugging.
*_FOREACH_* equivalents weren't implemented intentionally to avoid confusion. Also I don't see huge advantage in it.
Differential D54753
queue(3): add function-based API Authored by minsoochoo0122_proton.me on Sat, Jan 17, 4:14 AM. Tags Referenced Files
Subscribers
Details
Current implementation is macro-based and sometimes it is hard to identify issues during build stage or debugging. *_FOREACH_* equivalents weren't implemented intentionally to avoid confusion. Also I don't see huge advantage in it. Write a dummy program to run this following new examples in queue(3).
Diff Detail
Event TimelineComment Actions Unfortunately parsing diffs from git format-patch from phabricator side seems to be broken. It only shows the first (and the most trivial) commit. I'm using basic git diff here.
Comment Actions
We usually make a review for each commit, and link them together in a stack. Git arc does this, or you can click "add parent" in Phab.
Comment Actions @ziaee I splitted queue.3 into four man pages, so each of them should have length of 50% of the original NAME section (1/4 * 2 for function-based API).
Comment Actions generally I like the concept. If this isn't just text motion, though, I'd split it into (1) move things to new man page with as few other changes as is needed to make them work and (2) improvements, etc as a second commit. I'm just commenting on the copyright / spdx issues at the moment.
Comment Actions To be honest, I'm not thrilled to have a whole new set of functions for doing something already covered by queue.h and used extensively throughout the tree. These functions don't provide any type checking or debug assertions/poisoning like the queue.h macros do. These functions might be easier to use for someone not used to queue.h, but there are tons of examples of queue.h macro usage in the tree to draw from. Comment Actions @imp separated commits. I'll keep the 3-clause license and ask the foundation on Monday. Comment Actions asserts I wrote were... nonsense. We should let users declare their own asserts instead. Comment Actions Type checking is done here and there is no need for (void *) casting. containerof() will return the structure that contains the node and other data. For assertion, we can let users to declare their own assert functions and call it in the headers, but I forgot to implement it here. This might look like reinventing the wheel because the problem of macro hell isn't that significant in queue(3), but things are worse in tree(3). Tweaking logics in WAVL tree implementation often fails due to macro generate/prototype, which wouldn't have happened with function-based implementation. It also comes as a barrier to first-time contributors or junior programmers because most data structure courses at university teach struct+function mechanism, not macro-based ones. I'm also one of those junior developers, and building and debugging my scheduler patch with the macro-based API would be nightmare. Existing code and developers who prefer the macro-based APIs can stick with it. IMHO it will never be deprecated. Comment Actions No, I mean that when when I define a list or queue head with LIST_HEAD, etc., I also declare the type of the item within that list. Attempting to insert an item of a different type results in a compile error rather than runtime memory corruption. This checking is useful, and is the entire reason for using macros in the first place. containerof doesn't provide any checking.
This is really just an argument for moving away from C entirely. And I'd quite like that personally, but it's easier said than done. I'll also point out that a good way to confuse developers, especially junior developers, is to have more than one standard way to accomplish a common task.
I'm not worried about writing code, but rather reading and debugging it. There are lots of ways to implement linked lists, learning a new one isn't hard. What's more painful is dealing with code written using multiple styles, conventions, etc. because various authors think their style is superior for some subjective reason, versus something that is written in a consistent way. To wit, keeping in mind that we also have list.h, llist.h, etc. in the linuxkpi: https://xkcd.com/927/ My aim isn't to discourage you from improve upon system headers like queue.h or tree.h, but there's a lot of value in trying to familiarize oneself with existing conventions in a codebase before deciding that something needs to be replaced. Comment Actions Fair point.
My original implementation of minmax caching on wavl (using prev and next) always failed CI build on github, and only succeeded when I changed the logic to do full search from root. The issue was macro generation/prototype thing and it was hard to understand for me. Most cases macros are less flexible than functions. Many developers' first language is not C, and C macros could be quite challenging for them. Functions not only helps improving their DX but also prevents programming errors that comes from unfamiliarity with C macros (Other languages I use don't have C-style macros).
I started working on this when it was clear that cached wavl implementation needs a groundup implementation. It won't be implemented in macros like the existing RB_* for my sanity, and in that case users will question why cached rbtree is implemented in non-macro way and its usage differs from other data structures. Either case there will be multiple ways to work with data structures. I minimized the confusion of having two implementations by documenting them in the same man page. Splitting queue(3) is inevitable anyways because its name section is too long, and this gives a good opportunity to do so. Comment Actions I would strongly encourage you to work towards having a build-compile-test loop that does not rely on github or any third-party CI. You will be much more productive if you don't have to wait for CI to run in order to discover compile errors. It should take maybe 5 seconds to check whether your latest edits build.
I don't know what to say to this. C macros can be painful to read, are hard to write, and you can do terrible and magical things with them. Comment Actions I usually do. But it's snowing really bad outside while my PC is in the office, so I had to work from home with my macbook. I created PR to see my changes build or not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||