pep384ext.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright (C) 2024 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. #ifndef PEP384EXT_H
  4. #define PEP384EXT_H
  5. #include "pep384impl.h"
  6. /// Returns the allocator slot of the PyTypeObject.
  7. inline allocfunc PepExt_Type_GetAllocSlot(PyTypeObject *t)
  8. {
  9. return reinterpret_cast<allocfunc>(PepType_GetSlot(t, Py_tp_alloc));
  10. }
  11. /// Invokes the allocator slot of the PyTypeObject.
  12. template <class Type>
  13. inline Type *PepExt_TypeCallAlloc(PyTypeObject *t, Py_ssize_t nitems)
  14. {
  15. PyObject *result = PepExt_Type_GetAllocSlot(t)(t, nitems);
  16. return reinterpret_cast<Type *>(result);
  17. }
  18. /// Returns the getattro slot of the PyTypeObject.
  19. inline getattrofunc PepExt_Type_GetGetAttroSlot(PyTypeObject *t)
  20. {
  21. return reinterpret_cast<getattrofunc>(PepType_GetSlot(t, Py_tp_getattro));
  22. }
  23. /// Returns the setattro slot of the PyTypeObject.
  24. inline setattrofunc PepExt_Type_GetSetAttroSlot(PyTypeObject *t)
  25. {
  26. return reinterpret_cast<setattrofunc>(PepType_GetSlot(t, Py_tp_setattro));
  27. }
  28. /// Returns the descr_get slot of the PyTypeObject.
  29. inline descrgetfunc PepExt_Type_GetDescrGetSlot(PyTypeObject *t)
  30. {
  31. return reinterpret_cast<descrgetfunc>(PepType_GetSlot(t, Py_tp_descr_get));
  32. }
  33. /// Invokes the descr_get slot of the PyTypeObject.
  34. inline PyObject *PepExt_Type_CallDescrGet(PyObject *self, PyObject *obj, PyObject *type)
  35. {
  36. return PepExt_Type_GetDescrGetSlot(Py_TYPE(self))(self, obj, type);
  37. }
  38. /// Returns the descr_set slot of the PyTypeObject.
  39. inline descrsetfunc PepExt_Type_GetDescrSetSlot(PyTypeObject *t)
  40. {
  41. return reinterpret_cast<descrsetfunc>(PepType_GetSlot(t, Py_tp_descr_set));
  42. }
  43. /// Returns the call slot of the PyTypeObject.
  44. inline ternaryfunc PepExt_Type_GetCallSlot(PyTypeObject *t)
  45. {
  46. return reinterpret_cast<ternaryfunc>(PepType_GetSlot(t, Py_tp_call));
  47. }
  48. /// Returns the new slot of the PyTypeObject.
  49. inline newfunc PepExt_Type_GetNewSlot(PyTypeObject *t)
  50. {
  51. return reinterpret_cast<newfunc>(PepType_GetSlot(t, Py_tp_new));
  52. }
  53. /// Returns the init slot of the PyTypeObject.
  54. inline initproc PepExt_Type_GetInitSlot(PyTypeObject *t)
  55. {
  56. return reinterpret_cast<initproc>(PepType_GetSlot(t, Py_tp_init));
  57. }
  58. /// Returns the free slot of the PyTypeObject.
  59. inline freefunc PepExt_Type_GetFreeSlot(PyTypeObject *t)
  60. {
  61. return reinterpret_cast<freefunc>(PepType_GetSlot(t, Py_tp_free));
  62. }
  63. /// Invokes the free slot of the PyTypeObject.
  64. inline void PepExt_TypeCallFree(PyTypeObject *t, void *object)
  65. {
  66. PepExt_Type_GetFreeSlot(t)(object);
  67. }
  68. /// Invokes the free slot of the PyTypeObject.
  69. inline void PepExt_TypeCallFree(PyObject *object)
  70. {
  71. PepExt_Type_GetFreeSlot(Py_TYPE(object))(object);
  72. }
  73. LIBSHIBOKEN_API bool PepExt_Weakref_IsAlive(PyObject *weakRef);
  74. #endif // PEP384EXT_H