Merge pull request #2026 from pherl/cpjs

Fix missing import of jspb.Map (#1885)
This commit is contained in:
Jisi Liu 2016-09-02 11:12:25 -07:00 committed by GitHub
commit 9d30a98893
6 changed files with 66 additions and 14 deletions

View File

@ -21,23 +21,23 @@ case "$1" in
;; ;;
2.6.1) 2.6.1)
OLD_VERSION=2.6.1 OLD_VERSION=2.6.1
OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/2.6.1-build2/protoc-2.6.1-build2-linux-x86_32.exe OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/2.6.1-build2/protoc-2.6.1-build2-linux-x86_64.exe
;; ;;
3.0.0-beta-1) 3.0.0-beta-1)
OLD_VERSION=3.0.0-beta-1 OLD_VERSION=3.0.0-beta-1
OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-1/protoc-3.0.0-beta-1-linux-x86_32.exe OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-1/protoc-3.0.0-beta-1-linux-x86_64.exe
;; ;;
3.0.0-beta-2) 3.0.0-beta-2)
OLD_VERSION=3.0.0-beta-2 OLD_VERSION=3.0.0-beta-2
OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-2/protoc-3.0.0-beta-2-linux-x86_32.exe OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-2/protoc-3.0.0-beta-2-linux-x86_64.exe
;; ;;
3.0.0-beta-3) 3.0.0-beta-3)
OLD_VERSION=3.0.0-beta-3 OLD_VERSION=3.0.0-beta-3
OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-3/protoc-3.0.0-beta-3-linux-x86_32.exe OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-3/protoc-3.0.0-beta-3-linux-x86_64.exe
;; ;;
3.0.0-beta-4) 3.0.0-beta-4)
OLD_VERSION=3.0.0-beta-4 OLD_VERSION=3.0.0-beta-4
OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-4/protoc-3.0.0-beta-4-linux-x86_32.exe OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-4/protoc-3.0.0-beta-4-linux-x86_64.exe
;; ;;
*) *)
echo "[ERROR]: Unknown version number: $1" echo "[ERROR]: Unknown version number: $1"

View File

@ -11,7 +11,9 @@ goog.require('jspb.BinaryWriter');
goog.require('jspb.ExtensionFieldBinaryInfo'); goog.require('jspb.ExtensionFieldBinaryInfo');
goog.require('jspb.ExtensionFieldInfo'); goog.require('jspb.ExtensionFieldInfo');
goog.require('jspb.Message'); goog.require('jspb.Message');
goog.require('jspb.Map');
exports.Map = jspb.Map;
exports.Message = jspb.Message; exports.Message = jspb.Message;
exports.BinaryReader = jspb.BinaryReader; exports.BinaryReader = jspb.BinaryReader;
exports.BinaryWriter = jspb.BinaryWriter; exports.BinaryWriter = jspb.BinaryWriter;

View File

