Mercurial > cpython-lru_cache-weakref
annotate Python/frozen.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 | a06fc2c2342a |
| children |
| rev | line source |
|---|---|
|
3621
f158edccc72c
grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents:
2896
diff
changeset
|
1 |
|
f158edccc72c
grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents:
2896
diff
changeset
|
2 /* Dummy frozen modules initializer */ |
|
f158edccc72c
grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents:
2896
diff
changeset
|
3 |
|
f158edccc72c
grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents:
2896
diff
changeset
|
4 #include "Python.h" |
|
76303
2dd046be2c88
Issue #2377: Make importlib the implementation of __import__().
Brett Cannon <brett@python.org>
parents:
70152
diff
changeset
|
5 #include "importlib.h" |
|
3621
f158edccc72c
grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents:
2896
diff
changeset
|
6 |
| 2896 | 7 /* In order to test the support for frozen modules, by default we |
| 8 define a single frozen module, __hello__. Loading it will print | |
| 9 some famous words... */ | |
| 10 | |
|
20526
1f3c1e831f21
Fix the frozen bytecode for __hello__ (betcha didn't know that existed
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
11 /* To regenerate this data after the bytecode or marshal format has changed, |
|
43835
a2213060d9dd
Fix for refleak tests through regrtest.py -R:: bug #1414
Christian Heimes <christian@cheimes.de>
parents:
43569
diff
changeset
|
12 go to ../Tools/freeze/ and freeze the flag.py file; then copy and paste |
|
20526
1f3c1e831f21
Fix the frozen bytecode for __hello__ (betcha didn't know that existed
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
13 the appropriate bytes from M___main__.c. */ |
|
1f3c1e831f21
Fix the frozen bytecode for __hello__ (betcha didn't know that existed
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
14 |
|
40452
50ce56b24cbe
Oops, re-add 'static' qualifier.
Thomas Wouters <thomas@python.org>
parents:
40451
diff
changeset
|
15 static unsigned char M___hello__[] = { |
|
70152
44fd95cead7b
Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
16 99,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0, |
|
44fd95cead7b
Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
17 0,64,0,0,0,115,20,0,0,0,100,2,0,90,1,0, |
|
44fd95cead7b
Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
18 101,2,0,100,0,0,131,1,0,1,100,1,0,83,40,3, |
|
44fd95cead7b
Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
19 0,0,0,117,12,0,0,0,72,101,108,108,111,32,119,111, |
|
44fd95cead7b
Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
20 114,108,100,33,78,84,40,3,0,0,0,117,4,0,0,0, |
|
44fd95cead7b
Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
21 84,114,117,101,117,11,0,0,0,105,110,105,116,105,97,108, |
|
44fd95cead7b
Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
22 105,122,101,100,117,5,0,0,0,112,114,105,110,116,40,0, |
|
44fd95cead7b
Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
23 0,0,0,40,0,0,0,0,40,0,0,0,0,117,7,0, |
|
44fd95cead7b
Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
24 0,0,102,108,97,103,46,112,121,117,8,0,0,0,60,109, |
|
44fd95cead7b
Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
25 111,100,117,108,101,62,1,0,0,0,115,2,0,0,0,6, |
|
44fd95cead7b
Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
26 1, |
| 2896 | 27 }; |
| 28 | |
|
20528
cb334a8c8dd2
Squash compiler wng about signed/unsigned mismatch.
Tim Peters <tim.peters@gmail.com>
parents:
20526
diff
changeset
|
29 #define SIZE (int)sizeof(M___hello__) |
|
20526
1f3c1e831f21
Fix the frozen bytecode for __hello__ (betcha didn't know that existed
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
30 |
|
82649
a06fc2c2342a
make some freezing related stuff const
Benjamin Peterson <benjamin@python.org>
parents:
76303
diff
changeset
|
31 static const struct _frozen _PyImport_FrozenModules[] = { |
|
76303
2dd046be2c88
Issue #2377: Make importlib the implementation of __import__().
Brett Cannon <brett@python.org>
parents:
70152
diff
changeset
|
32 /* importlib */ |
|
2dd046be2c88
Issue #2377: Make importlib the implementation of __import__().
Brett Cannon <brett@python.org>
parents:
70152
diff
changeset
|
33 {"_frozen_importlib", _Py_M__importlib, (int)sizeof(_Py_M__importlib)}, |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
43835
diff
changeset
|
34 /* Test module */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
43835
diff
changeset
|
35 {"__hello__", M___hello__, SIZE}, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
43835
diff
changeset
|
36 /* Test package (negative size indicates package-ness) */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
43835
diff
changeset
|
37 {"__phello__", M___hello__, -SIZE}, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
43835
diff
changeset
|
38 {"__phello__.spam", M___hello__, SIZE}, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
43835
diff
changeset
|
39 {0, 0, 0} /* sentinel */ |
| 2896 | 40 }; |
|
3684
606c38535f30
New style interface via pointer variable.
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
41 |
|
606c38535f30
New style interface via pointer variable.
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
42 /* Embedding apps may change this pointer to point to their favorite |
|
606c38535f30
New style interface via pointer variable.
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
43 collection of frozen modules: */ |
|
606c38535f30
New style interface via pointer variable.
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
44 |
|
82649
a06fc2c2342a
make some freezing related stuff const
Benjamin Peterson <benjamin@python.org>
parents:
76303
diff
changeset
|
45 const struct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules; |
