MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / dumpString

Function dumpString

third-party/lua-5.5.0/src/ldump.c:143–168  ·  view source on GitHub ↗

** Dump a String. First dump its "size": ** size==0 is followed by an index and means "reuse saved string with ** that index"; index==0 means NULL. ** size>=1 is followed by the string contents with real size==size-1 and ** means that string, which will be saved with the next available index. ** The real size does not include the ending '\0' (which is not dumped), ** so adding 1 to it cannot overf

Source from the content-addressed store, hash-verified

141** so adding 1 to it cannot overflow a size_t.
142*/
143static void dumpString (DumpState *D, TString *ts) {
144 if (ts == NULL) {
145 dumpVarint(D, 0); /* will "reuse" NULL */
146 dumpVarint(D, 0); /* special index for NULL */
147 }
148 else {
149 TValue idx;
150 int tag = luaH_getstr(D->h, ts, &idx);
151 if (!tagisempty(tag)) { /* string already saved? */
152 dumpVarint(D, 0); /* reuse a saved string */
153 dumpVarint(D, l_castS2U(ivalue(&idx))); /* index of saved string */
154 }
155 else { /* must write and save the string */
156 TValue key, value; /* to save the string in the hash */
157 size_t size;
158 const char *s = getlstr(ts, size);
159 dumpSize(D, size + 1);
160 dumpVector(D, s, size + 1); /* include ending '\0' */
161 D->nstr++; /* one more saved string */
162 setsvalue(D->L, &key, ts); /* the string is the key */
163 setivalue(&value, l_castU2S(D->nstr)); /* its index is the value */
164 luaH_set(D->L, D->h, &key, &value); /* h[ts] = nstr */
165 /* integer value does not need barrier */
166 }
167 }
168}
169
170
171static void dumpCode (DumpState *D, const Proto *f) {

Callers 3

dumpConstantsFunction · 0.70
dumpDebugFunction · 0.70
dumpFunctionFunction · 0.70

Calls 4

dumpVarintFunction · 0.85
luaH_getstrFunction · 0.70
dumpSizeFunction · 0.70
luaH_setFunction · 0.70

Tested by

no test coverage detected