Mercurial > cpython-lru_cache-weakref
annotate Objects/cellobject.c @ 39042:c02fa187e0f4 legacy-trunk
Part of SF patch #1484695. This removes dead code. The chksum was
already verified in .frombuf() on the lines above. If there was
a problem an exception is raised, so there was no way this condition
could have been true.
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Mon, 10 Jul 2006 00:23:17 +0000 |
| parents | 1392561d5dd7 |
| children | 4cf9bb9cef91 6620a510e9a9 |
| rev | line source |
|---|---|
| 16256 | 1 /* Cell object implementation */ |
| 2 | |
| 3 #include "Python.h" | |
| 4 | |
| 5 PyObject * | |
| 6 PyCell_New(PyObject *obj) | |
| 7 { | |
| 8 PyCellObject *op; | |
| 9 | |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
10 op = (PyCellObject *)PyObject_GC_New(PyCellObject, &PyCell_Type); |
|
38969
1392561d5dd7
Another problem reported by Coverity. Backport candidate.
Neal Norwitz <nnorwitz@gmail.com>
parents:
37756
diff
changeset
|
11 if (op == NULL) |
|
1392561d5dd7
Another problem reported by Coverity. Backport candidate.
Neal Norwitz <nnorwitz@gmail.com>
parents:
37756
diff
changeset
|
12 return NULL; |
| 16256 | 13 op->ob_ref = obj; |
| 14 Py_XINCREF(obj); | |
| 15 | |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
16 _PyObject_GC_TRACK(op); |
| 16256 | 17 return (PyObject *)op; |
| 18 } | |
| 19 | |
| 20 PyObject * | |
| 21 PyCell_Get(PyObject *op) | |
| 22 { | |
| 23 if (!PyCell_Check(op)) { | |
| 24 PyErr_BadInternalCall(); | |
| 25 return NULL; | |
| 26 } | |
| 27 Py_XINCREF(((PyCellObject*)op)->ob_ref); | |
| 28 return PyCell_GET(op); | |
| 29 } | |
| 30 | |
| 31 int | |
| 32 PyCell_Set(PyObject *op, PyObject *obj) | |
| 33 { | |
| 34 if (!PyCell_Check(op)) { | |
| 35 PyErr_BadInternalCall(); | |
| 36 return -1; | |
| 37 } | |
| 38 Py_XDECREF(((PyCellObject*)op)->ob_ref); | |
| 39 Py_XINCREF(obj); | |
| 40 PyCell_SET(op, obj); | |
| 41 return 0; | |
| 42 } | |
| 43 | |
| 44 static void | |
| 45 cell_dealloc(PyCellObject *op) | |
| 46 { | |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
47 _PyObject_GC_UNTRACK(op); |
| 16256 | 48 Py_XDECREF(op->ob_ref); |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
49 PyObject_GC_Del(op); |
| 16256 | 50 } |
| 51 | |
| 52 static int | |
| 53 cell_compare(PyCellObject *a, PyCellObject *b) | |
| 54 { | |
| 55 if (a->ob_ref == NULL) { | |
| 56 if (b->ob_ref == NULL) | |
| 57 return 0; | |
| 58 return -1; | |
| 59 } else if (b->ob_ref == NULL) | |
| 60 return 1; | |
| 61 return PyObject_Compare(a->ob_ref, b->ob_ref); | |
| 62 } | |
| 63 | |
| 64 static PyObject * | |
| 65 cell_repr(PyCellObject *op) | |
| 66 { | |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
18933
diff
changeset
|
67 if (op->ob_ref == NULL) |
|
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
18933
diff
changeset
|
68 return PyString_FromFormat("<cell at %p: empty>", op); |
| 16256 | 69 |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
18933
diff
changeset
|
70 return PyString_FromFormat("<cell at %p: %.80s object at %p>", |
|
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
18933
diff
changeset
|
71 op, op->ob_ref->ob_type->tp_name, |
|
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
18933
diff
changeset
|
72 op->ob_ref); |
| 16256 | 73 } |
| 74 | |
| 75 static int | |
| 76 cell_traverse(PyCellObject *op, visitproc visit, void *arg) | |
| 77 { | |
|
37756
7b2e436a4a21
Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents:
37748
diff
changeset
|
78 Py_VISIT(op->ob_ref); |
| 16256 | 79 return 0; |
| 80 } | |
| 81 | |
| 82 static int | |
| 83 cell_clear(PyCellObject *op) | |
| 84 { | |
|
37748
d1547426ab61
Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents:
37073
diff
changeset
|
85 Py_CLEAR(op->ob_ref); |
| 16256 | 86 return 0; |
| 87 } | |
| 88 | |
|
37073
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
89 static PyObject * |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
90 cell_get_contents(PyCellObject *op, void *closure) |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
91 { |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
92 Py_XINCREF(op->ob_ref); |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
93 return op->ob_ref; |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
94 } |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
95 |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
96 static PyGetSetDef cell_getsetlist[] = { |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
97 {"cell_contents", (getter)cell_get_contents, NULL}, |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
98 {NULL} /* sentinel */ |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
99 }; |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
100 |
| 16256 | 101 PyTypeObject PyCell_Type = { |
| 102 PyObject_HEAD_INIT(&PyType_Type) | |
| 103 0, | |
| 104 "cell", | |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
105 sizeof(PyCellObject), |
| 16256 | 106 0, |
| 107 (destructor)cell_dealloc, /* tp_dealloc */ | |
| 108 0, /* tp_print */ | |
| 109 0, /* tp_getattr */ | |
| 110 0, /* tp_setattr */ | |
| 111 (cmpfunc)cell_compare, /* tp_compare */ | |
| 112 (reprfunc)cell_repr, /* tp_repr */ | |
| 113 0, /* tp_as_number */ | |
| 114 0, /* tp_as_sequence */ | |
| 115 0, /* tp_as_mapping */ | |
| 116 0, /* tp_hash */ | |
| 117 0, /* tp_call */ | |
| 118 0, /* tp_str */ | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17034
diff
changeset
|
119 PyObject_GenericGetAttr, /* tp_getattro */ |
| 16256 | 120 0, /* tp_setattro */ |
| 121 0, /* tp_as_buffer */ | |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
122 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ |
| 16256 | 123 0, /* tp_doc */ |
| 124 (traverseproc)cell_traverse, /* tp_traverse */ | |
| 125 (inquiry)cell_clear, /* tp_clear */ | |
|
37073
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
126 0, /* tp_richcompare */ |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
127 0, /* tp_weaklistoffset */ |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
128 0, /* tp_iter */ |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
129 0, /* tp_iternext */ |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
130 0, /* tp_methods */ |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
131 0, /* tp_members */ |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
132 cell_getsetlist, /* tp_getset */ |
| 16256 | 133 }; |
