_weakref.c.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*[clinic input]
  2. preserve
  3. [clinic start generated code]*/
  4. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5. # include "pycore_gc.h" // PyGC_Head
  6. # include "pycore_runtime.h" // _Py_ID()
  7. #endif
  8. PyDoc_STRVAR(_weakref_getweakrefcount__doc__,
  9. "getweakrefcount($module, object, /)\n"
  10. "--\n"
  11. "\n"
  12. "Return the number of weak references to \'object\'.");
  13. #define _WEAKREF_GETWEAKREFCOUNT_METHODDEF \
  14. {"getweakrefcount", (PyCFunction)_weakref_getweakrefcount, METH_O, _weakref_getweakrefcount__doc__},
  15. static Py_ssize_t
  16. _weakref_getweakrefcount_impl(PyObject *module, PyObject *object);
  17. static PyObject *
  18. _weakref_getweakrefcount(PyObject *module, PyObject *object)
  19. {
  20. PyObject *return_value = NULL;
  21. Py_ssize_t _return_value;
  22. _return_value = _weakref_getweakrefcount_impl(module, object);
  23. if ((_return_value == -1) && PyErr_Occurred()) {
  24. goto exit;
  25. }
  26. return_value = PyLong_FromSsize_t(_return_value);
  27. exit:
  28. return return_value;
  29. }
  30. PyDoc_STRVAR(_weakref__remove_dead_weakref__doc__,
  31. "_remove_dead_weakref($module, dct, key, /)\n"
  32. "--\n"
  33. "\n"
  34. "Atomically remove key from dict if it points to a dead weakref.");
  35. #define _WEAKREF__REMOVE_DEAD_WEAKREF_METHODDEF \
  36. {"_remove_dead_weakref", _PyCFunction_CAST(_weakref__remove_dead_weakref), METH_FASTCALL, _weakref__remove_dead_weakref__doc__},
  37. static PyObject *
  38. _weakref__remove_dead_weakref_impl(PyObject *module, PyObject *dct,
  39. PyObject *key);
  40. static PyObject *
  41. _weakref__remove_dead_weakref(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  42. {
  43. PyObject *return_value = NULL;
  44. PyObject *dct;
  45. PyObject *key;
  46. if (!_PyArg_CheckPositional("_remove_dead_weakref", nargs, 2, 2)) {
  47. goto exit;
  48. }
  49. if (!PyDict_Check(args[0])) {
  50. _PyArg_BadArgument("_remove_dead_weakref", "argument 1", "dict", args[0]);
  51. goto exit;
  52. }
  53. dct = args[0];
  54. key = args[1];
  55. return_value = _weakref__remove_dead_weakref_impl(module, dct, key);
  56. exit:
  57. return return_value;
  58. }
  59. PyDoc_STRVAR(_weakref_getweakrefs__doc__,
  60. "getweakrefs($module, object, /)\n"
  61. "--\n"
  62. "\n"
  63. "Return a list of all weak reference objects pointing to \'object\'.");
  64. #define _WEAKREF_GETWEAKREFS_METHODDEF \
  65. {"getweakrefs", (PyCFunction)_weakref_getweakrefs, METH_O, _weakref_getweakrefs__doc__},
  66. PyDoc_STRVAR(_weakref_proxy__doc__,
  67. "proxy($module, object, callback=None, /)\n"
  68. "--\n"
  69. "\n"
  70. "Create a proxy object that weakly references \'object\'.\n"
  71. "\n"
  72. "\'callback\', if given, is called with a reference to the\n"
  73. "proxy when \'object\' is about to be finalized.");
  74. #define _WEAKREF_PROXY_METHODDEF \
  75. {"proxy", _PyCFunction_CAST(_weakref_proxy), METH_FASTCALL, _weakref_proxy__doc__},
  76. static PyObject *
  77. _weakref_proxy_impl(PyObject *module, PyObject *object, PyObject *callback);
  78. static PyObject *
  79. _weakref_proxy(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  80. {
  81. PyObject *return_value = NULL;
  82. PyObject *object;
  83. PyObject *callback = NULL;
  84. if (!_PyArg_CheckPositional("proxy", nargs, 1, 2)) {
  85. goto exit;
  86. }
  87. object = args[0];
  88. if (nargs < 2) {
  89. goto skip_optional;
  90. }
  91. callback = args[1];
  92. skip_optional:
  93. return_value = _weakref_proxy_impl(module, object, callback);
  94. exit:
  95. return return_value;
  96. }
  97. /*[clinic end generated code: output=28265e89d583273d input=a9049054013a1b77]*/