From c1dd8e85a1314a7bcb2059b842c6830d854fbefa Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 23 Aug 2017 22:03:18 -0700 Subject: Move parse frame array to the Map object This makes the frame stack per-parser, and per-thread. Fixes #3250 --- ruby/ext/google/protobuf_c/encode_decode.c | 21 ++------------------- ruby/ext/google/protobuf_c/map.c | 12 ++++++++++++ ruby/ext/google/protobuf_c/protobuf.c | 2 -- ruby/ext/google/protobuf_c/protobuf.h | 5 +++-- ruby/tests/basic.rb | 25 +++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 23 deletions(-) (limited to 'ruby') diff --git a/ruby/ext/google/protobuf_c/encode_decode.c b/ruby/ext/google/protobuf_c/encode_decode.c index 6ce6d083..1427f4b8 100644 --- a/ruby/ext/google/protobuf_c/encode_decode.c +++ b/ruby/ext/google/protobuf_c/encode_decode.c @@ -280,11 +280,6 @@ rb_data_type_t MapParseFrame_type = { { 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); @@ -293,16 +288,12 @@ static map_parse_frame_t* map_push_frame(VALUE 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, + Map_push_frame(map, 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 // 'startsubmsg' handler on the msgdef that contains the map field. static void *startmapentry_handler(void *closure, const void *hd) { @@ -336,7 +327,7 @@ static bool endmap_handler(void *closure, const void *hd, upb_status* s) { &frame->value_storage); Map_index_set(frame->map, key, value); - map_pop_frame(); + Map_pop_frame(frame->map); return true; } @@ -775,10 +766,6 @@ VALUE Message_decode(VALUE klass, VALUE data) { msg_rb = rb_class_new_instance(0, NULL, msgklass); 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_handlers* h = upb_pbdecodermethod_desthandlers(method); @@ -823,10 +810,6 @@ VALUE Message_decode_json(VALUE klass, VALUE data) { msg_rb = rb_class_new_instance(0, NULL, msgklass); 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); stackenv se; diff --git a/ruby/ext/google/protobuf_c/map.c b/ruby/ext/google/protobuf_c/map.c index 4be54c39..0787f6d5 100644 --- a/ruby/ext/google/protobuf_c/map.c +++ b/ruby/ext/google/protobuf_c/map.c @@ -146,6 +146,7 @@ void Map_mark(void* _self) { Map* self = _self; rb_gc_mark(self->value_type_class); + rb_gc_mark(self->parse_frames); if (self->value_type == UPB_TYPE_STRING || self->value_type == UPB_TYPE_BYTES || @@ -174,6 +175,16 @@ VALUE Map_alloc(VALUE klass) { return TypedData_Wrap_Struct(klass, &Map_type, self); } +VALUE Map_push_frame(VALUE map, VALUE val) { + Map* self = ruby_to_Map(map); + return rb_ary_push(self->parse_frames, val); +} + +VALUE Map_pop_frame(VALUE map) { + Map* self = ruby_to_Map(map); + return rb_ary_pop(self->parse_frames); +} + static bool needs_typeclass(upb_fieldtype_t type) { switch (type) { case UPB_TYPE_MESSAGE: @@ -227,6 +238,7 @@ VALUE Map_init(int argc, VALUE* argv, VALUE _self) { self->key_type = ruby_to_fieldtype(argv[0]); self->value_type = ruby_to_fieldtype(argv[1]); + self->parse_frames = rb_ary_new(); // Check that the key type is an allowed type. switch (self->key_type) { diff --git a/ruby/ext/google/protobuf_c/protobuf.c b/ruby/ext/google/protobuf_c/protobuf.c index 98963667..7cde4aec 100644 --- a/ruby/ext/google/protobuf_c/protobuf.c +++ b/ruby/ext/google/protobuf_c/protobuf.c @@ -112,6 +112,4 @@ void Init_protobuf_c() { upb_def_to_ruby_obj_map = rb_hash_new(); rb_gc_register_address(&upb_def_to_ruby_obj_map); - map_parse_frames = rb_ary_new(); - rb_gc_register_address(&map_parse_frames); } diff --git a/ruby/ext/google/protobuf_c/protobuf.h b/ruby/ext/google/protobuf_c/protobuf.h index 520e9d9b..8fd1bc64 100644 --- a/ruby/ext/google/protobuf_c/protobuf.h +++ b/ruby/ext/google/protobuf_c/protobuf.h @@ -166,8 +166,6 @@ extern VALUE cBuilder; extern VALUE cError; extern VALUE cParseError; -extern VALUE map_parse_frames; - // We forward-declare all of the Ruby method implementations here because we // sometimes call the methods directly across .c files, rather than going // through Ruby's method dispatching (e.g. during message parse). It's cleaner @@ -397,6 +395,7 @@ typedef struct { upb_fieldtype_t key_type; upb_fieldtype_t value_type; VALUE value_type_class; + VALUE parse_frames; upb_strtable table; } Map; @@ -405,6 +404,8 @@ void Map_free(void* self); VALUE Map_alloc(VALUE klass); VALUE Map_init(int argc, VALUE* argv, VALUE self); void Map_register(VALUE module); +VALUE Map_push_frame(VALUE self, VALUE val); +VALUE Map_pop_frame(VALUE self); extern const rb_data_type_t Map_type; extern VALUE cMap; diff --git a/ruby/tests/basic.rb b/ruby/tests/basic.rb index 020effb0..94071ca0 100644 --- a/ruby/tests/basic.rb +++ b/ruby/tests/basic.rb @@ -96,8 +96,18 @@ module BasicTest optional :d, :enum, 4, "TestEnum" end end + + add_message "repro.Outer" do + map :items, :int32, :message, 1, "repro.Inner" + end + + add_message "repro.Inner" do + end end + + Outer = pool.lookup("repro.Outer").msgclass + Inner = pool.lookup("repro.Inner").msgclass Foo = pool.lookup("Foo").msgclass Bar = pool.lookup("Bar").msgclass Baz = pool.lookup("Baz").msgclass @@ -675,6 +685,21 @@ module BasicTest m.map_string_int32['aaa'] = 3 end + def test_concurrent_decoding + o = Outer.new + o.items[0] = Inner.new + raw = Outer.encode(o) + + thds = 2.times.map do + Thread.new do + 100000.times do + assert_equal o, Outer.decode(raw) + end + end + end + thds.map(&:join) + end + def test_map_encode_decode m = MapMessage.new( :map_string_int32 => {"a" => 1, "b" => 2}, -- cgit v1.2.3 From a459b224b5fbc30c328715a06f95ca494f1e5d6a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 30 Aug 2017 11:16:57 -0700 Subject: Storing the frame on the map means we don't need the array --- ruby/ext/google/protobuf_c/encode_decode.c | 4 ++-- ruby/ext/google/protobuf_c/map.c | 14 +++++--------- ruby/ext/google/protobuf_c/protobuf.h | 5 ++--- 3 files changed, 9 insertions(+), 14 deletions(-) (limited to 'ruby') diff --git a/ruby/ext/google/protobuf_c/encode_decode.c b/ruby/ext/google/protobuf_c/encode_decode.c index 1427f4b8..edbbe6a5 100644 --- a/ruby/ext/google/protobuf_c/encode_decode.c +++ b/ruby/ext/google/protobuf_c/encode_decode.c @@ -288,7 +288,7 @@ static map_parse_frame_t* map_push_frame(VALUE map, native_slot_init(handlerdata->key_field_type, &frame->key_storage); native_slot_init(handlerdata->value_field_type, &frame->value_storage); - Map_push_frame(map, + Map_set_frame(map, TypedData_Wrap_Struct(rb_cObject, &MapParseFrame_type, frame)); return frame; @@ -327,7 +327,7 @@ static bool endmap_handler(void *closure, const void *hd, upb_status* s) { &frame->value_storage); Map_index_set(frame->map, key, value); - Map_pop_frame(frame->map); + Map_set_frame(frame->map, Qnil); return true; } diff --git a/ruby/ext/google/protobuf_c/map.c b/ruby/ext/google/protobuf_c/map.c index 0787f6d5..26e22dc7 100644 --- a/ruby/ext/google/protobuf_c/map.c +++ b/ruby/ext/google/protobuf_c/map.c @@ -146,7 +146,7 @@ void Map_mark(void* _self) { Map* self = _self; rb_gc_mark(self->value_type_class); - rb_gc_mark(self->parse_frames); + rb_gc_mark(self->parse_frame); if (self->value_type == UPB_TYPE_STRING || self->value_type == UPB_TYPE_BYTES || @@ -175,14 +175,10 @@ VALUE Map_alloc(VALUE klass) { return TypedData_Wrap_Struct(klass, &Map_type, self); } -VALUE Map_push_frame(VALUE map, VALUE val) { +VALUE Map_set_frame(VALUE map, VALUE val) { Map* self = ruby_to_Map(map); - return rb_ary_push(self->parse_frames, val); -} - -VALUE Map_pop_frame(VALUE map) { - Map* self = ruby_to_Map(map); - return rb_ary_pop(self->parse_frames); + self->parse_frame = val; + return val; } static bool needs_typeclass(upb_fieldtype_t type) { @@ -238,7 +234,7 @@ VALUE Map_init(int argc, VALUE* argv, VALUE _self) { self->key_type = ruby_to_fieldtype(argv[0]); self->value_type = ruby_to_fieldtype(argv[1]); - self->parse_frames = rb_ary_new(); + self->parse_frame = Qnil; // Check that the key type is an allowed type. switch (self->key_type) { diff --git a/ruby/ext/google/protobuf_c/protobuf.h b/ruby/ext/google/protobuf_c/protobuf.h index 8fd1bc64..f4b110fe 100644 --- a/ruby/ext/google/protobuf_c/protobuf.h +++ b/ruby/ext/google/protobuf_c/protobuf.h @@ -395,7 +395,7 @@ typedef struct { upb_fieldtype_t key_type; upb_fieldtype_t value_type; VALUE value_type_class; - VALUE parse_frames; + VALUE parse_frame; upb_strtable table; } Map; @@ -404,8 +404,7 @@ void Map_free(void* self); VALUE Map_alloc(VALUE klass); VALUE Map_init(int argc, VALUE* argv, VALUE self); void Map_register(VALUE module); -VALUE Map_push_frame(VALUE self, VALUE val); -VALUE Map_pop_frame(VALUE self); +VALUE Map_set_frame(VALUE self, VALUE val); extern const rb_data_type_t Map_type; extern VALUE cMap; -- cgit v1.2.3 From dba647a6b2252e1876b0b8b63d42893c5b16ba14 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Thu, 14 Sep 2017 11:12:55 -0700 Subject: Bump version for minor release --- Protobuf.podspec | 2 +- configure.ac | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- csharp/src/Google.Protobuf/Google.Protobuf.csproj | 2 +- java/core/pom.xml | 2 +- java/pom.xml | 2 +- java/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 24 +++++++++++++++++++---- php/ext/google/protobuf/protobuf.h | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- 13 files changed, 32 insertions(+), 16 deletions(-) (limited to 'ruby') diff --git a/Protobuf.podspec b/Protobuf.podspec index 88bd5b7d..d559d18a 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.4.0' + s.version = '3.4.1' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index 04f7eb7a..0d3e5fb3 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.4.0],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.4.1],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index d32fd943..5b38241a 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.4.0 + 3.4.1 Google Inc. protobuf-packages https://github.com/google/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 4e63646b..75b38175 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.4.0 + 3.4.1 Google Inc. netstandard1.0;net45 true diff --git a/java/core/pom.xml b/java/core/pom.xml index 4608fce6..b0925f74 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -6,7 +6,7 @@ com.google.protobuf protobuf-parent - 3.4.0 + 3.4.1 protobuf-java diff --git a/java/pom.xml b/java/pom.xml index dd3ba3b8..bc8e89b5 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -11,7 +11,7 @@ com.google.protobuf protobuf-parent - 3.4.0 + 3.4.1 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 61abd146..35afb844 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -6,7 +6,7 @@ com.google.protobuf protobuf-parent - 3.4.0 + 3.4.1 protobuf-java-util diff --git a/js/package.json b/js/package.json index c8b75385..5231c846 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.4.0", + "version": "3.4.1", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 2d318517..4a473801 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,11 +10,11 @@ protobuf-opensource@google.com yes - 2017-01-13 - + 2017-09-14 + - 3.4.0 - 3.4.0 + 3.4.1 + 3.4.1 stable @@ -149,6 +149,22 @@ GA release. 3-Clause BSD License +GA release. + + + + + 3.4.1 + 3.4.1 + + + stable + stable + + 2017-09-14 + + 3-Clause BSD License + GA release. diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index b2838e56..eeb145e6 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -37,7 +37,7 @@ #include "upb.h" #define PHP_PROTOBUF_EXTNAME "protobuf" -#define PHP_PROTOBUF_VERSION "3.4.0" +#define PHP_PROTOBUF_VERSION "3.4.1" #define MAX_LENGTH_OF_INT64 20 #define SIZEOF_INT64 8 diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index d68709ea..c6f5a77f 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -10,7 +10,7 @@ com.google.protobuf protoc - 3.4.0 + 3.4.1 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index d26da0df..9f1a4f19 100755 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,7 +30,7 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.4.0' +__version__ = '3.4.1' if __name__ != '__main__': try: diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index bd1e39f1..550941c9 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.4.0.2" + s.version = "3.4.1" s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" s.description = "Protocol Buffers are Google's data interchange format." -- cgit v1.2.3 From 2eb1bacc266ec9496edf66d38f080004edca46bd Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Fri, 15 Sep 2017 13:57:16 -0700 Subject: Bumping minor version for ruby gems --- ruby/google-protobuf.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ruby') diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 550941c9..96606f06 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.4.1" + s.version = "3.4.1.1" s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" s.description = "Protocol Buffers are Google's data interchange format." -- cgit v1.2.3