| 9177 | |
| 9178 | |
| 9179 | static TString *newlstr (lua_State *L, const char *str, size_t l, |
| 9180 | unsigned int h) { |
| 9181 | TString *ts; |
| 9182 | stringtable *tb; |
| 9183 | if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) |
| 9184 | luaM_toobig(L); |
| 9185 | ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); |
| 9186 | ts->tsv.len = l; |
| 9187 | ts->tsv.hash = h; |
| 9188 | ts->tsv.marked = luaC_white(G(L)); |
| 9189 | ts->tsv.tt = LUA_TSTRING; |
| 9190 | ts->tsv.reserved = 0; |
| 9191 | memcpy(ts+1, str, l*sizeof(char)); |
| 9192 | ((char *)(ts+1))[l] = '\0'; /* ending 0 */ |
| 9193 | tb = &G(L)->strt; |
| 9194 | h = lmod(h, tb->size); |
| 9195 | ts->tsv.next = tb->hash[h]; /* chain new entry */ |
| 9196 | tb->hash[h] = obj2gco(ts); |
| 9197 | tb->nuse++; |
| 9198 | if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) |
| 9199 | luaS_resize(L, tb->size*2); /* too crowded */ |
| 9200 | return ts; |
| 9201 | } |
| 9202 | |
| 9203 | |
| 9204 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { |
no test coverage detected