Mercurial > cpython-lru_cache-weakref
annotate Modules/_weakref.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 | 78ec18f5cb45 |
| children |
| rev | line source |
|---|---|
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1 #include "Python.h" |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
2 |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
3 |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
4 #define GET_WEAKREFS_LISTPTR(o) \ |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
5 ((PyWeakReference **) PyObject_GET_WEAKREFS_LISTPTR(o)) |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
6 |
|
86465
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
7 /*[clinic] |
|
87470
78ec18f5cb45
Issue #19674: inspect.signature() now produces a correct signature
Larry Hastings <larry@hastings.org>
parents:
87466
diff
changeset
|
8 module _weakref |
|
78ec18f5cb45
Issue #19674: inspect.signature() now produces a correct signature
Larry Hastings <larry@hastings.org>
parents:
87466
diff
changeset
|
9 [clinic]*/ |
|
78ec18f5cb45
Issue #19674: inspect.signature() now produces a correct signature
Larry Hastings <larry@hastings.org>
parents:
87466
diff
changeset
|
10 /*[clinic checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
11 |
|
87470
78ec18f5cb45
Issue #19674: inspect.signature() now produces a correct signature
Larry Hastings <larry@hastings.org>
parents:
87466
diff
changeset
|
12 /*[clinic] |
|
86465
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
13 |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
14 _weakref.getweakrefcount -> Py_ssize_t |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
15 |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
16 object: object |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
17 / |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
18 |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
19 Return the number of weak references to 'object'. |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
20 [clinic]*/ |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
21 |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
22 PyDoc_STRVAR(_weakref_getweakrefcount__doc__, |
|
87470
78ec18f5cb45
Issue #19674: inspect.signature() now produces a correct signature
Larry Hastings <larry@hastings.org>
parents:
87466
diff
changeset
|
23 "getweakrefcount(object)\n" |
|
78ec18f5cb45
Issue #19674: inspect.signature() now produces a correct signature
Larry Hastings <larry@hastings.org>
parents:
87466
diff
changeset
|
24 "Return the number of weak references to \'object\'."); |
|
86465
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
25 |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
26 #define _WEAKREF_GETWEAKREFCOUNT_METHODDEF \ |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
27 {"getweakrefcount", (PyCFunction)_weakref_getweakrefcount, METH_O, _weakref_getweakrefcount__doc__}, |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
28 |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
29 static Py_ssize_t |
|
87466
760ccd78e874
Issue #19730: Argument Clinic now supports all the existing PyArg
Larry Hastings <larry@hastings.org>
parents:
87245
diff
changeset
|
30 _weakref_getweakrefcount_impl(PyModuleDef *module, PyObject *object); |
|
16659
deec6fa80471
Move docstrings out of function table to constants defined near the
Fred Drake <fdrake@acm.org>
parents:
16434
diff
changeset
|
31 |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
32 static PyObject * |
|
87466
760ccd78e874
Issue #19730: Argument Clinic now supports all the existing PyArg
Larry Hastings <larry@hastings.org>
parents:
87245
diff
changeset
|
33 _weakref_getweakrefcount(PyModuleDef *module, PyObject *object) |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
34 { |
|
86465
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
35 PyObject *return_value = NULL; |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
36 Py_ssize_t _return_value; |
|
87245
64c853a88a10
Argument Clinic: rename "self" to "module" for module-level functions.
Larry Hastings <larry@hastings.org>
parents:
86465
diff
changeset
|
37 _return_value = _weakref_getweakrefcount_impl(module, object); |
|
86465
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
38 if ((_return_value == -1) && PyErr_Occurred()) |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
39 goto exit; |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
40 return_value = PyLong_FromSsize_t(_return_value); |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
41 |
|
86465
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
42 exit: |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
43 return return_value; |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
44 } |
|
19306
a7bbac69c8ef
Use METH_O where possible (two functions). This does not lead to real
Fred Drake <fdrake@acm.org>
parents:
17670
diff
changeset
|
45 |
|
86465
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
46 static Py_ssize_t |
|
87466
760ccd78e874
Issue #19730: Argument Clinic now supports all the existing PyArg
Larry Hastings <larry@hastings.org>
parents:
87245
diff
changeset
|
47 _weakref_getweakrefcount_impl(PyModuleDef *module, PyObject *object) |
|
87470
78ec18f5cb45
Issue #19674: inspect.signature() now produces a correct signature
Larry Hastings <larry@hastings.org>
parents:
87466
diff
changeset
|
48 /*[clinic checksum: 436e8fbe0297434375f039d8c2d9fc3a9bbe773c]*/ |
|
86465
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
49 { |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
50 PyWeakReference **list; |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
51 |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
52 if (!PyType_SUPPORTS_WEAKREFS(Py_TYPE(object))) |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
53 return 0; |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
54 |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
55 list = GET_WEAKREFS_LISTPTR(object); |
|
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
56 return _PyWeakref_GetWeakrefCount(*list); |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
57 } |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
58 |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
59 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
20634
diff
changeset
|
60 PyDoc_STRVAR(weakref_getweakrefs__doc__, |
|
16659
deec6fa80471
Move docstrings out of function table to constants defined near the
Fred Drake <fdrake@acm.org>
parents:
16434
diff
changeset
|
61 "getweakrefs(object) -- return a list of all weak reference objects\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
20634
diff
changeset
|
62 "that point to 'object'."); |
|
16659
deec6fa80471
Move docstrings out of function table to constants defined near the
Fred Drake <fdrake@acm.org>
parents:
16434
diff
changeset
|
63 |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
64 static PyObject * |
|
19306
a7bbac69c8ef
Use METH_O where possible (two functions). This does not lead to real
Fred Drake <fdrake@acm.org>
parents:
17670
diff
changeset
|
65 weakref_getweakrefs(PyObject *self, PyObject *object) |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
66 { |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
67 PyObject *result = NULL; |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
68 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
69 if (PyType_SUPPORTS_WEAKREFS(Py_TYPE(object))) { |
|
19306
a7bbac69c8ef
Use METH_O where possible (two functions). This does not lead to real
Fred Drake <fdrake@acm.org>
parents:
17670
diff
changeset
|
70 PyWeakReference **list = GET_WEAKREFS_LISTPTR(object); |
|
39351
12ffed927a3d
_PyWeakref_GetWeakrefCount() now returns a Py_ssize_t instead of long.
Neal Norwitz <nnorwitz@gmail.com>
parents:
32472
diff
changeset
|
71 Py_ssize_t count = _PyWeakref_GetWeakrefCount(*list); |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
72 |
|
19306
a7bbac69c8ef
Use METH_O where possible (two functions). This does not lead to real
Fred Drake <fdrake@acm.org>
parents:
17670
diff
changeset
|
73 result = PyList_New(count); |
|
a7bbac69c8ef
Use METH_O where possible (two functions). This does not lead to real
Fred Drake <fdrake@acm.org>
parents:
17670
diff
changeset
|
74 if (result != NULL) { |
|
a7bbac69c8ef
Use METH_O where possible (two functions). This does not lead to real
Fred Drake <fdrake@acm.org>
parents:
17670
diff
changeset
|
75 PyWeakReference *current = *list; |
|
39351
12ffed927a3d
_PyWeakref_GetWeakrefCount() now returns a Py_ssize_t instead of long.
Neal Norwitz <nnorwitz@gmail.com>
parents:
32472
diff
changeset
|
76 Py_ssize_t i; |
|
19306
a7bbac69c8ef
Use METH_O where possible (two functions). This does not lead to real
Fred Drake <fdrake@acm.org>
parents:
17670
diff
changeset
|
77 for (i = 0; i < count; ++i) { |
|
a7bbac69c8ef
Use METH_O where possible (two functions). This does not lead to real
Fred Drake <fdrake@acm.org>
parents:
17670
diff
changeset
|
78 PyList_SET_ITEM(result, i, (PyObject *) current); |
|
a7bbac69c8ef
Use METH_O where possible (two functions). This does not lead to real
Fred Drake <fdrake@acm.org>
parents:
17670
diff
changeset
|
79 Py_INCREF(current); |
|
a7bbac69c8ef
Use METH_O where possible (two functions). This does not lead to real
Fred Drake <fdrake@acm.org>
parents:
17670
diff
changeset
|
80 current = current->wr_next; |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
81 } |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
82 } |
|
19306
a7bbac69c8ef
Use METH_O where possible (two functions). This does not lead to real
Fred Drake <fdrake@acm.org>
parents:
17670
diff
changeset
|
83 } |
|
a7bbac69c8ef
Use METH_O where possible (two functions). This does not lead to real
Fred Drake <fdrake@acm.org>
parents:
17670
diff
changeset
|
84 else { |
|
a7bbac69c8ef
Use METH_O where possible (two functions). This does not lead to real
Fred Drake <fdrake@acm.org>
parents:
17670
diff
changeset
|
85 result = PyList_New(0); |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
86 } |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
87 return result; |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
88 } |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
89 |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
90 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
20634
diff
changeset
|
91 PyDoc_STRVAR(weakref_proxy__doc__, |
|
16659
deec6fa80471
Move docstrings out of function table to constants defined near the
Fred Drake <fdrake@acm.org>
parents:
16434
diff
changeset
|
92 "proxy(object[, callback]) -- create a proxy object that weakly\n" |
|
deec6fa80471
Move docstrings out of function table to constants defined near the
Fred Drake <fdrake@acm.org>
parents:
16434
diff
changeset
|
93 "references 'object'. 'callback', if given, is called with a\n" |
|
24503
4897e29e19cc
Fix ref(), proxy() docstrings, based on comments from David Abrahams.
Fred Drake <fdrake@acm.org>
parents:
24471
diff
changeset
|
94 "reference to the proxy when 'object' is about to be finalized."); |
|
16659
deec6fa80471
Move docstrings out of function table to constants defined near the
Fred Drake <fdrake@acm.org>
parents:
16434
diff
changeset
|
95 |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
96 static PyObject * |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
97 weakref_proxy(PyObject *self, PyObject *args) |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
98 { |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
99 PyObject *object; |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
100 PyObject *callback = NULL; |
|
20285
ccb7abc714ed
Adjust the _weakref module to use the public API for the weak reference
Fred Drake <fdrake@acm.org>
parents:
19581
diff
changeset
|
101 PyObject *result = NULL; |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
102 |
|
20634
899bebc89047
Convert the ref() and proxy() implementations to use the new
Fred Drake <fdrake@acm.org>
parents:
20285
diff
changeset
|
103 if (PyArg_UnpackTuple(args, "proxy", 1, 2, &object, &callback)) { |
|
20285
ccb7abc714ed
Adjust the _weakref module to use the public API for the weak reference
Fred Drake <fdrake@acm.org>
parents:
19581
diff
changeset
|
104 result = PyWeakref_NewProxy(object, callback); |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
105 } |
|
20285
ccb7abc714ed
Adjust the _weakref module to use the public API for the weak reference
Fred Drake <fdrake@acm.org>
parents:
19581
diff
changeset
|
106 return result; |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
107 } |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
108 |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
109 |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
110 static PyMethodDef |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
111 weakref_functions[] = { |
|
86465
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
112 _WEAKREF_GETWEAKREFCOUNT_METHODDEF |
|
19306
a7bbac69c8ef
Use METH_O where possible (two functions). This does not lead to real
Fred Drake <fdrake@acm.org>
parents:
17670
diff
changeset
|
113 {"getweakrefs", weakref_getweakrefs, METH_O, |
|
16659
deec6fa80471
Move docstrings out of function table to constants defined near the
Fred Drake <fdrake@acm.org>
parents:
16434
diff
changeset
|
114 weakref_getweakrefs__doc__}, |
|
deec6fa80471
Move docstrings out of function table to constants defined near the
Fred Drake <fdrake@acm.org>
parents:
16434
diff
changeset
|
115 {"proxy", weakref_proxy, METH_VARARGS, |
|
deec6fa80471
Move docstrings out of function table to constants defined near the
Fred Drake <fdrake@acm.org>
parents:
16434
diff
changeset
|
116 weakref_proxy__doc__}, |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
117 {NULL, NULL, 0, NULL} |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
118 }; |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
119 |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
120 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
121 static struct PyModuleDef weakrefmodule = { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
122 PyModuleDef_HEAD_INIT, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
123 "_weakref", |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
124 "Weak-reference support module.", |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
125 -1, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
126 weakref_functions, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
127 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
128 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
129 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
130 NULL |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
131 }; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
132 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
23832
diff
changeset
|
133 PyMODINIT_FUNC |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
134 PyInit__weakref(void) |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
135 { |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
136 PyObject *m; |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
137 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
138 m = PyModule_Create(&weakrefmodule); |
|
86465
8fde1a2c94dc
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
Larry Hastings <larry@hastings.org>
parents:
47580
diff
changeset
|
139 |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
140 if (m != NULL) { |
|
20285
ccb7abc714ed
Adjust the _weakref module to use the public API for the weak reference
Fred Drake <fdrake@acm.org>
parents:
19581
diff
changeset
|
141 Py_INCREF(&_PyWeakref_RefType); |
|
32472
4383db77b19a
Make weak references subclassable:
Fred Drake <fdrake@acm.org>
parents:
24503
diff
changeset
|
142 PyModule_AddObject(m, "ref", |
|
4383db77b19a
Make weak references subclassable:
Fred Drake <fdrake@acm.org>
parents:
24503
diff
changeset
|
143 (PyObject *) &_PyWeakref_RefType); |
|
4383db77b19a
Make weak references subclassable:
Fred Drake <fdrake@acm.org>
parents:
24503
diff
changeset
|
144 Py_INCREF(&_PyWeakref_RefType); |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
145 PyModule_AddObject(m, "ReferenceType", |
|
20285
ccb7abc714ed
Adjust the _weakref module to use the public API for the weak reference
Fred Drake <fdrake@acm.org>
parents:
19581
diff
changeset
|
146 (PyObject *) &_PyWeakref_RefType); |
|
ccb7abc714ed
Adjust the _weakref module to use the public API for the weak reference
Fred Drake <fdrake@acm.org>
parents:
19581
diff
changeset
|
147 Py_INCREF(&_PyWeakref_ProxyType); |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
148 PyModule_AddObject(m, "ProxyType", |
|
20285
ccb7abc714ed
Adjust the _weakref module to use the public API for the weak reference
Fred Drake <fdrake@acm.org>
parents:
19581
diff
changeset
|
149 (PyObject *) &_PyWeakref_ProxyType); |
|
ccb7abc714ed
Adjust the _weakref module to use the public API for the weak reference
Fred Drake <fdrake@acm.org>
parents:
19581
diff
changeset
|
150 Py_INCREF(&_PyWeakref_CallableProxyType); |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
151 PyModule_AddObject(m, "CallableProxyType", |
|
20285
ccb7abc714ed
Adjust the _weakref module to use the public API for the weak reference
Fred Drake <fdrake@acm.org>
parents:
19581
diff
changeset
|
152 (PyObject *) &_PyWeakref_CallableProxyType); |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
153 } |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
44351
diff
changeset
|
154 return m; |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
155 } |
