Mercurial > cpython-lru_cache-weakref
annotate Objects/cellobject.c @ 44825:ef859cd754a7 legacy-trunk
Fixed a wrong assumption in configure.in and Include/pyport.h. The is finite function is not called isfinite() but finite(). Sorry, my fault. :)
| author | Christian Heimes <christian@cheimes.de> |
|---|---|
| date | Sun, 20 Jan 2008 14:28:28 +0000 |
| parents | 2183d72abfaa |
| children | 270fcd2e9782 |
| 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 { |
|
44010
2183d72abfaa
Issue #1445: Fix a SystemError when accessing the ``cell_contents``
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42333
diff
changeset
|
92 if (op->ob_ref == NULL) |
|
2183d72abfaa
Issue #1445: Fix a SystemError when accessing the ``cell_contents``
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42333
diff
changeset
|
93 { |
|
2183d72abfaa
Issue #1445: Fix a SystemError when accessing the ``cell_contents``
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42333
diff
changeset
|
94 PyErr_SetString(PyExc_ValueError, "Cell is empty"); |
|
2183d72abfaa
Issue #1445: Fix a SystemError when accessing the ``cell_contents``
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42333
diff
changeset
|
95 return NULL; |
|
2183d72abfaa
Issue #1445: Fix a SystemError when accessing the ``cell_contents``
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42333
diff
changeset
|
96 } |
|
2183d72abfaa
Issue #1445: Fix a SystemError when accessing the ``cell_contents``
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42333
diff
changeset
|
97 Py_INCREF(op->ob_ref); |
|
37073
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
98 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
|
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 |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
101 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
|
102 {"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
|
103 {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
|
104 }; |
|
81d0e93208d9
Previously, Python code had no easy way to access the contents of a
Georg Brandl <georg@python.org>
parents:
19581
diff
changeset
|
105 |
| 16256 | 106 PyTypeObject PyCell_Type = { |
|
42333
6620a510e9a9
PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents:
38969
diff
changeset
|
107 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
| 16256 | 108 "cell", |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
109 sizeof(PyCellObject), |
| 16256 | 110 0, |
| 111 (destructor)cell_dealloc, /* tp_dealloc */ | |
| 112 0, /* tp_print */ | |
| 113 0, /* tp_getattr */ | |
| 114 0, /* tp_setattr */ | |
| 115 (cmpfunc)cell_compare, /* tp_compare */ | |
| 116 (reprfunc)cell_repr, /* tp_repr */ | |
| 117 0, /* tp_as_number */ | |
| 118 0, /* tp_as_sequence */ | |
| 119 0, /* tp_as_mapping */ | |
| 120 0, /* tp_hash */ | |
| 121 0, /* tp_call */ | |
| 122 0, /* tp_str */ | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17034
diff
changeset
|
123 PyObject_GenericGetAttr, /* tp_getattro */ |
| 16256 | 124 0, /* tp_setattro */ |
| 125 0, /* tp_as_buffer */ | |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
126 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ |
| 16256 | 127 0, /* tp_doc */ |
| 128 (traverseproc)cell_traverse, /* tp_traverse */ | |
| 129 (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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 cell_getsetlist, /* tp_getset */ |
| 16256 | 137 }; |
