Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8844d52

Browse files
committed
The weak reference implementation, separated from the weakref module.
1 parent bb9fa21 commit 8844d52

2 files changed

Lines changed: 765 additions & 0 deletions

File tree

Include/weakrefobject.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* Weak references objects for Python. */
2+
3+
#ifndef Py_WEAKREFOBJECT_H
4+
#define Py_WEAKREFOBJECT_H
5+
#ifdef __cplusplus
6+
extern "C" {
7+
#endif
8+
9+
10+
typedef struct _PyWeakReference PyWeakReference;
11+
12+
struct _PyWeakReference {
13+
PyObject_HEAD
14+
PyObject *wr_object;
15+
PyObject *wr_callback;
16+
long hash;
17+
PyWeakReference *wr_prev;
18+
PyWeakReference *wr_next;
19+
};
20+
21+
extern DL_IMPORT(PyTypeObject) _PyWeakref_RefType;
22+
extern DL_IMPORT(PyTypeObject) _PyWeakref_ProxyType;
23+
extern DL_IMPORT(PyTypeObject) _PyWeakref_CallableProxyType;
24+
25+
extern DL_IMPORT(PyObject *) PyErr_ReferenceError;
26+
27+
#define PyWeakref_CheckRef(op) \
28+
((op)->ob_type == &_PyWeakref_RefType)
29+
#define PyWeakref_CheckProxy(op) \
30+
(((op)->ob_type == &_PyWeakref_ProxyType) || \
31+
((op)->ob_type == &_PyWeakref_CallableProxyType))
32+
#define PyWeakref_Check(op) \
33+
(PyWeakref_CheckRef(op) || PyWeakref_CheckProxy(op))
34+
35+
36+
extern DL_IMPORT(PyObject *) PyWeakref_NewRef(PyObject *ob,
37+
PyObject *callback);
38+
extern DL_IMPORT(PyObject *) PyWeakref_NewProxy(PyObject *ob,
39+
PyObject *callback);
40+
extern DL_IMPORT(PyObject *) PyWeakref_GetObject(PyObject *ref);
41+
42+
extern DL_IMPORT(long) _PyWeakref_GetWeakrefCount(PyWeakReference *head);
43+
44+
#define PyWeakref_GET_OBJECT(ref) (((PyWeakReference *)(ref))->wr_object)
45+
46+
47+
#ifdef __cplusplus
48+
}
49+
#endif
50+
#endif /* !Py_WEAKREFOBJECT_H */

0 commit comments

Comments
 (0)