context.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef Py_CONTEXT_H
  2. #define Py_CONTEXT_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #ifndef Py_LIMITED_API
  7. PyAPI_DATA(PyTypeObject) PyContext_Type;
  8. typedef struct _pycontextobject PyContext;
  9. PyAPI_DATA(PyTypeObject) PyContextVar_Type;
  10. typedef struct _pycontextvarobject PyContextVar;
  11. PyAPI_DATA(PyTypeObject) PyContextToken_Type;
  12. typedef struct _pycontexttokenobject PyContextToken;
  13. #define PyContext_CheckExact(o) (Py_TYPE(o) == &PyContext_Type)
  14. #define PyContextVar_CheckExact(o) (Py_TYPE(o) == &PyContextVar_Type)
  15. #define PyContextToken_CheckExact(o) (Py_TYPE(o) == &PyContextToken_Type)
  16. PyAPI_FUNC(PyObject *) PyContext_New(void);
  17. PyAPI_FUNC(PyObject *) PyContext_Copy(PyObject *);
  18. PyAPI_FUNC(PyObject *) PyContext_CopyCurrent(void);
  19. PyAPI_FUNC(int) PyContext_Enter(PyObject *);
  20. PyAPI_FUNC(int) PyContext_Exit(PyObject *);
  21. /* Create a new context variable.
  22. default_value can be NULL.
  23. */
  24. PyAPI_FUNC(PyObject *) PyContextVar_New(
  25. const char *name, PyObject *default_value);
  26. /* Get a value for the variable.
  27. Returns -1 if an error occurred during lookup.
  28. Returns 0 if value either was or was not found.
  29. If value was found, *value will point to it.
  30. If not, it will point to:
  31. - default_value, if not NULL;
  32. - the default value of "var", if not NULL;
  33. - NULL.
  34. '*value' will be a new ref, if not NULL.
  35. */
  36. PyAPI_FUNC(int) PyContextVar_Get(
  37. PyObject *var, PyObject *default_value, PyObject **value);
  38. /* Set a new value for the variable.
  39. Returns NULL if an error occurs.
  40. */
  41. PyAPI_FUNC(PyObject *) PyContextVar_Set(PyObject *var, PyObject *value);
  42. /* Reset a variable to its previous value.
  43. Returns 0 on success, -1 on error.
  44. */
  45. PyAPI_FUNC(int) PyContextVar_Reset(PyObject *var, PyObject *token);
  46. /* This method is exposed only for CPython tests. Don not use it. */
  47. PyAPI_FUNC(PyObject *) _PyContext_NewHamtForTests(void);
  48. PyAPI_FUNC(int) PyContext_ClearFreeList(void);
  49. #endif /* !Py_LIMITED_API */
  50. #ifdef __cplusplus
  51. }
  52. #endif
  53. #endif /* !Py_CONTEXT_H */