Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.6 KiB

  1. /* An arena-like memory interface for the compiler.
  2. */
  3. #ifndef Py_PYARENA_H
  4. #define Py_PYARENA_H
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. typedef struct _arena PyArena;
  9. /* PyArena_New() and PyArena_Free() create a new arena and free it,
  10. respectively. Once an arena has been created, it can be used
  11. to allocate memory via PyArena_Malloc(). Pointers to PyObject can
  12. also be registered with the arena via PyArena_AddPyObject(), and the
  13. arena will ensure that the PyObjects stay alive at least until
  14. PyArena_Free() is called. When an arena is freed, all the memory it
  15. allocated is freed, the arena releases internal references to registered
  16. PyObject*, and none of its pointers are valid.
  17. XXX (tim) What does "none of its pointers are valid" mean? Does it
  18. XXX mean that pointers previously obtained via PyArena_Malloc() are
  19. XXX no longer valid? (That's clearly true, but not sure that's what
  20. XXX the text is trying to say.)
  21. PyArena_New() returns an arena pointer. On error, it
  22. returns a negative number and sets an exception.
  23. XXX (tim): Not true. On error, PyArena_New() actually returns NULL,
  24. XXX and looks like it may or may not set an exception (e.g., if the
  25. XXX internal PyList_New(0) returns NULL, PyArena_New() passes that on
  26. XXX and an exception is set; OTOH, if the internal
  27. XXX block_new(DEFAULT_BLOCK_SIZE) returns NULL, that's passed on but
  28. XXX an exception is not set in that case).
  29. */
  30. PyAPI_FUNC(PyArena *) PyArena_New(void);
  31. PyAPI_FUNC(void) PyArena_Free(PyArena *);
  32. /* Mostly like malloc(), return the address of a block of memory spanning
  33. * `size` bytes, or return NULL (without setting an exception) if enough
  34. * new memory can't be obtained. Unlike malloc(0), PyArena_Malloc() with
  35. * size=0 does not guarantee to return a unique pointer (the pointer
  36. * returned may equal one or more other pointers obtained from
  37. * PyArena_Malloc()).
  38. * Note that pointers obtained via PyArena_Malloc() must never be passed to
  39. * the system free() or realloc(), or to any of Python's similar memory-
  40. * management functions. PyArena_Malloc()-obtained pointers remain valid
  41. * until PyArena_Free(ar) is called, at which point all pointers obtained
  42. * from the arena `ar` become invalid simultaneously.
  43. */
  44. PyAPI_FUNC(void *) PyArena_Malloc(PyArena *, size_t size);
  45. /* This routine isn't a proper arena allocation routine. It takes
  46. * a PyObject* and records it so that it can be DECREFed when the
  47. * arena is freed.
  48. */
  49. PyAPI_FUNC(int) PyArena_AddPyObject(PyArena *, PyObject *);
  50. #ifdef __cplusplus
  51. }
  52. #endif
  53. #endif /* !Py_PYARENA_H */