Fixes for the open-source build.

pull/13171/head
Josh Haberman 10 years ago
parent fa10302a50
commit 838009ba2b
  1. 1
      Makefile
  2. 2
      upb/bindings/lua/upb.c
  3. 15
      upb/bindings/lua/upb/pb.c
  4. 8
      upb/env.c
  5. 6
      upb/env.h
  6. 4
      upb/pb/decoder.c

@ -131,6 +131,7 @@ make_objs_cc = $$(patsubst upb/$$(pc).cc,obj/upb/$$(pc).$(1),$$($$(call to_srcs,
upb_SRCS = \
upb/def.c \
upb/env.c \
upb/handlers.c \
upb/refcounted.c \
upb/shim/shim.c \

@ -1358,7 +1358,7 @@ static size_t align_up(size_t val, size_t align) {
// If we always read/write as a consistent type to each value, this shouldn't
// violate aliasing.
#define DEREF(msg, ofs, type) *(type*)(&msg->data[ofs])
#define DEREF(msg, ofs, type) *(type*)((char*)msg + sizeof(lupb_msg) + ofs)
lupb_msg *lupb_msg_check(lua_State *L, int narg) {
lupb_msg *msg = luaL_checkudata(L, narg, LUPB_MSG);

@ -41,13 +41,6 @@ static int lupb_pbdecodermethod_new(lua_State *L) {
return 1; // The DecoderMethod wrapper.
}
// We implement upb's allocation function by allocating a Lua userdata.
// This is a raw hunk of memory that will be GC'd by Lua.
static void *lua_alloc(void *ud, size_t size) {
lua_State *L = ud;
return lua_newuserdata(L, size);
}
// Unlike most of our exposed Lua functions, this does not correspond to an
// actual method on the underlying DecoderMethod. But it's convenient, and
// important to implement in C because we can do stack allocation and
@ -77,11 +70,9 @@ static int lupb_pbdecodermethod_parse(lua_State *L) {
upb_pbdecoder *decoder = upb_pbdecoder_create(&env, method, &sink);
upb_bufsrc_putbuf(pb, len, upb_pbdecoder_input(decoder));
// This won't get called in the error case, which longjmp's across us. But
// since we made our alloc function allocate only GC-able memory, that
// shouldn't matter. It *would* matter if the environment had references to
// any non-memory resources (ie. filehandles). As an alternative to this we
// could make the environment itself a userdata.
// TODO: This won't get called in the error case, which longjmp's across us.
// This will cause the memory to leak. To remedy this, we should make the
// upb_env wrapped in a userdata that guarantees this will get called.
upb_env_uninit(&env);
lupb_checkstatus(L, &status);

@ -43,7 +43,7 @@ static void *default_alloc(void *_ud, void *ptr, size_t oldsize, size_t size) {
UPB_UNUSED(oldsize);
default_alloc_ud *ud = _ud;
mem_block *from = ptr ? ptr - sizeof(mem_block) : NULL;
mem_block *from = ptr ? (void*)((char*)ptr - sizeof(mem_block)) : NULL;
#ifndef NDEBUG
if (from) {
@ -214,7 +214,9 @@ UPB_FORCEINLINE static void *seeded_alloc(void *ud, void *ptr, size_t oldsize,
upb_seededalloc *a = ud;
size = align_up(size);
if (oldsize == 0 && size <= a->mem_limit - a->mem_ptr) {
assert(a->mem_limit >= a->mem_ptr);
if (oldsize == 0 && size <= (size_t)(a->mem_limit - a->mem_ptr)) {
// Fast path: we can satisfy from the initial allocation.
void *ret = a->mem_ptr;
a->mem_ptr += size;
@ -229,7 +231,7 @@ UPB_FORCEINLINE static void *seeded_alloc(void *ud, void *ptr, size_t oldsize,
void upb_seededalloc_init(upb_seededalloc *a, void *mem, size_t len) {
a->mem_base = mem;
a->mem_ptr = mem;
a->mem_limit = mem + len;
a->mem_limit = (char*)mem + len;
a->need_cleanup = false;
a->returned_allocfunc = false;

@ -177,9 +177,9 @@ UPB_DEFINE_STRUCT0(upb_seededalloc,
void *default_alloc_ud;
// Pointers for the initial memory region.
void *mem_base;
void *mem_ptr;
void *mem_limit;
char *mem_base;
char *mem_ptr;
char *mem_limit;
// For future expansion, since the size of this struct is exposed to users.
void *future1;

@ -966,7 +966,9 @@ size_t upb_pbdecoder_maxnesting(const upb_pbdecoder *d) {
}
bool upb_pbdecoder_setmaxnesting(upb_pbdecoder *d, size_t max) {
if (max < d->top - d->stack) {
assert(d->top >= d->stack);
if (max < (size_t)(d->top - d->stack)) {
// Can't set a limit smaller than what we are currently at.
return false;
}

Loading…
Cancel
Save