Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(14)

Side by Side Diff: Objects/typeobject.c

Issue 25750: tp_descr_get(self, obj, type) is called without owning a reference to "self"
Patch Set: Created 3 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Type object implementation */ 1 /* Type object implementation */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 #include "structmember.h" 4 #include "structmember.h"
5 5
6 #include <ctype.h> 6 #include <ctype.h>
7 7
8 8
9 /* Support type attribute cache */ 9 /* Support type attribute cache */
10 10
(...skipping 2590 matching lines...) Expand 10 before | Expand all | Expand 10 after
2601 } 2601 }
2602 2602
2603 /* This is similar to PyObject_GenericGetAttr(), 2603 /* This is similar to PyObject_GenericGetAttr(),
2604 but uses _PyType_Lookup() instead of just looking in type->tp_dict. */ 2604 but uses _PyType_Lookup() instead of just looking in type->tp_dict. */
2605 static PyObject * 2605 static PyObject *
2606 type_getattro(PyTypeObject *type, PyObject *name) 2606 type_getattro(PyTypeObject *type, PyObject *name)
2607 { 2607 {
2608 PyTypeObject *metatype = Py_TYPE(type); 2608 PyTypeObject *metatype = Py_TYPE(type);
2609 PyObject *meta_attribute, *attribute; 2609 PyObject *meta_attribute, *attribute;
2610 descrgetfunc meta_get; 2610 descrgetfunc meta_get;
2611 PyObject* res;
2611 2612
2612 if (!PyString_Check(name)) { 2613 if (!PyString_Check(name)) {
2613 PyErr_Format(PyExc_TypeError, 2614 PyErr_Format(PyExc_TypeError,
2614 "attribute name must be string, not '%.200s'", 2615 "attribute name must be string, not '%.200s'",
2615 name->ob_type->tp_name); 2616 name->ob_type->tp_name);
2616 return NULL; 2617 return NULL;
2617 } 2618 }
2618 2619
2619 /* Initialize this type (we'll assume the metatype is initialized) */ 2620 /* Initialize this type (we'll assume the metatype is initialized) */
2620 if (type->tp_dict == NULL) { 2621 if (type->tp_dict == NULL) {
2621 if (PyType_Ready(type) < 0) 2622 if (PyType_Ready(type) < 0)
2622 return NULL; 2623 return NULL;
2623 } 2624 }
2624 2625
2625 /* No readable descriptor found yet */ 2626 /* No readable descriptor found yet */
2626 meta_get = NULL; 2627 meta_get = NULL;
2627 2628
2628 /* Look for the attribute in the metatype */ 2629 /* Look for the attribute in the metatype */
2629 meta_attribute = _PyType_Lookup(metatype, name); 2630 meta_attribute = _PyType_Lookup(metatype, name);
2630 2631
2631 if (meta_attribute != NULL) { 2632 if (meta_attribute != NULL) {
2633 Py_INCREF(meta_attribute);
2632 meta_get = Py_TYPE(meta_attribute)->tp_descr_get; 2634 meta_get = Py_TYPE(meta_attribute)->tp_descr_get;
2633 2635
2634 if (meta_get != NULL && PyDescr_IsData(meta_attribute)) { 2636 if (meta_get != NULL && PyDescr_IsData(meta_attribute)) {
2635 /* Data descriptors implement tp_descr_set to intercept 2637 /* Data descriptors implement tp_descr_set to intercept
2636 * writes. Assume the attribute is not overridden in 2638 * writes. Assume the attribute is not overridden in
2637 * type's tp_dict (and bases): call the descriptor now. 2639 * type's tp_dict (and bases): call the descriptor now.
2638 */ 2640 */
2639 return meta_get(meta_attribute, (PyObject *)type, 2641 res = meta_get(meta_attribute, (PyObject *)type,
2640 (PyObject *)metatype); 2642 (PyObject *)metatype);
2643 Py_DECREF(meta_attribute);
2644 return res;
2641 } 2645 }
2642 Py_INCREF(meta_attribute);
2643 } 2646 }
2644 2647
2645 /* No data descriptor found on metatype. Look in tp_dict of this 2648 /* No data descriptor found on metatype. Look in tp_dict of this
2646 * type and its bases */ 2649 * type and its bases */
2647 attribute = _PyType_Lookup(type, name); 2650 attribute = _PyType_Lookup(type, name);
2648 if (attribute != NULL) { 2651 if (attribute != NULL) {
2649 /* Implement descriptor functionality, if any */ 2652 /* Implement descriptor functionality, if any */
2653 Py_INCREF(attribute);
2650 descrgetfunc local_get = Py_TYPE(attribute)->tp_descr_get; 2654 descrgetfunc local_get = Py_TYPE(attribute)->tp_descr_get;
2651 2655
2652 Py_XDECREF(meta_attribute); 2656 Py_XDECREF(meta_attribute);
2653 2657
2654 if (local_get != NULL) { 2658 if (local_get != NULL) {
2655 /* NULL 2nd argument indicates the descriptor was 2659 /* NULL 2nd argument indicates the descriptor was
2656 * found on the target object itself (or a base) */ 2660 * found on the target object itself (or a base) */
2657 return local_get(attribute, (PyObject *)NULL, 2661 res = local_get(attribute, (PyObject *)NULL,
2658 (PyObject *)type); 2662 (PyObject *)type);
2663 Py_DECREF(attribute);
2664 return res;
2659 } 2665 }
2660 2666
2661 Py_INCREF(attribute);
2662 return attribute; 2667 return attribute;
2663 } 2668 }
2664 2669
2665 /* No attribute found in local __dict__ (or bases): use the 2670 /* No attribute found in local __dict__ (or bases): use the
2666 * descriptor from the metatype, if any */ 2671 * descriptor from the metatype, if any */
2667 if (meta_get != NULL) { 2672 if (meta_get != NULL) {
2668 PyObject *res; 2673 PyObject *res;
2669 res = meta_get(meta_attribute, (PyObject *)type, 2674 res = meta_get(meta_attribute, (PyObject *)type,
2670 (PyObject *)metatype); 2675 (PyObject *)metatype);
2671 Py_DECREF(meta_attribute); 2676 Py_DECREF(meta_attribute);
(...skipping 4166 matching lines...) Expand 10 before | Expand all | Expand 10 after
6838 0, /* tp_base */ 6843 0, /* tp_base */
6839 0, /* tp_dict */ 6844 0, /* tp_dict */
6840 super_descr_get, /* tp_descr_get */ 6845 super_descr_get, /* tp_descr_get */
6841 0, /* tp_descr_set */ 6846 0, /* tp_descr_set */
6842 0, /* tp_dictoffset */ 6847 0, /* tp_dictoffset */
6843 super_init, /* tp_init */ 6848 super_init, /* tp_init */
6844 PyType_GenericAlloc, /* tp_alloc */ 6849 PyType_GenericAlloc, /* tp_alloc */
6845 PyType_GenericNew, /* tp_new */ 6850 PyType_GenericNew, /* tp_new */
6846 PyObject_GC_Del, /* tp_free */ 6851 PyObject_GC_Del, /* tp_free */
6847 }; 6852 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+