MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / newlstr

Function newlstr

Source/Misc/lua/src/lua.c:9179–9201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

luaS_newlstrFunction · 0.85

Calls 2

luaM_toobigFunction · 0.85
luaS_resizeFunction · 0.85

Tested by

no test coverage detected