summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-07-21 06:55:02 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2007-07-21 06:55:02 (GMT)
commit6819210b9e4e5719a6f7f9c1725f8fa70a8936f6 (patch)
tree456e2e6b3d9d71e966f3b0e419ecfe44ce3c1fdd /Objects/floatobject.c
parentb1994b4a5d0139a010eb0af1d6615a3df92fe786 (diff)
downloadcpython-6819210b9e4e5719a6f7f9c1725f8fa70a8936f6.zip
cpython-6819210b9e4e5719a6f7f9c1725f8fa70a8936f6.tar.gz
cpython-6819210b9e4e5719a6f7f9c1725f8fa70a8936f6.tar.bz2
PEP 3123: Provide forward compatibility with Python 3.0, while keeping
backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and PyVarObject_HEAD_INIT.
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 6d9e33f..4dd7d03 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -41,8 +41,8 @@ fill_free_list(void)
p = &((PyFloatBlock *)p)->objects[0];
q = p + N_FLOATOBJECTS;
while (--q > p)
- q->ob_type = (struct _typeobject *)(q-1);
- q->ob_type = NULL;
+ Py_Type(q) = (struct _typeobject *)(q-1);
+ Py_Type(q) = NULL;
return p + N_FLOATOBJECTS - 1;
}
@@ -56,7 +56,7 @@ PyFloat_FromDouble(double fval)
}
/* Inline PyObject_New */
op = free_list;
- free_list = (PyFloatObject *)op->ob_type;
+ free_list = (PyFloatObject *)Py_Type(op);
PyObject_INIT(op, &PyFloat_Type);
op->ob_fval = fval;
return (PyObject *) op;
@@ -175,11 +175,11 @@ static void
float_dealloc(PyFloatObject *op)
{
if (PyFloat_CheckExact(op)) {
- op->ob_type = (struct _typeobject *)free_list;
+ Py_Type(op) = (struct _typeobject *)free_list;
free_list = op;
}
else
- op->ob_type->tp_free((PyObject *)op);
+ Py_Type(op)->tp_free((PyObject *)op);
}
double
@@ -197,7 +197,7 @@ PyFloat_AsDouble(PyObject *op)
return -1;
}
- if ((nb = op->ob_type->tp_as_number) == NULL || nb->nb_float == NULL) {
+ if ((nb = Py_Type(op)->tp_as_number) == NULL || nb->nb_float == NULL) {
PyErr_SetString(PyExc_TypeError, "a float is required");
return -1;
}
@@ -986,7 +986,7 @@ float_getformat(PyTypeObject *v, PyObject* arg)
if (!PyString_Check(arg)) {
PyErr_Format(PyExc_TypeError,
"__getformat__() argument must be string, not %.500s",
- arg->ob_type->tp_name);
+ Py_Type(arg)->tp_name);
return NULL;
}
s = PyString_AS_STRING(arg);
@@ -1152,8 +1152,7 @@ static PyNumberMethods float_as_number = {
};
PyTypeObject PyFloat_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"float",
sizeof(PyFloatObject),
0,
@@ -1265,7 +1264,7 @@ PyFloat_Fini(void)
for (i = 0, p = &list->objects[0];
i < N_FLOATOBJECTS;
i++, p++) {
- if (PyFloat_CheckExact(p) && p->ob_refcnt != 0)
+ if (PyFloat_CheckExact(p) && Py_Refcnt(p) != 0)
frem++;
}
next = list->next;
@@ -1276,8 +1275,8 @@ PyFloat_Fini(void)
i < N_FLOATOBJECTS;
i++, p++) {
if (!PyFloat_CheckExact(p) ||
- p->ob_refcnt == 0) {
- p->ob_type = (struct _typeobject *)
+ Py_Refcnt(p) == 0) {
+ Py_Type(p) = (struct _typeobject *)
free_list;
free_list = p;
}
@@ -1309,7 +1308,7 @@ PyFloat_Fini(void)
i < N_FLOATOBJECTS;
i++, p++) {
if (PyFloat_CheckExact(p) &&
- p->ob_refcnt != 0) {
+ Py_Refcnt(p) != 0) {
char buf[100];
PyFloat_AsString(buf, p);
/* XXX(twouters) cast refcount to
@@ -1318,7 +1317,7 @@ PyFloat_Fini(void)
*/
fprintf(stderr,
"# <float at %p, refcnt=%ld, val=%s>\n",
- p, (long)p->ob_refcnt, buf);
+ p, (long)Py_Refcnt(p), buf);
}
}
list = list->next;