ltests.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. ** $Id: ltests.h $
  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 <stdio.h>
  9. #include <stdlib.h>
  10. /* test Lua with compatibility code */
  11. #define LUA_COMPAT_MATHLIB
  12. #define LUA_COMPAT_LT_LE
  13. #define LUA_DEBUG
  14. /* turn on assertions */
  15. #define LUAI_ASSERT
  16. /* compiled with -O0, Lua uses a lot of C stack space... */
  17. #undef LUAI_MAXCSTACK
  18. #define LUAI_MAXCSTACK 400
  19. /* to avoid warnings, and to make sure value is really unused */
  20. #define UNUSED(x) (x=0, (void)(x))
  21. /* test for sizes in 'l_sprintf' (make sure whole buffer is available) */
  22. #undef l_sprintf
  23. #if !defined(LUA_USE_C89)
  24. #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), snprintf(s,sz,f,i))
  25. #else
  26. #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), sprintf(s,f,i))
  27. #endif
  28. /* get a chance to test code without jump tables */
  29. #define LUA_USE_JUMPTABLE 0
  30. /* use 32-bit integers in random generator */
  31. #define LUA_RAND32
  32. /* memory-allocator control variables */
  33. typedef struct Memcontrol {
  34. int failnext;
  35. unsigned long numblocks;
  36. unsigned long total;
  37. unsigned long maxmem;
  38. unsigned long memlimit;
  39. unsigned long countlimit;
  40. unsigned long objcount[LUA_NUMTYPES];
  41. } Memcontrol;
  42. LUA_API Memcontrol l_memcontrol;
  43. /*
  44. ** generic variable for debug tricks
  45. */
  46. extern void *l_Trick;
  47. /*
  48. ** Function to traverse and check all memory used by Lua
  49. */
  50. LUAI_FUNC int lua_checkmemory (lua_State *L);
  51. /*
  52. ** Function to print an object GC-friendly
  53. */
  54. struct GCObject;
  55. LUAI_FUNC void lua_printobj (lua_State *L, struct GCObject *o);
  56. /* test for lock/unlock */
  57. struct L_EXTRA { int lock; int *plock; };
  58. #undef LUA_EXTRASPACE
  59. #define LUA_EXTRASPACE sizeof(struct L_EXTRA)
  60. #define getlock(l) cast(struct L_EXTRA*, lua_getextraspace(l))
  61. #define luai_userstateopen(l) \
  62. (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock))
  63. #define luai_userstateclose(l) \
  64. lua_assert(getlock(l)->lock == 1 && getlock(l)->plock == &(getlock(l)->lock))
  65. #define luai_userstatethread(l,l1) \
  66. lua_assert(getlock(l1)->plock == getlock(l)->plock)
  67. #define luai_userstatefree(l,l1) \
  68. lua_assert(getlock(l)->plock == getlock(l1)->plock)
  69. #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0)
  70. #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0)
  71. LUA_API int luaB_opentests (lua_State *L);
  72. LUA_API void *debug_realloc (void *ud, void *block,
  73. size_t osize, size_t nsize);
  74. #if defined(lua_c)
  75. #define luaL_newstate() lua_newstate(debug_realloc, &l_memcontrol)
  76. #define luaL_openlibs(L) \
  77. { (luaL_openlibs)(L); \
  78. luaL_requiref(L, "T", luaB_opentests, 1); \
  79. lua_pop(L, 1); }
  80. #endif
  81. /* change some sizes to give some bugs a chance */
  82. #undef LUAL_BUFFERSIZE
  83. #define LUAL_BUFFERSIZE 23
  84. #define MINSTRTABSIZE 2
  85. #define MAXIWTHABS 3
  86. #define STRCACHE_N 23
  87. #define STRCACHE_M 5
  88. #undef LUAI_USER_ALIGNMENT_T
  89. #define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; }
  90. /* make stack-overflow tests run faster */
  91. #undef LUAI_MAXSTACK
  92. #define LUAI_MAXSTACK 50000
  93. /* force Lua to use its own implementations */
  94. #undef lua_strx2number
  95. #undef lua_number2strx
  96. #endif