A tale of a fearless coder
July 23rd, 2011 by mwu
Once upon a time, there was a tool called prcheck which checked usage of PRBools and made sure only righteous 1s and 0s were assigned to PRBools. The goal was to correct all the uses of PRBool and hopefully turn PRBool into a Real Boolean.
This didn’t happen, though many abuses of PRBool were corrected along the way.
But, there may be hope now. A new PRBool checking tool based on clang has lead to a number of patches correcting various misuses of PRBool across the Mozilla codebase. The abuses of PRBool are varied and creative, but they all tend to fall under two categories:
- Using PRBool when some other type would be more appropriate or vice versa. (bug 671190 and bug 671417)
- Returning NS_ERROR_* codes in functions that return PRBool. This is particularly bad as error codes are likely to be treated as true, and true usually means success. (bug 671185)
With the help of this clang plugin, a bit of manual build fixing, and some hours lost in gdb, we can typedef PRBool as a (real) bool. The local build here is capable of starting up, passing make check, and passing all but one xpcshell test.
More updates and code release of this clang plugin to come.