From a185ba0aad1ab205e3b77bdf49ef6c6a737fd68b Mon Sep 17 00:00:00 2001 From: Louis Thibault Date: Thu, 28 Apr 2022 19:21:39 -0400 Subject: [PATCH 1/8] WIP. Represent :Capability type as capnp.Interface. --- capnpc-go/capnpc-go.go | 37 ++++++++++++++++++++++++++++------ capnpc-go/templateparams.go | 5 +++++ capnpc-go/templates/capability | 2 ++ 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 capnpc-go/templates/capability diff --git a/capnpc-go/capnpc-go.go b/capnpc-go/capnpc-go.go index 37add4f9..99491d66 100644 --- a/capnpc-go/capnpc-go.go +++ b/capnpc-go/capnpc-go.go @@ -15,6 +15,7 @@ import ( "flag" "fmt" "go/format" + "io" "math" "os" "path/filepath" @@ -369,14 +370,18 @@ func (g *generator) Value(rel *node, t schema.Type, v schema.Value) (string, err case schema.Type_Which_anyPointer: data, _ := v.AnyPointer() var buf bytes.Buffer + sd, err := g.data.copyData(data) - if err != nil { - return "", err + if err == nil { + switch t.AnyPointer().Which() { + case schema.Type_anyPointer_Which_unconstrained: + err = g.anyPointerUnconstrained(&buf, t, sd) + + default: + err = g.pointerValue(&buf, sd) + } } - err = templates.ExecuteTemplate(&buf, "pointerValue", pointerValueParams{ - G: g, - Value: sd, - }) + return buf.String(), err case schema.Type_Which_list: @@ -401,6 +406,26 @@ func (g *generator) Value(rel *node, t schema.Type, v schema.Value) (string, err } } +func (g *generator) anyPointerUnconstrained(w io.Writer, t schema.Type, sd staticDataRef) error { + switch t.AnyPointer().Unconstrained().Which() { + case schema.Type_anyPointer_unconstrained_Which_capability: + return templates.ExecuteTemplate(w, "capability", capabilityParams{ + G: g, + Value: sd, + }) + + default: + return g.pointerValue(w, sd) + } +} + +func (g *generator) pointerValue(w io.Writer, sd staticDataRef) error { + return templates.ExecuteTemplate(w, "pointerValue", pointerValueParams{ + G: g, + Value: sd, + }) +} + func (g *generator) defineAnnotation(n *node) error { err := g.r.Render(annotationParams{ G: g, diff --git a/capnpc-go/templateparams.go b/capnpc-go/templateparams.go index 0af00c02..6cdeefde 100644 --- a/capnpc-go/templateparams.go +++ b/capnpc-go/templateparams.go @@ -189,6 +189,11 @@ type pointerValueParams struct { Value staticDataRef } +type capabilityParams struct { + G *generator + Value staticDataRef +} + type listValueParams struct { G *generator Typ string diff --git a/capnpc-go/templates/capability b/capnpc-go/templates/capability new file mode 100644 index 00000000..5dd9d725 --- /dev/null +++ b/capnpc-go/templates/capability @@ -0,0 +1,2 @@ +{{.G.Capnp}}.MustUnmarshalRoot({{.Value}}).Interface() +{{- /* no EOL */ -}} From eefb14c0928e4ba18bf156d64ecdbe61e0de676a Mon Sep 17 00:00:00 2001 From: Louis Thibault Date: Thu, 28 Apr 2022 19:43:28 -0400 Subject: [PATCH 2/8] Map :Capability type to *capnp.Client instead of capnp.Interface --- capnpc-go/templates/capability | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/capnpc-go/templates/capability b/capnpc-go/templates/capability index 5dd9d725..9a8e6521 100644 --- a/capnpc-go/templates/capability +++ b/capnpc-go/templates/capability @@ -1,2 +1,2 @@ -{{.G.Capnp}}.MustUnmarshalRoot({{.Value}}).Interface() +{{.G.Capnp}}.MustUnmarshalRoot({{.Value}}).Interface().Client() {{- /* no EOL */ -}} From a55edb8c5a941a509a6e9844365969ebb06f8284 Mon Sep 17 00:00:00 2001 From: Louis Thibault Date: Thu, 28 Apr 2022 20:17:31 -0400 Subject: [PATCH 3/8] Define :Capability fields. --- capnpc-go/capnpc-go.go | 61 +++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/capnpc-go/capnpc-go.go b/capnpc-go/capnpc-go.go index 99491d66..ab7e4d85 100644 --- a/capnpc-go/capnpc-go.go +++ b/capnpc-go/capnpc-go.go @@ -15,7 +15,6 @@ import ( "flag" "fmt" "go/format" - "io" "math" "os" "path/filepath" @@ -372,16 +371,31 @@ func (g *generator) Value(rel *node, t schema.Type, v schema.Value) (string, err var buf bytes.Buffer sd, err := g.data.copyData(data) - if err == nil { - switch t.AnyPointer().Which() { - case schema.Type_anyPointer_Which_unconstrained: - err = g.anyPointerUnconstrained(&buf, t, sd) + if err != nil { + return "", err + } - default: - err = g.pointerValue(&buf, sd) + switch t.AnyPointer().Which() { + // Unconstrained? + case schema.Type_anyPointer_Which_unconstrained: + + switch t.AnyPointer().Unconstrained().Which() { + // Capability type? + case schema.Type_anyPointer_unconstrained_Which_capability: + err = templates.ExecuteTemplate(&buf, "capability", capabilityParams{ + G: g, + Value: sd, + }) + return buf.String(), err } } + // Fall back to default case => generic pointer value + err = templates.ExecuteTemplate(&buf, "pointerValue", pointerValueParams{ + G: g, + Value: sd, + }) + return buf.String(), err case schema.Type_Which_list: @@ -406,26 +420,6 @@ func (g *generator) Value(rel *node, t schema.Type, v schema.Value) (string, err } } -func (g *generator) anyPointerUnconstrained(w io.Writer, t schema.Type, sd staticDataRef) error { - switch t.AnyPointer().Unconstrained().Which() { - case schema.Type_anyPointer_unconstrained_Which_capability: - return templates.ExecuteTemplate(w, "capability", capabilityParams{ - G: g, - Value: sd, - }) - - default: - return g.pointerValue(w, sd) - } -} - -func (g *generator) pointerValue(w io.Writer, sd staticDataRef) error { - return templates.ExecuteTemplate(w, "pointerValue", pointerValueParams{ - G: g, - Value: sd, - }) -} - func (g *generator) defineAnnotation(n *node) error { err := g.r.Render(annotationParams{ G: g, @@ -615,6 +609,19 @@ func (g *generator) defineField(n *node, f field) (err error) { return err } } + + switch t.AnyPointer().Which() { + // Unconstrained? + case schema.Type_anyPointer_Which_unconstrained: + + switch t.AnyPointer().Unconstrained().Which() { + // Capability type? + case schema.Type_anyPointer_unconstrained_Which_capability: + return g.r.Render(structInterfaceFieldParams(params)) + } + } + + // Fall back to default case => generic pointer value return g.r.Render(structPointerFieldParams{ structFieldParams: params, Default: defref, From 25dcad4311b46e1781a7de55727be367241a3deb Mon Sep 17 00:00:00 2001 From: Louis Thibault Date: Thu, 28 Apr 2022 21:05:18 -0400 Subject: [PATCH 4/8] Make schema.Type_which_anyPointer a dynamic type. --- capnpc-go/capnpc-go.go | 50 +++++++++++++---------- capnpc-go/templateparams.go | 18 ++++---- capnpc-go/templates/capability | 2 - capnpc-go/templates/structCapabilityField | 18 ++++++++ internal/aircraftlib/aircraft.capnp.go | 14 +++++-- pogs/pogs_test.go | 5 +-- rpc/internal/testcapnp/test.capnp.go | 14 +++++-- rpc/receiveranswer_test.go | 8 ++-- 8 files changed, 78 insertions(+), 51 deletions(-) delete mode 100644 capnpc-go/templates/capability create mode 100644 capnpc-go/templates/structCapabilityField diff --git a/capnpc-go/capnpc-go.go b/capnpc-go/capnpc-go.go index ab7e4d85..a4c6ad18 100644 --- a/capnpc-go/capnpc-go.go +++ b/capnpc-go/capnpc-go.go @@ -382,11 +382,7 @@ func (g *generator) Value(rel *node, t schema.Type, v schema.Value) (string, err switch t.AnyPointer().Unconstrained().Which() { // Capability type? case schema.Type_anyPointer_unconstrained_Which_capability: - err = templates.ExecuteTemplate(&buf, "capability", capabilityParams{ - G: g, - Value: sd, - }) - return buf.String(), err + return "nil", nil } } @@ -617,7 +613,8 @@ func (g *generator) defineField(n *node, f field) (err error) { switch t.AnyPointer().Unconstrained().Which() { // Capability type? case schema.Type_anyPointer_unconstrained_Which_capability: - return g.r.Render(structInterfaceFieldParams(params)) + // params.FieldType = "*capnp.Client" + return g.r.Render(structCapabilityFieldParams(params)) } } @@ -679,21 +676,20 @@ func makeNodeTypeRef(n, rel *node) (typeRef, error) { var ( staticTypeRefs = map[schema.Type_Which]typeRef{ - schema.Type_Which_void: {}, - schema.Type_Which_bool: {name: "bool"}, - schema.Type_Which_int8: {name: "int8"}, - schema.Type_Which_int16: {name: "int16"}, - schema.Type_Which_int32: {name: "int32"}, - schema.Type_Which_int64: {name: "int64"}, - schema.Type_Which_uint8: {name: "uint8"}, - schema.Type_Which_uint16: {name: "uint16"}, - schema.Type_Which_uint32: {name: "uint32"}, - schema.Type_Which_uint64: {name: "uint64"}, - schema.Type_Which_float32: {name: "float32"}, - schema.Type_Which_float64: {name: "float64"}, - schema.Type_Which_text: {name: "string"}, - schema.Type_Which_data: {name: "[]byte"}, - schema.Type_Which_anyPointer: {name: "Pointer", imp: capnpImportSpec}, + schema.Type_Which_void: {}, + schema.Type_Which_bool: {name: "bool"}, + schema.Type_Which_int8: {name: "int8"}, + schema.Type_Which_int16: {name: "int16"}, + schema.Type_Which_int32: {name: "int32"}, + schema.Type_Which_int64: {name: "int64"}, + schema.Type_Which_uint8: {name: "uint8"}, + schema.Type_Which_uint16: {name: "uint16"}, + schema.Type_Which_uint32: {name: "uint32"}, + schema.Type_Which_uint64: {name: "uint64"}, + schema.Type_Which_float32: {name: "float32"}, + schema.Type_Which_float64: {name: "float64"}, + schema.Type_Which_text: {name: "string"}, + schema.Type_Which_data: {name: "[]byte"}, } staticListTypeRefs = map[schema.Type_Which]typeRef{ // TODO(light): omitting newfunc since it doesn't have a similar type signature (no errors). @@ -758,6 +754,18 @@ func makeTypeRef(t schema.Type, rel *node, nodes nodeMap) (typeRef, error) { case schema.Type_Which_anyPointer, schema.Type_Which_list, schema.Type_Which_interface: return typeRef{name: "PointerList", newfunc: "NewPointerList", imp: capnpImportSpec}, nil } + case schema.Type_Which_anyPointer: + switch t.AnyPointer().Which() { + case schema.Type_anyPointer_Which_unconstrained: + + switch t.AnyPointer().Unconstrained().Which() { + case schema.Type_anyPointer_unconstrained_Which_capability: + return typeRef{name: "Client", imp: capnpImportSpec}, nil + } + } + + return typeRef{name: "Ptr", imp: capnpImportSpec}, nil + } return typeRef{}, fmt.Errorf("unable to reference type %v", t.Which()) } diff --git a/capnpc-go/templateparams.go b/capnpc-go/templateparams.go index 6cdeefde..38d89a3a 100644 --- a/capnpc-go/templateparams.go +++ b/capnpc-go/templateparams.go @@ -61,12 +61,13 @@ type structFieldParams struct { } type ( - structFloatFieldParams structUintFieldParams - structInterfaceFieldParams structFieldParams - structVoidFieldParams structFieldParams - structListFieldParams structObjectFieldParams - structPointerFieldParams structObjectFieldParams - structStructFieldParams structObjectFieldParams + structFloatFieldParams structUintFieldParams + structInterfaceFieldParams structFieldParams + structCapabilityFieldParams structFieldParams + structVoidFieldParams structFieldParams + structListFieldParams structObjectFieldParams + structPointerFieldParams structObjectFieldParams + structStructFieldParams structObjectFieldParams ) type structBoolFieldParams struct { @@ -189,11 +190,6 @@ type pointerValueParams struct { Value staticDataRef } -type capabilityParams struct { - G *generator - Value staticDataRef -} - type listValueParams struct { G *generator Typ string diff --git a/capnpc-go/templates/capability b/capnpc-go/templates/capability deleted file mode 100644 index 9a8e6521..00000000 --- a/capnpc-go/templates/capability +++ /dev/null @@ -1,2 +0,0 @@ -{{.G.Capnp}}.MustUnmarshalRoot({{.Value}}).Interface().Client() -{{- /* no EOL */ -}} diff --git a/capnpc-go/templates/structCapabilityField b/capnpc-go/templates/structCapabilityField new file mode 100644 index 00000000..a7fc2d2b --- /dev/null +++ b/capnpc-go/templates/structCapabilityField @@ -0,0 +1,18 @@ +func (s {{.Node.Name}}) {{.Field.Name|title}}() *{{.FieldType}} { + {{template "_checktag" . -}} + p, _ := s.Struct.Ptr({{.Field.Slot.Offset}}) + return p.Interface().Client() +} + +{{template "_hasfield" .}} + +func (s {{.Node.Name}}) Set{{.Field.Name|title}}(c *{{.FieldType}}) error { + {{template "_settag" . -}} + if !c.IsValid() { + return s.Struct.SetPtr({{.Field.Slot.Offset}}, capnp.Ptr{}) + } + seg := s.Segment() + in := {{.G.Capnp}}.NewInterface(seg, seg.Message().AddCap(c)) + return s.Struct.SetPtr({{.Field.Slot.Offset}}, in.ToPtr()) +} + diff --git a/internal/aircraftlib/aircraft.capnp.go b/internal/aircraftlib/aircraft.capnp.go index 52e0aeac..f56166dd 100644 --- a/internal/aircraftlib/aircraft.capnp.go +++ b/internal/aircraftlib/aircraft.capnp.go @@ -2245,11 +2245,12 @@ func (s Z) SetAnyList(v capnp.Ptr) error { return s.Struct.SetPtr(0, v) } -func (s Z) AnyCapability() (capnp.Ptr, error) { +func (s Z) AnyCapability() *capnp.Client { if s.Struct.Uint16(0) != 48 { panic("Which() != anyCapability") } - return s.Struct.Ptr(0) + p, _ := s.Struct.Ptr(0) + return p.Interface().Client() } func (s Z) HasAnyCapability() bool { @@ -2259,9 +2260,14 @@ func (s Z) HasAnyCapability() bool { return s.Struct.HasPtr(0) } -func (s Z) SetAnyCapability(v capnp.Ptr) error { +func (s Z) SetAnyCapability(c *capnp.Client) error { s.Struct.SetUint16(0, 48) - return s.Struct.SetPtr(0, v) + if !c.IsValid() { + return s.Struct.SetPtr(0, capnp.Ptr{}) + } + seg := s.Segment() + in := capnp.NewInterface(seg, seg.Message().AddCap(c)) + return s.Struct.SetPtr(0, in.ToPtr()) } // Z_List is a list of Z. diff --git a/pogs/pogs_test.go b/pogs/pogs_test.go index 78e59f42..bbb68b73 100644 --- a/pogs/pogs_test.go +++ b/pogs/pogs_test.go @@ -1227,11 +1227,8 @@ func zfill(c air.Z, g *Z) error { case air.Z_Which_anyList: return c.SetAnyList(g.AnyList.ToPtr()) case air.Z_Which_anyCapability: - if g.AnyCapability == nil { - return c.SetAnyCapability(capnp.Ptr{}) - } cap := capnp.NewInterface(c.Segment(), c.Message().AddCap(g.AnyCapability)) - return c.SetAnyCapability(cap.ToPtr()) + return c.SetAnyCapability(cap.Client()) default: return fmt.Errorf("zfill: unknown type: %v", g.Which) } diff --git a/rpc/internal/testcapnp/test.capnp.go b/rpc/internal/testcapnp/test.capnp.go index 5b2b8a9f..4ce97388 100644 --- a/rpc/internal/testcapnp/test.capnp.go +++ b/rpc/internal/testcapnp/test.capnp.go @@ -502,16 +502,22 @@ func (s CapArgsTest_call_Params) String() string { return str } -func (s CapArgsTest_call_Params) Cap() (capnp.Ptr, error) { - return s.Struct.Ptr(0) +func (s CapArgsTest_call_Params) Cap() *capnp.Client { + p, _ := s.Struct.Ptr(0) + return p.Interface().Client() } func (s CapArgsTest_call_Params) HasCap() bool { return s.Struct.HasPtr(0) } -func (s CapArgsTest_call_Params) SetCap(v capnp.Ptr) error { - return s.Struct.SetPtr(0, v) +func (s CapArgsTest_call_Params) SetCap(c *capnp.Client) error { + if !c.IsValid() { + return s.Struct.SetPtr(0, capnp.Ptr{}) + } + seg := s.Segment() + in := capnp.NewInterface(seg, seg.Message().AddCap(c)) + return s.Struct.SetPtr(0, in.ToPtr()) } // CapArgsTest_call_Params_List is a list of CapArgsTest_call_Params. diff --git a/rpc/receiveranswer_test.go b/rpc/receiveranswer_test.go index fe256586..4efe6a63 100644 --- a/rpc/receiveranswer_test.go +++ b/rpc/receiveranswer_test.go @@ -29,9 +29,7 @@ func (me *capArgsTest) Self(ctx context.Context, p testcapnp.CapArgsTest_self) e func (me *capArgsTest) Call(ctx context.Context, p testcapnp.CapArgsTest_call) error { defer close(me.Errs) - cap, err := p.Args().Cap() - chkfatal(err) - client := cap.Interface().Client() + client := p.Args().Cap() chkfatal(client.Resolve(ctx)) brand, ok := server.IsServer(client.State().Brand) if !ok { @@ -81,7 +79,7 @@ func TestBootstrapReceiverAnswerRpc(t *testing.T) { res, rel := c.Call(ctx, func(p testcapnp.CapArgsTest_call_Params) error { capId := p.Message().AddCap(c.Client.AddRef()) - p.SetCap(capnp.NewInterface(p.Segment(), capId).ToPtr()) + p.SetCap(capnp.NewInterface(p.Segment(), capId).Client()) return nil }) defer rel() @@ -126,7 +124,7 @@ func TestCallReceiverAnswerRpc(t *testing.T) { self := selfRes.Self() callRes, rel := self.Call(ctx, func(p testcapnp.CapArgsTest_call_Params) error { capId := p.Message().AddCap(self.Client.AddRef()) - p.SetCap(capnp.NewInterface(p.Segment(), capId).ToPtr()) + p.SetCap(capnp.NewInterface(p.Segment(), capId).Client()) return nil }) self.Release() From 6fcf4d0e0d899bf95127ef66b568ccaf85c3ae97 Mon Sep 17 00:00:00 2001 From: Louis Thibault Date: Fri, 29 Apr 2022 09:55:42 -0400 Subject: [PATCH 5/8] Simplify switch statements for anyPointer in code generation. --- capnpc-go/capnpc-go.go | 45 ++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/capnpc-go/capnpc-go.go b/capnpc-go/capnpc-go.go index a4c6ad18..5bb79b1b 100644 --- a/capnpc-go/capnpc-go.go +++ b/capnpc-go/capnpc-go.go @@ -375,17 +375,14 @@ func (g *generator) Value(rel *node, t schema.Type, v schema.Value) (string, err return "", err } - switch t.AnyPointer().Which() { - // Unconstrained? - case schema.Type_anyPointer_Which_unconstrained: - - switch t.AnyPointer().Unconstrained().Which() { - // Capability type? - case schema.Type_anyPointer_unconstrained_Which_capability: - return "nil", nil - } + // capability pointer? + if t.AnyPointer().Which() == schema.Type_anyPointer_Which_unconstrained && + t.AnyPointer().Unconstrained().Which() == schema.Type_anyPointer_unconstrained_Which_capability { + return "nil", nil // static values of *Client are always nil. } + // TODO: handle other pointer types + // Fall back to default case => generic pointer value err = templates.ExecuteTemplate(&buf, "pointerValue", pointerValueParams{ G: g, @@ -606,18 +603,14 @@ func (g *generator) defineField(n *node, f field) (err error) { } } - switch t.AnyPointer().Which() { - // Unconstrained? - case schema.Type_anyPointer_Which_unconstrained: - - switch t.AnyPointer().Unconstrained().Which() { - // Capability type? - case schema.Type_anyPointer_unconstrained_Which_capability: - // params.FieldType = "*capnp.Client" - return g.r.Render(structCapabilityFieldParams(params)) - } + // capability pointer? + if t.AnyPointer().Which() == schema.Type_anyPointer_Which_unconstrained && + t.AnyPointer().Unconstrained().Which() == schema.Type_anyPointer_unconstrained_Which_capability { + return g.r.Render(structCapabilityFieldParams(params)) } + // TODO: handle other pointer types + // Fall back to default case => generic pointer value return g.r.Render(structPointerFieldParams{ structFieldParams: params, @@ -755,15 +748,15 @@ func makeTypeRef(t schema.Type, rel *node, nodes nodeMap) (typeRef, error) { return typeRef{name: "PointerList", newfunc: "NewPointerList", imp: capnpImportSpec}, nil } case schema.Type_Which_anyPointer: - switch t.AnyPointer().Which() { - case schema.Type_anyPointer_Which_unconstrained: - - switch t.AnyPointer().Unconstrained().Which() { - case schema.Type_anyPointer_unconstrained_Which_capability: - return typeRef{name: "Client", imp: capnpImportSpec}, nil - } + // capability pointer? + if t.AnyPointer().Which() == schema.Type_anyPointer_Which_unconstrained && + t.AnyPointer().Unconstrained().Which() == schema.Type_anyPointer_unconstrained_Which_capability { + return typeRef{name: "Client", imp: capnpImportSpec}, nil } + // TODO: handle other pointer types + + // Fall back to default => generic pointer type return typeRef{name: "Ptr", imp: capnpImportSpec}, nil } From 82f40e2a93fc80f4e02e8cc495a365cb92cbfd18 Mon Sep 17 00:00:00 2001 From: Louis Thibault Date: Fri, 29 Apr 2022 09:56:09 -0400 Subject: [PATCH 6/8] Remove excess newline at end of structCapabilityField template. --- capnpc-go/templates/structCapabilityField | 1 - 1 file changed, 1 deletion(-) diff --git a/capnpc-go/templates/structCapabilityField b/capnpc-go/templates/structCapabilityField index a7fc2d2b..db7107ad 100644 --- a/capnpc-go/templates/structCapabilityField +++ b/capnpc-go/templates/structCapabilityField @@ -15,4 +15,3 @@ func (s {{.Node.Name}}) Set{{.Field.Name|title}}(c *{{.FieldType}}) error { in := {{.G.Capnp}}.NewInterface(seg, seg.Message().AddCap(c)) return s.Struct.SetPtr({{.Field.Slot.Offset}}, in.ToPtr()) } - From dcc117fa00d095f9e4b3648b50bbe3248bd57b7d Mon Sep 17 00:00:00 2001 From: Louis Thibault Date: Fri, 29 Apr 2022 09:58:30 -0400 Subject: [PATCH 7/8] Simplify SetAnyCapability in pogs_test.go --- pogs/pogs_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pogs/pogs_test.go b/pogs/pogs_test.go index bbb68b73..61325365 100644 --- a/pogs/pogs_test.go +++ b/pogs/pogs_test.go @@ -1227,8 +1227,7 @@ func zfill(c air.Z, g *Z) error { case air.Z_Which_anyList: return c.SetAnyList(g.AnyList.ToPtr()) case air.Z_Which_anyCapability: - cap := capnp.NewInterface(c.Segment(), c.Message().AddCap(g.AnyCapability)) - return c.SetAnyCapability(cap.Client()) + return c.SetAnyCapability(g.AnyCapability) default: return fmt.Errorf("zfill: unknown type: %v", g.Which) } From 9d36a21d3fb9145cc578b6cbc62dc1ea17ff3e37 Mon Sep 17 00:00:00 2001 From: Louis Thibault Date: Fri, 29 Apr 2022 10:00:39 -0400 Subject: [PATCH 8/8] Simplify SetCap in receiveranswer_test.go --- rpc/receiveranswer_test.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/rpc/receiveranswer_test.go b/rpc/receiveranswer_test.go index 4efe6a63..6f640883 100644 --- a/rpc/receiveranswer_test.go +++ b/rpc/receiveranswer_test.go @@ -78,9 +78,7 @@ func TestBootstrapReceiverAnswerRpc(t *testing.T) { c := testcapnp.CapArgsTest{Client: clientConn.Bootstrap(ctx)} res, rel := c.Call(ctx, func(p testcapnp.CapArgsTest_call_Params) error { - capId := p.Message().AddCap(c.Client.AddRef()) - p.SetCap(capnp.NewInterface(p.Segment(), capId).Client()) - return nil + return p.SetCap(c.Client.AddRef()) }) defer rel() c.Release() @@ -123,9 +121,7 @@ func TestCallReceiverAnswerRpc(t *testing.T) { defer rel() self := selfRes.Self() callRes, rel := self.Call(ctx, func(p testcapnp.CapArgsTest_call_Params) error { - capId := p.Message().AddCap(self.Client.AddRef()) - p.SetCap(capnp.NewInterface(p.Segment(), capId).Client()) - return nil + return p.SetCap(self.Client.AddRef()) }) self.Release() defer rel()