commit | 75de6aa21a1039251eb7f747f5b84164a90a8e5f | [log] [tgz] |
---|---|---|
author | Joshua Haberman <jhaberman@gmail.com> | Thu May 27 09:55:45 2021 -0700 |
committer | Joshua Haberman <jhaberman@gmail.com> | Thu May 27 10:45:18 2021 -0700 |
tree | 77aecd0b7182e2254f7b10a7d3ba7093b5272288 | |
parent | 769826e338075ac4e13c4571f2f3f2b2f15e0353 [diff] |
Fixed sub-message getters for well-known types when message is unset. The well-known types generate C code into wkt.inc, and this C code was not testing isset($msg->submsg_field) like the generated code does: ```php // PHP generated getter: checks isset(). public function getOptions() { return isset($this->options) ? $this->options : null; } ``` ```c // C generated getter, does not check upb_msg_has() static PHP_METHOD(google_protobuf_Value, getListValue) { Message* intern = (Message*)Z_OBJ_P(getThis()); const upb_fielddef *f = upb_msgdef_ntofz(intern->desc->msgdef, "list_value"); zval ret; Message_get(intern, f, &ret); RETURN_COPY_VALUE(&ret); } ``` This led to an error where we wnuld try to get a sub-message field from upb when it `upb_msg_has(msg, field) == false`, which is an error according to upb. There are two possible fixes for this bug. A guiding principle is that we want the generated C code in wkt.inc to have the same behavior as PHP generated code. Following this principle, the two possible fixes are: 1. Change the code generator for wkt.inc to check upb_msg_has(f) before calling Message_get(). This would match the isset() check that the The PHP generated code does, and we would leave the PHP code unchanged. 2. Change Message_get() to itself perform the upb_msg_has(f) check for sub-message fields. This means that generated code would no longer need to perform an isset() check, so we would want to remove this check from the PHP generated code also to avoid a redundant check. Both of these are reasonable fixes, and it is not immediately obvious which is better. (1) has the benefit of resolving this case when we are in more specialized code (a getter function that already knows this is a sub-message field), and therefore avoids performing the check later in more generic code that would have to test the type again. On the other hand, the isset() check is not needed for the pure PHP implementation, as an unset PHP variable will return `null` anyway. And for the C extension, we'd rather check upb_msg_has() at the C level instead of PHP. So this change implements (2). The generated code in wkt.inc remains unchanged, and the PHP generated code for sub-message fields is changed to remove the isset() check.
Copyright 2008 Google Inc.
https://developers.google.com/protocol-buffers/
Protocol Buffers (a.k.a., protobuf) are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data. You can find protobuf's documentation on the Google Developers site.
This README file contains protobuf installation instructions. To install protobuf, you need to install the protocol compiler (used to compile .proto files) and the protobuf runtime for your chosen programming language.
The protocol compiler is written in C++. If you are using C++, please follow the C++ Installation Instructions to install protoc along with the C++ runtime.
For non-C++ users, the simplest way to install the protocol compiler is to download a pre-built binary from our release page:
https://github.com/protocolbuffers/protobuf/releases
In the downloads section of each release, you can find pre-built binaries in zip packages: protoc-$VERSION-$PLATFORM.zip. It contains the protoc binary as well as a set of standard .proto files distributed along with protobuf.
If you are looking for an old version that is not available in the release page, check out the maven repo here:
https://repo1.maven.org/maven2/com/google/protobuf/protoc/
These pre-built binaries are only provided for released versions. If you want to use the github master version at HEAD, or you need to modify protobuf code, or you are using C++, it's recommended to build your own protoc binary from source.
If you would like to build protoc binary from source, see the C++ Installation Instructions.
Protobuf supports several different programming languages. For each programming language, you can find instructions in the corresponding source directory about how to install protobuf runtime for that specific language:
Language | Source | Ubuntu | MacOS | Windows |
---|---|---|---|---|
C++ (include C++ runtime and protoc) | src | ![]() ![]() ![]() | ![]() ![]() | |
Java | java | ![]() ![]() ![]() ![]() | ||
Python | python | ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | ![]() ![]() ![]() | ![]() |
Objective-C | objectivec | ![]() ![]() ![]() ![]() | ||
C# | csharp | ![]() | ![]() | |
JavaScript | js | ![]() | ![]() | |
Ruby | ruby | ![]() ![]() ![]() ![]() ![]() | ![]() ![]() ![]() ![]() ![]() | |
Go | protocolbuffers/protobuf-go | |||
PHP | php | ![]() ![]() ![]() | ![]() ![]() | |
Dart | dart-lang/protobuf |
The best way to learn how to use protobuf is to follow the tutorials in our developer guide:
https://developers.google.com/protocol-buffers/docs/tutorials
If you want to learn from code examples, take a look at the examples in the examples directory.
The complete documentation for Protocol Buffers is available via the web at: