mwu's blog

A tale of a fearless coder

  • Home
  • About

Navigation Menu

  • « Previous
  • Next »

Categories

  • Mozilla
  • Uncategorized

Killing PRBool with clang and a little bit of fire

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.

Posted in Mozilla    4 Comments

4 Responses to “Killing PRBool with clang and a little bit of fire”

  1. on 23 Jul 2011 at 10:47 am   Jonathan Protzenko

    Michael, do you plan on running the same kind of analysis on comm-central? We have lots of misuses of PRBool in there, some of which have caused severe pains (see https://bugzilla.mozilla.org/show_bug.cgi?id=654126 for instance), and I’d love to see these analyses run there as well!

  2. on 23 Jul 2011 at 3:37 pm   Cameron McCormack

    Nice! (Death to PRBool!)

  3. on 25 Jul 2011 at 8:18 am   mwu

    Oh, didn’t think of that. I’ll try running the tool on comm-central and see what happens.

  4. on 29 Jul 2011 at 2:04 am   Jonathan Protzenko

    Thanks! Please CC me (:protz) on the relevant bug if there’s and if you don’t mind :-) .

Copyright © mwu's blog