Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: protocolbuffers/protobuf-go
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.36.1
Choose a base ref
...
head repository: protocolbuffers/protobuf-go
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.36.2
Choose a head ref
  • 3 commits
  • 14 files changed
  • 1 contributor

Commits on Dec 23, 2024

  1. all: start v1.36.1-devel

    Change-Id: I7c57fd7034f1a55e25fb0e5654c0e9fcde14d4c4
    Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/637938
    LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
    Reviewed-by: Chressie Himpel <chressie@google.com>
    stapelberg committed Dec 23, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c0c814f View commit details
  2. internal/impl: fix WhichOneof() to work with synthetic oneofs

    This is the equivalent of CL 638495, but for the Opaque API.
    
    While the behavior is the same for non-synthetic oneofs between
    the Open Struct API and Opaque API, the behavior for synthetic oneofs
    is not the same: Because the Opaque API uses a bitfield to store
    presence, we need to use the Opaque presence check in WhichOneof().
    
    This CL extends the testproto generator to use the protoc
    command-line flag for the test3 testproto (which specifies
    syntax = "proto3";), as the in-file api_level is only available
    in .proto files using editions (but editions does not use synthetic
    oneofs for optional fields, only proto3 does).
    
    For golang/protobuf#1659
    
    Change-Id: I0a1fd6e5fc6f96eeab043f966728ce2a14dbd446
    Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/638515
    LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
    Reviewed-by: Chressie Himpel <chressie@google.com>
    stapelberg committed Dec 23, 2024
    Copy the full SHA
    8878926 View commit details

Commits on Jan 7, 2025

  1. all: release v1.36.2

    Change-Id: If65cf0b9b0dbf5ee87344d75c663c3305506f298
    Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/641015
    Reviewed-by: Chressie Himpel <chressie@google.com>
    LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
    stapelberg committed Jan 7, 2025
    Copy the full SHA
    12c6ebd View commit details
34 changes: 32 additions & 2 deletions internal/cmd/generate-protos/main.go
Original file line number Diff line number Diff line change
@@ -182,7 +182,13 @@ func generateOpaqueDotProto(repoRoot, tmpDir, relPath string) {
if matches := goPackageRe.FindStringSubmatch(line); matches != nil {
goPkg := matches[1]
hybridGoPkg := strings.TrimSuffix(goPkg, "/") + "/" + filepath.Base(goPkg) + "_hybrid"
return `option go_package = "` + hybridGoPkg + `";` + "\n" +
goPackage := `option go_package = "` + hybridGoPkg + `";` + "\n"
if strings.HasPrefix(relPath, "internal/testprotos/test3/") {
// The test3 testproto must remain on syntax = "proto3";
// and therefore cannot use the editions-only api_level.
return goPackage
}
return goPackage +
`import "google/protobuf/go_features.proto";` + "\n" +
`option features.(pb.go).api_level = API_HYBRID;`
}
@@ -211,7 +217,13 @@ func generateOpaqueDotProto(repoRoot, tmpDir, relPath string) {
if matches := goPackageRe.FindStringSubmatch(line); matches != nil {
goPkg := matches[1]
opaqueGoPkg := strings.TrimSuffix(goPkg, "/") + "/" + filepath.Base(goPkg) + "_opaque"
return `option go_package = "` + opaqueGoPkg + `";` + "\n" +
goPackage := `option go_package = "` + opaqueGoPkg + `";` + "\n"
if strings.HasPrefix(relPath, "internal/testprotos/test3/") {
// The test3 testproto must remain on syntax = "proto3";
// and therefore cannot use the editions-only api_level.
return goPackage
}
return goPackage +
`import "google/protobuf/go_features.proto";` + "\n" +
`option features.(pb.go).api_level = API_OPAQUE;`
}
@@ -248,6 +260,12 @@ func generateOpaqueTestprotos() {
}{
{path: "internal/testprotos/required"},
{path: "internal/testprotos/testeditions"},
{
path: "internal/testprotos/test3",
exclude: map[string]bool{
"internal/testprotos/test3/test_extension.proto": true,
},
},
{path: "internal/testprotos/enums"},
{path: "internal/testprotos/textpbeditions"},
{path: "internal/testprotos/messageset"},
@@ -359,6 +377,18 @@ func generateLocalProtos() {
if d.annotate[filepath.ToSlash(relPath)] {
opts += ",annotate_code"
}
if strings.HasPrefix(relPath, "internal/testprotos/test3/") {
variant := strings.TrimPrefix(relPath, "internal/testprotos/test3/")
if idx := strings.IndexByte(variant, '/'); idx > -1 {
variant = variant[:idx]
}
switch variant {
case "test3_hybrid":
opts += fmt.Sprintf(",apilevelM%v=%v", relPath, "API_HYBRID")
case "test3_opaque":
opts += fmt.Sprintf(",apilevelM%v=%v", relPath, "API_OPAQUE")
}
}
protoc("-I"+filepath.Join(repoRoot, "src"), "-I"+filepath.Join(protoRoot, "src"), "-I"+repoRoot, "--go_out="+opts+":"+tmpDir, filepath.Join(repoRoot, relPath))
return nil
})
24 changes: 21 additions & 3 deletions internal/impl/message_opaque.go
Original file line number Diff line number Diff line change
@@ -88,9 +88,7 @@ func opaqueInitHook(mi *MessageInfo) bool {
mi.oneofs = map[protoreflect.Name]*oneofInfo{}
for i := 0; i < mi.Desc.Oneofs().Len(); i++ {
od := mi.Desc.Oneofs().Get(i)
if !od.IsSynthetic() {
mi.oneofs[od.Name()] = makeOneofInfo(od, si.structInfo, mi.Exporter)
}
mi.oneofs[od.Name()] = makeOneofInfoOpaque(mi, od, si.structInfo, mi.Exporter)
}

mi.denseFields = make([]*fieldInfo, fds.Len()*2)
@@ -119,6 +117,26 @@ func opaqueInitHook(mi *MessageInfo) bool {
return true
}

func makeOneofInfoOpaque(mi *MessageInfo, od protoreflect.OneofDescriptor, si structInfo, x exporter) *oneofInfo {
oi := &oneofInfo{oneofDesc: od}
if od.IsSynthetic() {
fd := od.Fields().Get(0)
index, _ := presenceIndex(mi.Desc, fd)
oi.which = func(p pointer) protoreflect.FieldNumber {
if p.IsNil() {
return 0
}
if !mi.present(p, index) {
return 0
}
return od.Fields().Get(0).Number()
}
return oi
}
// Dispatch to non-opaque oneof implementation for non-synthetic oneofs.
return makeOneofInfo(od, si, x)
}

func (mi *MessageInfo) fieldInfoForMapOpaque(si opaqueStructInfo, fd protoreflect.FieldDescriptor, fs reflect.StructField) fieldInfo {
ft := fs.Type
if ft.Kind() != reflect.Map {
Loading