Changeset 388 for python/vendor/current/Objects/weakrefobject.c
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/Objects/weakrefobject.c
r2 r388 53 53 PyObject *callback = self->wr_callback; 54 54 55 if (PyWeakref_GET_OBJECT(self) != Py_None) { 56 PyWeakReference **list = GET_WEAKREFS_LISTPTR( 57 PyWeakref_GET_OBJECT(self)); 55 if (self->wr_object != Py_None) { 56 PyWeakReference **list = GET_WEAKREFS_LISTPTR(self->wr_object); 58 57 59 58 if (*list == self) 60 61 62 59 /* If 'self' is the end of the list (and thus self->wr_next == NULL) 60 then the weakref list itself (and thus the value of *list) will 61 end up being set to NULL. */ 63 62 *list = self->wr_next; 64 63 self->wr_object = Py_None; … … 162 161 } 163 162 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 (PyString_Check(nameobj)) 170 name = PyString_AS_STRING(nameobj); 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); 163 char *name = NULL; 164 PyObject *nameobj = PyObject_GetAttrString(PyWeakref_GET_OBJECT(self), 165 "__name__"); 166 if (nameobj == NULL) 167 PyErr_Clear(); 168 else if (PyString_Check(nameobj)) 169 name = PyString_AS_STRING(nameobj); 170 if (name != NULL) { 171 PyOS_snprintf(buffer, sizeof(buffer), 172 "<weakref at %p; to '%.50s' at %p (%s)>", 173 self, 174 Py_TYPE(PyWeakref_GET_OBJECT(self))->tp_name, 175 PyWeakref_GET_OBJECT(self), 176 name); 177 } 178 else { 179 PyOS_snprintf(buffer, sizeof(buffer), 180 "<weakref at %p; to '%.50s' at %p>", 181 self, 182 Py_TYPE(PyWeakref_GET_OBJECT(self))->tp_name, 183 PyWeakref_GET_OBJECT(self)); 184 } 185 Py_XDECREF(nameobj); 179 186 } 180 187 return PyString_FromString(buffer); … … 188 195 weakref_richcompare(PyWeakReference* self, PyWeakReference* other, int op) 189 196 { 190 if ( op != Py_EQ|| self->ob_type != other->ob_type) {197 if ((op != Py_EQ && op != Py_NE) || self->ob_type != other->ob_type) { 191 198 Py_INCREF(Py_NotImplemented); 192 199 return Py_NotImplemented; … … 194 201 if (PyWeakref_GET_OBJECT(self) == Py_None 195 202 || PyWeakref_GET_OBJECT(other) == Py_None) { 196 PyObject *res = self==other ? Py_True : Py_False; 197 Py_INCREF(res); 198 return res; 203 int res = (self == other); 204 if (op == Py_NE) 205 res = !res; 206 if (res) 207 Py_RETURN_TRUE; 208 else 209 Py_RETURN_FALSE; 199 210 } 200 211 return PyObject_RichCompare(PyWeakref_GET_OBJECT(self), … … 338 349 0, 339 350 weakref_dealloc, /*tp_dealloc*/ 340 0, 351 0, /*tp_print*/ 341 352 0, /*tp_getattr*/ 342 353 0, /*tp_setattr*/ 343 0, 354 0, /*tp_compare*/ 344 355 (reprfunc)weakref_repr, /*tp_repr*/ 345 356 0, /*tp_as_number*/ … … 357 368 (traverseproc)gc_traverse, /*tp_traverse*/ 358 369 (inquiry)gc_clear, /*tp_clear*/ 359 (richcmpfunc)weakref_richcompare, 370 (richcmpfunc)weakref_richcompare, /*tp_richcompare*/ 360 371 0, /*tp_weaklistoffset*/ 361 372 0, /*tp_iter*/ … … 437 448 static PyObject * \ 438 449 method(PyObject *proxy) { \ 439 440 441 450 UNWRAP(proxy); \ 451 return PyObject_CallMethod(proxy, special, ""); \ 452 } 442 453 443 454 … … 453 464 char buf[160]; 454 465 PyOS_snprintf(buf, sizeof(buf), 455 456 457 466 "<weakproxy at %p to %.100s at %p>", proxy, 467 Py_TYPE(PyWeakref_GET_OBJECT(proxy))->tp_name, 468 PyWeakref_GET_OBJECT(proxy)); 458 469 return PyString_FromString(buf); 459 470 } … … 605 616 606 617 static PyMethodDef proxy_methods[] = { 607 608 618 {"__unicode__", (PyCFunction)proxy_unicode, METH_NOARGS}, 619 {NULL, NULL} 609 620 }; 610 621 … … 678 689 /* methods */ 679 690 (destructor)proxy_dealloc, /* tp_dealloc */ 680 0, 681 0, 682 0, 683 proxy_compare, 684 (reprfunc)proxy_repr, 685 &proxy_as_number, 686 &proxy_as_sequence, 687 &proxy_as_mapping, 688 0, 689 0, 691 0, /* tp_print */ 692 0, /* tp_getattr */ 693 0, /* tp_setattr */ 694 proxy_compare, /* tp_compare */ 695 (reprfunc)proxy_repr, /* tp_repr */ 696 &proxy_as_number, /* tp_as_number */ 697 &proxy_as_sequence, /* tp_as_sequence */ 698 &proxy_as_mapping, /* tp_as_mapping */ 699 0, /* tp_hash */ 700 0, /* tp_call */ 690 701 proxy_str, /* tp_str */ 691 702 proxy_getattr, /* tp_getattro */ 692 703 (setattrofunc)proxy_setattr, /* tp_setattro */ 693 0, 704 0, /* tp_as_buffer */ 694 705 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC 695 706 | Py_TPFLAGS_CHECKTYPES, /* tp_flags */ … … 701 712 (getiterfunc)proxy_iter, /* tp_iter */ 702 713 (iternextfunc)proxy_iternext, /* tp_iternext */ 703 714 proxy_methods, /* tp_methods */ 704 715 }; 705 716 … … 713 724 /* methods */ 714 725 (destructor)proxy_dealloc, /* tp_dealloc */ 715 0, 716 0, 717 0, 718 proxy_compare, 719 (unaryfunc)proxy_repr, 720 &proxy_as_number, 721 &proxy_as_sequence, 722 &proxy_as_mapping, 723 0, 724 proxy_call, 725 proxy_str, 726 0, /* tp_print */ 727 0, /* tp_getattr */ 728 0, /* tp_setattr */ 729 proxy_compare, /* tp_compare */ 730 (unaryfunc)proxy_repr, /* tp_repr */ 731 &proxy_as_number, /* tp_as_number */ 732 &proxy_as_sequence, /* tp_as_sequence */ 733 &proxy_as_mapping, /* tp_as_mapping */ 734 0, /* tp_hash */ 735 proxy_call, /* tp_call */ 736 proxy_str, /* tp_str */ 726 737 proxy_getattr, /* tp_getattro */ 727 738 (setattrofunc)proxy_setattr, /* tp_setattro */ 728 0, 739 0, /* tp_as_buffer */ 729 740 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC 730 741 | Py_TPFLAGS_CHECKTYPES, /* tp_flags */ … … 749 760 if (!PyType_SUPPORTS_WEAKREFS(Py_TYPE(ob))) { 750 761 PyErr_Format(PyExc_TypeError, 751 762 "cannot create weak reference to '%s' object", 752 763 Py_TYPE(ob)->tp_name); 753 764 return NULL; … … 808 819 if (!PyType_SUPPORTS_WEAKREFS(Py_TYPE(ob))) { 809 820 PyErr_Format(PyExc_TypeError, 810 821 "cannot create weak reference to '%s' object", 811 822 Py_TYPE(ob)->tp_name); 812 823 return NULL; … … 933 944 PyObject *tuple; 934 945 Py_ssize_t i = 0; 935 946 936 947 tuple = PyTuple_New(count * 2); 937 948 if (tuple == NULL) {
Note:
See TracChangeset
for help on using the changeset viewer.