diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-03-13 09:16:51 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-03-13 09:16:51 -0300 |
| commit | cc2b66c85687b095e68304c010b59851ca4093e1 (patch) | |
| tree | e85314ebbc0a27d4ece319c0313cebf77a62a96b /ldump.c | |
| parent | 65b07dd53d7938a60112fc4473f5cad3473e3534 (diff) | |
| download | lua-cc2b66c85687b095e68304c010b59851ca4093e1.tar.gz lua-cc2b66c85687b095e68304c010b59851ca4093e1.tar.bz2 lua-cc2b66c85687b095e68304c010b59851ca4093e1.zip | |
Removed type 'varint_t'
size_t should be big enough to count the number of strings in a dump.
(And, by definition, it is big enough to count the length of each
string.)
Diffstat (limited to 'ldump.c')
| -rw-r--r-- | ldump.c | 22 |
1 files changed, 13 insertions, 9 deletions
| @@ -30,7 +30,7 @@ typedef struct { | |||
| 30 | int strip; | 30 | int strip; |
| 31 | int status; | 31 | int status; |
| 32 | Table *h; /* table to track saved strings */ | 32 | Table *h; /* table to track saved strings */ |
| 33 | lua_Unsigned nstr; /* counter to number saved strings */ | 33 | lua_Integer nstr; /* counter for counting saved strings */ |
| 34 | } DumpState; | 34 | } DumpState; |
| 35 | 35 | ||
| 36 | 36 | ||
| @@ -86,12 +86,12 @@ static void dumpByte (DumpState *D, int y) { | |||
| 86 | ** size for 'dumpVarint' buffer: each byte can store up to 7 bits. | 86 | ** size for 'dumpVarint' buffer: each byte can store up to 7 bits. |
| 87 | ** (The "+6" rounds up the division.) | 87 | ** (The "+6" rounds up the division.) |
| 88 | */ | 88 | */ |
| 89 | #define DIBS ((sizeof(varint_t) * CHAR_BIT + 6) / 7) | 89 | #define DIBS ((sizeof(size_t) * CHAR_BIT + 6) / 7) |
| 90 | 90 | ||
| 91 | /* | 91 | /* |
| 92 | ** Dumps an unsigned integer using the MSB Varint encoding | 92 | ** Dumps an unsigned integer using the MSB Varint encoding |
| 93 | */ | 93 | */ |
| 94 | static void dumpVarint (DumpState *D, varint_t x) { | 94 | static void dumpVarint (DumpState *D, size_t x) { |
| 95 | lu_byte buff[DIBS]; | 95 | lu_byte buff[DIBS]; |
| 96 | int n = 1; | 96 | int n = 1; |
| 97 | buff[DIBS - 1] = x & 0x7f; /* fill least-significant byte */ | 97 | buff[DIBS - 1] = x & 0x7f; /* fill least-significant byte */ |
| @@ -101,9 +101,13 @@ static void dumpVarint (DumpState *D, varint_t x) { | |||
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | 103 | ||
| 104 | static void dumpSize (DumpState *D, size_t sz) { | ||
| 105 | dumpVarint(D, sz); | ||
| 106 | } | ||
| 107 | |||
| 104 | static void dumpInt (DumpState *D, int x) { | 108 | static void dumpInt (DumpState *D, int x) { |
| 105 | lua_assert(x >= 0); | 109 | lua_assert(x >= 0); |
| 106 | dumpVarint(D, x); | 110 | dumpVarint(D, cast(size_t, x)); |
| 107 | } | 111 | } |
| 108 | 112 | ||
| 109 | 113 | ||
| @@ -126,22 +130,22 @@ static void dumpInteger (DumpState *D, lua_Integer x) { | |||
| 126 | */ | 130 | */ |
| 127 | static void dumpString (DumpState *D, TString *ts) { | 131 | static void dumpString (DumpState *D, TString *ts) { |
| 128 | if (ts == NULL) | 132 | if (ts == NULL) |
| 129 | dumpVarint(D, 0); | 133 | dumpSize(D, 0); |
| 130 | else { | 134 | else { |
| 131 | TValue idx; | 135 | TValue idx; |
| 132 | if (luaH_getstr(D->h, ts, &idx) == HOK) { /* string already saved? */ | 136 | if (luaH_getstr(D->h, ts, &idx) == HOK) { /* string already saved? */ |
| 133 | dumpVarint(D, 1); /* reuse a saved string */ | 137 | dumpSize(D, 1); /* reuse a saved string */ |
| 134 | dumpVarint(D, l_castS2U(ivalue(&idx))); /* index of saved string */ | 138 | dumpSize(D, cast_sizet(ivalue(&idx))); /* index of saved string */ |
| 135 | } | 139 | } |
| 136 | else { /* must write and save the string */ | 140 | else { /* must write and save the string */ |
| 137 | TValue key, value; /* to save the string in the hash */ | 141 | TValue key, value; /* to save the string in the hash */ |
| 138 | size_t size; | 142 | size_t size; |
| 139 | const char *s = getlstr(ts, size); | 143 | const char *s = getlstr(ts, size); |
| 140 | dumpVarint(D, size + 2); | 144 | dumpSize(D, size + 2); |
| 141 | dumpVector(D, s, size + 1); /* include ending '\0' */ | 145 | dumpVector(D, s, size + 1); /* include ending '\0' */ |
| 142 | D->nstr++; /* one more saved string */ | 146 | D->nstr++; /* one more saved string */ |
| 143 | setsvalue(D->L, &key, ts); /* the string is the key */ | 147 | setsvalue(D->L, &key, ts); /* the string is the key */ |
| 144 | setivalue(&value, l_castU2S(D->nstr)); /* its index is the value */ | 148 | setivalue(&value, D->nstr); /* its index is the value */ |
| 145 | luaH_set(D->L, D->h, &key, &value); /* h[ts] = nstr */ | 149 | luaH_set(D->L, D->h, &key, &value); /* h[ts] = nstr */ |
| 146 | /* integer value does not need barrier */ | 150 | /* integer value does not need barrier */ |
| 147 | } | 151 | } |
