diff options
-rw-r--r-- | Objects/descrobject.c | 16 | ||||
-rw-r--r-- | Objects/typeobject.c | 35 | ||||
-rw-r--r-- | PC/winsound.c | 2 | ||||
-rw-r--r-- | Python/future.c | 2 | ||||
-rw-r--r-- | Python/pythonrun.c | 4 |
5 files changed, 37 insertions, 22 deletions
diff --git a/Objects/descrobject.c b/Objects/descrobject.c index a1a2c51..30ba461 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -316,7 +316,7 @@ method_get_doc(PyMethodDescrObject *descr, void *closure) Py_INCREF(Py_None); return Py_None; } - return PyString_FromString(descr->d_method->ml_doc); + return PyUnicode_FromString(descr->d_method->ml_doc); } static PyMemberDef descr_members[] = { @@ -337,7 +337,7 @@ member_get_doc(PyMemberDescrObject *descr, void *closure) Py_INCREF(Py_None); return Py_None; } - return PyString_FromString(descr->d_member->doc); + return PyUnicode_FromString(descr->d_member->doc); } static PyGetSetDef member_getset[] = { @@ -352,7 +352,7 @@ getset_get_doc(PyGetSetDescrObject *descr, void *closure) Py_INCREF(Py_None); return Py_None; } - return PyString_FromString(descr->d_getset->doc); + return PyUnicode_FromString(descr->d_getset->doc); } static PyGetSetDef getset_getset[] = { @@ -367,7 +367,7 @@ wrapperdescr_get_doc(PyWrapperDescrObject *descr, void *closure) Py_INCREF(Py_None); return Py_None; } - return PyString_FromString(descr->d_base->doc); + return PyUnicode_FromString(descr->d_base->doc); } static PyGetSetDef wrapperdescr_getset[] = { @@ -936,22 +936,22 @@ wrapper_objclass(wrapperobject *wp) static PyObject * wrapper_name(wrapperobject *wp) { - char *s = wp->descr->d_base->name; + const char *s = wp->descr->d_base->name; - return PyString_FromString(s); + return PyUnicode_FromString(s); } static PyObject * wrapper_doc(wrapperobject *wp) { - char *s = wp->descr->d_base->doc; + const char *s = wp->descr->d_base->doc; if (s == NULL) { Py_INCREF(Py_None); return Py_None; } else { - return PyString_FromString(s); + return PyUnicode_FromString(s); } } diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 4e5e09d..6ea8e1d 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -343,7 +343,7 @@ type_get_doc(PyTypeObject *type, void *context) { PyObject *result; if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && type->tp_doc != NULL) - return PyString_FromString(type->tp_doc); + return PyUnicode_FromString(type->tp_doc); result = PyDict_GetItemString(type->tp_dict, "__doc__"); if (result == NULL) { result = Py_None; @@ -1918,15 +1918,30 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) */ { PyObject *doc = PyDict_GetItemString(dict, "__doc__"); - if (doc != NULL && PyString_Check(doc)) { - const size_t n = (size_t)PyString_GET_SIZE(doc); - char *tp_doc = (char *)PyObject_MALLOC(n+1); - if (tp_doc == NULL) { - Py_DECREF(type); - return NULL; + if (doc != NULL) { + char *tp_doc; + const char *str = NULL; + size_t n; + if (PyString_Check(doc)) { + str = PyString_AS_STRING(doc); + n = (size_t)PyString_GET_SIZE(doc); + } else if (PyUnicode_Check(doc)) { + str = PyUnicode_AsString(doc); + if (str == NULL) { + Py_DECREF(type); + return NULL; + } + n = strlen(str); + } + if (str != NULL) { + tp_doc = (char *)PyObject_MALLOC(n+1); + if (tp_doc == NULL) { + Py_DECREF(type); + return NULL; + } + memcpy(tp_doc, str, n+1); + type->tp_doc = tp_doc; } - memcpy(tp_doc, PyString_AS_STRING(doc), n+1); - type->tp_doc = tp_doc; } } @@ -3485,7 +3500,7 @@ PyType_Ready(PyTypeObject *type) */ if (PyDict_GetItemString(type->tp_dict, "__doc__") == NULL) { if (type->tp_doc != NULL) { - PyObject *doc = PyString_FromString(type->tp_doc); + PyObject *doc = PyUnicode_FromString(type->tp_doc); if (doc == NULL) goto error; PyDict_SetItemString(type->tp_dict, "__doc__", doc); diff --git a/PC/winsound.c b/PC/winsound.c index 9ff3b7e..9fc7f6f 100644 --- a/PC/winsound.c +++ b/PC/winsound.c @@ -202,7 +202,7 @@ static struct PyMethodDef sound_methods[] = static void add_define(PyObject *dict, const char *key, long value) { - PyObject *k=PyString_FromString(key); + PyObject *k=PyUnicode_FromString(key); PyObject *v=PyLong_FromLong(value); if(v&&k) { diff --git a/Python/future.c b/Python/future.c index 2092f58..dca1d83 100644 --- a/Python/future.c +++ b/Python/future.c @@ -20,7 +20,7 @@ future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename) names = s->v.ImportFrom.names; for (i = 0; i < asdl_seq_LEN(names); i++) { alias_ty name = (alias_ty)asdl_seq_GET(names, i); - const char *feature = PyString_AsString(name->name); + const char *feature = PyUnicode_AsString(name->name); if (!feature) return 0; if (strcmp(feature, FUTURE_NESTED_SCOPES) == 0) { diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 32bc6f7..542fe38 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -707,12 +707,12 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flag } v = PySys_GetObject("ps1"); if (v == NULL) { - PySys_SetObject("ps1", v = PyString_FromString(">>> ")); + PySys_SetObject("ps1", v = PyUnicode_FromString(">>> ")); Py_XDECREF(v); } v = PySys_GetObject("ps2"); if (v == NULL) { - PySys_SetObject("ps2", v = PyString_FromString("... ")); + PySys_SetObject("ps2", v = PyUnicode_FromString("... ")); Py_XDECREF(v); } for (;;) { |