You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/06/09 16:22:54 UTC

[GitHub] [nifi-minifi-cpp] szaszm opened a new pull request #805: MINIFICPP-1252 Add gsl-lite

szaszm opened a new pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805


   Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [x] Is there a JIRA ticket associated with this PR? Is it referenced
        in the commit message?
   
   - [x] Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   ### For code changes:
   - [x] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   - [x] If applicable, have you updated the LICENSE file?
   - [x] If applicable, have you updated the NOTICE file?
   
   ### For documentation related changes:
   - [x] Have you ensured that format looks appropriate for the output in which it is rendered?
   
   ### Note:
   Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#discussion_r438146885



##########
File path: thirdparty/gsl-lite-0.37.0/README.md
##########
@@ -0,0 +1,1174 @@
+# *gsl-lite*: Guidelines Support Library for C++98, C++11 up

Review comment:
       We can get rid of this. The reason I kept readme was to keep a short description in-tree as I think this may provide some value to the future reader.
   
   Do you think saving ~72K is worth removing this potential value? (honest question)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#discussion_r438118065



##########
File path: libminifi/src/FlowController.cpp
##########
@@ -173,8 +173,7 @@ FlowController::~FlowController() {
   stop(true);
   stopC2();
   unload();
-  if (NULL != protocol_)
-    delete protocol_;
+  protocol_ = nullptr;

Review comment:
       I didn't want to risk bugs by changing the order of destruction here. This class is complex enough that this is a real possibility IMO.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] hunyadi-dev commented on a change in pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
hunyadi-dev commented on a change in pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#discussion_r438140240



##########
File path: thirdparty/gsl-lite-0.37.0/README.md
##########
@@ -0,0 +1,1174 @@
+# *gsl-lite*: Guidelines Support Library for C++98, C++11 up

Review comment:
       Maybe we can get rid of this file. The copyright does not specify any requirement aout the gsl code not being modifiable.
   
   > without limitation the rights to (...) modify




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] hunyadi-dev commented on a change in pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
hunyadi-dev commented on a change in pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#discussion_r438108011



##########
File path: libminifi/src/FlowControlProtocol.cpp
##########
@@ -162,11 +164,12 @@ int FlowControlProtocol::sendRegisterReq() {
     return -1;
 
   // Calculate the total payload msg size
-  uint32_t payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) + FlowControlMsgIDEncodingLen(FLOW_YML_NAME, this->_controller->getName().size() + 1);
-  uint32_t size = sizeof(FlowControlProtocolHeader) + payloadSize;
+  const auto payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) + FlowControlMsgIDEncodingLen(FLOW_YML_NAME, gsl::narrow<int>(this->_controller->getName().size() + 1));

Review comment:
       It does not matter if it throws here, it would still call terminate on the thread that is starting up. I suggest maybe we should surround the calling side with a `try`-`catch` block.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] arpadboda closed pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
arpadboda closed pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#discussion_r437540894



##########
File path: libminifi/src/FlowControlProtocol.cpp
##########
@@ -162,11 +164,12 @@ int FlowControlProtocol::sendRegisterReq() {
     return -1;
 
   // Calculate the total payload msg size
-  uint32_t payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) + FlowControlMsgIDEncodingLen(FLOW_YML_NAME, this->_controller->getName().size() + 1);
-  uint32_t size = sizeof(FlowControlProtocolHeader) + payloadSize;
+  const auto payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) + FlowControlMsgIDEncodingLen(FLOW_YML_NAME, gsl::narrow<int>(this->_controller->getName().size() + 1));

Review comment:
       Normally `gsl::narrow<T>` calls `std::terminate()` on failed conversion. I set the config options to change the behavior to throwing an exception in release builds, but we should normally not rely on this.
   
   The motivation here is to fail early at runtime instead of invoking undefined behavior. It should never fail, and if it does, it's a programming error. This should be a hard error, not an exception.

##########
File path: libminifi/src/FlowControlProtocol.cpp
##########
@@ -162,11 +164,12 @@ int FlowControlProtocol::sendRegisterReq() {
     return -1;
 
   // Calculate the total payload msg size
-  uint32_t payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) + FlowControlMsgIDEncodingLen(FLOW_YML_NAME, this->_controller->getName().size() + 1);
-  uint32_t size = sizeof(FlowControlProtocolHeader) + payloadSize;
+  const auto payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) + FlowControlMsgIDEncodingLen(FLOW_YML_NAME, gsl::narrow<int>(this->_controller->getName().size() + 1));

Review comment:
       Normally `gsl::narrow<T>` calls `std::terminate()` on failed conversion. I set the config options to change the behavior to throwing an exception in release builds by default, but we should normally not rely on this.
   
   The motivation here is to fail early at runtime instead of invoking undefined behavior. It should never fail, and if it does, it's a programming error. This should be a hard error, not an exception.

