The idea is to improve our comments in the .h/.c files where we have a #ifdef BLAH and the corresponding #endif is at least a non negligible amount of lines after. Of course that goes without saying to also comment the #ifndef. Pattern would look like this:
#ifdef BLAH[some non negligible amount of lines]#elif /* BLAH */[some other amount of lines]#endif /* BLAH */
According to nickm, the current situation is:
Our headers have 27 #endifs with a comment, and 435 without.
Good example is or.h:
#ifndef TOR_OR_H[5000+ lines in between]#endif /* TOR_OR_H */
This file src/or/shared_random.h is a good example of what it could look like.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items ...
Show closed items
Linked items 0
Link issues together to show that they're related.
Learn more.
I'd guess it's straightforward to make it count the number of lines between the if/else/elif and their endif, and suppress the output if that's fewer than N lines.
I'd guess it's straightforward to make it count the number of lines between the if/else/elif and their endif, and suppress the output if that's fewer than N lines.
I've done this now. I'll attach my changes to smartcommenter.vba as well as the patch against the Tor source. Some questions:
I set the minimum number of lines between #if..#endif before introducing an comment to be 20. Should it be larger? My thinking was that 20 lines is about a screenful at default terminal size.
In this stanza:
#ifdef FOO...#else /* FOO */...#endif /* FOO */
Should the #else comment be FOO, or !(FOO)?
In this stanza:
#ifndef FOO...#else /* FOO */...#endif /* FOO */
Should the #endif comment be FOO or !(FOO)?
The vim plugin is capable of annotating long braced/indented sections too. Is that attractive?
for fn in src/common/*.[ch] src/or/*.[ch] src/test/*.[ch] src/tools/*.[ch] ; do vim -c ':SmartPreProcCommenter' -c ':wq' $fn; done
I'm getting some pretty weird results though -- for instance, in compat.c, it makes this:
#if !defined(_WIN32)/** Defined iff we need to add locks whena defining fake versions of reentrant * versions of time-related functions. */#define TIME_FNS_NEED_LOCKS#endif /* HAVE_GMTIME_R, defined(TIME_FNS_NEED_LOCKS), defined(TIME_FNS_NEED_LOCKS) */
Hm, actually I can't reproduce your result. Might you be using the plugin from the sites.google.com link I posted, rather than my modified one that's attached to this ticket?
The reason I suspect that you're using the unmodified plugin is that it annotated a three-line block for you, but my modification is supposed to limit annotations to >20 line blocks, which it seems to be doing here -- the block you quoted isn't annotated at all when I run the plugin myself.
(I suppose it's also possible that we're seeing different vim behaviors somehow.)
Ideally, we don't want those "defined()" in there... Apart from that, the changes looks good so I'm deferring this to 031 but if by 030 stable we have a new patch version fixing the above, let's consider it! This is just comment change.
Trac: Milestone: Tor: 0.3.0.x-final to Tor: 0.3.1.x-final Status: needs_review to needs_revision
Hm. So, let's try again. I don't think we can require a specific vim plugin if we're going to have this be a regular part of our toolchain. So how about we try it in Python? I've put a script in an annotate_ifdefs branch in my public repository that I think does just about everything we want. I've put a sample of its output in annotate_ifdefs_sample_output, but we should re-run it immediately on merge if we decide to take it.
May I request a change, I know it's super nitpick but it's a personal preferences that we use /* ... */ instead of the // ?
Another thing, seems that top level ifdef are working with the script but not the one inside. If I take statefile.h for instance, #ifdef STATEFILE_PRIVATE its #endif doesn't the annotation. Bug or on purpose? Which is weird because I see other file correctly annotated...
We can do /* ... */, and I tried that at first, but it will make a lot more lines that are longer than 80 columns and need to get truncated. Still want it?
I think the issue you're reporting with statefile.h is not about outer vs inner, but about the rule that we don't annotate endifs that are within 4 lines of their ifs. (See LINE_OBVIOUSNESS_LIMIT in the script.)
We can do /* ... */, and I tried that at first, but it will make a lot more lines that are longer than 80 columns and need to get truncated. Still want it?
I made a test, I see 10 long line with // and 17 with /* */. I even volunteer to fix those after merge :P.
I think the issue you're reporting with statefile.h is not about outer vs inner, but about the rule that we don't annotate endifs that are within 4 lines of their ifs. (See LINE_OBVIOUSNESS_LIMIT in the script.)
Ok! Didn't catch that.
I found another "issue" in src/ext/OpenBSD_malloc_Linux.c:
#else // !(!defined(BUILDING_FOR_TOR)) ... which seems odd. Maybe the script is confused by the #define at the start of the file and then #ifndef later ?
I mean "double negative" is right just kind of harder to parse. If it is an easy fix to detect double negative to be just "defined()", great else no biggy. Anyway, I'm being picky here just for documentation :P.
Trac: Reviewer: N/Ato dgoulet Status: needs_revision to merge_ready
I think the src/ext/openbsd.. issue should be okay; I'm not planning to run this script on src/ext, since that isn't our code. We can improve the output there later if we want.
For the wide lines, I'll try to fix that one way or another when I merge, which I intend to do when we freeze, so that nothing runs into conflicts with this patch this week.