isave.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* Copyright (C) 1991, 1995, 1997, 1998, 1999 Aladdin Enterprises. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /*$Id: isave.h,v 1.2 2000/09/19 19:00:46 lpd Exp $ */
  16. /* Procedures for save/restore */
  17. /* Requires imemory.h */
  18. #ifndef isave_INCLUDED
  19. # define isave_INCLUDED
  20. #include "idosave.h"
  21. /*
  22. * According to the PostScript language definition, save objects are simple,
  23. * not composite. Consequently, we cannot use their natural representation,
  24. * namely a t_struct pointing to an alloc_save_t, since we aren't willing to
  25. * allocate them all in global VM and rely on garbage collection to clean
  26. * them up. Instead, we assign each one a unique "save ID", and store this
  27. * in the alloc_save_t object. Mapping the number to the object requires
  28. * at most searching the local save chain for the current gs_dual_memory_t,
  29. * and this approach means we don't have to do anything to invalidate
  30. * save objects when we do a restore.
  31. */
  32. #ifndef alloc_save_t_DEFINED /* also in inamedef.h */
  33. typedef struct alloc_save_s alloc_save_t;
  34. # define alloc_save_t_DEFINED
  35. #endif
  36. /* Initialize the save machinery. */
  37. extern void alloc_save_init(P1(gs_dual_memory_t *));
  38. /* Map a save ID to its save object. Return 0 if the ID is invalid. */
  39. alloc_save_t *alloc_find_save(P2(const gs_dual_memory_t *, ulong));
  40. /*
  41. * Save the state. Return 0 if we can't allocate the save object,
  42. * otherwise return the save ID. The second argument is a client data
  43. * pointer, assumed to point to an object.
  44. */
  45. ulong alloc_save_state(P2(gs_dual_memory_t *, void *));
  46. /* Get the client pointer passed to alloc_saved_state. */
  47. void *alloc_save_client_data(P1(const alloc_save_t *));
  48. /* Return (the id of) the innermost externally visible save object. */
  49. ulong alloc_save_current_id(P1(const gs_dual_memory_t *));
  50. alloc_save_t *alloc_save_current(P1(const gs_dual_memory_t *));
  51. /* Check whether a pointer refers to an object allocated since a given save. */
  52. bool alloc_is_since_save(P2(const void *, const alloc_save_t *));
  53. /* Check whether a name was created since a given save. */
  54. bool alloc_name_is_since_save(P2(const ref *, const alloc_save_t *));
  55. bool alloc_name_index_is_since_save(P2(uint, const alloc_save_t *));
  56. /*
  57. * Check whether any names have been created since a given save
  58. * that might be released by the restore.
  59. */
  60. bool alloc_any_names_since_save(P1(const alloc_save_t *));
  61. /*
  62. * Do one step of restoring the state. Return true if the argument
  63. * was the innermost save, in which case this is the last (or only) step.
  64. * Assume the caller obtained the argument by calling alloc_find_save;
  65. * if this is the case, the operation cannot fail.
  66. */
  67. bool alloc_restore_step_in(P2(gs_dual_memory_t *, alloc_save_t *));
  68. /* Backward compatibility */
  69. #define alloc_restore_state_step(save) alloc_restore_step_in(idmemory, save)
  70. /*
  71. * Forget a save -- like committing a transaction (restore is like
  72. * aborting a transaction). Assume the caller obtained the argument
  73. * by calling alloc_find_save. Note that forgetting a save does not
  74. * require checking pointers for recency.
  75. */
  76. void alloc_forget_save_in(P2(gs_dual_memory_t *, alloc_save_t *));
  77. /* Backward compatibility */
  78. #define alloc_forget_save(save) alloc_forget_save_in(idmemory, save)
  79. /* Release all memory -- like doing a restore "past the bottom". */
  80. void alloc_restore_all(P1(gs_dual_memory_t *));
  81. /* ------ Internals ------ */
  82. /*
  83. * If we are in a save, we want to save the old contents if l_new is
  84. * not set; if we are not in a save, we never want to save old contents.
  85. * We can test this quickly with a single mask that is l_new if we are
  86. * in a save, and -1 if we are not, since type_attrs of a valid ref
  87. * cannot be 0; this is the test_mask in a gs_dual_memory_t. Similarly,
  88. * we want to set the l_new bit in newly allocated objects iff we are in
  89. * a save; this is the new_mask in a gs_dual_memory_t.
  90. */
  91. /* Record that we are in a save. */
  92. void alloc_set_in_save(P1(gs_dual_memory_t *));
  93. /* Record that we are not in a save. */
  94. void alloc_set_not_in_save(P1(gs_dual_memory_t *));
  95. #endif /* isave_INCLUDED */