Ported Ruby extension to upb_msg (#8184)
* WIP. * WIP. * WIP. * WIP. * WIP. * WIP. * Added some missing files. * WIP. * WIP. * Updated upb. * Extension loads, but crashes immediately. * Gets through the test suite without SEGV! Still a lot of bugs to fix, but it is a major step! 214 tests, 378 assertions, 37 failures, 147 errors, 0 pendings, 0 omissions, 0 notifications 14.0187% passed * Test and build for Ruby 3.0 * Fixed a few more bugs, efficient #inspect is almost done. 214 tests, 134243 assertions, 30 failures, 144 errors, 0 pendings, 0 omissions, 0 notifications 18.6916% passed * Fixed message hash initialization and encode depth checking. 214 tests, 124651 assertions, 53 failures, 70 errors, 0 pendings, 0 omissions, 0 notifications 42.5234% passed * A bunch of fixes to failing tests, now 70% passing. 214 tests, 202091 assertions, 41 failures, 23 errors, 0 pendings, 0 omissions, 0 notifications 70.0935% passed * More than 80% of tests are passing now. 214 tests, 322331 assertions, 30 failures, 9 errors, 0 pendings, 0 omissions, 0 notifications 81.7757% passed Unfortunately there is also a sporadic bug/segfault hanging around that appears to be GC-related. * Add linux/ruby30 and macos/ruby30 * Use rvm master for 3.0.0-preview2 * Over 90% of tests are passing! 214 tests, 349898 assertions, 15 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications 92.5234% passed * Passes all tests! 214 tests, 369388 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 100% passed * A bunch of cleanup. 1. Removed a bunch of internal-only symbols from headers. 2. Required a frozen check to get a non-const pointer to a map or array. 3. De-duplicated the code to get a type argument for Map/RepeatedField. * Removed a bunch more stuff from protobuf.h. There is an intermittent assert failure. Intermittent failure: ruby: ../../../../ext/google/protobuf_c/protobuf.c:263: ObjectCache_Add: Assertion `rb_funcall(obj_cache2, (__builtin_constant_p("[]") ? __extension__ ({ static ID rb_intern_id_cache; if (!rb_intern_id_cache) rb_intern_id_cache = rb_intern2((("[]") ), (long)strlen(("[]"))); (ID) rb_intern_id_cache; }) : rb_intern("[]")), 1, key_rb) == val' failed * Removed a few more things from protobuf.h. * Ruby 3.0.0-preview2 to 3.0.0 * Require rake-compiler-dock >= 1.1.0 * More progress, fighting with the object cache. * Passes on all Ruby versions! * Updated and clarified comment regarding WeakMap. * Fixed the wyhash compile. * Fixed conformance tests for Ruby. Conformance results now look like: RUBYLIB=../ruby/lib:. ./conformance-test-runner --enforce_recommended --failure_list failure_list_ruby.txt --text_format_failure_list text_format_failure_list_ruby.txt ./conformance_ruby.rb CONFORMANCE TEST BEGIN ==================================== CONFORMANCE SUITE PASSED: 1955 successes, 0 skipped, 58 expected failures, 0 unexpected failures. CONFORMANCE TEST BEGIN ==================================== CONFORMANCE SUITE PASSED: 0 successes, 111 skipped, 8 expected failures, 0 unexpected failures. Fixes include: - Changed Ruby compiler to no longer reject proto2 maps. - Changed Ruby compiler to emit a warning when proto2 extensions are present instead of rejecting the .proto file completely. - Fixed conformance tests to allow proto2 and look up message by name instead of hardcoding a specific list of messages. - Fixed conformance test to support the "ignore unknown" option for JSON. - Fixed conformance test to properly report serialization errors. * Removed debug printf and fixed #inspect for floats. * Fixed compatibility test to have proper semantics for #to_json. * Updated Makefile.am with new file list. * Don't try to copy wyhash when inside Docker. * Fixed bug where we would forget that a sub-object is frozen in Ruby >=2.7. * Avoid exporting unneeded symbols and refactored a bit of code. * Some more refactoring. * Simplified and added more comments. * Some more comments and simplification. Added a missing license block. Co-authored-by: Masaki Hara <hara@wantedly.com>pull/8209/head
parent
468bc193ec
commit
9abf6e2ab0
42 changed files with 14071 additions and 23328 deletions
@ -1,114 +1,58 @@ |
||||
Recommended.FieldMaskNumbersDontRoundTrip.JsonOutput |
||||
Recommended.FieldMaskPathsDontRoundTrip.JsonOutput |
||||
Recommended.FieldMaskTooManyUnderscore.JsonOutput |
||||
Recommended.Proto2.JsonInput.FieldNameExtension.Validator |
||||
Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput |
||||
Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput |
||||
Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator |
||||
Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator |
||||
Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter |
||||
Recommended.Proto3.JsonInput.MapFieldValueIsNull |
||||
Recommended.Proto3.JsonInput.NullValueInNormalMessage.Validator |
||||
Recommended.Proto3.JsonInput.NullValueInOtherOneofNewFormat.Validator |
||||
Recommended.Proto3.JsonInput.NullValueInOtherOneofOldFormat.Validator |
||||
Recommended.Proto3.JsonInput.RepeatedFieldMessageElementIsNull |
||||
Recommended.Proto3.JsonInput.RepeatedFieldPrimitiveElementIsNull |
||||
Recommended.Proto3.JsonInput.StringEndsWithEscapeChar |
||||
Recommended.Proto3.JsonInput.StringFieldSurrogateInWrongOrder |
||||
Recommended.Proto3.JsonInput.StringFieldUnpairedHighSurrogate |
||||
Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate |
||||
Recommended.Proto3.JsonInput.TimestampHas3FractionalDigits.Validator |
||||
Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.BOOL.UnpackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.BOOL.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.PackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.UnpackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.BOOL.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.DOUBLE.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.DOUBLE.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED32.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED32.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED32.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED32.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT32.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT32.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataOneofBinary.MESSAGE.Merge.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.BOOL.UnpackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.PackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.UnpackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.PackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.UnpackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.PackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.UnpackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT32.PackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT32.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT32.UnpackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT32.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.DefaultOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.PackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.ENUM[3].ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.ENUM[4].ProtobufOutput |
||||
Required.DurationProtoInputTooLarge.JsonOutput |
||||
Required.DurationProtoInputTooSmall.JsonOutput |
||||
Required.Proto2.JsonInput.StoresDefaultPrimitive.Validator |
||||
Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput |
||||
Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput |
||||
Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.JsonOutput |
||||
Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.ProtobufOutput |
||||
Required.Proto3.JsonInput.DoubleFieldNan.JsonOutput |
||||
Required.Proto3.JsonInput.DurationMinValue.JsonOutput |
||||
Required.Proto3.JsonInput.DurationRepeatedValue.JsonOutput |
||||
Required.Proto3.JsonInput.FloatFieldInfinity.JsonOutput |
||||
Required.Proto3.JsonInput.FloatFieldNan.JsonOutput |
||||
Required.Proto3.JsonInput.FloatFieldNegativeInfinity.JsonOutput |
||||
Required.Proto3.JsonInput.IgnoreUnknownJsonFalse.ProtobufOutput |
||||
Required.Proto3.JsonInput.IgnoreUnknownJsonNull.ProtobufOutput |
||||
Required.Proto3.JsonInput.IgnoreUnknownJsonNumber.ProtobufOutput |
||||
Required.Proto3.JsonInput.IgnoreUnknownJsonObject.ProtobufOutput |
||||
Required.Proto3.JsonInput.IgnoreUnknownJsonString.ProtobufOutput |
||||
Required.Proto3.JsonInput.IgnoreUnknownJsonTrue.ProtobufOutput |
||||
Required.Proto3.JsonInput.OneofFieldDuplicate |
||||
Required.Proto3.JsonInput.RejectTopLevelNull |
||||
Required.Proto3.JsonInput.StringFieldSurrogatePair.JsonOutput |
||||
Required.Proto3.JsonInput.StringFieldSurrogatePair.ProtobufOutput |
||||
Required.Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput |
||||
Required.Proto3.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput |
||||
Required.Proto3.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput |
||||
Required.Proto3.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput |
||||
Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MissingDefault.JsonOutput |
||||
Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.JsonOutput |
||||
Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.JsonOutput |
||||
Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[2].JsonOutput |
||||
Required.TimestampProtoInputTooLarge.JsonOutput |
||||
Required.TimestampProtoInputTooSmall.JsonOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.PackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.UnpackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.PackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.UnpackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT32.PackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT32.UnpackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.UnpackedOutput.ProtobufOutput |
||||
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.UnpackedOutput.ProtobufOutput |
||||
|
@ -0,0 +1,18 @@ |
||||
#!/bin/bash |
||||
# |
||||
# This is the top-level script we give to Kokoro as the entry point for |
||||
# running the "pull request" project: |
||||
# |
||||
# This script selects a specific Dockerfile (for building a Docker image) and |
||||
# a script to run inside that image. Then we delegate to the general |
||||
# build_and_run_docker.sh script. |
||||
|
||||
# Change to repo root |
||||
cd $(dirname $0)/../../.. |
||||
|
||||
export DOCKERHUB_ORGANIZATION=protobuftesting |
||||
export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/ruby |
||||
export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh |
||||
export OUTPUT_DIR=testoutput |
||||
export TEST_SET="ruby30" |
||||
./kokoro/linux/build_and_run_docker.sh |
@ -0,0 +1,11 @@ |
||||
# Config file for running tests in Kokoro |
||||
|
||||
# Location of the build script in repository |
||||
build_file: "protobuf/kokoro/linux/ruby30/build.sh" |
||||
timeout_mins: 120 |
||||
|
||||
action { |
||||
define_artifacts { |
||||
regex: "**/sponge_log.xml" |
||||
} |
||||
} |
@ -0,0 +1,11 @@ |
||||
# Config file for running tests in Kokoro |
||||
|
||||
# Location of the build script in repository |
||||
build_file: "protobuf/kokoro/linux/ruby30/build.sh" |
||||
timeout_mins: 120 |
||||
|
||||
action { |
||||
define_artifacts { |
||||
regex: "**/sponge_log.xml" |
||||
} |
||||
} |
@ -0,0 +1,13 @@ |
||||
#!/bin/bash |
||||
# |
||||
# Build file to set up and run tests |
||||
|
||||
# Change to repo root |
||||
cd $(dirname $0)/../../.. |
||||
|
||||
# Prepare worker environment to run tests |
||||
KOKORO_INSTALL_RUBY=yes |
||||
KOKORO_INSTALL_RVM=yes |
||||
source kokoro/macos/prepare_build_macos_rc |
||||
|
||||
./tests.sh ruby30 |
@ -0,0 +1,5 @@ |
||||
# Config file for running tests in Kokoro |
||||
|
||||
# Location of the build script in repository |
||||
build_file: "protobuf/kokoro/macos/ruby30/build.sh" |
||||
timeout_mins: 1440 |
@ -0,0 +1,5 @@ |
||||
# Config file for running tests in Kokoro |
||||
|
||||
# Location of the build script in repository |
||||
build_file: "protobuf/kokoro/macos/ruby30/build.sh" |
||||
timeout_mins: 1440 |
@ -0,0 +1,349 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Ruby <-> upb data conversion functions.
|
||||
//
|
||||
// This file Also contains a few other assorted algorithms on upb_msgval.
|
||||
//
|
||||
// None of the algorithms in this file require any access to the internal
|
||||
// representation of Ruby or upb objects.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include "convert.h" |
||||
|
||||
#include "message.h" |
||||
#include "protobuf.h" |
||||
#include "third_party/wyhash/wyhash.h" |
||||
|
||||
static upb_strview Convert_StringData(VALUE str, upb_arena *arena) { |
||||
upb_strview ret; |
||||
if (arena) { |
||||
char *ptr = upb_arena_malloc(arena, RSTRING_LEN(str)); |
||||
memcpy(ptr, RSTRING_PTR(str), RSTRING_LEN(str)); |
||||
ret.data = ptr; |
||||
} else { |
||||
// Data is only needed temporarily (within map lookup).
|
||||
ret.data = RSTRING_PTR(str); |
||||
} |
||||
ret.size = RSTRING_LEN(str); |
||||
return ret; |
||||
} |
||||
|
||||
static bool is_ruby_num(VALUE value) { |
||||
return (TYPE(value) == T_FLOAT || |
||||
TYPE(value) == T_FIXNUM || |
||||
TYPE(value) == T_BIGNUM); |
||||
} |
||||
|
||||
static void Convert_CheckInt(const char* name, upb_fieldtype_t type, |
||||
VALUE val) { |
||||
if (!is_ruby_num(val)) { |
||||
rb_raise(cTypeError, |
||||
"Expected number type for integral field '%s' (given %s).", name, |
||||
rb_class2name(CLASS_OF(val))); |
||||
} |
||||
|
||||
// NUM2{INT,UINT,LL,ULL} macros do the appropriate range checks on upper
|
||||
// bound; we just need to do precision checks (i.e., disallow rounding) and
|
||||
// check for < 0 on unsigned types.
|
||||
if (TYPE(val) == T_FLOAT) { |
||||
double dbl_val = NUM2DBL(val); |
||||
if (floor(dbl_val) != dbl_val) { |
||||
rb_raise(rb_eRangeError, |
||||
"Non-integral floating point value assigned to integer field " |
||||
"'%s' (given %s).", |
||||
name, rb_class2name(CLASS_OF(val))); |
||||
} |
||||
} |
||||
if (type == UPB_TYPE_UINT32 || type == UPB_TYPE_UINT64) { |
||||
if (NUM2DBL(val) < 0) { |
||||
rb_raise( |
||||
rb_eRangeError, |
||||
"Assigning negative value to unsigned integer field '%s' (given %s).", |
||||
name, rb_class2name(CLASS_OF(val))); |
||||
} |
||||
} |
||||
} |
||||
|
||||
static int32_t Convert_ToEnum(VALUE value, const char* name, |
||||
const upb_enumdef* e) { |
||||
int32_t val; |
||||
|
||||
switch (TYPE(value)) { |
||||
case T_FLOAT: |
||||
case T_FIXNUM: |
||||
case T_BIGNUM: |
||||
Convert_CheckInt(name, UPB_TYPE_INT32, value); |
||||
val = NUM2INT(value); |
||||
break; |
||||
case T_STRING: |
||||
if (!upb_enumdef_ntoi(e, RSTRING_PTR(value), RSTRING_LEN(value), &val)) { |
||||
goto unknownval; |
||||
} |
||||
break; |
||||
case T_SYMBOL: |
||||
if (!upb_enumdef_ntoiz(e, rb_id2name(SYM2ID(value)), &val)) { |
||||
goto unknownval; |
||||
} |
||||
break; |
||||
default: |
||||
rb_raise(cTypeError, |
||||
"Expected number or symbol type for enum field '%s'.", name); |
||||
} |
||||
|
||||
return val; |
||||
|
||||
unknownval: |
||||
rb_raise(rb_eRangeError, "Unknown symbol value for enum field '%s'.", name); |
||||
} |
||||
|
||||
upb_msgval Convert_RubyToUpb(VALUE value, const char* name, TypeInfo type_info, |
||||
upb_arena* arena) { |
||||
upb_msgval ret; |
||||
|
||||
switch (type_info.type) { |
||||
case UPB_TYPE_FLOAT: |
||||
if (!is_ruby_num(value)) { |
||||
rb_raise(cTypeError, "Expected number type for float field '%s' (given %s).", |
||||
name, rb_class2name(CLASS_OF(value))); |
||||
} |
||||
ret.float_val = NUM2DBL(value); |
||||
break; |
||||
case UPB_TYPE_DOUBLE: |
||||
if (!is_ruby_num(value)) { |
||||
rb_raise(cTypeError, "Expected number type for double field '%s' (given %s).", |
||||
name, rb_class2name(CLASS_OF(value))); |
||||
} |
||||
ret.double_val = NUM2DBL(value); |
||||
break; |
||||
case UPB_TYPE_BOOL: { |
||||
if (value == Qtrue) { |
||||
ret.bool_val = 1; |
||||
} else if (value == Qfalse) { |
||||
ret.bool_val = 0; |
||||
} else { |
||||
rb_raise(cTypeError, "Invalid argument for boolean field '%s' (given %s).", |
||||
name, rb_class2name(CLASS_OF(value))); |
||||
} |
||||
break; |
||||
} |
||||
case UPB_TYPE_STRING: { |
||||
VALUE utf8 = rb_enc_from_encoding(rb_utf8_encoding()); |
||||
if (CLASS_OF(value) == rb_cSymbol) { |
||||
value = rb_funcall(value, rb_intern("to_s"), 0); |
||||
} else if (CLASS_OF(value) != rb_cString) { |
||||
rb_raise(cTypeError, "Invalid argument for string field '%s' (given %s).", |
||||
name, rb_class2name(CLASS_OF(value))); |
||||
} |
||||
|
||||
if (rb_obj_encoding(value) != utf8) { |
||||
// Note: this will not duplicate underlying string data unless necessary.
|
||||
value = rb_str_encode(value, utf8, 0, Qnil); |
||||
|
||||
if (rb_enc_str_coderange(value) == ENC_CODERANGE_BROKEN) { |
||||
rb_raise(rb_eEncodingError, "String is invalid UTF-8"); |
||||
} |
||||
} |
||||
|
||||
ret.str_val = Convert_StringData(value, arena); |
||||
break; |
||||
} |
||||
case UPB_TYPE_BYTES: { |
||||
VALUE bytes = rb_enc_from_encoding(rb_ascii8bit_encoding()); |
||||
if (CLASS_OF(value) != rb_cString) { |
||||
rb_raise(cTypeError, "Invalid argument for bytes field '%s' (given %s).", |
||||
name, rb_class2name(CLASS_OF(value))); |
||||
} |
||||
|
||||
if (rb_obj_encoding(value) != bytes) { |
||||
// Note: this will not duplicate underlying string data unless necessary.
|
||||
// TODO(haberman): is this really necessary to get raw bytes?
|
||||
value = rb_str_encode(value, bytes, 0, Qnil); |
||||
} |
||||
|
||||
ret.str_val = Convert_StringData(value, arena); |
||||
break; |
||||
} |
||||
case UPB_TYPE_MESSAGE: |
||||
ret.msg_val = |
||||
Message_GetUpbMessage(value, type_info.def.msgdef, name, arena); |
||||
break; |
||||
case UPB_TYPE_ENUM: |
||||
ret.int32_val = Convert_ToEnum(value, name, type_info.def.enumdef); |
||||
break; |
||||
case UPB_TYPE_INT32: |
||||
case UPB_TYPE_INT64: |
||||
case UPB_TYPE_UINT32: |
||||
case UPB_TYPE_UINT64: |
||||
Convert_CheckInt(name, type_info.type, value); |
||||
switch (type_info.type) { |
||||
case UPB_TYPE_INT32: |
||||
ret.int32_val = NUM2INT(value); |
||||
break; |
||||
case UPB_TYPE_INT64: |
||||
ret.int64_val = NUM2LL(value); |
||||
break; |
||||
case UPB_TYPE_UINT32: |
||||
ret.uint32_val = NUM2UINT(value); |
||||
break; |
||||
case UPB_TYPE_UINT64: |
||||
ret.uint64_val = NUM2ULL(value); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
VALUE Convert_UpbToRuby(upb_msgval upb_val, TypeInfo type_info, VALUE arena) { |
||||
switch (type_info.type) { |
||||
case UPB_TYPE_FLOAT: |
||||
return DBL2NUM(upb_val.float_val); |
||||
case UPB_TYPE_DOUBLE: |
||||
return DBL2NUM(upb_val.double_val); |
||||
case UPB_TYPE_BOOL: |
||||
return upb_val.bool_val ? Qtrue : Qfalse; |
||||
case UPB_TYPE_INT32: |
||||
return INT2NUM(upb_val.int32_val); |
||||
case UPB_TYPE_INT64: |
||||
return LL2NUM(upb_val.int64_val); |
||||
case UPB_TYPE_UINT32: |
||||
return UINT2NUM(upb_val.uint32_val); |
||||
case UPB_TYPE_UINT64: |
||||
return ULL2NUM(upb_val.int64_val); |
||||
case UPB_TYPE_ENUM: { |
||||
const char* name = |
||||
upb_enumdef_iton(type_info.def.enumdef, upb_val.int32_val); |
||||
if (name) { |
||||
return ID2SYM(rb_intern(name)); |
||||
} else { |
||||
return INT2NUM(upb_val.int32_val); |
||||
} |
||||
} |
||||
case UPB_TYPE_STRING: { |
||||
VALUE str_rb = rb_str_new(upb_val.str_val.data, upb_val.str_val.size); |
||||
rb_enc_associate(str_rb, rb_utf8_encoding()); |
||||
rb_obj_freeze(str_rb); |
||||
return str_rb; |
||||
} |
||||
case UPB_TYPE_BYTES: { |
||||
VALUE str_rb = rb_str_new(upb_val.str_val.data, upb_val.str_val.size); |
||||
rb_enc_associate(str_rb, rb_ascii8bit_encoding()); |
||||
rb_obj_freeze(str_rb); |
||||
return str_rb; |
||||
} |
||||
case UPB_TYPE_MESSAGE: |
||||
return Message_GetRubyWrapper((upb_msg*)upb_val.msg_val, |
||||
type_info.def.msgdef, arena); |
||||
default: |
||||
rb_raise(rb_eRuntimeError, "Convert_UpbToRuby(): Unexpected type %d", |
||||
(int)type_info.type); |
||||
} |
||||
} |
||||
|
||||
upb_msgval Msgval_DeepCopy(upb_msgval msgval, TypeInfo type_info, |
||||
upb_arena* arena) { |
||||
upb_msgval new_msgval; |
||||
|
||||
switch (type_info.type) { |
||||
default: |
||||
memcpy(&new_msgval, &msgval, sizeof(msgval)); |
||||
break; |
||||
case UPB_TYPE_STRING: |
||||
case UPB_TYPE_BYTES: { |
||||
size_t n = msgval.str_val.size; |
||||
char *mem = upb_arena_malloc(arena, n); |
||||
new_msgval.str_val.data = mem; |
||||
new_msgval.str_val.size = n; |
||||
memcpy(mem, msgval.str_val.data, n); |
||||
break; |
||||
} |
||||
case UPB_TYPE_MESSAGE: |
||||
new_msgval.msg_val = |
||||
Message_deep_copy(msgval.msg_val, type_info.def.msgdef, arena); |
||||
break; |
||||
} |
||||
|
||||
return new_msgval; |
||||
} |
||||
|
||||
bool Msgval_IsEqual(upb_msgval val1, upb_msgval val2, TypeInfo type_info) { |
||||
switch (type_info.type) { |
||||
case UPB_TYPE_BOOL: |
||||
return memcmp(&val1, &val2, 1) == 0; |
||||
case UPB_TYPE_FLOAT: |
||||
case UPB_TYPE_INT32: |
||||
case UPB_TYPE_UINT32: |
||||
case UPB_TYPE_ENUM: |
||||
return memcmp(&val1, &val2, 4) == 0; |
||||
case UPB_TYPE_DOUBLE: |
||||
case UPB_TYPE_INT64: |
||||
case UPB_TYPE_UINT64: |
||||
return memcmp(&val1, &val2, 8) == 0; |
||||
case UPB_TYPE_STRING: |
||||
case UPB_TYPE_BYTES: |
||||
return val1.str_val.size != val2.str_val.size || |
||||
memcmp(val1.str_val.data, val2.str_val.data, |
||||
val1.str_val.size) == 0; |
||||
case UPB_TYPE_MESSAGE: |
||||
return Message_Equal(val1.msg_val, val2.msg_val, type_info.def.msgdef); |
||||
default: |
||||
rb_raise(rb_eRuntimeError, "Internal error, unexpected type"); |
||||
} |
||||
} |
||||
|
||||
uint64_t Msgval_GetHash(upb_msgval val, TypeInfo type_info, uint64_t seed) { |
||||
switch (type_info.type) { |
||||
case UPB_TYPE_BOOL: |
||||
return wyhash(&val, 1, seed, _wyp); |
||||
case UPB_TYPE_FLOAT: |
||||
case UPB_TYPE_INT32: |
||||
case UPB_TYPE_UINT32: |
||||
case UPB_TYPE_ENUM: |
||||
return wyhash(&val, 4, seed, _wyp); |
||||
case UPB_TYPE_DOUBLE: |
||||
case UPB_TYPE_INT64: |
||||
case UPB_TYPE_UINT64: |
||||
return wyhash(&val, 8, seed, _wyp); |
||||
case UPB_TYPE_STRING: |
||||
case UPB_TYPE_BYTES: |
||||
return wyhash(val.str_val.data, val.str_val.size, seed, _wyp); |
||||
case UPB_TYPE_MESSAGE: |
||||
return Message_Hash(val.msg_val, type_info.def.msgdef, seed); |
||||
default: |
||||
rb_raise(rb_eRuntimeError, "Internal error, unexpected type"); |
||||
} |
||||
} |
@ -0,0 +1,72 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef RUBY_PROTOBUF_CONVERT_H_ |
||||
#define RUBY_PROTOBUF_CONVERT_H_ |
||||
|
||||
#include <ruby/ruby.h> |
||||
|
||||
#include "protobuf.h" |
||||
#include "ruby-upb.h" |
||||
|
||||
// Converts |ruby_val| to a upb_msgval according to |type_info|.
|
||||
//
|
||||
// The |arena| parameter indicates the lifetime of the container where this
|
||||
// value will be assigned. It is used as follows:
|
||||
// - If type is string or bytes, the string data will be copied into |arena|.
|
||||
// - If type is message, and we need to auto-construct a message due to implicit
|
||||
// conversions (eg. Time -> Google::Protobuf::Timestamp), the new message
|
||||
// will be created in |arena|.
|
||||
// - If type is message and the Ruby value is a message instance, we will fuse
|
||||
// the message's arena into |arena|, to ensure that this message outlives the
|
||||
// container.
|
||||
upb_msgval Convert_RubyToUpb(VALUE ruby_val, const char *name, |
||||
TypeInfo type_info, upb_arena *arena); |
||||
|
||||
// Converts |upb_val| to a Ruby VALUE according to |type_info|. This may involve
|
||||
// creating a Ruby wrapper object.
|
||||
//
|
||||
// The |arena| parameter indicates the arena that owns the lifetime of
|
||||
// |upb_val|. Any Ruby wrapper object that is created will reference |arena|
|
||||
// and ensure it outlives the wrapper.
|
||||
VALUE Convert_UpbToRuby(upb_msgval upb_val, TypeInfo type_info, VALUE arena); |
||||
|
||||
// Creates a deep copy of |msgval| in |arena|.
|
||||
upb_msgval Msgval_DeepCopy(upb_msgval msgval, TypeInfo type_info, |
||||
upb_arena *arena); |
||||
|
||||
// Returns true if |val1| and |val2| are equal. Their type is given by
|
||||
// |type_info|.
|
||||
bool Msgval_IsEqual(upb_msgval val1, upb_msgval val2, TypeInfo type_info); |
||||
|
||||
// Returns a hash value for the given upb_msgval.
|
||||
uint64_t Msgval_GetHash(upb_msgval val, TypeInfo type_info, uint64_t seed); |
||||
|
||||
#endif // RUBY_PROTOBUF_CONVERT_H_
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,107 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef RUBY_PROTOBUF_DEFS_H_ |
||||
#define RUBY_PROTOBUF_DEFS_H_ |
||||
|
||||
#include <ruby/ruby.h> |
||||
|
||||
#include "protobuf.h" |
||||
#include "ruby-upb.h" |
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// TypeInfo
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// This bundles a upb_fieldtype_t and msgdef/enumdef when appropriate. This is
|
||||
// convenient for functions that need type information but cannot necessarily
|
||||
// assume a upb_fielddef will be available.
|
||||
//
|
||||
// For example, Google::Protobuf::Map and Google::Protobuf::RepeatedField can
|
||||
// be constructed with type information alone:
|
||||
//
|
||||
// # RepeatedField will internally store the type information in a TypeInfo.
|
||||
// Google::Protobuf::RepeatedField.new(:message, FooMessage)
|
||||
|
||||
typedef struct { |
||||
upb_fieldtype_t type; |
||||
union { |
||||
const upb_msgdef* msgdef; // When type == UPB_TYPE_MESSAGE
|
||||
const upb_enumdef* enumdef; // When type == UPB_TYPE_ENUM
|
||||
} def; |
||||
} TypeInfo; |
||||
|
||||
static inline TypeInfo TypeInfo_get(const upb_fielddef *f) { |
||||
TypeInfo ret = {upb_fielddef_type(f), {NULL}}; |
||||
switch (ret.type) { |
||||
case UPB_TYPE_MESSAGE: |
||||
ret.def.msgdef = upb_fielddef_msgsubdef(f); |
||||
break; |
||||
case UPB_TYPE_ENUM: |
||||
ret.def.enumdef = upb_fielddef_enumsubdef(f); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
return ret; |
||||
} |
||||
|
||||
TypeInfo TypeInfo_FromClass(int argc, VALUE* argv, int skip_arg, |
||||
VALUE* type_class, VALUE* init_arg); |
||||
|
||||
static inline TypeInfo TypeInfo_from_type(upb_fieldtype_t type) { |
||||
TypeInfo ret = {type}; |
||||
assert(type != UPB_TYPE_MESSAGE && type != UPB_TYPE_ENUM); |
||||
return ret; |
||||
} |
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Other utilities
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
VALUE Descriptor_DefToClass(const upb_msgdef *m); |
||||
|
||||
// Returns the underlying msgdef, enumdef, or symtab (respectively) for the
|
||||
// given Descriptor, EnumDescriptor, or DescriptorPool Ruby object.
|
||||
const upb_enumdef *EnumDescriptor_GetEnumDef(VALUE enum_desc_rb); |
||||
const upb_symtab *DescriptorPool_GetSymtab(VALUE desc_pool_rb); |
||||
const upb_msgdef *Descriptor_GetMsgDef(VALUE desc_rb); |
||||
|
||||
// Returns a upb field type for the given Ruby symbol
|
||||
// (eg. :float => UPB_TYPE_FLOAT).
|
||||
upb_fieldtype_t ruby_to_fieldtype(VALUE type); |
||||
|
||||
// The singleton generated pool (a DescriptorPool object).
|
||||
extern VALUE generated_pool; |
||||
|
||||
// Call at startup to register all types in this module.
|
||||
void Defs_register(VALUE module); |
||||
|
||||
#endif // RUBY_PROTOBUF_DEFS_H_
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,66 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef RUBY_PROTOBUF_MAP_H_ |
||||
#define RUBY_PROTOBUF_MAP_H_ |
||||
|
||||
#include <ruby/ruby.h> |
||||
|
||||
#include "protobuf.h" |
||||
#include "ruby-upb.h" |
||||
|
||||
// Returns a Ruby wrapper object for the given map, which will be created if
|
||||
// one does not exist already.
|
||||
VALUE Map_GetRubyWrapper(upb_map *map, upb_fieldtype_t key_type, |
||||
TypeInfo value_type, VALUE arena); |
||||
|
||||
// Gets the underlying upb_map for this Ruby map object, which must have
|
||||
// key/value type that match |field|. If this is not a map or the type doesn't
|
||||
// match, raises an exception.
|
||||
const upb_map *Map_GetUpbMap(VALUE val, const upb_fielddef *field); |
||||
|
||||
// Implements #inspect for this map by appending its contents to |b|.
|
||||
void Map_Inspect(StringBuilder *b, const upb_map *map, upb_fieldtype_t key_type, |
||||
TypeInfo val_type); |
||||
|
||||
// Returns a new Hash object containing the contents of this Map.
|
||||
VALUE Map_CreateHash(const upb_map* map, upb_fieldtype_t key_type, |
||||
TypeInfo val_info); |
||||
|
||||
// Returns a deep copy of this Map object.
|
||||
VALUE Map_deep_copy(VALUE obj); |
||||
|
||||
// Ruby class of Google::Protobuf::Map.
|
||||
extern VALUE cMap; |
||||
|
||||
// Call at startup to register all types in this module.
|
||||
void Map_register(VALUE module); |
||||
|
||||
#endif // RUBY_PROTOBUF_MAP_H_
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,98 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef RUBY_PROTOBUF_MESSAGE_H_ |
||||
#define RUBY_PROTOBUF_MESSAGE_H_ |
||||
|
||||
#include <ruby/ruby.h> |
||||
|
||||
#include "protobuf.h" |
||||
#include "ruby-upb.h" |
||||
|
||||
// Gets the underlying upb_msg* and upb_msgdef for the given Ruby message
|
||||
// wrapper. Requires that |value| is indeed a message object.
|
||||
const upb_msg *Message_Get(VALUE value, const upb_msgdef **m); |
||||
|
||||
// Like Message_Get(), but checks that the object is not frozen and returns a
|
||||
// mutable pointer.
|
||||
upb_msg *Message_GetMutable(VALUE value, const upb_msgdef **m); |
||||
|
||||
// Returns the Arena object for this message.
|
||||
VALUE Message_GetArena(VALUE value); |
||||
|
||||
// Converts |value| into a upb_msg value of the expected upb_msgdef type,
|
||||
// raising an error if this is not possible. Used when assigning |value| to a
|
||||
// field of another message, which means the message must be of a particular
|
||||
// type.
|
||||
//
|
||||
// This will perform automatic conversions in some cases (for example, Time ->
|
||||
// Google::Protobuf::Timestamp). If any new message is created, it will be
|
||||
// created on |arena|, and any existing message will have its arena fused with
|
||||
// |arena|.
|
||||
const upb_msg* Message_GetUpbMessage(VALUE value, const upb_msgdef* m, |
||||
const char* name, upb_arena* arena); |
||||
|
||||
// Gets or constructs a Ruby wrapper object for the given message. The wrapper
|
||||
// object will reference |arena| and ensure that it outlives this object.
|
||||
VALUE Message_GetRubyWrapper(upb_msg* msg, const upb_msgdef* m, VALUE arena); |
||||
|
||||
// Implements #inspect for this message, printing the text to |b|.
|
||||
void Message_PrintMessage(StringBuilder* b, const upb_msg* msg, |
||||
const upb_msgdef* m); |
||||
|
||||
// Returns a hash value for the given message.
|
||||
uint64_t Message_Hash(const upb_msg *msg, const upb_msgdef *m, uint64_t seed); |
||||
|
||||
// Returns a deep copy of the given message.
|
||||
upb_msg* Message_deep_copy(const upb_msg* msg, const upb_msgdef* m, |
||||
upb_arena *arena); |
||||
|
||||
// Returns true if these two messages are equal.
|
||||
bool Message_Equal(const upb_msg *m1, const upb_msg *m2, const upb_msgdef *m); |
||||
|
||||
// Checks that this Ruby object is a message, and raises an exception if not.
|
||||
void Message_CheckClass(VALUE klass); |
||||
|
||||
// Returns a new Hash object containing the contents of this message.
|
||||
VALUE Scalar_CreateHash(upb_msgval val, TypeInfo type_info); |
||||
|
||||
// Creates a message class or enum module for this descriptor, respectively.
|
||||
VALUE build_class_from_descriptor(VALUE descriptor); |
||||
VALUE build_module_from_enumdesc(VALUE _enumdesc); |
||||
|
||||
// Returns the Descriptor/EnumDescriptor for the given message class or enum
|
||||
// module, respectively. Returns nil if this is not a message class or enum
|
||||
// module.
|
||||
VALUE MessageOrEnum_GetDescriptor(VALUE klass); |
||||
|
||||
// Call at startup to register all types in this module.
|
||||
void Message_register(VALUE protobuf); |
||||
|
||||
#endif // RUBY_PROTOBUF_MESSAGE_H_
|
@ -0,0 +1,62 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef RUBY_PROTOBUF_REPEATED_FIELD_H_ |
||||
#define RUBY_PROTOBUF_REPEATED_FIELD_H_ |
||||
|
||||
#include <ruby/ruby.h> |
||||
|
||||
#include "protobuf.h" |
||||
#include "ruby-upb.h" |
||||
|
||||
// Returns a Ruby wrapper object for the given upb_array, which will be created
|
||||
// if one does not exist already.
|
||||
VALUE RepeatedField_GetRubyWrapper(upb_array* msg, TypeInfo type_info, |
||||
VALUE arena); |
||||
|
||||
// Gets the underlying upb_array for this Ruby RepeatedField object, which must
|
||||
// have a type that matches |f|. If this is not a repeated field or the type
|
||||
// doesn't match, raises an exception.
|
||||
const upb_array* RepeatedField_GetUpbArray(VALUE value, const upb_fielddef* f); |
||||
|
||||
// Implements #inspect for this repeated field by appending its contents to |b|.
|
||||
void RepeatedField_Inspect(StringBuilder* b, const upb_array* array, |
||||
TypeInfo info); |
||||
|
||||
// Returns a deep copy of this RepeatedField object.
|
||||
VALUE RepeatedField_deep_copy(VALUE obj); |
||||
|
||||
// Ruby class of Google::Protobuf::RepeatedField.
|
||||
extern VALUE cRepeatedField; |
||||
|
||||
// Call at startup to register all types in this module.
|
||||
void RepeatedField_register(VALUE module); |
||||
|
||||
#endif // RUBY_PROTOBUF_REPEATED_FIELD_H_
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue