PEP 3123: Provide forward compatibility with Python 3.0, while keeping

backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and
PyVarObject_HEAD_INIT.
This commit is contained in:
Martin v. Löwis 2007-07-21 06:55:02 +00:00
parent b1994b4a5d
commit 6819210b9e
129 changed files with 1090 additions and 1250 deletions

View file

@ -312,7 +312,7 @@ void unicode_dealloc(register PyUnicodeObject *unicode)
else {
PyMem_DEL(unicode->str);
Py_XDECREF(unicode->defenc);
unicode->ob_type->tp_free((PyObject *)unicode);
Py_Type(unicode)->tp_free((PyObject *)unicode);
}
}
@ -326,7 +326,7 @@ int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
return -1;
}
v = (PyUnicodeObject *)*unicode;
if (v == NULL || !PyUnicode_Check(v) || v->ob_refcnt != 1 || length < 0) {
if (v == NULL || !PyUnicode_Check(v) || Py_Refcnt(v) != 1 || length < 0) {
PyErr_BadInternalCall();
return -1;
}
@ -554,7 +554,7 @@ PyObject *PyUnicode_FromEncodedObject(register PyObject *obj,
PyErr_Format(PyExc_TypeError,
"coercing to Unicode: need string or buffer, "
"%.80s found",
obj->ob_type->tp_name);
Py_Type(obj)->tp_name);
goto onError;
}
@ -604,7 +604,7 @@ PyObject *PyUnicode_Decode(const char *s,
if (!PyUnicode_Check(unicode)) {
PyErr_Format(PyExc_TypeError,
"decoder did not return an unicode object (type=%.400s)",
unicode->ob_type->tp_name);
Py_Type(unicode)->tp_name);
Py_DECREF(unicode);
goto onError;
}
@ -714,7 +714,7 @@ PyObject *PyUnicode_AsEncodedString(PyObject *unicode,
if (!PyString_Check(v)) {
PyErr_Format(PyExc_TypeError,
"encoder did not return a string object (type=%.400s)",
v->ob_type->tp_name);
Py_Type(v)->tp_name);
Py_DECREF(v);
goto onError;
}
@ -3242,8 +3242,7 @@ encoding_map_dealloc(PyObject* o)
}
static PyTypeObject EncodingMapType = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
PyVarObject_HEAD_INIT(NULL, 0)
"EncodingMap", /*tp_name*/
sizeof(struct encoding_map), /*tp_basicsize*/
0, /*tp_itemsize*/
@ -3502,7 +3501,7 @@ charmapencode_result charmapencode_output(Py_UNICODE c, PyObject *mapping,
char *outstart;
Py_ssize_t outsize = PyString_GET_SIZE(*outobj);
if (mapping->ob_type == &EncodingMapType) {
if (Py_Type(mapping) == &EncodingMapType) {
int res = encoding_map_lookup(c, mapping);
Py_ssize_t requiredsize = *outpos+1;
if (res == -1)
@ -3574,7 +3573,7 @@ int charmap_encoding_error(
/* find all unencodable characters */
while (collendpos < size) {
PyObject *rep;
if (mapping->ob_type == &EncodingMapType) {
if (Py_Type(mapping) == &EncodingMapType) {
int res = encoding_map_lookup(p[collendpos], mapping);
if (res != -1)
break;
@ -4632,7 +4631,7 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
PyErr_Format(PyExc_TypeError,
"sequence item %zd: expected string or Unicode,"
" %.80s found",
i, item->ob_type->tp_name);
i, Py_Type(item)->tp_name);
goto onError;
}
item = PyUnicode_FromObject(item);
@ -5632,7 +5631,7 @@ unicode_encode(PyUnicodeObject *self, PyObject *args)
PyErr_Format(PyExc_TypeError,
"encoder did not return a string/unicode object "
"(type=%.400s)",
v->ob_type->tp_name);
Py_Type(v)->tp_name);
Py_DECREF(v);
return NULL;
}
@ -5668,7 +5667,7 @@ unicode_decode(PyUnicodeObject *self, PyObject *args)
PyErr_Format(PyExc_TypeError,
"decoder did not return a string/unicode object "
"(type=%.400s)",
v->ob_type->tp_name);
Py_Type(v)->tp_name);
Py_DECREF(v);
return NULL;
}
@ -7499,7 +7498,7 @@ PyObject *PyUnicode_Format(PyObject *format,
arglen = -1;
argidx = -2;
}
if (args->ob_type->tp_as_mapping && !PyTuple_Check(args) &&
if (Py_Type(args)->tp_as_mapping && !PyTuple_Check(args) &&
!PyObject_TypeCheck(args, &PyBaseString_Type))
dict = args;
@ -7963,8 +7962,7 @@ encoding defaults to the current default string encoding.\n\
errors can be 'strict', 'replace' or 'ignore' and defaults to 'strict'.");
PyTypeObject PyUnicode_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"unicode", /* tp_name */
sizeof(PyUnicodeObject), /* tp_size */
0, /* tp_itemsize */