Closed Bug 965022 Opened 10 years ago Closed 10 years ago

Add __attribute__((format)) to printf like apis

Categories

(Core :: XPCOM, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla34

People

(Reporter: jrmuizel, Assigned: botond)

References

Details

Attachments

(8 files, 5 obsolete files)

8.24 KB, patch
Details | Diff | Splinter Review
1.17 KB, patch
botond
: review+
Details | Diff | Splinter Review
2.29 KB, patch
botond
: review+
Details | Diff | Splinter Review
9.83 KB, patch
jrmuizel
: review+
Details | Diff | Splinter Review
816 bytes, patch
jrmuizel
: review+
Details | Diff | Splinter Review
6.78 KB, patch
jrmuizel
: review+
Details | Diff | Splinter Review
33.43 KB, patch
Details | Diff | Splinter Review
1.38 KB, patch
Details | Diff | Splinter Review
This makes for useful warnings.
Attached patch patch (obsolete) — Splinter Review
Attachment #8366955 - Flags: review?(ehsan)
>+      MOZ_FORMAT_PRINTF(2, 3)
>       void AppendPrintf( const char* format, ... );

Shouldn't that be "1, 2"?
(In reply to Mats Palmgren (:mats) from comment #2)
> >+      MOZ_FORMAT_PRINTF(2, 3)
> >       void AppendPrintf( const char* format, ... );
> 
> Shouldn't that be "1, 2"?

parameter 1 is the implicit 'this'
Comment on attachment 8366955 [details] [diff] [review]
patch

Review of attachment 8366955 [details] [diff] [review]:
-----------------------------------------------------------------

I don't know anything about this attribute.  Making this Nathan's problem.  :-)
Attachment #8366955 - Flags: review?(ehsan) → review?(nfroyd)
Comment on attachment 8366955 [details] [diff] [review]
patch

Review of attachment 8366955 [details] [diff] [review]:
-----------------------------------------------------------------

r=me with the comments below addressed.  We get a gold star if adding these doesn't trigger additional warnings...

::: xpcom/glue/nsCRTGlue.cpp
@@ +308,5 @@
>    vfprintf(stderr, fmt, args);
>  }
>  #endif
>  
> +MOZ_FORMAT_PRINTF(1, 2)

This should go on the declaration of printf_stderr in nsDebug.h.  At that location, it should go after the argument list, as is typical for function attributes in the codebase.

@@ +318,5 @@
>    vprintf_stderr(fmt, args);
>    va_end(args);
>  }
>  
> +MOZ_FORMAT_PRINTF(2, 3)

Same comments as above, for fprintf_stderr.

::: xpcom/string/public/nsTSubstring.h
@@ +460,1 @@
>        void AppendPrintf( const char* format, ... );

Move this to after the argument list.
Attachment #8366955 - Flags: review?(nfroyd) → review+
Depends on: 973256
Depends on: 973257
Attached patch formatSplinter Review
Attachment #8366955 - Attachment is obsolete: true
Blocks: 1057642
Going to take this because it would be extremely helpful for bug 1057642.
Assignee: nobody → botond
This bit is straight out of Jeff's patch, which was r+'d by :froydnj, so carrying r+ for it.
Attachment #8478527 - Flags: review+
Attachment #8478528 - Flags: review?(mchang)
Doing a build-only Try push to flush out any errors on other platforms: https://tbpl.mozilla.org/?tree=Try&rev=3a62ed8f607c
Comment on attachment 8478528 [details] [diff] [review]
Part 2 - Avoid pintf'ing a TimeStamp in PrintUniformityInfo

Review of attachment 8478528 [details] [diff] [review]:
-----------------------------------------------------------------

