Skip to content

Commit

Permalink
Sync with internal Google development.
Browse files Browse the repository at this point in the history
This breaks the open-source build, will
follow up with a change to fix it.
  • Loading branch information
haberman committed Dec 22, 2011
1 parent b5f5ee8 commit 1bcab13
Show file tree
Hide file tree
Showing 31 changed files with 2,118 additions and 774 deletions.
16 changes: 5 additions & 11 deletions Makefile
Expand Up @@ -162,13 +162,9 @@ upb/pb/jit_debug_elf_file.o: upb/pb/jit_debug_elf_file.s
$(E) GAS $<
$(Q) gcc -c upb/pb/jit_debug_elf_file.s -o upb/pb/jit_debug_elf_file.o

upb/pb/jit_debug_elf_file2.o: upb/pb/jit_debug_elf_file.o
$(E) OBJCOPY $<
$(Q) objcopy --change-section-address .text=0x12345678 $< $@

upb/pb/jit_debug_elf_file.h: upb/pb/jit_debug_elf_file2.o
upb/pb/jit_debug_elf_file.h: upb/pb/jit_debug_elf_file.o
$(E) XXD $<
$(Q) xxd -i < upb/pb/jit_debug_elf_file2.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

Expand Down Expand Up @@ -232,15 +228,13 @@ VALGRIND=valgrind --leak-check=full --error-exitcode=1
test: tests
@echo Running all tests under valgrind.
@set -e # Abort on error.
@for test in $(SIMPLE_TESTS) $(SIMPLE_CXX_TESTS); do \
@for test in $(TESTS); do \
if [ -x ./$$test ] ; then \
echo !!! $(VALGRIND) ./$$test; \
$(VALGRIND) ./$$test tests/test.proto.pb || exit 1; \
$(VALGRIND) ./$$test || exit 1; \
fi \
done; \
$(VALGRIND) ./tests/t.test_vs_proto2.googlemessage1 benchmarks/google_messages.proto.pb benchmarks/google_message1.dat
$(VALGRIND) ./tests/t.test_vs_proto2.googlemessage2 benchmarks/google_messages.proto.pb benchmarks/google_message2.dat
@echo "All tests passed!"
echo "All tests passed!"

tests/t.test_vs_proto2.googlemessage1 \
tests/t.test_vs_proto2.googlemessage2: \
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/parsestream.upb.c
Expand Up @@ -76,7 +76,8 @@ static size_t run(int i)
(void)i;
upb_status status = UPB_STATUS_INIT;
upb_stringsrc_reset(&stringsrc, input_str, input_len);
upb_decoder_reset(&decoder, upb_stringsrc_allbytes(&stringsrc), NULL);
upb_decoder_reset(&decoder, upb_stringsrc_bytesrc(&stringsrc),
0, UPB_NONDELIMITED, NULL);
upb_decoder_decode(&decoder, &status);
if(!upb_ok(&status)) goto err;
return input_len;
Expand Down
24 changes: 8 additions & 16 deletions benchmarks/parsetoproto2.upb.cc
Expand Up @@ -24,7 +24,6 @@
#include <google/protobuf/descriptor.h>
#undef private

char *str;
static size_t len;
MESSAGE_CIDENT msg[NUM_MESSAGES];
MESSAGE_CIDENT msg2;
Expand Down Expand Up @@ -54,13 +53,9 @@ upb_flow_t proto2_setstr(void *m, upb_value fval, upb_value val) {
const upb_fielddef *f = upb_value_getfielddef(fval);
std::string **str = (std::string**)UPB_INDEX(m, f->offset, 1);
if (*str == f->default_ptr) *str = new std::string;
const upb_byteregion *ref = upb_value_getbyteregion(val);
uint32_t len;
(*str)->assign(
upb_byteregion_getptr(ref, upb_byteregion_startofs(ref), &len),
upb_byteregion_len(ref));
assert(len == upb_byteregion_len(ref));
const upb_strref *ref = upb_value_getstrref(val);
// XXX: only supports contiguous strings atm.
(*str)->assign(ref->ptr, ref->len);
return UPB_CONTINUE;
}

Expand All @@ -69,13 +64,9 @@ upb_flow_t proto2_append_str(void *_r, upb_value fval, upb_value val) {
typedef google::protobuf::RepeatedPtrField<std::string> R;
(void)fval;
R *r = (R*)_r;
const upb_byteregion *ref = upb_value_getbyteregion(val);
const upb_strref *ref = upb_value_getstrref(val);
// XXX: only supports contiguous strings atm.
uint32_t len;
r->Add()->assign(
upb_byteregion_getptr(ref, upb_byteregion_startofs(ref), &len),
upb_byteregion_len(ref));
assert(len == upb_byteregion_len(ref));
r->Add()->assign(ref->ptr, ref->len);
return UPB_CONTINUE;
}

