Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@
#if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON)

static void
unknown_presentation_type(Py_UCS4 presentation_type,
const char* type_name)
unknown_presentation_type(Py_UCS4 presentation_type, PyObject* type_name)
{
/* %c might be out-of-range, hence the two cases. */
if (presentation_type > 32 && presentation_type < 128) {
PyErr_Format(PyExc_ValueError,
"Unknown format code '%c' "
"for object of type '%.200s'",
(char)presentation_type,
type_name);
"Unknown format code '%c' for object of type '%U'",
(char)presentation_type, type_name);
}
else {
PyErr_Format(PyExc_ValueError,
"Unknown format code '\\x%x' "
"for object of type '%.200s'",
(unsigned int)presentation_type,
type_name);
"Unknown format code '\\x%x' for object of type '%U'",
(unsigned int)presentation_type, type_name);
}
}

Expand Down Expand Up @@ -301,7 +296,7 @@ parse_internal_render_format_spec(PyObject *obj,
PyErr_Format(PyExc_ValueError,
("Invalid format specifier '%U' for object "
"of type '%.200s'"), actual_format_spec,
Py_TYPE(obj)->tp_name);
PyType_GetName(Py_TYPE(obj)));
Py_DECREF(actual_format_spec);
}
return 0;
Expand Down Expand Up @@ -492,6 +487,7 @@ _PyUnicode_InsertThousandsGrouping(_PyUnicodeWriter *writer,
assert(0 <= d_pos);
assert(0 <= n_digits);
assert(grouping != NULL);
assert(PyUnicode_Check(thousands_sep));

Py_ssize_t count = 0;
Py_ssize_t n_zeros;
Expand All @@ -509,7 +505,7 @@ _PyUnicode_InsertThousandsGrouping(_PyUnicodeWriter *writer,
returns 0. */
GroupGenerator groupgen;
GroupGenerator_init(&groupgen, grouping);
const Py_ssize_t thousands_sep_len = PyUnicode_GET_LENGTH(thousands_sep);
const Py_ssize_t thousands_sep_len = PyUnicode_GetLength(thousands_sep);

/* if digits are not grouped, thousands separator
should be an empty string */
Expand All @@ -518,8 +514,8 @@ _PyUnicode_InsertThousandsGrouping(_PyUnicodeWriter *writer,
digits_pos = d_pos + n_digits;
if (writer) {
buffer_pos = writer->pos + n_buffer;
assert(buffer_pos <= PyUnicode_GET_LENGTH(writer->buffer));
assert(digits_pos <= PyUnicode_GET_LENGTH(digits));
assert(buffer_pos <= PyUnicode_GetLength(writer->buffer));
assert(digits_pos <= PyUnicode_GetLength(digits));
}
else {
buffer_pos = n_buffer;
Expand Down Expand Up @@ -586,7 +582,7 @@ calc_number_widths(NumberFieldWidths *spec, Py_ssize_t n_prefix,
spec->n_digits = n_end - n_start - n_frac - n_remainder - (has_decimal?1:0);
spec->n_lpadding = 0;
spec->n_prefix = n_prefix;
spec->n_decimal = has_decimal ? PyUnicode_GET_LENGTH(locale->decimal_point) : 0;
spec->n_decimal = has_decimal ? PyUnicode_GetLength(locale->decimal_point) : 0;
spec->n_remainder = n_remainder;
spec->n_frac = n_frac;
spec->n_spadding = 0;
Expand Down Expand Up @@ -1032,6 +1028,7 @@ format_long_internal(MPZ_Object *value, const InternalFormatSpec *format)
}
/* Do the hard part, converting to a string in a given base */
tmp = MPZ_to_str(value, base, OPT_PREFIX);
assert(PyUnicode_Check(tmp));
if (tmp == NULL) {
goto done; /* LCOV_EXCL_LINE */
}
Expand All @@ -1041,11 +1038,11 @@ format_long_internal(MPZ_Object *value, const InternalFormatSpec *format)
n_prefix = leading_chars_to_skip;
}
inumeric_chars = 0;
n_digits = PyUnicode_GET_LENGTH(tmp);
n_digits = PyUnicode_GetLength(tmp);
prefix = inumeric_chars;
/* Is a sign character present in the output? If so, remember it
and skip it */
if (PyUnicode_READ_CHAR(tmp, inumeric_chars) == '-') {
if (PyUnicode_ReadChar(tmp, inumeric_chars) == '-') {
sign_char = '-';
++prefix;
++leading_chars_to_skip;
Expand Down Expand Up @@ -1098,7 +1095,7 @@ extern PyObject * to_float(PyObject *self);
PyObject *
__format__(PyObject *self, PyObject *format_spec)
{
Py_ssize_t end = PyUnicode_GET_LENGTH(format_spec);
Py_ssize_t end = PyUnicode_GetLength(format_spec);

if (!end) {
return PyObject_Str(self);
Expand Down Expand Up @@ -1141,7 +1138,7 @@ __format__(PyObject *self, PyObject *format_spec)
return res;
}
default:
unknown_presentation_type(format.type, Py_TYPE(self)->tp_name);
unknown_presentation_type(format.type, PyType_GetName(Py_TYPE(self)));
return NULL;
}
}
Expand Down
Loading