Skip to content

Commit 92fdae1

Browse files
committed
[core] Introduce _R_QUOTEVAL_ macro to quote preprecessor macro values
This introduces a new helper macro that is used in several places in ROOT.
1 parent 43ec084 commit 92fdae1

5 files changed

Lines changed: 9 additions & 16 deletions

File tree

core/base/src/TROOT.cxx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,9 +1993,7 @@ void TROOT::InitSystem()
19931993
if (gSystem->Init())
19941994
fprintf(stderr, "Fatal in <TROOT::InitSystem>: can't init operating system layer\n");
19951995

1996-
#define TO_LITERAL(string) _QUOTE_(string)
1997-
1998-
TString rootincludedir = TO_LITERAL(CMAKE_INSTALL_INCLUDEDIR);
1996+
TString rootincludedir = _R_QUOTEVAL_(CMAKE_INSTALL_INCLUDEDIR);
19991997
gSystem->PrependPathName(GetRootSys(), rootincludedir);
20001998
gSystem->SetIncludePath(("-I" + rootincludedir).Data());
20011999

@@ -3052,7 +3050,7 @@ const TString &TROOT::GetLibDir()
30523050
continue;
30533051

30543052
fs::path p(path);
3055-
if (p.filename() == TO_LITERAL(LIB_CORE_NAME)) {
3053+
if (p.filename() == _R_QUOTEVAL_(LIB_CORE_NAME)) {
30563054
rootlibdir = p.parent_path().c_str();
30573055
break;
30583056
}
@@ -3072,7 +3070,7 @@ const TString &TROOT::GetLibDir()
30723070
return 0;
30733071

30743072
fs::path p = info->dlpi_name;
3075-
if (p.filename() == TO_LITERAL(LIB_CORE_NAME)) {
3073+
if (p.filename() == _R_QUOTEVAL_(LIB_CORE_NAME)) {
30763074
libdir = p.parent_path().c_str();
30773075
return 1; // stop iteration
30783076
}

core/foundation/inc/ROOT/RConfig.hxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@
447447

448448
#endif
449449

450+
#define _R_QUOTEVAL_(string) _QUOTE_(string)
451+
450452
/* produce an identifier that is almost unique inside a file */
451453
# define _R__JOIN_(X,Y) _NAME2_(X,Y)
452454
# define _R__JOIN3_(F,X,Y) _NAME3_(F,X,Y)

roofit/batchcompute/src/RooBatchCompute.cxx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,7 @@ class RooBatchComputeClass : public RooBatchComputeInterface {
9292
std::string architectureName() const override
9393
{
9494
// transform to lower case to match the original architecture name passed to the compiler
95-
#ifdef _QUOTEVAL_ // to quote the value of the preprocessor macro instead of the name
96-
#error "It's unexpected that _QUOTEVAL_ is defined at this point!"
97-
#endif
98-
#define _QUOTEVAL_(x) _QUOTE_(x)
99-
std::string out = _QUOTEVAL_(RF_ARCH);
100-
#undef _QUOTEVAL_
95+
std::string out = _R_QUOTEVAL_(RF_ARCH);
10196
std::transform(out.begin(), out.end(), out.begin(), [](unsigned char c) { return std::tolower(c); });
10297
return out;
10398
};

tree/tree/test/TTreeRegressions.cxx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,11 @@ TEST(TTreeRegressions, EmptyLeafObject)
238238
#define MYCLASS struct MyClass { std::vector<MySubClass> sub; MySubClass *Get(int id) { for (size_t i = 0; i < sub.size(); ++i) if (sub[i].id == id) return &sub[i]; return nullptr; } };
239239
MYSUBCLASS
240240
MYCLASS
241-
#define TO_LITERAL(string) _QUOTE_(string)
242241

243242
TEST(TTreeRegressions, TTreeFormulaMemberIndex)
244243
{
245-
gInterpreter->Declare(TO_LITERAL(MYSUBCLASS));
246-
gInterpreter->Declare(TO_LITERAL(MYCLASS));
244+
gInterpreter->Declare(_R_QUOTEVAL_(MYSUBCLASS));
245+
gInterpreter->Declare(_R_QUOTEVAL_(MYCLASS));
247246

248247
TTree tree("tree", "tree");
249248
MyClass mc;

tree/treeplayer/test/regressions.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,9 @@ TEST(TTreeFormulaRegressions, ConstantAlias)
216216
// ROOT-8577 (JIRA)
217217
#define MYSTRUCT struct MyS { int x; };
218218
MYSTRUCT
219-
#define TO_LITERAL(string) _QUOTE_(string)
220219
TEST(TTreeFormulaRegressions, WrongName)
221220
{
222-
gInterpreter->Declare(TO_LITERAL(MYSTRUCT));
221+
gInterpreter->Declare(_R_QUOTEVAL_(MYSTRUCT));
223222
MyS s;
224223
TLorentzVector v(1, 2, 3, 4);
225224
TTree t("t", "t");

0 commit comments

Comments
 (0)