LGTM. Can we print the TimeDuration::ToMilliseconds instead of MicroSeconds? Thanks!
Attachment #8478528 - Flags: review?(mchang) → review+
(In reply to Mason Chang [:mchang] from comment #11)
> LGTM. Can we print the TimeDuration::ToMilliseconds instead of MicroSeconds?
> Thanks!

Done. Updated, carrying r+.
Attachment #8478528 - Attachment is obsolete: true
Attachment #8478619 - Flags: review+
Attached patch Part 3 - Introduce PRISize (obsolete) — Splinter Review
Attachment #8478660 - Flags: review?(nfroyd)
Updated to fix some missing cases caught by Try, and to use PRISize.
Attachment #8478530 - Attachment is obsolete: true
Another buildonly Try push: https://tbpl.mozilla.org/?tree=Try&rev=67cb664acdef
Comment on attachment 8478660 [details] [diff] [review]
Part 3 - Introduce PRISize

Review of attachment 8478660 [details] [diff] [review]:
-----------------------------------------------------------------

PR

::: mfbt/IntegerPrintfMacros.h
@@ +62,5 @@
> +/**
> + * For printing size_t.
> + */
> +#define PRISize PRIuPTR
> +

PRIuSIZE is probably a more consistent name and is used by other projects.
(In reply to Botond Ballo [:botond] from comment #16)
> Another buildonly Try push:
> https://tbpl.mozilla.org/?tree=Try&rev=67cb664acdef

Gah, OS X build error from the AppendPrintf patch.

Here's a buildonly Try push for just the [f]printf_stderr patch, so that I can at least land that while I play whac-a-mole with the AppendPrintf OS X errors on Try (not having a local OS X build): https://tbpl.mozilla.org/?tree=Try&rev=79a16a82455a
(In reply to Jeff Muizelaar [:jrmuizel] from comment #17)
> > +/**
> > + * For printing size_t.
> > + */
> > +#define PRISize PRIuPTR
> > +
> 
> PRIuSIZE is probably a more consistent name and is used by other projects.

Good point. Updated.
Attachment #8478660 - Attachment is obsolete: true
Attachment #8478660 - Flags: review?(nfroyd)
Attachment #8478708 - Flags: review?(nfroyd)
Updated to change PRISize to PRIuSIZE.
Attachment #8478662 - Attachment is obsolete: true
Comment on attachment 8478709 [details] [diff] [review]
Part 4 - Add MOZ_FORMAT_PRINTF to [f]printf_stderr and fix fallout

This one's clean.
Attachment #8478709 - Flags: review?(nfroyd)
Attachment #8478708 - Flags: review?(nfroyd) → review?(jmuizelaar)
Attachment #8478709 - Flags: review?(nfroyd) → review?(jmuizelaar)
OS X whac-a-mole, attempt 2: https://tbpl.mozilla.org/?tree=Try&rev=38a816b10ea2
(In reply to Botond Ballo [:botond] from comment #13)
> Part 3 - Introduce PRISize

I'm +0 on this; the state of portably printing size_t values is sad-making, and we should try to make it pleasant, but IntegerPrintfMacros.h was intended as a polyfill for <inttypes.h>, so adding things to it that aren't standardized would be frowned upon.
Comment on attachment 8478664 [details] [diff] [review]
Part 5 - Add MOZ_FORMAT_PRINTF to AppendPrintf and fix fallout

Clean as well.

Now on to nsPrintfCString.
Attachment #8478664 - Flags: review?(jmuizelaar)
Comment on attachment 8478708 [details] [diff] [review]
Part 3 - Introduce PRIuSIZE

This should be fine it might be worth still asking Nathan for a post commit review to make sure there are no objections.
Attachment #8478708 - Flags: review?(jmuizelaar) → review+
Attachment #8478709 - Flags: review?(jmuizelaar) → review+
Attachment #8478664 - Flags: review?(jmuizelaar) → review+
A bit more fallout here, including lots of ugly PRIu64 stuff...
Built-only Try push that includes the nsPrintCString change: https://tbpl.mozilla.org/?tree=Try&rev=9fde4221f009
I want to say this broke lots of Windows tests as well, but they weren't run for several pushes including this one's. The tests turned green sometime after this was backed out: https://tbpl.mozilla.org/?tree=Mozilla-Inbound&rev=3a545eb9828b&jobname=Windows
I looked into the WebGL test failures. The cause is that AppendPrintf uses a custom-written printf implementation (PR_vsxprintf from NSPR), which treats %l differently than the standard printf functions (it treats %l as always 32-bit, whereas standard printf function treat %l as whatever size 'long' is on that platform).

This patch modifies PR_vsxprintf to treat %l the same standard print functions do.

Try push for parts 1-5, including tests this time: https://tbpl.mozilla.org/?tree=Try&rev=a9bb070916b9
(In reply to Botond Ballo [:botond] from comment #27)
> Built-only Try push that includes the nsPrintCString change:
> https://tbpl.mozilla.org/?tree=Try&rev=9fde4221f009

Fixed OS X failures in nsPrintfCString patch. Trying again: https://tbpl.mozilla.org/?tree=Try&rev=f7b5a1d73e10
(In reply to Botond Ballo [:botond] from comment #31)
> Created attachment 8480210 [details] [diff] [review]
> Part 4.5 - Make PR_vsxprintf's handling of %l consistent with standard printf
> 
> I looked into the WebGL test failures. The cause is that AppendPrintf uses a
> custom-written printf implementation (PR_vsxprintf from NSPR), which treats
> %l differently than the standard printf functions (it treats %l as always
> 32-bit, whereas standard printf function treat %l as whatever size 'long' is
> on that platform).
> 
> This patch modifies PR_vsxprintf to treat %l the same standard print
> functions do.
> 
> Try push for parts 1-5, including tests this time:
> https://tbpl.mozilla.org/?tree=Try&rev=a9bb070916b9

The test results indicate that my modification to PR_vsxprintf isn't correct.

Unfortunately I don't have more time to spend on this right now, so I will try landing parts 1-4 instead and leave the AppendPrintf/nsPrintfCString part for later.

Try push for parts 1-4: https://tbpl.mozilla.org/?tree=Try&rev=b2677c7b2dca
No longer blocks: 1057642
Blocks: 1060419
Filed bug 1060419 as a follow-up for the AppendPrintf/nsPrintfCString work.
Sorry, meant to close this when I filed the follow-up.
Status: NEW → RESOLVED
Closed: 10 years ago
Keywords: leave-open
Resolution: --- → FIXED
Target Milestone: --- → mozilla34
Depends on: 1114724
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: