Fixes to get upb to compile inside Google.

pull/13171/head
Joshua Haberman 14 years ago
parent 56f7a345d7
commit c0a08a6827
  1. 2
      Makefile
  2. 2
      upb/bytestream.c
  3. 7
      upb/bytestream.h
  4. 6
      upb/pb/decoder_x64.dasc
  5. 4
      upb/pb/textprinter.c
  6. 8
      upb/table.c
  7. 2
      upb/upb.h

@ -164,7 +164,7 @@ upb/pb/jit_debug_elf_file.o: upb/pb/jit_debug_elf_file.s
upb/pb/jit_debug_elf_file.h: upb/pb/jit_debug_elf_file.o
$(E) XXD $<
$(Q) xxd -i upb/pb/jit_debug_elf_file.o > upb/pb/jit_debug_elf_file.h
$(Q) xxd -i < upb/pb/jit_debug_elf_file.o > upb/pb/jit_debug_elf_file.h
upb/pb/decoder_x64.h: upb/pb/jit_debug_elf_file.h
endif

@ -63,7 +63,7 @@ static upb_stdio_buf *upb_stdio_findbuf(const upb_stdio *s, uint64_t ofs) {
}
static upb_stdio_buf *upb_stdio_rotatebufs(upb_stdio *s) {
upb_stdio_buf *reuse[s->nbuf];
upb_stdio_buf **reuse = NULL; // XXX
uint32_t num_reused = 0, num_inuse = 0;
// Could sweep only a subset of bufs if this was a hotspot.

@ -215,9 +215,10 @@ INLINE int upb_bytesink_putc(upb_bytesink *sink, char ch) {
}
INLINE int upb_bytesink_putrepeated(upb_bytesink *sink, char ch, int len) {
char buf[len];
memset(buf, ch, len);
return upb_bytesink_write(sink, buf, len);
for (int i = 0; i < len; i++)
if (upb_bytesink_write(sink, &ch, 1) < 0)
return -1;
return len;
}
INLINE uint64_t upb_bytesink_getoffset(upb_bytesink *sink) {

@ -44,7 +44,9 @@
// for a few magic numbers and doing a dumb string replacement.
#ifndef __APPLE__
const unsigned char upb_jit_debug_elf_file[] = {
#include "upb/pb/jit_debug_elf_file.h"
};
typedef enum
{
@ -73,9 +75,9 @@ void __attribute__((noinline)) __jit_debug_register_code() { __asm__ __volatile_
void upb_reg_jit_gdb(upb_decoder *d) {
// Create debug info.
size_t elf_len = upb_pb_jit_debug_elf_file_o_len;
size_t elf_len = sizeof(upb_jit_debug_elf_file);
d->debug_info = malloc(elf_len);
memcpy(d->debug_info, upb_pb_jit_debug_elf_file_o, elf_len);
memcpy(d->debug_info, upb_jit_debug_elf_file, elf_len);
uint64_t *p = (void*)d->debug_info;
for (; (void*)(p+1) <= (void*)d->debug_info + elf_len; ++p) {
if (*p == 0x12345678) { *p = (uintptr_t)d->jit_code; }

@ -41,7 +41,7 @@ static int upb_textprinter_putescaped(upb_textprinter *p, const upb_strref *strr
// TODO; we could read directly from a bytesrc's buffer instead.
// TODO; we could write strrefs to the sink when possible.
char dstbuf[4096], *dst = dstbuf, *dstend = dstbuf + sizeof(dstbuf);
char buf[strref->len], *src = buf;
char *buf = malloc(strref->len), *src = buf;
char *end = src + strref->len;
upb_bytesrc_read(strref->bytesrc, strref->stream_offset, strref->len, buf);
@ -81,8 +81,10 @@ static int upb_textprinter_putescaped(upb_textprinter *p, const upb_strref *strr
}
// Flush remaining data.
CHECK(upb_bytesink_write(p->sink, dst, dst - dstbuf));
free(buf);
return 0;
err:
free(buf);
return -1;
}

@ -189,7 +189,7 @@ void upb_inttable_compact(upb_inttable *t) {
int lg2_array = 0;
while ((1UL << lg2_array) < largest_key) ++lg2_array;
++lg2_array; // Undo the first iteration.
size_t array_size;
size_t array_size = 0;
int array_count = 0;
while (lg2_array > 0) {
array_size = (1 << --lg2_array);
@ -306,10 +306,12 @@ void *upb_strtable_lookup(const upb_strtable *t, const char *key) {
void *upb_strtable_lookupl(const upb_strtable *t, const char *key, size_t len) {
// TODO: improve.
char key2[len+1];
char *key2 = malloc(len+1);
memcpy(key2, key, len);
key2[len] = '\0';
return upb_strtable_lookup(t, key2);
void *ret = upb_strtable_lookup(t, key2);
free(key2);
return ret;
}
static uint32_t empty_strbucket(upb_strtable *table) {

@ -115,7 +115,7 @@ typedef struct {
uint8_t size;
uint8_t native_wire_type;
uint8_t inmemory_type; // For example, INT32, SINT32, and SFIXED32 -> INT32
char *ctype;
const char *ctype;
} upb_type_info;
// A static array of info about all of the field types, indexed by type number.

Loading…
Cancel
Save