Mercurial > cpython-lru_cache-weakref
annotate Objects/cellobject.c @ 48416:fb02fedfe647
Merged revisions 64677 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r64677 | brett.cannon | 2008-07-02 14:52:42 -0700 (Wed, 02 Jul 2008) | 2 lines
Revert r64673 and instead just change the file encoding.
........
| author | Brett Cannon <bcannon@gmail.com> |
|---|---|
| date | Wed, 02 Jul 2008 22:06:12 +0000 |
| parents | 1657f0acca78 |
| children | e9675d72e3e3 |
| 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); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
11 if (op == NULL) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
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 { | |
|
45377
1872bd6cf4b4
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60873 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44025
diff
changeset
|
34 PyObject* oldobj; |
| 16256 | 35 if (!PyCell_Check(op)) { |
| 36 PyErr_BadInternalCall(); | |
| 37 return -1; | |
| 38 } | |
|
45377
1872bd6cf4b4
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60873 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44025
diff
changeset
|
39 oldobj = PyCell_GET(op); |
| 16256 | 40 Py_XINCREF(obj); |
| 41 PyCell_SET(op, obj); | |
|
45377
1872bd6cf4b4
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60873 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44025
diff
changeset
|
42 Py_XDECREF(oldobj); |
| 16256 | 43 return 0; |
| 44 } | |
| 45 | |
| 46 static void | |
| 47 cell_dealloc(PyCellObject *op) | |
| 48 { | |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
49 _PyObject_GC_UNTRACK(op); |
| 16256 | 50 Py_XDECREF(op->ob_ref); |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
51 PyObject_GC_Del(op); |
| 16256 | 52 } |
| 53 | |
|
45931
1657f0acca78
Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45377
diff
changeset
|
54 static int |
|
1657f0acca78
Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45377
diff
changeset
|
55 cell_compare(PyCellObject *a, PyCellObject *b) |
|
1657f0acca78
Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45377
diff
changeset
|
56 { |
|
1657f0acca78
Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45377
diff
changeset
|
57 if (a->ob_ref == NULL) { |
|
1657f0acca78
Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45377
diff
changeset
|
58 if (b->ob_ref == NULL) |
|
1657f0acca78
Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45377
diff
changeset
|
59 return 0; |
|
1657f0acca78
Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45377
diff
changeset
|
60 return -1; |
|
1657f0acca78
Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45377
diff
changeset
|
61 } else if (b->ob_ref == NULL) |
|
1657f0acca78
Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45377
diff
changeset
|
62 return 1; |
|
1657f0acca78
Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45377
diff
changeset
|
63 return PyObject_Compare(a->ob_ref, b->ob_ref); |
|
1657f0acca78
Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45377
diff
changeset
|
64 } |
|
1657f0acca78
Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45377
diff
changeset
|
65 |
| 16256 | 66 static PyObject * |
| 67 cell_repr(PyCellObject *op) | |
| 68 { | |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
18933
diff
changeset
|
69 if (op->ob_ref == NULL) |
|
41769
b29d71d43c80
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents:
39644
diff
changeset
|
70 return PyUnicode_FromFormat("<cell at %p: empty>", op); |
| 16256 | 71 |
|
41769
b29d71d43c80
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents:
39644
diff
changeset
|
72 return PyUnicode_FromFormat("<cell at %p: %.80s object at %p>", |
|
19476
0e70df98424e
repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents:
18933
diff
changeset
|
73 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
|
74 op->ob_ref); |
| 16256 | 75 } |
| 76 | |
| 77 static int | |
| 78 cell_traverse(PyCellObject *op, visitproc visit, void *arg) | |
| 79 { | |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
80 Py_VISIT(op->ob_ref); |
| 16256 | 81 return 0; |
| 82 } | |
| 83 | |
| 84 static int | |
| 85 cell_clear(PyCellObject *op) | |
| 86 { | |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
87 Py_CLEAR(op->ob_ref); |
| 16256 | 88 return 0; |
| 89 } | |
| 90 | |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
91 static PyObject * |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
92 cell_get_contents(PyCellObject *op, void *closure) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
93 { |
|
44025
ebc7389297d6
Merged revisions 59107-59186 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
94 if (op->ob_ref == NULL) |
|
ebc7389297d6
Merged revisions 59107-59186 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
95 { |
|
ebc7389297d6
Merged revisions 59107-59186 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
96 PyErr_SetString(PyExc_ValueError, "Cell is empty"); |
|
ebc7389297d6
Merged revisions 59107-59186 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
97 return NULL; |
|
ebc7389297d6
Merged revisions 59107-59186 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
98 } |
|
ebc7389297d6
Merged revisions 59107-59186 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
99 Py_INCREF(op->ob_ref); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
100 return op->ob_ref; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
101 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
102 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
103 static PyGetSetDef cell_getsetlist[] = { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
104 {"cell_contents", (getter)cell_get_contents, NULL}, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
105 {NULL} /* sentinel */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
106 }; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
107 |
| 16256 | 108 PyTypeObject PyCell_Type = { |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
41769
diff
changeset
|
109 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
| 16256 | 110 "cell", |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
111 sizeof(PyCellObject), |
| 16256 | 112 0, |
| 113 (destructor)cell_dealloc, /* tp_dealloc */ | |
| 114 0, /* tp_print */ | |
| 115 0, /* tp_getattr */ | |
| 116 0, /* tp_setattr */ | |
|
45931
1657f0acca78
Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45377
diff
changeset
|
117 (cmpfunc)cell_compare, /* tp_compare */ |
| 16256 | 118 (reprfunc)cell_repr, /* tp_repr */ |
| 119 0, /* tp_as_number */ | |
| 120 0, /* tp_as_sequence */ | |
| 121 0, /* tp_as_mapping */ | |
| 122 0, /* tp_hash */ | |
| 123 0, /* tp_call */ | |
| 124 0, /* tp_str */ | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17034
diff
changeset
|
125 PyObject_GenericGetAttr, /* tp_getattro */ |
| 16256 | 126 0, /* tp_setattro */ |
| 127 0, /* tp_as_buffer */ | |
|
19581
fd48a55ac364
Use new GC API.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19476
diff
changeset
|
128 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ |
| 16256 | 129 0, /* tp_doc */ |
| 130 (traverseproc)cell_traverse, /* tp_traverse */ | |
| 131 (inquiry)cell_clear, /* tp_clear */ | |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
132 0, /* tp_richcompare */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
133 0, /* tp_weaklistoffset */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
134 0, /* tp_iter */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
135 0, /* tp_iternext */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
136 0, /* tp_methods */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
137 0, /* tp_members */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
19581
diff
changeset
|
138 cell_getsetlist, /* tp_getset */ |
| 16256 | 139 }; |
