summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-07-21 17:22:18 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2007-07-21 17:22:18 (GMT)
commit9f2e346911988cda95fec7c901e8d10d34fa9563 (patch)
tree1632c78fb8e18b2f789102451bedd15996bff6c5 /Objects/object.c
parentb972a78e17beeb997d809d87f2e422e6622efd52 (diff)
downloadcpython-9f2e346911988cda95fec7c901e8d10d34fa9563.zip
cpython-9f2e346911988cda95fec7c901e8d10d34fa9563.tar.gz
cpython-9f2e346911988cda95fec7c901e8d10d34fa9563.tar.bz2
Merged revisions 56467-56482 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r56477 | martin.v.loewis | 2007-07-21 09:04:38 +0200 (Sa, 21 Jul 2007) | 11 lines Merged revisions 56466-56476 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r56476 | martin.v.loewis | 2007-07-21 08:55:02 +0200 (Sa, 21 Jul 2007) | 4 lines PEP 3123: Provide forward compatibility with Python 3.0, while keeping backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and PyVarObject_HEAD_INIT. ........ ................ r56478 | martin.v.loewis | 2007-07-21 09:47:23 +0200 (Sa, 21 Jul 2007) | 2 lines PEP 3123: Use proper C inheritance for PyObject. ................ r56479 | martin.v.loewis | 2007-07-21 10:06:55 +0200 (Sa, 21 Jul 2007) | 3 lines Add longintrepr.h to Python.h, so that the compiler can see that PyFalse is really some kind of PyObject*. ................ r56480 | martin.v.loewis | 2007-07-21 10:47:18 +0200 (Sa, 21 Jul 2007) | 2 lines Qualify SHIFT, MASK, BASE. ................ r56482 | martin.v.loewis | 2007-07-21 19:10:57 +0200 (Sa, 21 Jul 2007) | 2 lines Correctly refer to _ob_next. ................
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c68
1 files changed, 34 insertions, 34 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 3583bca..a725022 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -214,7 +214,7 @@ PyObject_Init(PyObject *op, PyTypeObject *tp)
if (op == NULL)
return PyErr_NoMemory();
/* Any changes should be reflected in PyObject_INIT (objimpl.h) */
- op->ob_type = tp;
+ Py_Type(op) = tp;
_Py_NewReference(op);
return op;
}
@@ -226,7 +226,7 @@ PyObject_InitVar(PyVarObject *op, PyTypeObject *tp, Py_ssize_t size)
return (PyVarObject *) PyErr_NoMemory();
/* Any changes should be reflected in PyObject_INIT_VAR */
op->ob_size = size;
- op->ob_type = tp;
+ Py_Type(op) = tp;
_Py_NewReference((PyObject *)op);
return op;
}
@@ -279,7 +279,7 @@ internal_print(PyObject *op, FILE *fp, int flags, int nesting)
universally available */
fprintf(fp, "<refcnt %ld at %p>",
(long)op->ob_refcnt, op);
- else if (op->ob_type->tp_print == NULL) {
+ else if (Py_Type(op)->tp_print == NULL) {
PyObject *s;
if (flags & Py_PRINT_RAW)
s = PyObject_Str(op);
@@ -294,7 +294,7 @@ internal_print(PyObject *op, FILE *fp, int flags, int nesting)
Py_XDECREF(s);
}
else
- ret = (*op->ob_type->tp_print)(op, fp, flags);
+ ret = (*Py_Type(op)->tp_print)(op, fp, flags);
}
if (ret == 0) {
if (ferror(fp)) {
@@ -334,7 +334,7 @@ _PyObject_Dump(PyObject* op)
"type : %s\n"
"refcount: %ld\n"
"address : %p\n",
- op->ob_type==NULL ? "NULL" : op->ob_type->tp_name,
+ Py_Type(op)==NULL ? "NULL" : Py_Type(op)->tp_name,
(long)op->ob_refcnt,
op);
}
@@ -354,7 +354,7 @@ PyObject_Repr(PyObject *v)
#endif
if (v == NULL)
return PyUnicode_FromString("<NULL>");
- else if (v->ob_type->tp_repr == NULL)
+ else if (Py_Type(v)->tp_repr == NULL)
return PyUnicode_FromFormat("<%s object at %p>", v->ob_type->tp_name, v);
else {
ress = (*v->ob_type->tp_repr)(v);
@@ -408,16 +408,16 @@ _PyObject_Str(PyObject *v)
Py_INCREF(v);
return v;
}
- if (v->ob_type->tp_str == NULL)
+ if (Py_Type(v)->tp_str == NULL)
return PyObject_Repr(v);
- res = (*v->ob_type->tp_str)(v);
+ res = (*Py_Type(v)->tp_str)(v);
if (res == NULL)
return NULL;
if (!(PyString_Check(res) || PyUnicode_Check(res))) {
PyErr_Format(PyExc_TypeError,
"__str__ returned non-string (type %.200s)",
- res->ob_type->tp_name);
+ Py_Type(res)->tp_name);
Py_DECREF(res);
return NULL;
}
@@ -486,8 +486,8 @@ PyObject_Unicode(PyObject *v)
res = v;
}
else {
- if (v->ob_type->tp_str != NULL)
- res = (*v->ob_type->tp_str)(v);
+ if (Py_Type(v)->tp_str != NULL)
+ res = (*Py_Type(v)->tp_str)(v);
else
res = PyObject_Repr(v);
}
@@ -849,8 +849,8 @@ PyObject_GetAttrString(PyObject *v, const char *name)
{
PyObject *w, *res;
- if (v->ob_type->tp_getattr != NULL)
- return (*v->ob_type->tp_getattr)(v, (char*)name);
+ if (Py_Type(v)->tp_getattr != NULL)
+ return (*Py_Type(v)->tp_getattr)(v, (char*)name);
w = PyUnicode_InternFromString(name);
if (w == NULL)
return NULL;
@@ -877,8 +877,8 @@ PyObject_SetAttrString(PyObject *v, const char *name, PyObject *w)
PyObject *s;
int res;
- if (v->ob_type->tp_setattr != NULL)
- return (*v->ob_type->tp_setattr)(v, (char*)name, w);
+ if (Py_Type(v)->tp_setattr != NULL)
+ return (*Py_Type(v)->tp_setattr)(v, (char*)name, w);
s = PyUnicode_InternFromString(name);
if (s == NULL)
return -1;
@@ -890,9 +890,9 @@ PyObject_SetAttrString(PyObject *v, const char *name, PyObject *w)
PyObject *
PyObject_GetAttr(PyObject *v, PyObject *name)
{
- PyTypeObject *tp = v->ob_type;
+ PyTypeObject *tp = Py_Type(v);
- if (!PyUnicode_Check(name)) {
+ if (!PyUnicode_Check(name)) {
PyErr_Format(PyExc_TypeError,
"attribute name must be string, not '%.200s'",
name->ob_type->tp_name);
@@ -923,7 +923,7 @@ PyObject_HasAttr(PyObject *v, PyObject *name)
int
PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
{
- PyTypeObject *tp = v->ob_type;
+ PyTypeObject *tp = Py_Type(v);
int err;
if (!PyUnicode_Check(name)) {
@@ -970,7 +970,7 @@ PyObject **
_PyObject_GetDictPtr(PyObject *obj)
{
Py_ssize_t dictoffset;
- PyTypeObject *tp = obj->ob_type;
+ PyTypeObject *tp = Py_Type(obj);
dictoffset = tp->tp_dictoffset;
if (dictoffset == 0)
@@ -1003,7 +1003,7 @@ PyObject_SelfIter(PyObject *obj)
PyObject *
PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
{
- PyTypeObject *tp = obj->ob_type;
+ PyTypeObject *tp = Py_Type(obj);
PyObject *descr = NULL;
PyObject *res = NULL;
descrgetfunc f;
@@ -1087,7 +1087,7 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
}
if (f != NULL) {
- res = f(descr, obj, (PyObject *)obj->ob_type);
+ res = f(descr, obj, (PyObject *)Py_Type(obj));
Py_DECREF(descr);
goto done;
}
@@ -1109,7 +1109,7 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
int
PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
{
- PyTypeObject *tp = obj->ob_type;
+ PyTypeObject *tp = Py_Type(obj);
PyObject *descr;
descrsetfunc f;
PyObject **dictptr;
@@ -1309,7 +1309,7 @@ _dir_locals(void)
if (!PyList_Check(names)) {
PyErr_Format(PyExc_TypeError,
"dir(): expected keys() of locals to be a list, "
- "not '%.200s'", names->ob_type->tp_name);
+ "not '%.200s'", Py_Type(names)->tp_name);
Py_DECREF(names);
return NULL;
}
@@ -1437,7 +1437,7 @@ _dir_object(PyObject *obj)
if (!PyList_Check(result)) {
PyErr_Format(PyExc_TypeError,
"__dir__() must return a list, not %.200s",
- result->ob_type->tp_name);
+ Py_Type(result)->tp_name);
Py_DECREF(result);
result = NULL;
}
@@ -1499,8 +1499,7 @@ none_dealloc(PyObject* ignore)
static PyTypeObject PyNone_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"NoneType",
0,
0,
@@ -1517,7 +1516,8 @@ static PyTypeObject PyNone_Type = {
};
PyObject _Py_NoneStruct = {
- PyObject_HEAD_INIT(&PyNone_Type)
+ _PyObject_EXTRA_INIT
+ 1, &PyNone_Type
};
/* NotImplemented is an object that can be used to signal that an
@@ -1530,8 +1530,7 @@ NotImplemented_repr(PyObject *op)
}
static PyTypeObject PyNotImplemented_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"NotImplementedType",
0,
0,
@@ -1548,7 +1547,8 @@ static PyTypeObject PyNotImplemented_Type = {
};
PyObject _Py_NotImplementedStruct = {
- PyObject_HEAD_INIT(&PyNotImplemented_Type)
+ _PyObject_EXTRA_INIT
+ 1, &PyNotImplemented_Type
};
void
@@ -1625,7 +1625,7 @@ _Py_ForgetReference(register PyObject *op)
void
_Py_Dealloc(PyObject *op)
{
- destructor dealloc = op->ob_type->tp_dealloc;
+ destructor dealloc = Py_Type(op)->tp_dealloc;
_Py_ForgetReference(op);
(*dealloc)(op);
}
@@ -1656,7 +1656,7 @@ _Py_PrintReferenceAddresses(FILE *fp)
fprintf(fp, "Remaining object addresses:\n");
for (op = refchain._ob_next; op != &refchain; op = op->_ob_next)
fprintf(fp, "%p [%" PY_FORMAT_SIZE_T "d] %s\n", op,
- op->ob_refcnt, op->ob_type->tp_name);
+ op->ob_refcnt, Py_Type(op)->tp_name);
}
PyObject *
@@ -1674,7 +1674,7 @@ _Py_GetObjects(PyObject *self, PyObject *args)
return NULL;
for (i = 0; (n == 0 || i < n) && op != &refchain; i++) {
while (op == self || op == args || op == res || op == t ||
- (t != NULL && op->ob_type != (PyTypeObject *) t)) {
+ (t != NULL && Py_Type(op) != (PyTypeObject *) t)) {
op = op->_ob_next;
if (op == &refchain)
return res;
@@ -1817,7 +1817,7 @@ _PyTrash_destroy_chain(void)
{
while (_PyTrash_delete_later) {
PyObject *op = _PyTrash_delete_later;
- destructor dealloc = op->ob_type->tp_dealloc;
+ destructor dealloc = Py_Type(op)->tp_dealloc;
_PyTrash_delete_later =
(PyObject*) _Py_AS_GC(op)->gc.gc_prev;