This is an automated email from the ASF dual-hosted git repository. sruehl pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push: new bc2dd5a plc4go: fixed inlineIf failing on complex statements bc2dd5a is described below commit bc2dd5a8f0db9bdc56fb915c4cb58f9003248e2f Author: Sebastian Rühl <sru...@apache.org> AuthorDate: Tue Apr 13 00:22:41 2021 +0200 plc4go: fixed inlineIf failing on complex statements + replaced InlineIf a,b with func-suppliers so they get lazy evaluate. Without this it defeats its purpose + fixed RequestTransactionManager.go not closing channel properly --- .../java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java | 4 ++-- go.mod | 2 +- go.sum | 2 ++ plc4go/internal/plc4go/s7/readwrite/model/COTPPacket.go | 2 +- plc4go/internal/plc4go/s7/readwrite/model/S7Message.go | 4 ++-- plc4go/internal/plc4go/spi/RequestTransactionManager.go | 2 ++ plc4go/internal/plc4go/spi/utils/Utils.go | 6 +++--- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/build-utils/language-go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java b/build-utils/language-go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java index 1bd4e00..619bc5a 100644 --- a/build-utils/language-go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java +++ b/build-utils/language-go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java @@ -534,8 +534,8 @@ public class GoLanguageTemplateHelper extends BaseFreemarkerLanguageTemplateHelp Term c = tt.getC(); // TODO: This is not quite correct with the cast to uint16 return "utils.InlineIf(" + toExpression(new DefaultBooleanTypeReference(), a, parserArguments, serializerArguments, serialize, false) + ", " + - "uint16(" + toExpression(fieldType, b, parserArguments, serializerArguments, serialize, false) + "), " + - "uint16(" + toExpression(fieldType, c, parserArguments, serializerArguments, serialize, false) + "))"; + "func() uint16 {return uint16(" + toExpression(fieldType, b, parserArguments, serializerArguments, serialize, false) + ")}, " + + "func() uint16 {return uint16(" + toExpression(fieldType, c, parserArguments, serializerArguments, serialize, false) + ")})"; } else { throw new RuntimeException("Unsupported ternary operation type " + tt.getOperation()); } diff --git a/go.mod b/go.mod index 148bc7e..db0f2f6 100644 --- a/go.mod +++ b/go.mod @@ -21,6 +21,6 @@ module github.com/apache/plc4x go 1.15 require ( - github.com/apache/plc4x/plc4go v0.0.0-20210410051938-faf80e5a6aa9 // indirect + github.com/apache/plc4x/plc4go v0.0.0-20210412213847-80045494b056 // indirect github.com/sirupsen/logrus v1.7.0 // indirect ) diff --git a/go.sum b/go.sum index 8497467..9992770 100644 --- a/go.sum +++ b/go.sum @@ -40,6 +40,8 @@ github.com/apache/plc4x/plc4go v0.0.0-20210410044310-edcf761e75f2 h1:C9/CEAUCxTu github.com/apache/plc4x/plc4go v0.0.0-20210410044310-edcf761e75f2/go.mod h1:NfO8uGKPGwDxn1GqOb4oNhAtPF7St1A9LRk1J/qSlWU= github.com/apache/plc4x/plc4go v0.0.0-20210410051938-faf80e5a6aa9 h1:Vah0ugkonhbrCwHLaUYTTUMpG/TWTokLVLxmmSvyi5E= github.com/apache/plc4x/plc4go v0.0.0-20210410051938-faf80e5a6aa9/go.mod h1:NfO8uGKPGwDxn1GqOb4oNhAtPF7St1A9LRk1J/qSlWU= +github.com/apache/plc4x/plc4go v0.0.0-20210412213847-80045494b056 h1:0WyQtKcnPH+j5LYvTk1ZNXD57xfmNQmSBLzd6yANjbs= +github.com/apache/plc4x/plc4go v0.0.0-20210412213847-80045494b056/go.mod h1:NfO8uGKPGwDxn1GqOb4oNhAtPF7St1A9LRk1J/qSlWU= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= diff --git a/plc4go/internal/plc4go/s7/readwrite/model/COTPPacket.go b/plc4go/internal/plc4go/s7/readwrite/model/COTPPacket.go index 7671bc4..b7eca96 100644 --- a/plc4go/internal/plc4go/s7/readwrite/model/COTPPacket.go +++ b/plc4go/internal/plc4go/s7/readwrite/model/COTPPacket.go @@ -185,7 +185,7 @@ func (m *COTPPacket) Serialize(io utils.WriteBuffer) error { func (m *COTPPacket) SerializeParent(io utils.WriteBuffer, child ICOTPPacket, serializeChildFunction func() error) error { // Implicit Field (headerLength) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - headerLength := uint8(uint8(uint8(m.LengthInBytes())) - uint8(uint8(uint8(uint8(utils.InlineIf(bool(bool((m.Payload) != (nil))), uint16(m.Payload.LengthInBytes()), uint16(uint8(0)))))+uint8(uint8(1))))) + headerLength := uint8(uint8(uint8(m.LengthInBytes())) - uint8(uint8(uint8(uint8(utils.InlineIf(bool(bool((m.Payload) != (nil))), func() uint16 { return uint16(m.Payload.LengthInBytes()) }, func() uint16 { return uint16(uint8(0)) })))+uint8(uint8(1))))) _headerLengthErr := io.WriteUint8(8, (headerLength)) if _headerLengthErr != nil { return errors.Wrap(_headerLengthErr, "Error serializing 'headerLength' field") diff --git a/plc4go/internal/plc4go/s7/readwrite/model/S7Message.go b/plc4go/internal/plc4go/s7/readwrite/model/S7Message.go index 5819c7a..c6ba8e0 100644 --- a/plc4go/internal/plc4go/s7/readwrite/model/S7Message.go +++ b/plc4go/internal/plc4go/s7/readwrite/model/S7Message.go @@ -254,14 +254,14 @@ func (m *S7Message) SerializeParent(io utils.WriteBuffer, child IS7Message, seri } // Implicit Field (parameterLength) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - parameterLength := uint16(utils.InlineIf(bool((m.Parameter) != (nil)), uint16(m.Parameter.LengthInBytes()), uint16(uint16(0)))) + parameterLength := uint16(utils.InlineIf(bool((m.Parameter) != (nil)), func() uint16 { return uint16(m.Parameter.LengthInBytes()) }, func() uint16 { return uint16(uint16(0)) })) _parameterLengthErr := io.WriteUint16(16, (parameterLength)) if _parameterLengthErr != nil { return errors.Wrap(_parameterLengthErr, "Error serializing 'parameterLength' field") } // Implicit Field (payloadLength) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - payloadLength := uint16(utils.InlineIf(bool((m.Payload) != (nil)), uint16(m.Payload.LengthInBytes()), uint16(uint16(0)))) + payloadLength := uint16(utils.InlineIf(bool((m.Payload) != (nil)), func() uint16 { return uint16(m.Payload.LengthInBytes()) }, func() uint16 { return uint16(uint16(0)) })) _payloadLengthErr := io.WriteUint16(16, (payloadLength)) if _payloadLengthErr != nil { return errors.Wrap(_payloadLengthErr, "Error serializing 'payloadLength' field") diff --git a/plc4go/internal/plc4go/spi/RequestTransactionManager.go b/plc4go/internal/plc4go/spi/RequestTransactionManager.go index cce5e00..594c656 100644 --- a/plc4go/internal/plc4go/spi/RequestTransactionManager.go +++ b/plc4go/internal/plc4go/spi/RequestTransactionManager.go @@ -134,11 +134,13 @@ func (e *Executor) stop() { return } e.shutdown = true + close(e.queue) for i := 0; i < len(e.worker); i++ { worker := e.worker[i] worker.shutdown = true worker.interrupted = true } + e.running = false } type CompletionFuture struct { diff --git a/plc4go/internal/plc4go/spi/utils/Utils.go b/plc4go/internal/plc4go/spi/utils/Utils.go index 2ad9b93..d00772a 100644 --- a/plc4go/internal/plc4go/spi/utils/Utils.go +++ b/plc4go/internal/plc4go/spi/utils/Utils.go @@ -19,10 +19,10 @@ package utils // InlineIf is basically a inline if like construct for golang -func InlineIf(test bool, a uint16, b uint16) uint16 { +func InlineIf(test bool, a func() uint16, b func() uint16) uint16 { if test { - return a + return a() } else { - return b + return b() } }