1
0

Identity.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef Identity_H
  16. #define Identity_H
  17. #include "util/Assert.h"
  18. #include "util/CompileTimeRandom.h"
  19. <?js file.Identity_hash = "0x" + CompileTimeRandom_hexString(16) + "ull"; ?>
  20. #define Identity_MAGIC ((unsigned long) <?js return file.Identity_hash ?>)
  21. #if defined(Identity_CHECK)
  22. /** This goes in each structure which will be checked. */
  23. #define Identity \
  24. unsigned long Identity_verifier;
  25. #define Identity_set(pointer) \
  26. (pointer)->Identity_verifier = Identity_MAGIC
  27. #define Identity_check(pointer) \
  28. (__extension__ ({ \
  29. __typeof__(pointer) Identity_ptr = (pointer); \
  30. Assert_always(Identity_ptr->Identity_verifier == Identity_MAGIC); \
  31. Identity_ptr; \
  32. }))
  33. #define Identity_ncheck(pointer) \
  34. (__extension__ ({ \
  35. __typeof__(pointer) Identity_ptr = (pointer); \
  36. Assert_always(!Identity_ptr || Identity_ptr->Identity_verifier == Identity_MAGIC); \
  37. Identity_ptr; \
  38. }))
  39. #else
  40. #define Identity
  41. #define Identity_set(pointer)
  42. #define Identity_check(pointer) (pointer)
  43. #define Identity_ncheck(pointer) (pointer)
  44. #endif
  45. #endif