https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48925

--- Comment #5 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
Created attachment 38707
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38707&action=edit
A preliminary patch

This patch does a major reorganization of the code for writing formatted real
numbers.

Actual writing is lifted up into write_float_string. This allows the kind=4
char unit code to be consolidated there and removed from the macros in
write_float.def.  write_float is renamed to get_float_string and returns a
pointer to a null terminated string containing the final result of formatting.

output_float is renamed build_float string, it no longer writes the result.

Buffer allocation is consolidated into a helper function. This done to allow
two separate buffers later for write_complex to enable padding the formatted
complex with leading blanks and no intervening spaces (right justification in
the default field width for list directed writes)

Yet to be done:

1)Currently have an extra xmalloc down deep in build_float_string and
build_infnan_string. I want to get rid of xmalloc here and combine it with the
allocation in write_real, etc. My intent is to have a single buffer with an
area for scratch or working and another area for the result.

2)Modify write complex to use the new helper functions and resolve pr48852.

Reviews and testing appreciated. Have not checked for leaks yet.

Reply via email to