Fix compiling problems with lua 5.4

^ Conflicts:
^	upb/text/encode.c

Fix some checking codes.

Remove the useless checking for lua version less than 5.1

Fix compiling problem.
pull/15113/head
owent 12 months ago
parent 4c923285a3
commit dd3a847a06
No known key found for this signature in database
GPG Key ID: D47669FAAFD65E89
  1. 6
      lua/def.c
  2. 2
      lua/upb.c
  3. 9
      lua/upbc.cc

@ -597,7 +597,7 @@ const upb_FileDef* lupb_FileDef_check(lua_State* L, int narg) {
static int lupb_FileDef_Dependency(lua_State* L) {
const upb_FileDef* f = lupb_FileDef_check(L, 1);
int index = luaL_checkint(L, 2);
int index = lupb_checkint32(L, 2);
const upb_FileDef* dep = upb_FileDef_Dependency(f, index);
lupb_wrapper_pushwrapper(L, 1, dep, LUPB_FILEDEF);
return 1;
@ -611,7 +611,7 @@ static int lupb_FileDef_DependencyCount(lua_State* L) {
static int lupb_FileDef_enum(lua_State* L) {
const upb_FileDef* f = lupb_FileDef_check(L, 1);
int index = luaL_checkint(L, 2);
int index = lupb_checkint32(L, 2);
const upb_EnumDef* e = upb_FileDef_TopLevelEnum(f, index);
lupb_wrapper_pushwrapper(L, 1, e, LUPB_ENUMDEF);
return 1;
@ -625,7 +625,7 @@ static int lupb_FileDef_enumcount(lua_State* L) {
static int lupb_FileDef_msg(lua_State* L) {
const upb_FileDef* f = lupb_FileDef_check(L, 1);
int index = luaL_checkint(L, 2);
int index = lupb_checkint32(L, 2);
const upb_MessageDef* m = upb_FileDef_TopLevelMessage(f, index);
lupb_wrapper_pushwrapper(L, 1, m, LUPB_MSGDEF);
return 1;

@ -41,11 +41,13 @@
/* Lua compatibility code *****************************************************/
/* Shims for upcoming Lua 5.3 functionality. */
#if LUA_VERSION_NUM < 503
static bool lua_isinteger(lua_State* L, int argn) {
LUPB_UNUSED(L);
LUPB_UNUSED(argn);
return false;
}
#endif
/* Utility functions **********************************************************/

@ -5,13 +5,13 @@
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#include "google/protobuf/descriptor.pb.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/string_view.h"
#include "absl/strings/substitute.h"
#include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/compiler/plugin.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/printer.h"
namespace protoc = ::google::protobuf::compiler;
@ -50,6 +50,11 @@ static void PrintHexDigit(char digit, protobuf::io::Printer* printer) {
printer->WriteRaw(&text, 1);
}
static bool IsPrint(int ch) {
// isprint(ch) with negative values is UB.
return ch < 0 ? false : isprint(ch);
}
static void PrintString(int max_cols, absl::string_view* str,
protobuf::io::Printer* printer) {
printer->Print("\'");
@ -61,7 +66,7 @@ static void PrintString(int max_cols, absl::string_view* str,
} else if (ch == '\'') {
printer->PrintRaw("\\'");
max_cols--;
} else if (isprint(ch)) {
} else if (IsPrint(ch)) {
printer->WriteRaw(&ch, 1);
max_cols--;
} else {

Loading…
Cancel
Save