~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_simple_set_pyx.pyx

  • Committer: John Arbash Meinel
  • Date: 2009-10-15 18:18:44 UTC
  • mfrom: (4748 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4749.
  • Revision ID: john@arbash-meinel.com-20091015181844-ame1y9yxta689ojp
Merge bzr.dev, resolve NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
cdef extern from "Python.h":
23
23
    ctypedef unsigned long size_t
24
 
    ctypedef long (*hashfunc)(PyObject*)
25
 
    ctypedef PyObject *(*richcmpfunc)(PyObject *, PyObject *, int)
 
24
    ctypedef long (*hashfunc)(PyObject*) except -1
 
25
    ctypedef object (*richcmpfunc)(PyObject *, PyObject *, int)
26
26
    ctypedef int (*visitproc)(PyObject *, void *)
27
27
    ctypedef int (*traverseproc)(PyObject *, visitproc, void *)
28
28
    int Py_EQ
29
 
    PyObject *Py_True
30
 
    PyObject *Py_NotImplemented
31
29
    void Py_INCREF(PyObject *)
32
30
    void Py_DECREF(PyObject *)
33
31
    ctypedef struct PyTypeObject:
36
34
        traverseproc tp_traverse
37
35
 
38
36
    PyTypeObject *Py_TYPE(PyObject *)
39
 
    int PyObject_IsTrue(PyObject *)
40
37
    # Note: *Don't* use hash(), Pyrex 0.9.8.5 thinks it returns an 'int', and
41
38
    #       thus silently truncates to 32-bits on 64-bit machines.
42
39
    long PyObject_Hash(PyObject *) except -1
58
55
_dummy = <PyObject *>_dummy_obj
59
56
 
60
57
 
 
58
cdef object _NotImplemented
 
59
_NotImplemented = NotImplemented
 
60
 
 
61
 
61
62
cdef int _is_equal(PyObject *this, long this_hash, PyObject *other) except -1:
62
63
    cdef long other_hash
63
 
    cdef PyObject *res
64
64
 
65
65
    if this == other:
66
66
        return 1
76
76
    #      equal. (It doesn't try to cast them both to some intermediate form
77
77
    #      that would compare equal.)
78
78
    res = Py_TYPE(this).tp_richcompare(this, other, Py_EQ)
79
 
    if res == NULL: # Exception
80
 
        return -1
81
 
    if PyObject_IsTrue(res):
82
 
        Py_DECREF(res)
83
 
        return 1
84
 
    if res == Py_NotImplemented:
85
 
        Py_DECREF(res)
 
79
    if res is _NotImplemented:
86
80
        res = Py_TYPE(other).tp_richcompare(other, this, Py_EQ)
87
 
    if res == NULL:
88
 
        return -1
89
 
    if PyObject_IsTrue(res):
90
 
        Py_DECREF(res)
 
81
        if res is _NotImplemented:
 
82
            return 0
 
83
    if res:
91
84
        return 1
92
 
    Py_DECREF(res)
93
85
    return 0
94
86
 
95
87