Revising code for Varint encoding in dumps

- Usign lua_Unsigned to count strings.
- Varint uses a type large enough both for size_t and lua_Unsigned.
- Most-Significant Bit 0 means last byte, to conform to common usage.
- (unrelated) Change in macro 'getaddr' so that multiplication is
  by constants.
This commit is contained in:
Roberto Ierusalimschy
2024-02-12 15:16:11 -03:00
parent 7360f8d0fd
commit c8121ce34b
3 changed files with 45 additions and 29 deletions

View File

@@ -7,6 +7,8 @@
#ifndef lundump_h
#define lundump_h
#include <limits.h>
#include "llimits.h"
#include "lobject.h"
#include "lzio.h"
@@ -25,6 +27,19 @@
#define LUAC_FORMAT 0 /* this is the official format */
/*
** Type to handle MSB Varint encoding: Try to get the largest unsigned
** integer available. (It was enough to be the largest between size_t and
** lua_Integer, but the C89 preprocessor knows nothing about size_t.)
*/
#if !defined(LUA_USE_C89) && defined(LLONG_MAX)
typedef unsigned long long varint_t;
#else
typedef unsigned long varint_t;
#endif
/* load one chunk; from lundump.c */
LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name,
int fixed);