@@ -14618,7 +14618,7 @@ unicode_new_impl(PyTypeObject *type, PyObject *x, const char *encoding,
14618
14618
}
14619
14619
14620
14620
static const char *
14621
- as_const_char (PyObject * obj , const char * name )
14621
+ arg_as_utf8 (PyObject * obj , const char * name )
14622
14622
{
14623
14623
if (!PyUnicode_Check (obj )) {
14624
14624
PyErr_Format (PyExc_TypeError ,
@@ -14640,9 +14640,8 @@ unicode_vectorcall(PyObject *type, PyObject *const *args,
14640
14640
assert (Py_Is (_PyType_CAST (type ), & PyUnicode_Type ));
14641
14641
14642
14642
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()
14646
14645
PyObject * tuple = _PyTuple_FromArray (args , nargs );
14647
14646
if (tuple == NULL ) {
14648
14647
return NULL ;
@@ -14652,11 +14651,14 @@ unicode_vectorcall(PyObject *type, PyObject *const *args,
14652
14651
Py_DECREF (tuple );
14653
14652
return NULL ;
14654
14653
}
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 ;
14656
14658
}
14657
14659
if (nargs > 3 ) {
14658
14660
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 );
14660
14662
return NULL ;
14661
14663
}
14662
14664
if (nargs == 0 ) {
@@ -14666,8 +14668,8 @@ unicode_vectorcall(PyObject *type, PyObject *const *args,
14666
14668
if (nargs == 1 ) {
14667
14669
return PyObject_Str (object );
14668
14670
}
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" );
14671
14673
return PyUnicode_FromEncodedObject (object , encoding , errors );
14672
14674
}
14673
14675
0 commit comments