2
0

ltests.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. ** $Id: ltests.h,v 2.42 2014/11/29 19:45:37 roberto Exp roberto $
  3. ** Internal Header for Debugging of the Lua Implementation
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef ltests_h
  7. #define ltests_h
  8. #include <stdlib.h>
  9. /* test Lua with no compatibility code */
  10. #undef LUA_COMPAT_MATHLIB
  11. #undef LUA_COMPAT_IPAIRS
  12. #undef LUA_COMPAT_BITLIB
  13. #undef LUA_COMPAT_APIINTCASTS
  14. #undef LUA_COMPAT_FLOATSTRING
  15. #undef LUA_COMPAT_UNPACK
  16. #undef LUA_COMPAT_LOADERS
  17. #undef LUA_COMPAT_LOG10
  18. #undef LUA_COMPAT_LOADSTRING
  19. #undef LUA_COMPAT_MAXN
  20. #undef LUA_COMPAT_MODULE
  21. /* test without preloding debug library */
  22. #define LUA_NODEBUGLIB
  23. #define LUA_DEBUG
  24. /* turn on assertions */
  25. #undef NDEBUG
  26. #include <assert.h>
  27. #define lua_assert(c) assert(c)
  28. /* to avoid warnings, and to make sure value is really unused */
  29. #define UNUSED(x) (x=0, (void)(x))
  30. /* memory-allocator control variables */
  31. typedef struct Memcontrol {
  32. unsigned long numblocks;
  33. unsigned long total;
  34. unsigned long maxmem;
  35. unsigned long memlimit;
  36. unsigned long objcount[LUA_NUMTAGS];
  37. } Memcontrol;
  38. LUA_API Memcontrol l_memcontrol;
  39. /*
  40. ** generic variable for debug tricks
  41. */
  42. extern void *l_Trick;
  43. /*
  44. ** Function to traverse and check all memory used by Lua
  45. */
  46. int lua_checkmemory (lua_State *L);
  47. /* test for lock/unlock */
  48. struct L_EXTRA { int lock; int *plock; };
  49. #undef LUA_EXTRASPACE
  50. #define LUA_EXTRASPACE sizeof(struct L_EXTRA)
  51. #define getlock(l) cast(struct L_EXTRA*, lua_getextraspace(l))
  52. #define luai_userstateopen(l) \
  53. (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock))
  54. #define luai_userstateclose(l) \
  55. lua_assert(getlock(l)->lock == 1 && getlock(l)->plock == &(getlock(l)->lock))
  56. #define luai_userstatethread(l,l1) \
  57. lua_assert(getlock(l1)->plock == getlock(l)->plock)
  58. #define luai_userstatefree(l,l1) \
  59. lua_assert(getlock(l)->plock == getlock(l1)->plock)
  60. #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0)
  61. #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0)
  62. LUA_API int luaB_opentests (lua_State *L);
  63. LUA_API void *debug_realloc (void *ud, void *block,
  64. size_t osize, size_t nsize);
  65. #if defined(lua_c)
  66. #define luaL_newstate() lua_newstate(debug_realloc, &l_memcontrol)
  67. #define luaL_openlibs(L) \
  68. { (luaL_openlibs)(L); luaL_requiref(L, "T", luaB_opentests, 1); }
  69. #endif
  70. /* change some sizes to give some bugs a chance */
  71. #undef LUAL_BUFFERSIZE
  72. #define LUAL_BUFFERSIZE 23
  73. #define MINSTRTABSIZE 2
  74. #undef LUAI_USER_ALIGNMENT_T
  75. #define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; }
  76. /* check macro 'luai_numinvalidop' */
  77. #undef luai_numinvalidop
  78. #define luai_numinvalidop(op,a,b) (op == LUA_OPADD && a == 1.1 && b == 1)
  79. #endif