Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3dcb5ac

Browse files
author
Victor Stinner
committed
Issue #8838, #8339: Remove codecs.charbuffer_encode() and "t#" parsing format
Remove last references to the "char buffer" of the buffer protocol from Python3.
1 parent 1fbd36b commit 3dcb5ac

6 files changed

Lines changed: 11 additions & 77 deletions

File tree

Doc/c-api/arg.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,6 @@ Unless otherwise stated, buffers are not NUL-terminated.
150150
any conversion. Raises :exc:`TypeError` if the object is not a Unicode
151151
object. The C variable may also be declared as :ctype:`PyObject\*`.
152152

153-
``t#`` (:class:`bytes`, :class:`bytearray` or read-only character buffer) [char \*, int]
154-
Like ``s#``, but accepts any object which implements the read-only buffer
155-
interface. The :ctype:`char\*` variable is set to point to the first byte of
156-
the buffer, and the :ctype:`int` is set to the length of the buffer. Only
157-
single-segment buffer objects are accepted; :exc:`TypeError` is raised for all
158-
others.
159-
160153
``w`` (:class:`bytearray` or read-write character buffer) [char \*]
161154
Similar to ``s``, but accepts any object which implements the read-write buffer
162155
interface. The caller must determine the length of the buffer by other means,

Doc/whatsnew/3.2.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,7 @@ that may require changes to your code:
173173

174174
* bytearray objects cannot be used anymore as filenames: convert them to bytes
175175

176+
* "t#" format of PyArg_Parse*() functions has been removed: use "s#" or "s*"
177+
instead
178+
176179
* Stub

Lib/test/test_codecs.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def check_partial(self, input, partialresults):
7272
# check that there's nothing left in the buffers
7373
self.assertEqual(r.read(), "")
7474
self.assertEqual(r.bytebuffer, b"")
75-
self.assertEqual(r.charbuffer, "")
7675

7776
# do the check again, this time using a incremental decoder
7877
d = codecs.getincrementaldecoder(self.encoding)()
@@ -628,18 +627,6 @@ def test_bad_args(self):
628627
self.assertRaises(TypeError, codecs.readbuffer_encode)
629628
self.assertRaises(TypeError, codecs.readbuffer_encode, 42)
630629

631-
class CharBufferTest(unittest.TestCase):
632-
633-
def test_string(self):
634-
self.assertEqual(codecs.charbuffer_encode(b"spam"), (b"spam", 4))
635-
636-
def test_empty(self):
637-
self.assertEqual(codecs.charbuffer_encode(b""), (b"", 0))
638-
639-
def test_bad_args(self):
640-
self.assertRaises(TypeError, codecs.charbuffer_encode)
641-
self.assertRaises(TypeError, codecs.charbuffer_encode, 42)
642-
643630
class UTF8SigTest(ReadTest):
644631
encoding = "utf-8-sig"
645632

@@ -1663,7 +1650,6 @@ def test_main():
16631650
UTF7Test,
16641651
UTF16ExTest,
16651652
ReadBufferTest,
1666-
CharBufferTest,
16671653
RecodingTest,
16681654
PunycodeTest,
16691655
UnicodeInternalTest,

Misc/NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ What's New in Python 3.2 Alpha 1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #8838: Remove codecs.charbuffer_encode() function. The buffer protocol
16+
doesn't support "char buffer" anymore in Python3.
17+
18+
- Issue #8339: Remove "t#" format of PyArg_Parse*() functions, use "s#" or "s*"
19+
instead. codecs.charbuffer_encode() now accepts modifiable buffer objects
20+
like bytearray.
21+
1522
- Issue #8837: Remove "O?" format of PyArg_Parse*() functions. The format is no
1623
used anymore and it was never documented.
1724

Modules/_codecsmodule.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -638,21 +638,6 @@ readbuffer_encode(PyObject *self,
638638
return codec_tuple(result, size);
639639
}
640640

641-
static PyObject *
642-
charbuffer_encode(PyObject *self,
643-
PyObject *args)
644-
{
645-
const char *data;
646-
Py_ssize_t size;
647-
const char *errors = NULL;
648-
649-
if (!PyArg_ParseTuple(args, "t#|z:charbuffer_encode",
650-
&data, &size, &errors))
651-
return NULL;
652-
653-
return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
654-
}
655-
656641
static PyObject *
657642
unicode_internal_encode(PyObject *self,
658643
PyObject *args)
@@ -1116,7 +1101,6 @@ static PyMethodDef _codecs_functions[] = {
11161101
{"charmap_decode", charmap_decode, METH_VARARGS},
11171102
{"charmap_build", charmap_build, METH_VARARGS},
11181103
{"readbuffer_encode", readbuffer_encode, METH_VARARGS},
1119-
{"charbuffer_encode", charbuffer_encode, METH_VARARGS},
11201104
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
11211105
{"mbcs_encode", mbcs_encode, METH_VARARGS},
11221106
{"mbcs_decode", mbcs_decode, METH_VARARGS},

Python/getargs.c

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
864864
break;
865865
}
866866

867-
/* XXX WAAAAH! 's', 'y', 'z', 'u', 'Z', 'e', 'w', 't' codes all
867+
/* XXX WAAAAH! 's', 'y', 'z', 'u', 'Z', 'e', 'w' codes all
868868
need to be cleaned up! */
869869

870870
case 's': {/* text string */
@@ -1362,45 +1362,6 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
13621362
break;
13631363
}
13641364

1365-
/*TEO: This can be eliminated --- here only for backward
1366-
compatibility */
1367-
case 't': { /* 8-bit character buffer, read-only access */
1368-
char **p = va_arg(*p_va, char **);
1369-
PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
1370-
Py_ssize_t count;
1371-
Py_buffer view;
1372-
1373-
if (*format++ != '#')
1374-
return converterr(
1375-
"invalid use of 't' format character",
1376-
arg, msgbuf, bufsize);
1377-
if (pb == NULL || pb->bf_getbuffer == NULL)
1378-
return converterr(
1379-
"bytes or read-only character buffer",
1380-
arg, msgbuf, bufsize);
1381-
1382-
if (PyObject_GetBuffer(arg, &view, PyBUF_SIMPLE) != 0)
1383-
return converterr("string or single-segment read-only buffer",
1384-
arg, msgbuf, bufsize);
1385-
1386-
count = view.len;
1387-
*p = view.buf;
1388-
if (pb->bf_releasebuffer)
1389-
return converterr(
1390-
"string or pinned buffer",
1391-
arg, msgbuf, bufsize);
1392-
1393-
PyBuffer_Release(&view);
1394-
1395-
if (count < 0)
1396-
return converterr("(unspecified)", arg, msgbuf, bufsize);
1397-
{
1398-
FETCH_SIZE;
1399-
STORE_SIZE(count);
1400-
}
1401-
break;
1402-
}
1403-
14041365
default:
14051366
return converterr("impossible<bad format char>", arg, msgbuf, bufsize);
14061367

0 commit comments

Comments
 (0)