##########
File path: libminifi/include/FlowController.h
##########
@@ -50,6 +51,7 @@
 #include "utils/Id.h"
 #include "core/state/UpdateController.h"
 #include "core/state/nodes/FlowInformation.h"
+#include "utils/gsl.h"

Review comment:
       Redundant include

##########
File path: extensions/librdkafka/PublishKafka.cpp
##########
@@ -31,6 +31,7 @@
 #include "utils/StringUtils.h"
 #include "utils/ScopeGuard.h"
 #include "utils/GeneralUtils.h"
+#include "utils/gsl.h"

Review comment:
       Redundant include

##########
File path: extensions/librdkafka/PublishKafka.cpp
##########
@@ -31,6 +31,7 @@
 #include "utils/StringUtils.h"
 #include "utils/ScopeGuard.h"
 #include "utils/GeneralUtils.h"
+#include "utils/gsl.h"

Review comment:
       2259722

##########
File path: libminifi/include/FlowController.h
##########
@@ -50,6 +51,7 @@
 #include "utils/Id.h"
 #include "core/state/UpdateController.h"
 #include "core/state/nodes/FlowInformation.h"
+#include "utils/gsl.h"

Review comment:
       2259722




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] hunyadi-dev commented on a change in pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
hunyadi-dev commented on a change in pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#discussion_r438140240



##########
File path: thirdparty/gsl-lite-0.37.0/README.md
##########
@@ -0,0 +1,1174 @@
+# *gsl-lite*: Guidelines Support Library for C++98, C++11 up

Review comment:
       Maybe we can get rid of this file. The copyright does not specify any requirement about the gsl code not being modifiable.
   
   > without limitation the rights to (...) modify




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] hunyadi-dev commented on a change in pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
hunyadi-dev commented on a change in pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#discussion_r438167691



##########
File path: thirdparty/gsl-lite-0.37.0/README.md
##########
@@ -0,0 +1,1174 @@
+# *gsl-lite*: Guidelines Support Library for C++98, C++11 up

Review comment:
       I think it is, I never actively look for dependency documentation in the repository but google/github search for them. Maybe others do? Also I like having less then a dozen matches returned when I ask my editor for `README.md` :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#discussion_r438124894



##########
File path: libminifi/src/FlowControlProtocol.cpp
##########
@@ -162,11 +164,12 @@ int FlowControlProtocol::sendRegisterReq() {
     return -1;
 
   // Calculate the total payload msg size
-  uint32_t payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) + FlowControlMsgIDEncodingLen(FLOW_YML_NAME, this->_controller->getName().size() + 1);
-  uint32_t size = sizeof(FlowControlProtocolHeader) + payloadSize;
+  const auto payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) + FlowControlMsgIDEncodingLen(FLOW_YML_NAME, gsl::narrow<int>(this->_controller->getName().size() + 1));

Review comment:
       I don't think it would ever throw/terminate in practice. The thread that initiates the termination shouldn't matter, it crashes the whole process by default.
   
   If it actually happened in a version that throws instead of terminate, a log line would indeed be helpful in debugging, but I think the chances of this is so low that it's not worth complicating the code with the log line.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#discussion_r438089179



##########
File path: CMakeLists.txt
##########
@@ -72,6 +72,15 @@ endif ()
 
 cmake_dependent_option(ASAN_BUILD "Uses AddressSanitizer to instrument the code" OFF "NOT WIN32" OFF)
 
+# Option: STRICT_GSL_CHECKS
+# AUDIT: Enable all checks, including gsl_ExpectsAudit() and gsl_EnsuresAudit()
+# ON: Enable all checks, excluding gsl_ExpectsAudit() and gsl_EnsuresAudit() (GSL default)

Review comment:
       enable these for CI




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] hunyadi-dev commented on a change in pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
hunyadi-dev commented on a change in pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#discussion_r438110890



##########
File path: libminifi/src/FlowController.cpp
##########
@@ -173,8 +173,7 @@ FlowController::~FlowController() {
   stop(true);
   stopC2();
   unload();
-  if (NULL != protocol_)
-    delete protocol_;
+  protocol_ = nullptr;

Review comment:
       Maybe this is redundant?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] hunyadi-dev commented on a change in pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
hunyadi-dev commented on a change in pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#discussion_r438108011



##########
File path: libminifi/src/FlowControlProtocol.cpp
##########
@@ -162,11 +164,12 @@ int FlowControlProtocol::sendRegisterReq() {
     return -1;
 
   // Calculate the total payload msg size
-  uint32_t payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) + FlowControlMsgIDEncodingLen(FLOW_YML_NAME, this->_controller->getName().size() + 1);
-  uint32_t size = sizeof(FlowControlProtocolHeader) + payloadSize;
+  const auto payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) + FlowControlMsgIDEncodingLen(FLOW_YML_NAME, gsl::narrow<int>(this->_controller->getName().size() + 1));

