• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 typedef struct _PyWeakReference PyWeakReference;
10 
11 PyAPI_DATA(PyTypeObject) _PyWeakref_RefType;
12 PyAPI_DATA(PyTypeObject) _PyWeakref_ProxyType;
13 PyAPI_DATA(PyTypeObject) _PyWeakref_CallableProxyType;
14 
15 #define PyWeakref_CheckRef(op) PyObject_TypeCheck((op), &_PyWeakref_RefType)
16 #define PyWeakref_CheckRefExact(op) \
17         Py_IS_TYPE((op), &_PyWeakref_RefType)
18 #define PyWeakref_CheckProxy(op) \
19         (Py_IS_TYPE((op), &_PyWeakref_ProxyType) \
20          || Py_IS_TYPE((op), &_PyWeakref_CallableProxyType))
21 
22 #define PyWeakref_Check(op) \
23         (PyWeakref_CheckRef(op) || PyWeakref_CheckProxy(op))
24 
25 
26 PyAPI_FUNC(PyObject *) PyWeakref_NewRef(PyObject *ob,
27                                         PyObject *callback);
28 PyAPI_FUNC(PyObject *) PyWeakref_NewProxy(PyObject *ob,
29                                           PyObject *callback);
30 Py_DEPRECATED(3.13) PyAPI_FUNC(PyObject *) PyWeakref_GetObject(PyObject *ref);
31 
32 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030D0000
33 PyAPI_FUNC(int) PyWeakref_GetRef(PyObject *ref, PyObject **pobj);
34 #endif
35 
36 
37 #ifndef Py_LIMITED_API
38 #  define Py_CPYTHON_WEAKREFOBJECT_H
39 #  include "cpython/weakrefobject.h"
40 #  undef Py_CPYTHON_WEAKREFOBJECT_H
41 #endif
42 
43 #ifdef __cplusplus
44 }
45 #endif
46 #endif /* !Py_WEAKREFOBJECT_H */
47