Use unicode

This commit is contained in:
Neal Norwitz 2007-08-25 07:41:59 +00:00
parent 1978470c3b
commit a369c5aba6
5 changed files with 37 additions and 22 deletions

View File

@ -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);
}
}

View File

@ -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,17 +1918,32 @@ 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 (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, PyString_AS_STRING(doc), n+1);
memcpy(tp_doc, str, n+1);
type->tp_doc = tp_doc;
}
}
}
/* Special-case __new__: if it's a plain function,
make it a static function */
@ -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);

View File

@ -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)
{

View File

@ -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) {

View File

@ -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 (;;) {