Commit Graph

52 Commits

Author SHA1 Message Date
Luc Thevenard
d54cafb7c8 Avoid negative indexes for JRuby 2022-04-06 15:49:08 -04:00
Luc Thevenard
d85f03d66a [Ruby] Fix RepeatedField#last, #first inconsistencies 2022-04-01 17:09:22 -04:00
なつき
6c8bda86fe Suppress warning for intentional circular require 2022-02-27 13:15:57 -08:00
Lukas Fittl
fbe6ab2487
[Ruby] Message.decode/encode: Add max_recursion_depth option (#9218)
* Message.decode/encode: Add max_recursion_depth option

This allows increasing the recursing depth from the default of 64, by
setting the "max_recursion_depth" to the desired integer value. This is
useful to encode or decode complex nested protobuf messages that otherwise
error out with a RuntimeError or "Error occurred during parsing".

Fixes #1493

* Address review comments

Co-authored-by: Adam Cozzette <acozzette@google.com>
2022-02-09 08:44:12 -08:00
Joel Courtney
4d94a7cd93 Fixed: incorrect tests 2021-10-27 22:20:45 +11:00
Joel Courtney
947a51a464 Test coverage: .from_ruby / #from_ruby 2021-10-26 12:43:57 +11:00
Joel Courtney
e4ce58cd60
Merge branch 'master' into feature/ruby-better-from_-support-well_known_types 2021-10-17 22:58:15 +11:00
deannagarcia
ed58b7d26b
Merge pull request #8562 from mcclymont/timestamp-from-time-class-method
Add class method Timestamp.from_time to ruby well known types
2021-10-14 11:01:11 -07:00
Jason Lunn
05ddf82f20 Remove blank line 2021-10-04 17:04:03 +00:00
Jason Lunn
3581d85ced Update JRuby to leverage pure-Ruby DSL.
JRuby unit and conformance test fixes.
2021-10-03 18:25:43 -04:00
Joshua Haberman
6d8b05bfd4 Added missing "options" parameter. 2021-08-30 22:58:58 -07:00
Joshua Haberman
3d51eb5d9f Make the Ruby DSL use a unique filename for each implicit file. 2021-08-02 20:43:43 -07:00
Joshua Haberman
b7ab6255d6 Addressed PR comments. 2021-08-02 12:59:49 -07:00
Joshua Haberman
cb649b61e3 Fix for newer Rubies where you cannot #force_encoding on a frozen string. 2021-07-31 13:12:14 -07:00
Joshua Haberman
16e16eb8cd pure-Ruby DSL is passing all tests! 2021-07-31 11:13:08 -07:00
Chris McClymont
6d847adda7 Add class method from_time to ruby well known types - Timestamp 2021-05-05 13:38:05 +10:00
Joel Courtney
ef70acbc03 Improvement: better ruby from_* support in well_known_types.rb
* Added capability to support from_* requests properly by adding class methods and returning self for instance methods
    * `Timestamp.from_time`
    * `Value.from_ruby`
2021-02-03 12:49:20 +11:00
Joshua Haberman
2adea4c64a Some preliminary work towards a ruby builder. 2020-04-19 11:40:59 -07:00
Joshua Haberman
c649397029
Set execute bit on files if and only if they begin with (#!). (#7347)
* Set execute bit on files if and only if they begin with (#!).

Git only tracks the 'x' (executable) bit on each file. Prior to this
CL, our files were a random mix of executable and non-executable.
This change imposes some order by making files executable if and only
if they have shebang (#!) lines at the beginning.

We don't have any executable binaries checked into the repo, so
we shouldn't need to worry about that case.

* Added fix_permissions.sh script to set +x iff a file begins with (#!).
2020-04-01 15:28:25 -07:00
Joshua Haberman
35da84bf64 Ported names fix for Ruby to the release branch. 2019-10-11 14:52:08 -07:00
Joshua Haberman
63f324a993 Roll forward Ruby upb changes now that protobuf Ruby build is fixed (#5866)
* Rolled forward again with "Updated upb from defcleanup branch..."

Revert "Revert "Updated upb from defcleanup branch and modified Ruby to use it (#5539)" (#5848)"

This reverts commit 1568deab40.

* A few more merge fixes.

* Updated for defcleanup2 branch.

* Fixed upb to define upb_decode().

* Fixed names of nested messages.

* Revert submodule.

* Set -std=gnu90 and fixed warnings/errors.

Some of our Kokoro tests seem to run with this level of warnings,
and the source strives to be gnu90 compatible.  Enforcing it for
every build removes the possibility of some errors showing up in
Kokoro/Travis tests only.

* Fixed remaining warnings with gnu90 mode.

I tried to match warning flags with what Ruby appears to do
in our Kokoro tests.

* Initialize values registered by rb_gc_register_address().

* Fixed subtle GC bug.

We need to initialize this marked value before creating the instance.

* Truly fix the GC bug.

* Updated upb for mktime() fix.

* Removed XOPEN_SOURCE as we are not using strptime().

* Removed fixed tests from the conformance failure list for Ruby.

* Fixed memory error related to oneof def names.

* Picked up new upb changes re: JSON printing.

* Uncomment concurrent decoding test.
2019-08-14 14:41:37 -07:00
Chris Gaffney
7da7bec441 ruby: Improve performance of Google::Protobuf::Timestamp#to_time (#6360)
This changes to_time to use Ruby's built in Time.at with nanos support
rather than calculating a float and passing it to Time.at. The new
version runs about 3 times faster than the original version and
allocates fewer objects.

Warming up --------------------------------------
    protobuf#to_time    57.296k i/100ms
      faster#to_time   133.229k i/100ms
Calculating -------------------------------------
    protobuf#to_time    635.361k (± 2.1%) i/s -      3.209M in   5.052169s
      faster#to_time      1.873M (± 3.3%) i/s -      9.459M in   5.055169s

Comparison:
      faster#to_time:  1873368.8 i/s
    protobuf#to_time:   635361.4 i/s - 2.95x  slower

Calculating -------------------------------------
    protobuf#to_time   326.000  memsize (   126.000  retained)
                         7.000  objects (     2.000  retained)
                         0.000  strings (     0.000  retained)
      faster#to_time    86.000  memsize (     0.000  retained)
                         1.000  objects (     0.000  retained)
                         0.000  strings (     0.000  retained)

Comparison:
      faster#to_time:         86 allocated
    protobuf#to_time:        326 allocated - 3.79x more
2019-07-10 09:41:11 -07:00
Joshua Haberman
d57581348d
Revert "Convert Google::Protobuf.deep_copy to pure Ruby" 2019-05-14 14:25:11 -07:00
Aaron Patterson
3b67455319
Convert Google::Protobuf.deep_copy to pure Ruby
In general, I think it will help us to debug issues if we have less C
code and more Ruby code.  This method can be implemented in pure Ruby,
so this commit converts it to pure Ruby.
2019-05-13 15:37:13 -07:00
Joshua Haberman
1568deab40
Revert "Updated upb from defcleanup branch and modified Ruby to use it (#5539)" (#5848)
This reverts commit 37581380fb.
2019-03-06 15:44:38 -08:00
Joshua Haberman
37581380fb
Updated upb from defcleanup branch and modified Ruby to use it (#5539) 2019-03-06 10:20:18 -08:00
Paul Yang
aa5c12e882
Revert "Revert "Enable the ignore_unknown_field option in the Ruby unmarshal options" (#5511)" (#5533)
* Revert "Revert "Enable the ignore_unknown_field option in the Ruby unmarshal options" (#5511)"

This reverts commit be1716a6d0.

* Separate ruby conformance test on Mac

* Fix shell syntax

* Fix test
2019-01-08 10:53:34 -08:00
Paul Yang
be1716a6d0
Revert "Enable the ignore_unknown_field option in the Ruby unmarshal options" (#5511) 2018-12-26 12:26:24 -08:00
Erik Benoist
9ac11326df Adds the ability to ignore unknown fields on parse
This adds the ability for the MRI Ruby library to optionally pass in a
ignore_unknown_fields option when decoding JSON. The functionality was
added upstream in upb, this change exposes that option.
2018-12-21 16:06:21 -06:00
Toby Hsieh
63d2f3bc80 Fix RepeatedField#first in Ruby gem (#5293)
Given an argument, the previous implementation was off by one
(`.first(2)` would return 3 elements) compared to the `Enumerable#first`
method.
2018-10-29 11:32:50 -07:00
Joshua Haberman
e00266a74e
Merge pull request #3847 from FX-HAO/master
Google::Protobuf::Struct can access a missing key (#3846)
2018-07-02 13:56:25 -07:00
Erik Benoist
74f8e24232 Adds a base class for all explicitly raised TypeErrors (#4255)
* This allows for ruby code to catch and handle Protobuf
    TypeErrors separately from the standard Ruby TypeError

  * Maintains backwards compatibility by having the new
    Google::Protobuf::TypeError inherit from the base
    TypeError. Any code that was catching TypeError should
    continue to work.
2018-06-26 20:24:24 -07:00
igorpeshansky
944693c44c Add Google::Protobuf::Any.pack convenience class method. (#4719) 2018-06-19 13:26:41 -07:00
Erik Benoist
a8e2359329 Allows the json marshaller to be passed json marshal options (#4252) 2018-05-22 08:14:04 -07:00
Stuart Campbell
05c2d01b61 Fix RepeatedField#delete_if (#4292)
Make RepeatedField#delete_if consistent with Array#delete_if.
2018-04-30 16:04:13 -07:00
parker
8695997eb5 Google::Protobuf::Struct can access a missing key (#3846) 2017-11-17 11:43:14 +08:00
Andreas Eger
ad203bcb2b fix floating point accuracy problem in Timestamp#to_f
`.quo` return the most exact devision which fixes accuracy problems for the
timestamp coercion
2017-05-13 21:38:15 +02:00
Joshua Haberman
057389cae3 Ruby: removed redundant RepeatedField#slice. (#2449) 2016-12-07 13:39:09 -08:00
Nicolas Noble
866d3e5327 Fixing regular expression...
This will allow loading the extension for Ruby 2.1.10...
2016-08-23 22:46:26 -07:00
Josh Haberman
3cec2ea8d6 Ruby: added custom Struct exception type and fixed Makefile.am. 2016-08-01 14:34:54 -07:00
Josh Haberman
e3094a8d80 Ruby: added API support for well-known types. 2016-07-28 17:02:33 -07:00
Otto Kekäläinen
3808d091f8 Fix spelling in strings and comments 2016-07-03 15:26:04 +03:00
Adam Cozzette
bbb68fe63d Added dig and bsearch_index to RepeatedField methods forwarded to array
This fixes the test_acts_likes_an_array test in RepeatedFieldTest, which
checks that repeated fields respond to the same methods as regular Ruby
arrays. The bsearch_index and dig array methods seem to be new in Ruby
2.3 and so we should support those.
2016-04-27 10:51:22 -07:00
Josh Haberman
af4aa9bd64 Added support for binary gems. 2016-02-04 10:44:22 -08:00
Josh Haberman
c2c43a4917 Fixed lint errors and responded to CR comments.
Change-Id: If7b1cc0f03f609a7f43ddafc8509b44207c60910
2015-07-17 16:29:10 -07:00
Josh Haberman
181c7f2636 Added Ruby to conformance tests.
This involved fixing a few important bugs in the
Ruby implementation -- mostly cases of mixing
upb field types and descriptor types (upb field
types do not distinguish between int/sint/fixed/sfixed
like descriptor types do).

Also added protobuf-specific exceptions so parse
errors can be caught specifically.

Change-Id: Ib49d3db976900b2c6f3455c8b88af52cfb86e036
2015-07-16 12:25:55 -07:00
Chris Fallin
a526605aec Merge pull request #338 from skippy/encode-decode-helpers
ruby: Encode decode cleanup and behavior normalization
2015-05-15 10:52:56 -07:00
Adam Greene
cd7ebbe54f make repeated_field quack like an array 2015-05-14 10:38:11 -07:00
Adam Greene
d1b52a00e0 adding and simplifying encoders/decoders
* make consistent between mri and jruby
* create a #to_h and have it use symbols for keys
* add #to_json and #to_proto helpers on the Google::Protobuf message classes
2015-05-13 10:03:56 -07:00
Adam Greene
c70b6058ea add size alias for length
starting to make `RepeatedField` quack like an array

additional changes:
* make sure gemspec gets all ruby code files
* add homepage in gem spec removes one of the warnings, and the gem spec authors are pushing
everyone to include a homepage in the gem
* remove excess whitespace in test suite to bring formatting inline with the rest of the file
2015-05-01 11:48:04 -07:00