| 1192 | |
| 1193 | |
| 1194 | void *luaL_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { |
| 1195 | #ifndef PLUTO_MEMORY_LIMIT |
| 1196 | UNUSED(ud); UNUSED(osize); |
| 1197 | #endif |
| 1198 | if (nsize == 0) { |
| 1199 | free(ptr); |
| 1200 | return NULL; |
| 1201 | } |
| 1202 | else { |
| 1203 | #ifdef PLUTO_MEMORY_LIMIT |
| 1204 | if (ud /* state has finished opening? */ |
| 1205 | && (!ptr || nsize > osize) /* new allocation or increasing existing allocation? */ |
| 1206 | && reinterpret_cast<global_State*>(ud)->totalbytes >= PLUTO_MEMORY_LIMIT /* limit reached? */ |
| 1207 | ) { |
| 1208 | return NULL; |
| 1209 | } |
| 1210 | #endif |
| 1211 | return realloc(ptr, nsize); |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | |
| 1216 | /* |
nothing calls this directly
no outgoing calls
no test coverage detected