forked from protocolbuffers/protobuf
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ruby segment fault (protocolbuffers#3708)
* Fix ruby segment fault 1) rb_ary_new cannot be called during allocate function. During allocate fucntion, the containing object hasn't been marked and rb_ary_new may invoke gc to collect containing object. 2) The global map should be marked before allocating it. Otherwise it may be garbage collected. * Add test * Remove commented code * Fix grammer error
- Loading branch information
Showing
8 changed files
with
88 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/ruby | ||
# | ||
# generated_code.rb is in the same directory as this test. | ||
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) | ||
|
||
old_gc = GC.stress | ||
GC.stress = 0x01 | 0x04 | ||
require 'generated_code_pb' | ||
GC.stress = old_gc | ||
|
||
require 'test/unit' | ||
|
||
class GCTest < Test::Unit::TestCase | ||
def get_msg | ||
A::B::C::TestMessage.new( | ||
:optional_int32 => 1, | ||
:optional_int64 => 1, | ||
:optional_uint32 => 1, | ||
:optional_uint64 => 1, | ||
:optional_bool => true, | ||
:optional_double => 1.0, | ||
:optional_float => 1.0, | ||
:optional_string => "a", | ||
:optional_bytes => "b", | ||
:optional_enum => A::B::C::TestEnum::A, | ||
:optional_msg => A::B::C::TestMessage.new(), | ||
:repeated_int32 => [1], | ||
:repeated_int64 => [1], | ||
:repeated_uint32 => [1], | ||
:repeated_uint64 => [1], | ||
:repeated_bool => [true], | ||
:repeated_double => [1.0], | ||
:repeated_float => [1.0], | ||
:repeated_string => ["a"], | ||
:repeated_bytes => ["b"], | ||
:repeated_enum => [A::B::C::TestEnum::A], | ||
:repeated_msg => [A::B::C::TestMessage.new()], | ||
:map_int32_string => {1 => "a"}, | ||
:map_int64_string => {1 => "a"}, | ||
:map_uint32_string => {1 => "a"}, | ||
:map_uint64_string => {1 => "a"}, | ||
:map_bool_string => {true => "a"}, | ||
:map_string_string => {"a" => "a"}, | ||
:map_string_msg => {"a" => A::B::C::TestMessage.new()}, | ||
:map_string_int32 => {"a" => 1}, | ||
:map_string_bool => {"a" => true}, | ||
) | ||
end | ||
def test_generated_msg | ||
old_gc = GC.stress | ||
GC.stress = 0x01 | 0x04 | ||
from = get_msg | ||
data = A::B::C::TestMessage.encode(from) | ||
to = A::B::C::TestMessage.decode(data) | ||
GC.stress = old_gc | ||
puts "passed" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters