Mercurial > cpython-lru_cache-weakref
annotate PC/example_nt/example.c @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | cab14be0ada1 |
| children |
| rev | line source |
|---|---|
|
4223
180c1d3dac41
A directory with a working example of how to build an extension.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 #include "Python.h" |
|
180c1d3dac41
A directory with a working example of how to build an extension.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
180c1d3dac41
A directory with a working example of how to build an extension.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 static PyObject * |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
4223
diff
changeset
|
4 ex_foo(PyObject *self, PyObject *args) |
|
4223
180c1d3dac41
A directory with a working example of how to build an extension.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
6 printf("Hello, world\n"); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
7 Py_INCREF(Py_None); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
8 return Py_None; |
|
4223
180c1d3dac41
A directory with a working example of how to build an extension.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 } |
|
180c1d3dac41
A directory with a working example of how to build an extension.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 |
|
180c1d3dac41
A directory with a working example of how to build an extension.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 static PyMethodDef example_methods[] = { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
12 {"foo", ex_foo, METH_VARARGS, "foo() doc string"}, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
13 {NULL, NULL} |
|
4223
180c1d3dac41
A directory with a working example of how to build an extension.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 }; |
|
180c1d3dac41
A directory with a working example of how to build an extension.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 |
|
50557
bd0e361bd642
Merged revisions 68169-68170 via svnmerge from
Georg Brandl <georg@python.org>
parents:
38669
diff
changeset
|
16 static struct PyModuleDef examplemodule = { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
17 PyModuleDef_HEAD_INIT, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
18 "example", |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
19 "example module doc string", |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
20 -1, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
21 example_methods, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
22 NULL, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
23 NULL, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
24 NULL, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
25 NULL |
|
50557
bd0e361bd642
Merged revisions 68169-68170 via svnmerge from
Georg Brandl <georg@python.org>
parents:
38669
diff
changeset
|
26 }; |
|
bd0e361bd642
Merged revisions 68169-68170 via svnmerge from
Georg Brandl <georg@python.org>
parents:
38669
diff
changeset
|
27 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
13660
diff
changeset
|
28 PyMODINIT_FUNC |
|
50557
bd0e361bd642
Merged revisions 68169-68170 via svnmerge from
Georg Brandl <georg@python.org>
parents:
38669
diff
changeset
|
29 PyInit_example(void) |
|
4223
180c1d3dac41
A directory with a working example of how to build an extension.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50557
diff
changeset
|
31 return PyModule_Create(&examplemodule); |
|
4223
180c1d3dac41
A directory with a working example of how to build an extension.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 } |
