@@ -1881,6 +1881,36 @@ test_unicodewriter_format(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
18811881#endif
18821882
18831883
1884+ static PyObject *
1885+ test_bytes (PyObject * Py_UNUSED (module ), PyObject * Py_UNUSED (args ))
1886+ {
1887+ PyObject * abc = PyBytes_FromString ("a b c" );
1888+ if (abc == NULL ) {
1889+ return NULL ;
1890+ }
1891+ PyObject * list = PyObject_CallMethod (abc , "split" , NULL );
1892+ Py_DECREF (abc );
1893+ if (list == NULL ) {
1894+ return NULL ;
1895+ }
1896+ PyObject * sep = PyBytes_FromString ("-" );
1897+ if (sep == NULL ) {
1898+ Py_DECREF (list );
1899+ return NULL ;
1900+ }
1901+
1902+ PyObject * join = PyBytes_Join (sep , list );
1903+ assert (join != NULL );
1904+ assert (PyBytes_Check (join ));
1905+ assert (memcmp (PyBytes_AS_STRING (join ), "a-b-c" , 5 ) == 0 );
1906+ Py_DECREF (join );
1907+
1908+ Py_DECREF (list );
1909+ Py_DECREF (sep );
1910+ Py_RETURN_NONE ;
1911+ }
1912+
1913+
18841914static struct PyMethodDef methods [] = {
18851915 {"test_object" , test_object , METH_NOARGS , _Py_NULL },
18861916 {"test_py_is" , test_py_is , METH_NOARGS , _Py_NULL },
@@ -1924,6 +1954,7 @@ static struct PyMethodDef methods[] = {
19241954 {"test_unicodewriter_widechar" , test_unicodewriter_widechar , METH_NOARGS , _Py_NULL },
19251955 {"test_unicodewriter_format" , test_unicodewriter_format , METH_NOARGS , _Py_NULL },
19261956#endif
1957+ {"test_bytes" , test_bytes , METH_NOARGS , _Py_NULL },
19271958 {_Py_NULL , _Py_NULL , 0 , _Py_NULL }
19281959};
19291960
0 commit comments