Fix postProcessors having value semantics when unset
Currently, if postProcessors was empty, it would be set to a new pointer value. But that would only apply for the current Configurable, so if you passed a Configurable by value to a function and then that function added a postProcessor, the caller wouldn't see that. Configurable properties in general have a confusing mix of pointer and value semantics (thanks go...), this fixes one part of it but in followup cls I'll try to make it consistent. Bug: 362579941 Test: m nothing --no-skip-soong-tests Change-Id: Ib33497768be3af45233cf1a682adffb28ee64bfd
This commit is contained in:
parent
c472e38ec1
commit
0a002f5985
2 changed files with 24 additions and 2 deletions
|
@ -502,8 +502,12 @@ func (c *Configurable[T]) AddPostProcessor(p func(T) T) {
|
||||||
// See Configurable.evaluate for more details on the postProcessors algorithm
|
// See Configurable.evaluate for more details on the postProcessors algorithm
|
||||||
// and data structure.
|
// and data structure.
|
||||||
num_links := c.inner.numLinks()
|
num_links := c.inner.numLinks()
|
||||||
if c.postProcessors == nil || len(*c.postProcessors) == 0 {
|
if c.postProcessors == nil {
|
||||||
c.postProcessors = &[][]postProcessor[T]{{{
|
var nilCases []ConfigurableCase[T]
|
||||||
|
c.initialize(nil, "", nil, nilCases)
|
||||||
|
}
|
||||||
|
if len(*c.postProcessors) == 0 {
|
||||||
|
*c.postProcessors = [][]postProcessor[T]{{{
|
||||||
f: p,
|
f: p,
|
||||||
start: 0,
|
start: 0,
|
||||||
end: num_links,
|
end: num_links,
|
||||||
|
|
|
@ -43,6 +43,24 @@ func TestPostProcessor(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPostProcessorWhenPassedToHelperFunction(t *testing.T) {
|
||||||
|
prop := NewConfigurable[[]string](nil, nil)
|
||||||
|
prop.AppendSimpleValue([]string{"a"})
|
||||||
|
prop.AppendSimpleValue([]string{"b"})
|
||||||
|
|
||||||
|
helper := func(p Configurable[[]string]) {
|
||||||
|
p.AddPostProcessor(addToElements("1"))
|
||||||
|
}
|
||||||
|
|
||||||
|
helper(prop)
|
||||||
|
|
||||||
|
expected := []string{"a1", "b1"}
|
||||||
|
x := prop.Get(&configurableEvalutorForTesting{})
|
||||||
|
if !reflect.DeepEqual(x.Get(), expected) {
|
||||||
|
t.Fatalf("Expected %v, got %v", expected, x.Get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func addToElements(s string) func([]string) []string {
|
func addToElements(s string) func([]string) []string {
|
||||||
return func(arr []string) []string {
|
return func(arr []string) []string {
|
||||||
for i := range arr {
|
for i := range arr {
|
||||||
|
|
Loading…
Reference in a new issue