Use unicode
This commit is contained in:
parent
1978470c3b
commit
a369c5aba6
|
@ -316,7 +316,7 @@ method_get_doc(PyMethodDescrObject *descr, void *closure)
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return 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[] = {
|
static PyMemberDef descr_members[] = {
|
||||||
|
@ -337,7 +337,7 @@ member_get_doc(PyMemberDescrObject *descr, void *closure)
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
return PyString_FromString(descr->d_member->doc);
|
return PyUnicode_FromString(descr->d_member->doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyGetSetDef member_getset[] = {
|
static PyGetSetDef member_getset[] = {
|
||||||
|
@ -352,7 +352,7 @@ getset_get_doc(PyGetSetDescrObject *descr, void *closure)
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
return PyString_FromString(descr->d_getset->doc);
|
return PyUnicode_FromString(descr->d_getset->doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyGetSetDef getset_getset[] = {
|
static PyGetSetDef getset_getset[] = {
|
||||||
|
@ -367,7 +367,7 @@ wrapperdescr_get_doc(PyWrapperDescrObject *descr, void *closure)
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
return PyString_FromString(descr->d_base->doc);
|
return PyUnicode_FromString(descr->d_base->doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyGetSetDef wrapperdescr_getset[] = {
|
static PyGetSetDef wrapperdescr_getset[] = {
|
||||||
|
@ -936,22 +936,22 @@ wrapper_objclass(wrapperobject *wp)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
wrapper_name(wrapperobject *wp)
|
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 *
|
static PyObject *
|
||||||
wrapper_doc(wrapperobject *wp)
|
wrapper_doc(wrapperobject *wp)
|
||||||
{
|
{
|
||||||
char *s = wp->descr->d_base->doc;
|
const char *s = wp->descr->d_base->doc;
|
||||||
|
|
||||||
if (s == NULL) {
|
if (s == NULL) {
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return PyString_FromString(s);
|
return PyUnicode_FromString(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -343,7 +343,7 @@ type_get_doc(PyTypeObject *type, void *context)
|
||||||
{
|
{
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && type->tp_doc != NULL)
|
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__");
|
result = PyDict_GetItemString(type->tp_dict, "__doc__");
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
result = Py_None;
|
result = Py_None;
|
||||||
|
@ -1918,15 +1918,30 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PyObject *doc = PyDict_GetItemString(dict, "__doc__");
|
PyObject *doc = PyDict_GetItemString(dict, "__doc__");
|
||||||
if (doc != NULL && PyString_Check(doc)) {
|
if (doc != NULL) {
|
||||||
const size_t n = (size_t)PyString_GET_SIZE(doc);
|
char *tp_doc;
|
||||||
char *tp_doc = (char *)PyObject_MALLOC(n+1);
|
const char *str = NULL;
|
||||||
if (tp_doc == NULL) {
|
size_t n;
|
||||||
Py_DECREF(type);
|
if (PyString_Check(doc)) {
|
||||||
return NULL;
|
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 (PyDict_GetItemString(type->tp_dict, "__doc__") == NULL) {
|
||||||
if (type->tp_doc != NULL) {
|
if (type->tp_doc != NULL) {
|
||||||
PyObject *doc = PyString_FromString(type->tp_doc);
|
PyObject *doc = PyUnicode_FromString(type->tp_doc);
|
||||||
if (doc == NULL)
|
if (doc == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
PyDict_SetItemString(type->tp_dict, "__doc__", doc);
|
PyDict_SetItemString(type->tp_dict, "__doc__", doc);
|
||||||
|
|
|
@ -202,7 +202,7 @@ static struct PyMethodDef sound_methods[] =
|
||||||
static void
|
static void
|
||||||
add_define(PyObject *dict, const char *key, long value)
|
add_define(PyObject *dict, const char *key, long value)
|
||||||
{
|
{
|
||||||
PyObject *k=PyString_FromString(key);
|
PyObject *k=PyUnicode_FromString(key);
|
||||||
PyObject *v=PyLong_FromLong(value);
|
PyObject *v=PyLong_FromLong(value);
|
||||||
if(v&&k)
|
if(v&&k)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,7 +20,7 @@ future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename)
|
||||||
names = s->v.ImportFrom.names;
|
names = s->v.ImportFrom.names;
|
||||||
for (i = 0; i < asdl_seq_LEN(names); i++) {
|
for (i = 0; i < asdl_seq_LEN(names); i++) {
|
||||||
alias_ty name = (alias_ty)asdl_seq_GET(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)
|
if (!feature)
|
||||||
return 0;
|
return 0;
|
||||||
if (strcmp(feature, FUTURE_NESTED_SCOPES) == 0) {
|
if (strcmp(feature, FUTURE_NESTED_SCOPES) == 0) {
|
||||||
|
|
|
@ -707,12 +707,12 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flag
|
||||||
}
|
}
|
||||||
v = PySys_GetObject("ps1");
|
v = PySys_GetObject("ps1");
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
PySys_SetObject("ps1", v = PyString_FromString(">>> "));
|
PySys_SetObject("ps1", v = PyUnicode_FromString(">>> "));
|
||||||
Py_XDECREF(v);
|
Py_XDECREF(v);
|
||||||
}
|
}
|
||||||
v = PySys_GetObject("ps2");
|
v = PySys_GetObject("ps2");
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
PySys_SetObject("ps2", v = PyString_FromString("... "));
|
PySys_SetObject("ps2", v = PyUnicode_FromString("... "));
|
||||||
Py_XDECREF(v);
|
Py_XDECREF(v);
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
Loading…
Reference in New Issue