@@ -343,7 +343,7 @@ type_get_doc(PyTypeObject *type, void *context)
343343{
344344 PyObject * result ;
345345 if (!(type -> tp_flags & Py_TPFLAGS_HEAPTYPE ) && type -> tp_doc != NULL )
346- return PyString_FromString (type -> tp_doc );
346+ return PyUnicode_FromString (type -> tp_doc );
347347 result = PyDict_GetItemString (type -> tp_dict , "__doc__" );
348348 if (result == NULL ) {
349349 result = Py_None ;
@@ -1918,15 +1918,30 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
19181918 */
19191919 {
19201920 PyObject * doc = PyDict_GetItemString (dict , "__doc__" );
1921- if (doc != NULL && PyString_Check (doc )) {
1922- const size_t n = (size_t )PyString_GET_SIZE (doc );
1923- char * tp_doc = (char * )PyObject_MALLOC (n + 1 );
1924- if (tp_doc == NULL ) {
1925- Py_DECREF (type );
1926- return NULL ;
1921+ if (doc != NULL ) {
1922+ char * tp_doc ;
1923+ const char * str = NULL ;
1924+ size_t n ;
1925+ if (PyString_Check (doc )) {
1926+ str = PyString_AS_STRING (doc );
1927+ n = (size_t )PyString_GET_SIZE (doc );
1928+ } else if (PyUnicode_Check (doc )) {
1929+ str = PyUnicode_AsString (doc );
1930+ if (str == NULL ) {
1931+ Py_DECREF (type );
1932+ return NULL ;
1933+ }
1934+ n = strlen (str );
1935+ }
1936+ if (str != NULL ) {
1937+ tp_doc = (char * )PyObject_MALLOC (n + 1 );
1938+ if (tp_doc == NULL ) {
1939+ Py_DECREF (type );
1940+ return NULL ;
1941+ }
1942+ memcpy (tp_doc , str , n + 1 );
1943+ type -> tp_doc = tp_doc ;
19271944 }
1928- memcpy (tp_doc , PyString_AS_STRING (doc ), n + 1 );
1929- type -> tp_doc
10BC0
= tp_doc ;
19301945 }
19311946 }
19321947
@@ -3485,7 +3500,7 @@ PyType_Ready(PyTypeObject *type)
34853500 */
34863501 if (PyDict_GetItemString (type -> tp_dict , "__doc__" ) == NULL ) {
34873502 if (type -> tp_doc != NULL ) {
3488- PyObject * doc = PyString_FromString (type -> tp_doc );
3503+ PyObject * doc = PyUnicode_FromString (type -> tp_doc );
34893504 if (doc == NULL )
34903505 goto error ;
34913506 PyDict_SetItemString (type -> tp_dict , "__doc__" , doc );
0 commit comments