-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Patches for clean Fedora RPM builds that pass unit tests #123
base: master
Are you sure you want to change the base?
Changes from 1 commit
e9eae56
b82796e
5d0e69c
97d3c1c
5ee4e43
6ba4a6e
ae87c70
6f5eae8
2da94c3
6159d89
da386ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
#ifndef NETGEN_CORE_VERSION_HPP | ||
#define NETGEN_CORE_VERSION_HPP | ||
|
||
#include <ostream> | ||
#include <iostream> | ||
#include <string> | ||
#include <tuple> | ||
#include "exception.hpp" | ||
|
||
#include "ngcore_api.hpp" | ||
|
||
|
@@ -18,37 +19,44 @@ namespace ngcore | |
VersionInfo() = default; | ||
VersionInfo(std::string vstring) | ||
{ | ||
minor_ = release = patch = 0; | ||
git_hash = ""; | ||
if(vstring.substr(0,1) == "v") | ||
vstring = vstring.substr(1,vstring.size()-1); | ||
auto dot = vstring.find('.'); | ||
mayor_ = std::stoi(vstring.substr(0,dot)); | ||
if(dot == size_t(-1)) vstring = ""; | ||
else vstring = vstring.substr(dot+1, vstring.size()-dot-1); | ||
if(!vstring.empty()) | ||
{ | ||
dot = vstring.find('.'); | ||
minor_ = std::stoi(vstring.substr(0,dot)); | ||
if (dot == size_t(-1)) vstring = ""; | ||
else vstring = vstring.substr(dot+1, vstring.size()-dot-1); | ||
if(!vstring.empty()) | ||
{ | ||
dot = vstring.find('-'); | ||
release = std::stoi(vstring.substr(0,dot)); | ||
if(dot == size_t(-1)) vstring = ""; | ||
else vstring = vstring.substr(dot+1,vstring.size()-dot-1); | ||
if(!vstring.empty()) | ||
{ | ||
dot = vstring.find('-'); | ||
patch = std::stoi(vstring.substr(0,dot)); | ||
if(dot == size_t(-1)) vstring = ""; | ||
else vstring = vstring.substr(dot+1, vstring.size()-dot-1); | ||
if(!vstring.empty()) | ||
git_hash = vstring; | ||
} | ||
} | ||
} | ||
std::string save = vstring; | ||
try { | ||
minor_ = release = patch = 0; | ||
git_hash = ""; | ||
if(vstring.substr(0,1) == "v") | ||
vstring = vstring.substr(1,vstring.size()-1); | ||
auto dot = vstring.find('.'); | ||
mayor_ = std::stoi(vstring.substr(0,dot)); | ||
if(dot == size_t(-1)) vstring = ""; | ||
else vstring = vstring.substr(dot+1, vstring.size()-dot-1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. substr() returns up to the end when the second argument is omitted (i.e. uses the std::string::npos default argument). |
||
if(!vstring.empty()) | ||
{ | ||
dot = vstring.find('.'); | ||
minor_ = std::stoi(vstring.substr(0,dot)); | ||
if (dot == size_t(-1)) vstring = ""; | ||
else vstring = vstring.substr(dot+1, vstring.size()-dot-1); | ||
if(!vstring.empty()) | ||
{ | ||
dot = vstring.find('-'); | ||
release = std::stoi(vstring.substr(0,dot)); | ||
if(dot == size_t(-1)) vstring = ""; | ||
else vstring = vstring.substr(dot+1,vstring.size()-dot-1); | ||
if(!vstring.empty()) | ||
{ | ||
dot = vstring.find('-'); | ||
patch = std::stoi(vstring.substr(0,dot)); | ||
if(dot == size_t(-1)) vstring = ""; | ||
else vstring = vstring.substr(dot+1, vstring.size()-dot-1); | ||
if(!vstring.empty()) | ||
git_hash = vstring; | ||
} | ||
} | ||
} | ||
} catch(...) { | ||
std::cerr << "Malformed NETGEN_VERSION (" << save <<"\n"; | ||
std::cerr << "Micompiled/mispackaged Netgen library\n"; | ||
abort(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO this goes into the totally wrong direction. netgen is (also) a library, and libraries should not abort if possible. VersionInfo is also e.g. used by netgens Archive class, i.e. on user provided data, i.e. the error message would be incorrect and misleading. If you want to catch these errors:
|
||
} | ||
} | ||
VersionInfo(const char* cstr) : VersionInfo(std::string(cstr)) { } | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compare with std::string::npos, instead of type-casting.