Skip to content

Commit 519e794

Browse files
Address review
1 parent 2ce7104 commit 519e794

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Objects/unicodeobject.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14618,7 +14618,7 @@ unicode_new_impl(PyTypeObject *type, PyObject *x, const char *encoding,
1461814618
}
1461914619

1462014620
static const char *
14621-
as_const_char(PyObject *obj, const char *name)
14621+
arg_as_utf8(PyObject *obj, const char *name)
1462214622
{
1462314623
if (!PyUnicode_Check(obj)) {
1462414624
PyErr_Format(PyExc_TypeError,
@@ -14640,9 +14640,8 @@ unicode_vectorcall(PyObject *type, PyObject *const *args,
1464014640
assert(Py_Is(_PyType_CAST(type), &PyUnicode_Type));
1464114641

1464214642
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
14643-
Py_ssize_t nkwargs = (kwnames) ? PyTuple_GET_SIZE(kwnames) : 0;
14644-
if (nkwargs) {
14645-
// Fallback to tp_call()
14643+
if (kwnames != NULL && PyTuple_GET_SIZE(kwnames) != 0) {
14644+
// Fallback to unicode_new()
1464614645
PyObject *tuple = _PyTuple_FromArray(args, nargs);
1464714646
if (tuple == NULL) {
1464814647
return NULL;
@@ -14652,11 +14651,14 @@ unicode_vectorcall(PyObject *type, PyObject *const *args,
1465214651
Py_DECREF(tuple);
1465314652
return NULL;
1465414653
}
14655-
return unicode_new(_PyType_CAST(type), tuple, dict);
14654+
PyObject *ret = unicode_new(_PyType_CAST(type), tuple, dict);
14655+
Py_DECREF(tuple);
14656+
Py_DECREF(dict);
14657+
return ret;
1465614658
}
1465714659
if (nargs > 3) {
1465814660
PyErr_Format(PyExc_TypeError,
14659-
"str() takes at most 3 arguments (%d given)", nargs + nkwargs);
14661+
"str() takes at most 3 arguments (%d given)", nargs);
1466014662
return NULL;
1466114663
}
1466214664
if (nargs == 0) {
@@ -14666,8 +14668,8 @@ unicode_vectorcall(PyObject *type, PyObject *const *args,
1466614668
if (nargs == 1) {
1466714669
return PyObject_Str(object);
1466814670
}
14669-
const char *encoding = as_const_char(args[1], "encoding");
14670-
const char *errors = (nargs == 2) ? NULL : as_const_char(args[2], "errors");
14671+
const char *encoding = arg_as_utf8(args[1], "encoding");
14672+
const char *errors = (nargs == 2) ? NULL : arg_as_utf8(args[2], "errors");
1467114673
return PyUnicode_FromEncodedObject(object, encoding, errors);
1467214674
}
1467314675

0 commit comments

Comments
 (0)