~ubuntu-branches/ubuntu/karmic/python3.0/karmic

« back to all changes in this revision

Viewing changes to Objects/abstract.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-02-16 17:18:23 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090216171823-1d5cm5qnnjvmnzzm
Tags: 3.0.1-0ubuntu1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
/* Operations on any object */
29
29
 
30
 
int
31
 
PyObject_Cmp(PyObject *o1, PyObject *o2, int *result)
32
 
{
33
 
        int r;
34
 
 
35
 
        if (o1 == NULL || o2 == NULL) {
36
 
                null_error();
37
 
                return -1;
38
 
        }
39
 
        r = PyObject_Compare(o1, o2);
40
 
        if (PyErr_Occurred())
41
 
                return -1;
42
 
        *result = r;
43
 
        return 0;
44
 
}
45
 
 
46
30
PyObject *
47
31
PyObject_Type(PyObject *o)
48
32
{
83
67
 
84
68
/* The length hint function returns a non-negative value from o.__len__()
85
69
   or o.__length_hint__().  If those methods aren't found or return a negative
86
 
   value, then the defaultvalue is returned.  This function never fails. 
87
 
   Accordingly, it will mask exceptions raised in either method.
 
70
   value, then the defaultvalue is returned.  If one of the calls fails,
 
71
   this function returns -1.
88
72
*/
89
73
 
90
74
Py_ssize_t
98
82
        rv = PyObject_Size(o);
99
83
        if (rv >= 0)
100
84
                return rv;
101
 
        if (PyErr_Occurred())
 
85
        if (PyErr_Occurred()) {
 
86
                if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
 
87
                        !PyErr_ExceptionMatches(PyExc_AttributeError))
 
88
                                return -1;
102
89
                PyErr_Clear();
 
90
        }
103
91
 
104
92
        /* cache a hashed version of the attribute string */
105
93
        if (hintstrobj == NULL) {
106
94
                hintstrobj = PyUnicode_InternFromString("__length_hint__");
107
95
                if (hintstrobj == NULL)
108
 
                        goto defaultcase;
 
96
                        return -1;
109
97
        }
110
98
 
111
99
        /* try o.__length_hint__() */
112
100
        ro = PyObject_CallMethodObjArgs(o, hintstrobj, NULL);
113
 
        if (ro == NULL)
114
 
                goto defaultcase;
115
 
        rv = PyLong_AsSsize_t(ro);
 
101
        if (ro == NULL) {
 
102
                if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
 
103
                        !PyErr_ExceptionMatches(PyExc_AttributeError))
 
104
                                return -1;
 
105
                PyErr_Clear();
 
106
                return defaultvalue;
 
107
        }
 
108
        rv = PyLong_Check(ro) ? PyLong_AsSsize_t(ro) : defaultvalue;
116
109
        Py_DECREF(ro);
117
 
        if (rv >= 0)
118
 
                return rv;
119
 
 
120
 
defaultcase:
121
 
        if (PyErr_Occurred())
122
 
                PyErr_Clear();
123
 
        return defaultvalue;
 
110
        return rv;
124
111
}
125
112
 
126
113
PyObject *
1379
1366
                }
1380
1367
                return res;
1381
1368
        }
1382
 
        if (m && m->nb_long) { /* This should include subclasses of long */
1383
 
                /* Classic classes always take this branch. */
1384
 
                PyObject *res = m->nb_long(o);
1385
 
                if (res && !PyLong_Check(res)) {
1386
 
                        PyErr_Format(PyExc_TypeError,
1387
 
                                     "__long__ returned non-long (type %.200s)",
1388
 
                                     res->ob_type->tp_name);
1389
 
                        Py_DECREF(res);
1390
 
                        return NULL;
1391
 
                }
1392
 
                return res;
1393
 
        }
1394
 
        if (PyLong_Check(o)) /* A long subclass without nb_long */
 
1369
        if (PyLong_Check(o)) /* An int subclass without nb_int */
1395
1370
                return _PyLong_Copy((PyLongObject *)o);
1396
1371
        trunc_func = PyObject_GetAttr(o, trunc_name);
1397
1372
        if (trunc_func) {
1770
1745
{
1771
1746
        PyObject *it;  /* iter(v) */
1772
1747
        Py_ssize_t n;         /* guess for result tuple size */
1773
 
        PyObject *result;
 
1748
        PyObject *result = NULL;
1774
1749
        Py_ssize_t j;
1775
1750
 
1776
1751
        if (v == NULL)
1795
1770
 
1796
1771
        /* Guess result size and allocate space. */
1797
1772
        n = _PyObject_LengthHint(v, 10);
 
1773
        if (n == -1)
 
1774
                goto Fail;
1798
1775
        result = PyTuple_New(n);
1799
1776
        if (result == NULL)
1800
1777
                goto Fail;