Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/modules/RootConfiguration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ else()
endif()

CHECK_CXX_SOURCE_COMPILES("#include <tuple>
int main() { std::tuple<int> tup;std::apply(tup, [](int){}); return 0;}" found_stdapply)
int main() { std::apply([](int, int){}, std::make_tuple(1,2)); return 0;}" found_stdapply)
if(found_stdapply)
set(hasstdapply define)
else()
Expand Down
2 changes: 2 additions & 0 deletions core/base/v7/inc/ROOT/impl_tuple_apply.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ decltype(auto) invoke(F&& f, ArgTypes&&... args) {
}
#endif // ndef R__HAS_STD_INVOKE

#ifndef R__HAS_STD_APPLY
// From http://en.cppreference.com/w/cpp/experimental/apply
namespace detail {
template<class F, class Tuple, std::size_t... I>
Expand All @@ -82,6 +83,7 @@ constexpr decltype(auto) apply(F &&f, Tuple &&t) {
std::make_index_sequence < std::tuple_size <
std::decay_t < Tuple >> {} > {});
}
#endif // ndef R__HAS_STD_APPLY
} // namespace __ROOT
} // namespace std

Expand Down
1 change: 1 addition & 0 deletions hist/hist/v7/inc/ROOT/THistImpl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define ROOT7_THistImpl

#include <cctype>
#include <functional>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, David!

#include "ROOT/RArrayView.hxx"
#include "ROOT/RTupleApply.hxx"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,11 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
else if (!LangOpts.GNUMode && LangOpts.Digraphs)
Builder.defineMacro("__STDC_VERSION__", "199409L");
} else {
// FIXME: Use correct value for C++17.
// C++17 [cpp.predefined]p1:
// The name __cplusplus is defined to the value 201703L when compiling a
// C++ translation unit.
if (LangOpts.CPlusPlus1z)
Builder.defineMacro("__cplusplus", "201406L");
Builder.defineMacro("__cplusplus", "201703L");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to match clang value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no real need. The compiler will not care as it's not using this value. Clang 3.9 which is embedded in ROOT already supported majority of C++17 features. Changing __cplusplus to a proper value does not mean that C++17 is out experimental land. This is basically for people who use __cplusplus to figure out what C++ features they want to use.

// C++1y [cpp.predefined]p1:
// The name __cplusplus is defined to the value 201402L when compiling a
// C++ translation unit.
Expand Down
2 changes: 1 addition & 1 deletion io/io/v7/inc/ROOT/TFile.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public:

/// Write an object that is already lifetime managed by this TFileImplBase.
void Write(std::string_view name) {
auto dep = Find(name.to_string());
auto dep = Find(std::string(name.data(), name.size()));
WriteMemoryWithType(name, dep.GetPointer().get(), dep.GetType());
}

Expand Down
6 changes: 3 additions & 3 deletions io/io/v7/src/TFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class TV6Storage: public ROOT::Experimental::Internal::TFileStorageInterface {
}

void WriteMemoryWithType(std::string_view name, const void* address, TClass* cl) final {
fOldFile->WriteObjectAny(address, cl, name.to_string().c_str());
fOldFile->WriteObjectAny(address, cl, name.data());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't data() not guaranteed to be null terminated? (which WriteObjectAny requires)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. Starting C++11 std::string .data() and .c_str() both provide null-terminated result, but the same does not apply to std::string_view. The example I am looking even shows that one needs to create a temporary string and then call .data().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you point me to the comment in the code which states that it's required? At first look I don't see it explicitly mentioned in TBufferFile::WriteObjectClass or TBufferFile::WriteObjectAny and I didn't see any breakage in CMSSW.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops, it should be TDirectoryFile::WriteObjectAny, but same story. No comments mention that it should be null-terminated. Even provided example is not null-terminated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting C++11 std::string .data() and .c_str() both provide null-terminated result

I somehow did not catch that. Thanks!

Could you point me to the comment in the code which states that it's required?

Humm ... WriteObjectAny takes a const char* and use it as null terminated string, I am not sure why there would be a 'special' comment in this routine to make that explicit ...

It is clear that std::string_view::data is not appropriate here, as this returns the first characters of the view, which could for example be a sub-part of a larger string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weekend already. I was looking at completely different argument :)

}
};
}
Expand Down Expand Up @@ -144,7 +144,7 @@ OpenV6TFile(std::string_view name, const char* mode,
}
} setCacheDirRAII(opts.fCachedRead);

auto v6storage = std::make_unique<TV6Storage>(name.to_string(), GetV6TFileOpts(mode, opts));
auto v6storage = std::make_unique<TV6Storage>(std::string(name.data(), name.size()), GetV6TFileOpts(mode, opts));

using namespace ROOT::Experimental::Internal;
return std::unique_ptr<TFileStorageInterface>{std::move(v6storage)};
Expand Down Expand Up @@ -191,7 +191,7 @@ std::string ROOT::Experimental::TFile::SetCacheDir(std::string_view path) {
std::lock_guard<std::mutex> lock(GetCacheDirMutex());

std::string ret = ::TFile::GetCacheFileDir();
::TFile::SetCacheFileDir(path.to_string().c_str());
::TFile::SetCacheFileDir(path.data());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need a null terminated string here?
Alternatively, what about adding a string_view overload of ::TFile::SetCacheFileDir ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we could do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the end I didn't like idea of overload. It would cause more lines to be changed at this point and wouldn't work with TString (ambiguity). Let's do more minimal change for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we don't need an overload just a replacement as a string_view can be constructed implicitly from a const char*. I uploaded the change in signature of TFile::SetCacheFileDir.

return ret;
}

Expand Down