Review comment:
       It does not matter if it throws here, it would still call terminate on the thread that is starting up. I suggest maybe we should surround the calling side with a `try` `catch` block.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] hunyadi-dev commented on a change in pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
hunyadi-dev commented on a change in pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#discussion_r438110890



##########
File path: libminifi/src/FlowController.cpp
##########
@@ -173,8 +173,7 @@ FlowController::~FlowController() {
   stop(true);
   stopC2();
   unload();
-  if (NULL != protocol_)
-    delete protocol_;
+  protocol_ = nullptr;

Review comment:
       This might be redundant?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] hunyadi-dev commented on a change in pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
hunyadi-dev commented on a change in pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#discussion_r437522246



##########
File path: libminifi/include/utils/ScopeGuard.h
##########
@@ -22,39 +22,19 @@
 
 #include <functional>
 
+#include "gsl.h"
+
 namespace org {
 namespace apache {
 namespace nifi {
 namespace minifi {
 namespace utils {
 
-class ScopeGuard {
- private:
-  bool enabled_;
-  std::function<void()> func_;
-
- public:
-  explicit ScopeGuard(std::function<void()>&& func)
-    : enabled_(true)
-    , func_(std::move(func)) {
-  }
-
-  ~ScopeGuard() {
-    if (enabled_) {
-      try {
-        func_();
-      } catch (...) {
-      }
-    }
-  }
-
-  ScopeGuard(const ScopeGuard&) = delete;
-  ScopeGuard(ScopeGuard&&) = delete;
-  ScopeGuard& operator=(const ScopeGuard&) = delete;
-  ScopeGuard& operator=(ScopeGuard&&) = delete;
+struct ScopeGuard : ::gsl::final_action<std::function<void()>> {

Review comment:
       👍 

##########
File path: libminifi/src/FlowControlProtocol.cpp
##########
@@ -162,11 +164,12 @@ int FlowControlProtocol::sendRegisterReq() {
     return -1;
 
   // Calculate the total payload msg size
-  uint32_t payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) + FlowControlMsgIDEncodingLen(FLOW_YML_NAME, this->_controller->getName().size() + 1);
-  uint32_t size = sizeof(FlowControlProtocolHeader) + payloadSize;
+  const auto payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) + FlowControlMsgIDEncodingLen(FLOW_YML_NAME, gsl::narrow<int>(this->_controller->getName().size() + 1));

Review comment:
       I don't see any try catch block around this.
   
   Maybe we should catch and log narrowing exceptions in `FlowControlProtocol::run()`, so that if the thread catches due to them we see the reson.

##########
File path: libminifi/src/FlowControlProtocol.cpp
##########
@@ -162,11 +164,12 @@ int FlowControlProtocol::sendRegisterReq() {
     return -1;
 
   // Calculate the total payload msg size
-  uint32_t payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) + FlowControlMsgIDEncodingLen(FLOW_YML_NAME, this->_controller->getName().size() + 1);
-  uint32_t size = sizeof(FlowControlProtocolHeader) + payloadSize;
+  const auto payloadSize = FlowControlMsgIDEncodingLen(FLOW_SERIAL_NUMBER, 0) + FlowControlMsgIDEncodingLen(FLOW_YML_NAME, gsl::narrow<int>(this->_controller->getName().size() + 1));

Review comment:
       I don't see any try catch block around this.
   
   Maybe we should catch and log narrowing exceptions in `FlowControlProtocol::run()`, so that if the thread catches due to them we see the reason.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
szaszm commented on pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#issuecomment-641414413


   Only README.md, LICENSE and include/ are included now from gsl-lite


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#discussion_r438176831



##########
File path: thirdparty/gsl-lite-0.37.0/README.md
##########
@@ -0,0 +1,1174 @@
+# *gsl-lite*: Guidelines Support Library for C++98, C++11 up

Review comment:
       done in 06854d2




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] hunyadi-dev commented on a change in pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
hunyadi-dev commented on a change in pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#discussion_r438167691



##########
File path: thirdparty/gsl-lite-0.37.0/README.md
##########
@@ -0,0 +1,1174 @@
+# *gsl-lite*: Guidelines Support Library for C++98, C++11 up

Review comment:
       I think it is, I never actively look for dependency documentation in the repository but google/github search for them. Maybe others do? Also I like having less then a dozen matches returned when I ask my editor for "Readme.md" :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi-minifi-cpp] szaszm commented on pull request #805: MINIFICPP-1252 Add gsl-lite

Posted by GitBox <gi...@apache.org>.
szaszm commented on pull request #805:
URL: https://github.com/apache/nifi-minifi-cpp/pull/805#issuecomment-641338217


   Since header-only libraries are [recommended to be included in the source tree](https://github.com/apache/nifi-minifi-cpp/blob/master/ThirdParties.md#interface-libraries), I separated the gsl-lite inclusion from the rest of the changes for easier review.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org