vendor/google.golang.org/protobuf/internal/impl/checkinit.go
changeset 260 445e01aede7e
parent 256 6d9efbef00a9
equal deleted inserted replaced
259:db4911b0c721 260:445e01aede7e
     6 
     6 
     7 import (
     7 import (
     8 	"sync"
     8 	"sync"
     9 
     9 
    10 	"google.golang.org/protobuf/internal/errors"
    10 	"google.golang.org/protobuf/internal/errors"
    11 	pref "google.golang.org/protobuf/reflect/protoreflect"
    11 	"google.golang.org/protobuf/reflect/protoreflect"
    12 	piface "google.golang.org/protobuf/runtime/protoiface"
    12 	"google.golang.org/protobuf/runtime/protoiface"
    13 )
    13 )
    14 
    14 
    15 func (mi *MessageInfo) checkInitialized(in piface.CheckInitializedInput) (piface.CheckInitializedOutput, error) {
    15 func (mi *MessageInfo) checkInitialized(in protoiface.CheckInitializedInput) (protoiface.CheckInitializedOutput, error) {
    16 	var p pointer
    16 	var p pointer
    17 	if ms, ok := in.Message.(*messageState); ok {
    17 	if ms, ok := in.Message.(*messageState); ok {
    18 		p = ms.pointer()
    18 		p = ms.pointer()
    19 	} else {
    19 	} else {
    20 		p = in.Message.(*messageReflectWrapper).pointer()
    20 		p = in.Message.(*messageReflectWrapper).pointer()
    21 	}
    21 	}
    22 	return piface.CheckInitializedOutput{}, mi.checkInitializedPointer(p)
    22 	return protoiface.CheckInitializedOutput{}, mi.checkInitializedPointer(p)
    23 }
    23 }
    24 
    24 
    25 func (mi *MessageInfo) checkInitializedPointer(p pointer) error {
    25 func (mi *MessageInfo) checkInitializedPointer(p pointer) error {
    26 	mi.init()
    26 	mi.init()
    27 	if !mi.needsInitCheck {
    27 	if !mi.needsInitCheck {
    88 )
    88 )
    89 
    89 
    90 // needsInitCheck reports whether a message needs to be checked for partial initialization.
    90 // needsInitCheck reports whether a message needs to be checked for partial initialization.
    91 //
    91 //
    92 // It returns true if the message transitively includes any required or extension fields.
    92 // It returns true if the message transitively includes any required or extension fields.
    93 func needsInitCheck(md pref.MessageDescriptor) bool {
    93 func needsInitCheck(md protoreflect.MessageDescriptor) bool {
    94 	if v, ok := needsInitCheckMap.Load(md); ok {
    94 	if v, ok := needsInitCheckMap.Load(md); ok {
    95 		if has, ok := v.(bool); ok {
    95 		if has, ok := v.(bool); ok {
    96 			return has
    96 			return has
    97 		}
    97 		}
    98 	}
    98 	}
    99 	needsInitCheckMu.Lock()
    99 	needsInitCheckMu.Lock()
   100 	defer needsInitCheckMu.Unlock()
   100 	defer needsInitCheckMu.Unlock()
   101 	return needsInitCheckLocked(md)
   101 	return needsInitCheckLocked(md)
   102 }
   102 }
   103 
   103 
   104 func needsInitCheckLocked(md pref.MessageDescriptor) (has bool) {
   104 func needsInitCheckLocked(md protoreflect.MessageDescriptor) (has bool) {
   105 	if v, ok := needsInitCheckMap.Load(md); ok {
   105 	if v, ok := needsInitCheckMap.Load(md); ok {
   106 		// If has is true, we've previously determined that this message
   106 		// If has is true, we've previously determined that this message
   107 		// needs init checks.
   107 		// needs init checks.
   108 		//
   108 		//
   109 		// If has is false, we've previously determined that it can never
   109 		// If has is false, we've previously determined that it can never