fgerlits commented on code in PR #1883:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1883#discussion_r1819040969


##########
extensions/python/PythonInterpreter.cpp:
##########
@@ -34,30 +44,53 @@ GlobalInterpreterLock::~GlobalInterpreterLock() {
 }
 
 namespace {
+struct version {
+  int major;
+  int minor;
+};
+
+std::optional<version> getPythonVersion() {
+  // example version: "3.0a5+ (py3k:63103M, May 12 2008, 00:53:55) \n[GCC 
4.2.3]"
+  //                  "3.12.6 (main, Sep  8 2024, 13:18:56) [GCC 14.2.1 
20240805]"
+  std::string ver_str = Py_GetVersion();
+  std::smatch match;
+  if (std::regex_search(ver_str, match, std::regex{"^(\\d+)\\.(\\d+)"})) {
+    return version{std::stoi(match[1]), std::stoi(match[2])};
+  } else {
+    return std::nullopt;
+  }
+}
+
 // PyEval_InitThreads might be marked deprecated (depending on the version of 
Python.h)
-// Python <= 3.6: This needs to be called manually after Py_Initialize to 
initialize threads
+// Python <= 3.6: This needs to be called manually after Py_Initialize to 
initialize threads (python < 3.6 is unsupported by us)
 // Python >= 3.7: Noop function since its functionality is included in 
Py_Initialize
 // Python >= 3.9: Marked as deprecated (still noop)
+// Python >= 3.11: removed
 // This can be removed if we drop the support for Python 3.6
 void initThreads() {
+  using namespace std::literals;
+  if (const auto version = getPythonVersion(); version->major == 3 && 
version->minor <= 6) { return; }

Review Comment:
   ```suggestion
     if (const auto version = getPythonVersion(); version && version->major == 
3 && version->minor <= 6) { return; }
   ```
   or we can log something and terminate if `version` is `nullopt`, but let's 
not just crash



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to