Bug 7072

Summary: use _stp_reserve_bytes for printf buffer
Product: systemtap Reporter: Kent Sebastian <ksebasti>
Component: runtimeAssignee: Kent Sebastian <ksebasti>
Status: RESOLVED FIXED    
Severity: enhancement CC: dsmith
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:
Attachments: patch _stp_printf and _stp_vsnprintf to allocate exact size printf buffer
patch _stp_printf and _stp_vsnprintf to allocate exact size printf buffer, w/comments

Description Kent Sebastian 2008-12-05 19:31:14 UTC
As per fche's suggestion, have _stp_printf allocate the exact size needed for
the print buffer instead of using the default STP_BUFFER_SIZE.
Comment 1 Kent Sebastian 2009-04-03 21:31:03 UTC
Created attachment 3867 [details]
patch _stp_printf and _stp_vsnprintf to allocate exact size printf buffer

Submitting the changes as a patch instead of committing for some comments. The
printf tests pass on F10 x86 and x86_64, and there are no different failures on
the full testsuite between patched/unpatched.

fche did say to not duplicate code as much as possible but especially with
number(), which returns a char*, getting an integer size out of it would have
been hacky. As well in _stp_vsnprintf putting if statements everywhere didn't
shorten the size of the function but made it much harder to read, so I took
this route.

Any comments/suggestions/flames? :)
Comment 2 David Smith 2009-04-06 15:06:59 UTC
(In reply to comment #1)
> Created an attachment (id=3867)
> patch _stp_printf and _stp_vsnprintf to allocate exact size printf buffer
> 
> Submitting the changes as a patch instead of committing for some comments. The
> printf tests pass on F10 x86 and x86_64, and there are no different failures on
> the full testsuite between patched/unpatched.
> 
> fche did say to not duplicate code as much as possible but especially with
> number(), which returns a char*, getting an integer size out of it would have
> been hacky. As well in _stp_vsnprintf putting if statements everywhere didn't
> shorten the size of the function but made it much harder to read, so I took
> this route.
> 
> Any comments/suggestions/flames? :)

I think I see what you are trying to do here.  I don't really like the
duplicated code, but I also don't see a good way around it.

Could you add a comment to the new code in _stp_vsnprintf() mentioning that any
changes in it need to be reflected in the code lower down?  A comment in the
lower part mentioning the reverse might also be a good idea.
Comment 3 Kent Sebastian 2009-04-17 15:45:32 UTC
Created attachment 3889 [details]
patch _stp_printf and _stp_vsnprintf to allocate exact size printf buffer, w/comments

Added comments explaining the requirement to change the corresponding 'sizing'
code.
Comment 4 Kent Sebastian 2009-04-17 16:04:47 UTC
Committed in 9831040e54178a1b6eb4637213bb3c81f6ed254b.