Skip to content

Commit

Permalink
Issue python#8848: U / U# formats of Py_BuildValue() are just alias t…
Browse files Browse the repository at this point in the history
…o s / s#
  • Loading branch information
Victor Stinner committed Jun 7, 2010
1 parent fa68a61 commit 7eeb5b5
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 43 deletions.
6 changes: 2 additions & 4 deletions Doc/c-api/arg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,10 @@ Building values
and ``None`` is returned.

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

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

``i`` (integer) [int]
Convert a plain C :ctype:`int` to a Python integer object.
Expand Down
2 changes: 1 addition & 1 deletion Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -4467,7 +4467,7 @@ PyCArrayType_from_ctype(PyObject *itemtype, Py_ssize_t length)
#endif

result = PyObject_CallFunction((PyObject *)&PyCArrayType_Type,
"U(O){s:n,s:O}",
"s(O){s:n,s:O}",
name,
&PyCArray_Type,
"_length_",
Expand Down
4 changes: 2 additions & 2 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ PyUnicodeEncodeError_Create(
const char *encoding, const Py_UNICODE *object, Py_ssize_t length,
Py_ssize_t start, Py_ssize_t end, const char *reason)
{
return PyObject_CallFunction(PyExc_UnicodeEncodeError, "Uu#nnU",
return PyObject_CallFunction(PyExc_UnicodeEncodeError, "su#nns",
encoding, object, length, start, end, reason);
}

Expand Down Expand Up @@ -1625,7 +1625,7 @@ PyUnicodeDecodeError_Create(
assert(length < INT_MAX);
assert(start < INT_MAX);
assert(end < INT_MAX);
return PyObject_CallFunction(PyExc_UnicodeDecodeError, "Uy#nnU",
return PyObject_CallFunction(PyExc_UnicodeDecodeError, "sy#nns",
encoding, object, length, start, end, reason);
}

Expand Down
2 changes: 1 addition & 1 deletion Python/Python-ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int
}
PyTuple_SET_ITEM(fnames, i, field);
}
result = PyObject_CallFunction((PyObject*)&PyType_Type, "U(O){sOss}",
result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
type, base, "_fields", fnames, "__module__", "_ast");
Py_DECREF(fnames);
return (PyTypeObject*)result;
Expand Down
2 changes: 1 addition & 1 deletion Python/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
goto failure;
}
/* Create a real new-style class. */
result = PyObject_CallFunction((PyObject *)&PyType_Type, "UOO",
result = PyObject_CallFunction((PyObject *)&PyType_Type, "sOO",
dot+1, bases, dict);
failure:
Py_XDECREF(bases);
Expand Down
34 changes: 1 addition & 33 deletions Python/modsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,39 +302,7 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags)

case 's':
case 'z':
{
PyObject *v;
char *str = va_arg(*p_va, char *);
Py_ssize_t n;
if (**p_format == '#') {
++*p_format;
if (flags & FLAG_SIZE_T)
n = va_arg(*p_va, Py_ssize_t);
else
n = va_arg(*p_va, int);
}
else
n = -1;
if (str == NULL) {
v = Py_None;
Py_INCREF(v);
}
else {
if (n < 0) {
size_t m = strlen(str);
if (m > PY_SSIZE_T_MAX) {
PyErr_SetString(PyExc_OverflowError,
"string too long for Python string");
return NULL;
}
n = (Py_ssize_t)m;
}
v = PyUnicode_FromStringAndSize(str, n);
}
return v;
}

case 'U':
case 'U': /* XXX deprecated alias */
{
PyObject *v;
char *str = va_arg(*p_va, char *);
Expand Down
2 changes: 1 addition & 1 deletion Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ _PySys_Init(void)
PyLong_FromLong(PY_VERSION_HEX));
svnversion_init();
SET_SYS_FROM_STRING("subversion",
Py_BuildValue("(UUU)", "CPython", branch,
Py_BuildValue("(sss)", "CPython", branch,
svn_revision));
SET_SYS_FROM_STRING("dont_write_bytecode",
PyBool_FromLong(Py_DontWriteBytecodeFlag));
Expand Down

0 comments on commit 7eeb5b5

Please sign in to comment.