@ -255,10 +255,54 @@ typedef struct {
// value into the map. // value into the map.
typedef struct { typedef struct {
VALUE map; VALUE map;
const map_handlerdata_t* handlerdata;
char key_storage[NATIVE_SLOT_MAX_SIZE]; char key_storage[NATIVE_SLOT_MAX_SIZE];
char value_storage[NATIVE_SLOT_MAX_SIZE]; char value_storage[NATIVE_SLOT_MAX_SIZE];
} map_parse_frame_t; } map_parse_frame_t;
static void MapParseFrame_mark(void* _self) {
map_parse_frame_t* frame = _self;
// This shouldn't strictly be necessary since this should be rooted by the
// message itself, but it can't hurt.
rb_gc_mark(frame->map);
native_slot_mark(frame->handlerdata->key_field_type, &frame->key_storage);
native_slot_mark(frame->handlerdata->value_field_type, &frame->value_storage);
}
void MapParseFrame_free(void* self) {
xfree(self);
}
rb_data_type_t MapParseFrame_type = {
"MapParseFrame",
{ MapParseFrame_mark, MapParseFrame_free, NULL },
};
// Array of Ruby objects wrapping map_parse_frame_t.
// We don't allow multiple concurrent decodes, so we assume that this global
// variable is specific to the "current" decode.
VALUE map_parse_frames;
static map_parse_frame_t* map_push_frame(VALUE map,
const map_handlerdata_t* handlerdata) {
map_parse_frame_t* frame = ALLOC(map_parse_frame_t);
frame->handlerdata = handlerdata;
frame->map = map;
native_slot_init(handlerdata->key_field_type, &frame->key_storage);
native_slot_init(handlerdata->value_field_type, &frame->value_storage);
rb_ary_push(map_parse_frames,
TypedData_Wrap_Struct(rb_cObject, &MapParseFrame_type, frame));
return frame;
}
static void map_pop_frame() {
rb_ary_pop(map_parse_frames);
}
// Handler to begin a map entry: allocates a temporary frame. This is the // Handler to begin a map entry: allocates a temporary frame. This is the
// 'startsubmsg' handler on the msgdef that contains the map field. // 'startsubmsg' handler on the msgdef that contains the map field.
static void *startmapentry_handler(void *closure, const void *hd) { static void *startmapentry_handler(void *closure, const void *hd) {
@ -266,13 +310,7 @@ static void *startmapentry_handler(void *closure, const void *hd) {
const map_handlerdata_t* mapdata = hd; const map_handlerdata_t* mapdata = hd;
VALUE map_rb = DEREF(msg, mapdata->ofs, VALUE); VALUE map_rb = DEREF(msg, mapdata->ofs, VALUE);
map_parse_frame_t* frame = ALLOC(map_parse_frame_t); return map_push_frame(map_rb, mapdata);
frame->map = map_rb;
native_slot_init(mapdata->key_field_type, &frame->key_storage);
native_slot_init(mapdata->value_field_type, &frame->value_storage);
return frame;
} }
// Handler to end a map entry: inserts the value defined during the message into // Handler to end a map entry: inserts the value defined during the message into
@ -298,7 +336,7 @@ static bool endmap_handler(void *closure, const void *hd, upb_status* s) {
&frame->value_storage); &frame->value_storage);
Map_index_set(frame->map, key, value); Map_index_set(frame->map, key, value);
xfree(frame); map_pop_frame();
return true; return true;
} }
@ -737,6 +775,10 @@ VALUE Message_decode(VALUE klass, VALUE data) {
msg_rb = rb_class_new_instance(0, NULL, msgklass); msg_rb = rb_class_new_instance(0, NULL, msgklass);
TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg); TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg);
// We generally expect this to be clear already, but clear it in case parsing
// previously got interrupted somehow.
rb_ary_clear(map_parse_frames);
{ {
const upb_pbdecodermethod* method = msgdef_decodermethod(desc); const upb_pbdecodermethod* method = msgdef_decodermethod(desc);
const upb_handlers* h = upb_pbdecodermethod_desthandlers(method); const upb_handlers* h = upb_pbdecodermethod_desthandlers(method);
@ -781,6 +823,10 @@ VALUE Message_decode_json(VALUE klass, VALUE data) {
msg_rb = rb_class_new_instance(0, NULL, msgklass); msg_rb = rb_class_new_instance(0, NULL, msgklass);
TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg); TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg);
// We generally expect this to be clear already, but clear it in case parsing
// previously got interrupted somehow.
rb_ary_clear(map_parse_frames);
{ {
const upb_json_parsermethod* method = msgdef_jsonparsermethod(desc); const upb_json_parsermethod* method = msgdef_jsonparsermethod(desc);
stackenv se; stackenv se;

View File

@ -112,4 +112,6 @@ void Init_protobuf_c() {
upb_def_to_ruby_obj_map = rb_hash_new(); upb_def_to_ruby_obj_map = rb_hash_new();
rb_gc_register_address(&upb_def_to_ruby_obj_map); rb_gc_register_address(&upb_def_to_ruby_obj_map);
map_parse_frames = rb_ary_new();
rb_gc_register_address(&map_parse_frames);
} }

View File

@ -166,6 +166,8 @@ extern VALUE cBuilder;
extern VALUE cError; extern VALUE cError;
extern VALUE cParseError; extern VALUE cParseError;
extern VALUE map_parse_frames;
// We forward-declare all of the Ruby method implementations here because we // We forward-declare all of the Ruby method implementations here because we
// sometimes call the methods directly across .c files, rather than going // sometimes call the methods directly across .c files, rather than going
// through Ruby's method dispatching (e.g. during message parse). It's cleaner // through Ruby's method dispatching (e.g. during message parse). It's cleaner

View File

@ -11175,7 +11175,7 @@ static bool parse_mapentry_key(upb_json_parser *p) {
sel = getsel_for_handlertype(p, UPB_HANDLER_STRING); sel = getsel_for_handlertype(p, UPB_HANDLER_STRING);
upb_sink_putstring(&subsink, sel, buf, len, NULL); upb_sink_putstring(&subsink, sel, buf, len, NULL);
sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR);
upb_sink_endstr(&subsink, sel); upb_sink_endstr(&p->top->sink, sel);
multipart_end(p); multipart_end(p);
break; break;
} }