Skip to content

Commit d1470b0

Browse files
committed
Revert "use cstring not string.h, add terminator, fill buffer with space"
This reverts commit a1b1b66.
1 parent b55bb5f commit d1470b0

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

flang/include/flang/Runtime/time-intrinsic.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,6 @@
99
// Defines the API between compiled code and the implementations of time-related
1010
// intrinsic subroutines in the runtime library.
1111

12-
// time-intrinsic.h
13-
#ifndef TIME_INTRINSIC_H
14-
#define TIME_INTRINSIC_H
15-
16-
#include <cstddef>
17-
18-
void CopyBufferAndPad(
19-
char *dest, std::size_t destChars, const char *buffer, std::size_t len);
20-
21-
#endif // TIME_INTRINSIC_H
22-
2312
#ifndef FORTRAN_RUNTIME_TIME_INTRINSIC_H_
2413
#define FORTRAN_RUNTIME_TIME_INTRINSIC_H_
2514

flang/runtime/extensions.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "flang/Runtime/command.h"
1515
#include "flang/Runtime/descriptor.h"
1616
#include "flang/Runtime/io-api.h"
17-
#include "flang/Runtime/time-intrinsic.h" // CopyBufferAndPad
1817
#include <cstring>
1918

2019
#ifdef _WIN32
@@ -82,14 +81,14 @@ void FORTRAN_PROCEDURE_NAME(getarg)(
8281
}
8382

8483
void FORTRAN_PROCEDURE_NAME(getlog)(std::int8_t *arg, std::int64_t length) {
85-
std::array<char, LOGIN_NAME_MAX + 1> str;
84+
int charLen{LOGIN_NAME_MAX + 1};
85+
char str[charLen];
8686

87-
int error{getlogin_r(str.data(), str.size())};
87+
int error{getlogin_r(*str, charLen)};
8888
Terminator terminator{__FILE__, __LINE__};
8989
RUNTIME_CHECK(terminator, error == 0);
9090

91-
CopyBufferAndPad(
92-
reinterpret_cast<char *>(arg), length, str.data(), str.size());
91+
CopyBufferAndPad(reinterpret_cast<char *>(arg), length, *str, charLen);
9392
}
9493

9594
} // namespace Fortran::runtime

flang/runtime/time-intrinsic.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,6 @@
3939
// overload will have a dummy parameter whose type indicates whether or not it
4040
// should be preferred. Any other parameters required for SFINAE should have
4141
// default values provided.
42-
43-
// outside anonymous namespace, function reused
44-
void CopyBufferAndPad(
45-
char *dest, std::size_t destChars, const char *buffer, std::size_t len) {
46-
auto copyLen{std::min(len, destChars)};
47-
std::memcpy(dest, buffer, copyLen);
48-
for (auto i{copyLen}; i < destChars; ++i) {
49-
dest[i] = ' ';
50-
}
51-
}
52-
5342
namespace {
5443
// Types for the dummy parameter indicating the priority of a given overload.
5544
// We will invoke our helper with an integer literal argument, so the overload
@@ -290,22 +279,29 @@ static void GetDateAndTime(Fortran::runtime::Terminator &terminator, char *date,
290279

291280
static constexpr std::size_t buffSize{16};
292281
char buffer[buffSize];
293-
282+
auto copyBufferAndPad{
283+
[&](char *dest, std::size_t destChars, std::size_t len) {
284+
auto copyLen{std::min(len, destChars)};
285+
std::memcpy(dest, buffer, copyLen);
286+
for (auto i{copyLen}; i < destChars; ++i) {
287+
dest[i] = ' ';
288+
}
289+
}};
294290
if (date) {
295291
auto len = std::strftime(buffer, buffSize, "%Y%m%d", &localTime);
296-
CopyBufferAndPad(date, dateChars, buffer, len);
292+
copyBufferAndPad(date, dateChars, len);
297293
}
298294
if (time) {
299295
auto len{std::snprintf(buffer, buffSize, "%02d%02d%02d.%03jd",
300296
localTime.tm_hour, localTime.tm_min, localTime.tm_sec, ms)};
301-
CopyBufferAndPad(time, timeChars, buffer, len);
297+
copyBufferAndPad(time, timeChars, len);
302298
}
303299
if (zone) {
304300
// Note: this may leave the buffer empty on many platforms. Classic flang
305301
// has a much more complex way of doing this (see __io_timezone in classic
306302
// flang).
307303
auto len{std::strftime(buffer, buffSize, "%z", &localTime)};
308-
CopyBufferAndPad(zone, zoneChars, buffer, len);
304+
copyBufferAndPad(zone, zoneChars, len);
309305
}
310306
if (values) {
311307
auto typeCode{values->type().GetCategoryAndKind()};

0 commit comments

Comments
 (0)