Updated upb and simplified ruby code a bit with new upb method.

pull/1455/head
Josh Haberman 9 years ago
parent 4057447997
commit d419ca10b4
  1. 7
      ruby/ext/google/protobuf_c/encode_decode.c
  2. 38
      ruby/ext/google/protobuf_c/message.c
  3. 1412
      ruby/ext/google/protobuf_c/upb.c
  4. 1429
      ruby/ext/google/protobuf_c/upb.h

@ -656,7 +656,6 @@ static const upb_json_parsermethod *msgdef_jsonparsermethod(Descriptor* desc) {
#define STACK_ENV_STACKBYTES 4096 #define STACK_ENV_STACKBYTES 4096
typedef struct { typedef struct {
upb_env env; upb_env env;
upb_seededalloc alloc;
const char* ruby_error_template; const char* ruby_error_template;
char allocbuf[STACK_ENV_STACKBYTES]; char allocbuf[STACK_ENV_STACKBYTES];
} stackenv; } stackenv;
@ -681,16 +680,12 @@ static bool env_error_func(void* ud, const upb_status* status) {
static void stackenv_init(stackenv* se, const char* errmsg) { static void stackenv_init(stackenv* se, const char* errmsg) {
se->ruby_error_template = errmsg; se->ruby_error_template = errmsg;
upb_env_init(&se->env); upb_env_init2(&se->env, se->allocbuf, sizeof(se->allocbuf), NULL);
upb_seededalloc_init(&se->alloc, &se->allocbuf, STACK_ENV_STACKBYTES);
upb_env_setallocfunc(
&se->env, upb_seededalloc_getallocfunc(&se->alloc), &se->alloc);
upb_env_seterrorfunc(&se->env, env_error_func, se); upb_env_seterrorfunc(&se->env, env_error_func, se);
} }
static void stackenv_uninit(stackenv* se) { static void stackenv_uninit(stackenv* se) {
upb_env_uninit(&se->env); upb_env_uninit(&se->env);
upb_seededalloc_uninit(&se->alloc);
} }
/* /*

@ -151,32 +151,30 @@ VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self) {
name_len--; name_len--;
} }
// Check for a oneof name first. // See if this name corresponds to either a oneof or field in this message.
o = upb_msgdef_ntoo(self->descriptor->msgdef, if (!upb_msgdef_lookupname(self->descriptor->msgdef, name, name_len, &f,
name, name_len); &o)) {
return rb_call_super(argc, argv);
}
if (o != NULL) { if (o != NULL) {
// This is a oneof -- return which field inside the oneof is set.
if (setter) { if (setter) {
rb_raise(rb_eRuntimeError, "Oneof accessors are read-only."); rb_raise(rb_eRuntimeError, "Oneof accessors are read-only.");
} }
return which_oneof_field(self, o); return which_oneof_field(self, o);
}
// Otherwise, check for a field with that name.
f = upb_msgdef_ntof(self->descriptor->msgdef,
name, name_len);
if (f == NULL) {
return rb_call_super(argc, argv);
}
if (setter) {
if (argc < 2) {
rb_raise(rb_eArgError, "No value provided to setter.");
}
layout_set(self->descriptor->layout, Message_data(self), f, argv[1]);
return Qnil;
} else { } else {
return layout_get(self->descriptor->layout, Message_data(self), f); // This is a field -- get or set the field's value.
assert(f);
if (setter) {
if (argc < 2) {
rb_raise(rb_eArgError, "No value provided to setter.");
}
layout_set(self->descriptor->layout, Message_data(self), f, argv[1]);
return Qnil;
} else {
return layout_get(self->descriptor->layout, Message_data(self), f);
}
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save