Skip to content

Commit 7eeb5b5

Browse files
author
Victor Stinner
committed
Issue #8848: U / U# formats of Py_BuildValue() are just alias to s / s#
1 parent fa68a61 commit 7eeb5b5

7 files changed

Lines changed: 9 additions & 43 deletions

File tree

Doc/c-api/arg.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,12 +530,10 @@ Building values
530530
and ``None`` is returned.
531531

532532
``U`` (string) [char \*]
533-
Convert a null-terminated C string to a Python unicode object. If the C string
534-
pointer is *NULL*, ``None`` is used.
533+
Same as ``s``.
535534

536535
``U#`` (string) [char \*, int]
537-
Convert a C string and its length to a Python unicode object. If the C string
538-
pointer is *NULL*, the length is ignored and ``None`` is returned.
536+
Same as ``s#``.
539537

540538
``i`` (integer) [int]
541539
Convert a plain C :ctype:`int` to a Python integer object.

Modules/_ctypes/_ctypes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4467,7 +4467,7 @@ PyCArrayType_from_ctype(PyObject *itemtype, Py_ssize_t length)
44674467
#endif
44684468

44694469
result = PyObject_CallFunction((PyObject *)&PyCArrayType_Type,
4470-
"U(O){s:n,s:O}",
4470+
"s(O){s:n,s:O}",
44714471
name,
44724472
&PyCArray_Type,
44734473
"_length_",

Objects/exceptions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ PyUnicodeEncodeError_Create(
15101510
const char *encoding, const Py_UNICODE *object, Py_ssize_t length,
15111511
Py_ssize_t start, Py_ssize_t end, const char *reason)
15121512
{
1513-
return PyObject_CallFunction(PyExc_UnicodeEncodeError, "Uu#nnU",
1513+
return PyObject_CallFunction(PyExc_UnicodeEncodeError, "su#nns",
15141514
encoding, object, length, start, end, reason);
15151515
}
15161516

@@ -1625,7 +1625,7 @@ PyUnicodeDecodeError_Create(
16251625
assert(length < INT_MAX);
16261626
assert(start < INT_MAX);
16271627
assert(end < INT_MAX);
1628-
return PyObject_CallFunction(PyExc_UnicodeDecodeError, "Uy#nnU",
1628+
return PyObject_CallFunction(PyExc_UnicodeDecodeError, "sy#nns",
16291629
encoding, object, length, start, end, reason);
16301630
}
16311631

Python/Python-ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int
527527
}
528528
PyTuple_SET_ITEM(fnames, i, field);
529529
}
530-
result = PyObject_CallFunction((PyObject*)&PyType_Type, "U(O){sOss}",
530+
result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
531531
type, base, "_fields", fnames, "__module__", "_ast");
532532
Py_DECREF(fnames);
533533
return (PyTypeObject*)result;

Python/errors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
679679
goto failure;
680680
}
681681
/* Create a real new-style class. */
682-
result = PyObject_CallFunction((PyObject *)&PyType_Type, "UOO",
682+
result = PyObject_CallFunction((PyObject *)&PyType_Type, "sOO",
683683
dot+1, bases, dict);
684684
failure:
685685
Py_XDECREF(bases);

Python/modsupport.c

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -302,39 +302,7 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags)
302302

303303
case 's':
304304
case 'z':
305-
{
306-
PyObject *v;
307-
char *str = va_arg(*p_va, char *);
308-
Py_ssize_t n;
309-
if (**p_format == '#') {
310-
++*p_format;
311-
if (flags & FLAG_SIZE_T)
312-
n = va_arg(*p_va, Py_ssize_t);
313-
else
314-
n = va_arg(*p_va, int);
315-
}
316-
else
317-
n = -1;
318-
if (str == NULL) {
319-
v = Py_None;
320-
Py_INCREF(v);
321-
}
322-
else {
323-
if (n < 0) {
324-
size_t m = strlen(str);
325-
if (m > PY_SSIZE_T_MAX) {
326-
PyErr_SetString(PyExc_OverflowError,
327-
"string too long for Python string");
328-
return NULL;
329-
}
330-
n = (Py_ssize_t)m;
331-
}
332-
v = PyUnicode_FromStringAndSize(str, n);
333-
}
334-
return v;
335-
}
336-
337-
case 'U':
305+
case 'U': /* XXX deprecated alias */
338306
{
339307
PyObject *v;
340308
char *str = va_arg(*p_va, char *);

Python/sysmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ _PySys_Init(void)
15101510
PyLong_FromLong(PY_VERSION_HEX));
15111511
svnversion_init();
15121512
SET_SYS_FROM_STRING("subversion",
1513-
Py_BuildValue("(UUU)", "CPython", branch,
1513+
Py_BuildValue("(sss)", "CPython", branch,
15141514
svn_revision));
15151515
SET_SYS_FROM_STRING("dont_write_bytecode",
15161516
PyBool_FromLong(Py_DontWriteBytecodeFlag));

0 commit comments

Comments
 (0)