@@ -313,8 +313,8 @@ calc_number_widths(NumberFieldWidths *r, STRINGLIB_CHAR actual_sign,
313313 as determined in _calc_integer_widths(). returns the pointer to
314314 where the digits go. */
315315static STRINGLIB_CHAR *
316- fill_number (STRINGLIB_CHAR * p_buf , const NumberFieldWidths * spec ,
317- Py_ssize_t n_digits , STRINGLIB_CHAR fill_char )
316+ fill_non_digits (STRINGLIB_CHAR * p_buf , const NumberFieldWidths * spec ,
317+ Py_ssize_t n_digits , STRINGLIB_CHAR fill_char )
318318{
319319 STRINGLIB_CHAR * p_digits ;
320320
@@ -557,17 +557,17 @@ format_int_or_long_internal(PyObject *value, const InternalFormatSpec *format,
557557 pnumeric_chars += leading_chars_to_skip ;
558558 }
559559
560- /* Calculate the widths of the various leading and trailing parts */
561- calc_number_widths (& spec , sign , n_digits , format );
562-
563560 if (format -> type == 'n' )
564561 /* Compute how many additional chars we need to allocate
565562 to hold the thousands grouping. */
566563 STRINGLIB_GROUPING (NULL , n_digits , n_digits ,
567564 0 , & n_grouping_chars , 0 );
568565
566+ /* Calculate the widths of the various leading and trailing parts */
567+ calc_number_widths (& spec , sign , n_digits + n_grouping_chars , format );
568+
569569 /* Allocate a new string to hold the result */
570- result = STRINGLIB_NEW (NULL , spec .n_total + n_grouping_chars );
570+ result = STRINGLIB_NEW (NULL , spec .n_total );
571571 if (!result )
572572 goto done ;
573573 p = STRINGLIB_STR (result );
@@ -587,7 +587,7 @@ format_int_or_long_internal(PyObject *value, const InternalFormatSpec *format,
587587
588588 /* Insert the grouping, if any, after the uppercasing of 'X', so we can
589589 ensure that grouping chars won't be affected. */
590- if (n_grouping_chars && format -> type == 'n' ) {
590+ if (n_grouping_chars ) {
591591 /* We know this can't fail, since we've already
592592 reserved enough space. */
593593 STRINGLIB_CHAR * pstart = p + n_leading_chars ;
@@ -597,9 +597,9 @@ format_int_or_long_internal(PyObject *value, const InternalFormatSpec *format,
597597 assert (r );
598598 }
599599
600- /* Fill in the non-digit parts */
601- fill_number (p , & spec , n_digits ,
602- format -> fill_char == '\0' ? ' ' : format -> fill_char );
600+ /* Fill in the non-digit parts (padding, sign, etc.) */
601+ fill_non_digits (p , & spec , n_digits + n_grouping_chars ,
602+ format -> fill_char == '\0' ? ' ' : format -> fill_char );
603603
604604done :
605605 Py_XDECREF (tmp );
@@ -737,9 +737,9 @@ format_float_internal(PyObject *value,
737737 if (result == NULL )
738738 goto done ;
739739
740- /* fill in the non-digit parts */
741- fill_number (STRINGLIB_STR (result ), & spec , n_digits ,
742- format -> fill_char == '\0' ? ' ' : format -> fill_char );
740+ /* Fill in the non-digit parts (padding, sign, etc.) */
741+ fill_non_digits (STRINGLIB_STR (result ), & spec , n_digits ,
742+ format -> fill_char == '\0' ? ' ' : format -> fill_char );
743743
744744 /* fill in the digit parts */
745745 memmove (STRINGLIB_STR (result ) +
0 commit comments