~ubuntu-branches/ubuntu/natty/python3.1/natty-security

« back to all changes in this revision

Viewing changes to Objects/weakrefobject.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-07-06 16:52:42 UTC
  • mfrom: (1.2.1 upstream) (2.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20100706165242-2xv4i019r3et6c0j
Tags: 3.1.2+20100706-1ubuntu1
* Merge with Debian; remaining changes:
  - Regenerate the control file.
  - Add debian/patches/overwrite-semaphore-check for Lucid buildds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
            PyWeakref_GET_OBJECT(self));
58
58
 
59
59
        if (*list == self)
60
 
            /* If 'self' is the end of the list (and thus self->wr_next == NULL)
61
 
               then the weakref list itself (and thus the value of *list) will
62
 
               end up being set to NULL. */
 
60
            /* If 'self' is the end of the list (and thus self->wr_next == NULL)
 
61
               then the weakref list itself (and thus the value of *list) will
 
62
               end up being set to NULL. */
63
63
            *list = self->wr_next;
64
64
        self->wr_object = Py_None;
65
65
        if (self->wr_prev != NULL)
161
161
        PyOS_snprintf(buffer, sizeof(buffer), "<weakref at %p; dead>", self);
162
162
    }
163
163
    else {
164
 
        char *name = NULL;
165
 
        PyObject *nameobj = PyObject_GetAttrString(PyWeakref_GET_OBJECT(self),
166
 
                                                   "__name__");
167
 
        if (nameobj == NULL)
168
 
                PyErr_Clear();
169
 
        else if (PyUnicode_Check(nameobj))
170
 
                name = _PyUnicode_AsString(nameobj);
 
164
        char *name = NULL;
 
165
        PyObject *nameobj = PyObject_GetAttrString(PyWeakref_GET_OBJECT(self),
 
166
                                                   "__name__");
 
167
        if (nameobj == NULL)
 
168
                PyErr_Clear();
 
169
        else if (PyUnicode_Check(nameobj))
 
170
                name = _PyUnicode_AsString(nameobj);
171
171
        PyOS_snprintf(buffer, sizeof(buffer),
172
 
                      name ? "<weakref at %p; to '%.50s' at %p (%s)>"
173
 
                           : "<weakref at %p; to '%.50s' at %p>",
174
 
                      self,
175
 
                      Py_TYPE(PyWeakref_GET_OBJECT(self))->tp_name,
176
 
                      PyWeakref_GET_OBJECT(self),
177
 
                      name);
178
 
        Py_XDECREF(nameobj);
 
172
                      name ? "<weakref at %p; to '%.50s' at %p (%s)>"
 
173
                           : "<weakref at %p; to '%.50s' at %p>",
 
174
                      self,
 
175
                      Py_TYPE(PyWeakref_GET_OBJECT(self))->tp_name,
 
176
                      PyWeakref_GET_OBJECT(self),
 
177
                      name);
 
178
        Py_XDECREF(nameobj);
179
179
    }
180
180
    return PyUnicode_FromString(buffer);
181
181
}
188
188
weakref_richcompare(PyWeakReference* self, PyWeakReference* other, int op)
189
189
{
190
190
    if ((op != Py_EQ && op != Py_NE) ||
191
 
        !PyWeakref_Check(self) ||
192
 
        !PyWeakref_Check(other)) {
 
191
        !PyWeakref_Check(self) ||
 
192
        !PyWeakref_Check(other)) {
193
193
        Py_INCREF(Py_NotImplemented);
194
194
        return Py_NotImplemented;
195
195
    }
339
339
    sizeof(PyWeakReference),
340
340
    0,
341
341
    weakref_dealloc,            /*tp_dealloc*/
342
 
    0,                          /*tp_print*/
 
342
    0,                          /*tp_print*/
343
343
    0,                          /*tp_getattr*/
344
344
    0,                          /*tp_setattr*/
345
 
    0,                          /*tp_reserved*/
 
345
    0,                          /*tp_reserved*/
346
346
    (reprfunc)weakref_repr,     /*tp_repr*/
347
347
    0,                          /*tp_as_number*/
348
348
    0,                          /*tp_as_sequence*/
358
358
    0,                          /*tp_doc*/
359
359
    (traverseproc)gc_traverse,  /*tp_traverse*/
360
360
    (inquiry)gc_clear,          /*tp_clear*/
361
 
    (richcmpfunc)weakref_richcompare,   /*tp_richcompare*/
 
361
    (richcmpfunc)weakref_richcompare,   /*tp_richcompare*/
362
362
    0,                          /*tp_weaklistoffset*/
363
363
    0,                          /*tp_iter*/
364
364
    0,                          /*tp_iternext*/
438
438
#define WRAP_METHOD(method, special) \
439
439
    static PyObject * \
440
440
    method(PyObject *proxy) { \
441
 
            UNWRAP(proxy); \
442
 
                return PyObject_CallMethod(proxy, special, ""); \
443
 
        }
 
441
            UNWRAP(proxy); \
 
442
                return PyObject_CallMethod(proxy, special, ""); \
 
443
        }
444
444
 
445
445
 
446
446
/* direct slots */
454
454
{
455
455
    char buf[160];
456
456
    PyOS_snprintf(buf, sizeof(buf),
457
 
                  "<weakproxy at %p to %.100s at %p>", proxy,
458
 
                  Py_TYPE(PyWeakref_GET_OBJECT(proxy))->tp_name,
459
 
                  PyWeakref_GET_OBJECT(proxy));
 
457
                  "<weakproxy at %p to %.100s at %p>", proxy,
 
458
                  Py_TYPE(PyWeakref_GET_OBJECT(proxy))->tp_name,
 
459
                  PyWeakref_GET_OBJECT(proxy));
460
460
    return PyUnicode_FromString(buf);
