Skip to content

Commit a921fb0

Browse files
committed
Py_BuildValue's 'c' code should use byte strings python#5666
1 parent a3b1ac8 commit a921fb0

4 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎Doc/c-api/arg.rst‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ variable(s) whose address should be passed.
212212
:ctype:`char`.
213213

214214
``C`` (string of length 1) [int]
215-
Covert a Python character, represented as a unicode string of length 1, to a
215+
Convert a Python character, represented as a unicode string of length 1, to a
216216
C :ctype:`int`.
217217

218218
``f`` (float) [float]
@@ -511,8 +511,12 @@ and the following format units are left untouched.
511511
Convert a C :ctype:`Py_ssize_t` to a Python integer.
512512

513513
``c`` (string of length 1) [char]
514-
Convert a C :ctype:`int` representing a character to a Python string of length
515-
1.
514+
Convert a C :ctype:`int` representing a byte to a Python byte string of
515+
length 1.
516+
517+
``C`` (string of length 1) [int]
518+
Convert a C :ctype:`int` representing a character to Python unicode
519+
string of length 1.
516520

517521
``d`` (float) [double]
518522
Convert a C :ctype:`double` to a Python floating point number.

‎Modules/_cursesmodule.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
890890
PyErr_SetString(PyCursesError, "no input");
891891
return NULL;
892892
} else if (rtn<=255)
893-
return Py_BuildValue("c", rtn);
893+
return Py_BuildValue("C", rtn);
894894
else
895895
#if defined(__NetBSD__)
896896
return PyUnicode_FromString(unctrl(rtn));

‎Modules/arraymodule.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,14 +1141,14 @@ array_reduce(arrayobject *array)
11411141
> PY_SSIZE_T_MAX / Py_SIZE(array)) {
11421142
return PyErr_NoMemory();
11431143
}
1144-
result = Py_BuildValue("O(cy#)O",
1144+
result = Py_BuildValue("O(Cy#)O",
11451145
Py_TYPE(array),
11461146
array->ob_descr->typecode,
11471147
array->ob_item,
11481148
Py_SIZE(array) * array->ob_descr->itemsize,
11491149
dict);
11501150
} else {
1151-
result = Py_BuildValue("O(c)O",
1151+
result = Py_BuildValue("O(C)O",
11521152
Py_TYPE(array),
11531153
array->ob_descr->typecode,
11541154
dict);

‎Python/modsupport.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags)
289289
{
290290
char p[1];
291291
p[0] = (char)va_arg(*p_va, int);
292-
return PyUnicode_FromStringAndSize(p, 1);
292+
return PyBytes_FromStringAndSize(p, 1);
293293
}
294294
case 'C':
295295
{

0 commit comments

Comments
 (0)