** 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
| 141 | ** so adding 1 to it cannot overflow a size_t. |
| 142 | */ |
| 143 | static 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 | |
| 171 | static void dumpCode (DumpState *D, const Proto *f) { |
no test coverage detected