461
461
}
462
462
 
587
587
 
588
588
 
589
589
static PyMethodDef proxy_methods[] = {
590
 
        {"__bytes__", (PyCFunction)proxy_bytes, METH_NOARGS},
591
 
        {NULL, NULL}
 
590
        {"__bytes__", (PyCFunction)proxy_bytes, METH_NOARGS},
 
591
        {NULL, NULL}
592
592
};
593
593
 
594
594
 
636
636
    0,                          /*sq_item*/
637
637
    0,                          /*sq_slice*/
638
638
    0,                          /*sq_ass_item*/
639
 
    0,                           /*sq_ass_slice*/
 
639
    0,                           /*sq_ass_slice*/
640
640
    (objobjproc)proxy_contains, /* sq_contains */
641
641
};
642
642
 
655
655
    0,
656
656
    /* methods */
657
657
    (destructor)proxy_dealloc,          /* tp_dealloc */
658
 
    0,                                  /* tp_print */
659
 
    0,                                  /* tp_getattr */
660
 
    0,                                  /* tp_setattr */
661
 
    0,                                  /* tp_reserved */
662
 
    (reprfunc)proxy_repr,               /* tp_repr */
663
 
    &proxy_as_number,                   /* tp_as_number */
664
 
    &proxy_as_sequence,                 /* tp_as_sequence */
665
 
    &proxy_as_mapping,                  /* tp_as_mapping */
666
 
    0,                                  /* tp_hash */
667
 
    0,                                  /* tp_call */
 
658
    0,                                  /* tp_print */
 
659
    0,                                  /* tp_getattr */
 
660
    0,                                  /* tp_setattr */
 
661
    0,                                  /* tp_reserved */
 
662
    (reprfunc)proxy_repr,               /* tp_repr */
 
663
    &proxy_as_number,                   /* tp_as_number */
 
664
    &proxy_as_sequence,                 /* tp_as_sequence */
 
665
    &proxy_as_mapping,                  /* tp_as_mapping */
 
666
    0,                                  /* tp_hash */
 
667
    0,                                  /* tp_call */
668
668
    proxy_str,                          /* tp_str */
669
669
    proxy_getattr,                      /* tp_getattro */
670
670
    (setattrofunc)proxy_setattr,        /* tp_setattro */
671
 
    0,                                  /* tp_as_buffer */
 
671
    0,                                  /* tp_as_buffer */
672
672
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
673
673
    0,                                  /* tp_doc */
674
674
    (traverseproc)gc_traverse,          /* tp_traverse */
677
677
    0,                                  /* tp_weaklistoffset */
678
678
    (getiterfunc)proxy_iter,            /* tp_iter */
679
679
    (iternextfunc)proxy_iternext,       /* tp_iternext */
680
 
        proxy_methods,                      /* tp_methods */
 
680
        proxy_methods,                      /* tp_methods */
681
681
};
682
682
 
683
683
 
689
689
    0,
690
690
    /* methods */
691
691
    (destructor)proxy_dealloc,          /* tp_dealloc */
692
 
    0,                                  /* tp_print */
693
 
    0,                                  /* tp_getattr */
694
 
    0,                                  /* tp_setattr */
695
 
    0,                                  /* tp_reserved */
696
 
    (unaryfunc)proxy_repr,              /* tp_repr */
697
 
    &proxy_as_number,                   /* tp_as_number */
698
 
    &proxy_as_sequence,                 /* tp_as_sequence */
699
 
    &proxy_as_mapping,                  /* tp_as_mapping */
700
 
    0,                                  /* tp_hash */
701
 
    proxy_call,                         /* tp_call */
702
 
    proxy_str,                          /* tp_str */
 
692
    0,                                  /* tp_print */
 
693
    0,                                  /* tp_getattr */
 
694
    0,                                  /* tp_setattr */
 
695
    0,                                  /* tp_reserved */
 
696
    (unaryfunc)proxy_repr,              /* tp_repr */
 
697
    &proxy_as_number,                   /* tp_as_number */
 
698
    &proxy_as_sequence,                 /* tp_as_sequence */
 
699
    &proxy_as_mapping,                  /* tp_as_mapping */
 
700
    0,                                  /* tp_hash */
 
701
    proxy_call,                         /* tp_call */
 
702
    proxy_str,                          /* tp_str */
703
703
    proxy_getattr,                      /* tp_getattro */
704
704
    (setattrofunc)proxy_setattr,        /* tp_setattro */
705
 
    0,                                  /* tp_as_buffer */
 
705
    0,                                  /* tp_as_buffer */
706
706
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
707
707
    0,                                  /* tp_doc */
708
708
    (traverseproc)gc_traverse,          /* tp_traverse */
724
724
 
725
725
    if (!PyType_SUPPORTS_WEAKREFS(Py_TYPE(ob))) {
726
726
        PyErr_Format(PyExc_TypeError,
727
 
                     "cannot create weak reference to '%s' object",
 
727
                     "cannot create weak reference to '%s' object",
728
728
                     Py_TYPE(ob)->tp_name);
729
729
        return NULL;
730
730
    }
783
783
 
784
784
    if (!PyType_SUPPORTS_WEAKREFS(Py_TYPE(ob))) {
785
785
        PyErr_Format(PyExc_TypeError,
786
 
                     "cannot create weak reference to '%s' object",
 
786
                     "cannot create weak reference to '%s' object",
787
787
                     Py_TYPE(ob)->tp_name);
788
788
        return NULL;
789
789
    }
908
908
        else {
909
909
            PyObject *tuple;
910
910
            Py_ssize_t i = 0;
911
 
    
 
911
 
912
912
            tuple = PyTuple_New(count * 2);
913
913
            if (tuple == NULL) {
914
914
                if (restore_error)