Skip to content

Commit 48b9266

Browse files
committed
Disable empty strings exclusively for ADIOS1
1 parent baaf7ed commit 48b9266

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

src/IO/ADIOS/CommonADIOS1IOHandler.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ void CommonADIOS1IOHandlerImpl<ChildClass>::flush_attribute(
235235
}
236236
case DT::STRING: {
237237
auto const &v = att.get<std::string>();
238+
if (v.empty())
239+
{
240+
error::throwOperationUnsupportedInBackend(
241+
"ADIOS1", "Empty string attributes not supported.");
242+
}
238243
values = auxiliary::allocatePtr(Datatype::CHAR, v.length() + 1u);
239244
strcpy((char *)values.get(), v.c_str());
240245
break;
@@ -352,6 +357,11 @@ void CommonADIOS1IOHandlerImpl<ChildClass>::flush_attribute(
352357
auto const &vec = att.get<std::vector<std::string> >();
353358
for (size_t i = 0; i < vec.size(); ++i)
354359
{
360+
if (vec[i].empty())
361+
{
362+
error::throwOperationUnsupportedInBackend(
363+
"ADIOS1", "Empty string attributes not supported.");
364+
}
355365
size_t size = vec[i].size() + 1;
356366
ptr[i] = new char[size];
357367
strncpy(ptr[i], vec[i].c_str(), size);

test/SerialIOTest.cpp

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,7 @@ inline void dtype_test(const std::string &backend)
12511251
bool test_long_long = (backend != "json") || sizeof(long long) <= 8;
12521252
{
12531253
Series s = Series("../samples/dtype_test." + backend, Access::CREATE);
1254+
bool adios1 = s.backend() == "ADIOS1" || s.backend() == "MPI_ADIOS1";
12541255

12551256
char c = 'c';
12561257
s.setAttribute("char", c);
@@ -1281,7 +1282,10 @@ inline void dtype_test(const std::string &backend)
12811282
}
12821283
std::string str = "string";
12831284
s.setAttribute("string", str);
1284-
s.setAttribute("emptyString", "");
1285+
if (!adios1)
1286+
{
1287+
s.setAttribute("emptyString", "");
1288+
}
12851289
s.setAttribute("vecChar", std::vector<char>({'c', 'h', 'a', 'r'}));
12861290
s.setAttribute("vecInt16", std::vector<int16_t>({32766, 32767}));
12871291
s.setAttribute(
@@ -1311,9 +1315,13 @@ inline void dtype_test(const std::string &backend)
13111315
}
13121316
s.setAttribute(
13131317
"vecString", std::vector<std::string>({"vector", "of", "strings"}));
1314-
s.setAttribute("vecEmptyString", std::vector<std::string>{"", "", ""});
1315-
s.setAttribute(
1316-
"vecMixedString", std::vector<std::string>{"hi", "", "ho"});
1318+
if (!adios1)
1319+
{
1320+
s.setAttribute(
1321+
"vecEmptyString", std::vector<std::string>{"", "", ""});
1322+
s.setAttribute(
1323+
"vecMixedString", std::vector<std::string>{"hi", "", "ho"});
1324+
}
13171325
s.setAttribute("bool", true);
13181326
s.setAttribute("boolF", false);
13191327

@@ -1373,6 +1381,7 @@ inline void dtype_test(const std::string &backend)
13731381
}
13741382

13751383
Series s = Series("../samples/dtype_test." + backend, Access::READ_ONLY);
1384+
bool adios1 = s.backend() == "ADIOS1" || s.backend() == "MPI_ADIOS1";
13761385

13771386
REQUIRE(s.getAttribute("char").get<char>() == 'c');
13781387
REQUIRE(s.getAttribute("uchar").get<unsigned char>() == 'u');
@@ -1390,7 +1399,10 @@ inline void dtype_test(const std::string &backend)
13901399
REQUIRE(s.getAttribute("longdouble").get<long double>() == 1.e80L);
13911400
}
13921401
REQUIRE(s.getAttribute("string").get<std::string>() == "string");
1393-
REQUIRE(s.getAttribute("emptyString").get<std::string>().empty());
1402+
if (!adios1)
1403+
{
1404+
REQUIRE(s.getAttribute("emptyString").get<std::string>().empty());
1405+
}
13941406
REQUIRE(
13951407
s.getAttribute("vecChar").get<std::vector<char> >() ==
13961408
std::vector<char>({'c', 'h', 'a', 'r'}));
@@ -1434,12 +1446,15 @@ inline void dtype_test(const std::string &backend)
14341446
REQUIRE(
14351447
s.getAttribute("vecString").get<std::vector<std::string> >() ==
14361448
std::vector<std::string>({"vector", "of", "strings"}));
1437-
REQUIRE(
1438-
s.getAttribute("vecEmptyString").get<std::vector<std::string> >() ==
1439-
std::vector<std::string>({"", "", ""}));
1440-
REQUIRE(
1441-
s.getAttribute("vecMixedString").get<std::vector<std::string> >() ==
1442-
std::vector<std::string>({"hi", "", "ho"}));
1449+
if (!adios1)
1450+
{
1451+
REQUIRE(
1452+
s.getAttribute("vecEmptyString").get<std::vector<std::string> >() ==
1453+
std::vector<std::string>({"", "", ""}));
1454+
REQUIRE(
1455+
s.getAttribute("vecMixedString").get<std::vector<std::string> >() ==
1456+
std::vector<std::string>({"hi", "", "ho"}));
1457+
}
14431458
REQUIRE(s.getAttribute("bool").get<bool>() == true);
14441459
REQUIRE(s.getAttribute("boolF").get<bool>() == false);
14451460

0 commit comments

Comments
 (0)