| 97 | |
| 98 | |
| 99 | LUA_API int lua_setcstacklimit (lua_State *L, unsigned int limit) { |
| 100 | global_State *g = G(L); |
| 101 | int ccalls; |
| 102 | luaE_freeCI(L); /* release unused CIs */ |
| 103 | ccalls = getCcalls(L); |
| 104 | if (limit >= 40000) |
| 105 | return 0; /* out of bounds */ |
| 106 | limit += CSTACKERR; |
| 107 | if (L != g-> mainthread) |
| 108 | return 0; /* only main thread can change the C stack */ |
| 109 | else if (ccalls <= CSTACKERR) |
| 110 | return 0; /* handling overflow */ |
| 111 | else { |
| 112 | int diff = limit - g->Cstacklimit; |
| 113 | if (ccalls + diff <= CSTACKERR) |
| 114 | return 0; /* new limit would cause an overflow */ |
| 115 | g->Cstacklimit = limit; /* set new limit */ |
| 116 | L->nCcalls += diff; /* correct 'nCcalls' */ |
| 117 | return limit - diff - CSTACKERR; /* success; return previous limit */ |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | |
| 122 | /* |
no test coverage detected