Expand Down Expand Up @@ -274,7 +265,7 @@ static bool initialize()
upb_symtab_unref(s);

// Read the message data itself.
str = upb_readfile(MESSAGE_FILE, &len);
char *str = upb_readfile(MESSAGE_FILE, &len);
if(str == NULL) {
fprintf(stderr, "Error reading " MESSAGE_FILE "\n");
return false;
Expand All @@ -284,6 +275,7 @@ static bool initialize()
msg2.ParseFromArray(str, len);

upb_stringsrc_init(&strsrc);
upb_stringsrc_reset(&strsrc, str, len);
upb_handlers *h = upb_handlers_new();
upb_accessors_reghandlers(h, def);
if (!JIT) h->should_jit = false;
Expand All @@ -304,8 +296,8 @@ static size_t run(int i)
(void)i;
upb_status status = UPB_STATUS_INIT;
msg[i % NUM_MESSAGES].Clear();
upb_stringsrc_reset(&strsrc, str, len);
upb_decoder_reset(&d, upb_stringsrc_allbytes(&strsrc), &msg[i % NUM_MESSAGES]);
upb_decoder_reset(&d, upb_stringsrc_bytesrc(&strsrc),
0, UPB_NONDELIMITED, &msg[i % NUM_MESSAGES]);
upb_decoder_decode(&d, &status);
if(!upb_ok(&status)) goto err;
return len;
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/parsetostruct.upb.c
Expand Up @@ -8,7 +8,6 @@
#include "upb/pb/glue.h"

static const upb_msgdef *def;
char *str;
static size_t len;
static void *msg[NUM_MESSAGES];
static upb_stringsrc strsrc;
Expand All @@ -34,7 +33,7 @@ static bool initialize()
upb_symtab_unref(s);

// Read the message data itself.
str = upb_readfile(MESSAGE_FILE, &len);
char *str = upb_readfile(MESSAGE_FILE, &len);
if(str == NULL) {
fprintf(stderr, "Error reading " MESSAGE_FILE "\n");
return false;
Expand All @@ -44,6 +43,7 @@ static bool initialize()
msg[i] = upb_stdmsg_new(def);

upb_stringsrc_init(&strsrc);
upb_stringsrc_reset(&strsrc, str, len);
upb_handlers *h = upb_handlers_new();
upb_accessors_reghandlers(h, def);
if (!JIT) h->should_jit = false;
Expand All @@ -70,8 +70,8 @@ static size_t run(int i)
upb_status status = UPB_STATUS_INIT;
i %= NUM_MESSAGES;
upb_msg_clear(msg[i], def);
upb_stringsrc_reset(&strsrc, str, len);
upb_decoder_reset(&d, upb_stringsrc_allbytes(&strsrc), msg[i]);
upb_decoder_reset(&d, upb_stringsrc_bytesrc(&strsrc),
0, UPB_NONDELIMITED, msg[i]);
upb_decoder_decode(&d, &status);
if(!upb_ok(&status)) goto err;
return len;
Expand Down
39 changes: 39 additions & 0 deletions bindings/cpp/upb/bytestream.cc
@@ -0,0 +1,39 @@
//
// upb - a minimalist implementation of protocol buffers.
//
// Copyright (c) 2011 Google Inc. See LICENSE for details.
// Author: Josh Haberman <jhaberman@gmail.com>

#include "bytestream.hpp"

namespace upb {

upb_bytesrc_vtbl* ByteSourceBase::vtable() {
static upb_bytesrc_vtbl vtbl = {
&ByteSourceBase::VFetch,
&ByteSourceBase::VDiscard,
&ByteSourceBase::VCopy,
&ByteSourceBase::VGetPtr,
};
return &vtbl;
}

upb_bytesuccess_t ByteSourceBase::VFetch(void *src, uint64_t ofs, size_t *len) {
return static_cast<ByteSourceBase*>(src)->Fetch(ofs, len);
}

void ByteSourceBase::VCopy(
const void *src, uint64_t ofs, size_t len, char* dest) {
static_cast<const ByteSourceBase*>(src)->Copy(ofs, len, dest);
}

void ByteSourceBase::VDiscard(void *src, uint64_t ofs) {
static_cast<ByteSourceBase*>(src)->Discard(ofs);
}

const char * ByteSourceBase::VGetPtr(
const void *src, uint64_t ofs, size_t* len) {
return static_cast<const ByteSourceBase*>(src)->GetPtr(ofs, len);
}

} // namespace upb

0 comments on commit 1bcab13

Please sign in to comment.