Files
RedBear-OS/local/recipes/dev/libclc/source/flang-rt/lib/runtime/io-api-common.h
T
vasilito cb424d7448 build: static patch-sanity linter (shift-left the malformed-patch class)
verify-patch-sanity.py validates every active recipe .patch has internally-
consistent hunk line counts — catching the 'malformed patch at line N' failure
at commit/CI/preflight time instead of hours into a cook. This cycle hit that
class three times (qtwaylandscanner, sddm, xwayland), each only discovered when
cookbook tried to apply the patch.

Running it across the repo found 29 latent malformed patches (validated against
GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22').
They were harmless only because they sit in vendored recipes (baked, not re-
applied) — but would fail on any version-bump re-derivation. --fix recounts the
hunk headers (body untouched) and repaired all 29.

Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test
(test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats
(empty placeholders, bare-@@ git hunks).
2026-08-01 05:13:02 +03:00

98 lines
3.4 KiB
C++

//===-- lib/runtime/io-api-common.h -----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef FLANG_RT_RUNTIME_IO_API_COMMON_H_
#define FLANG_RT_RUNTIME_IO_API_COMMON_H_
#include "unit.h"
#include "flang-rt/runtime/io-stmt.h"
#include "flang-rt/runtime/terminator.h"
#include "flang/Common/api-attrs.h"
#include "flang/Common/optional.h"
#include "flang/Runtime/io-api.h"
namespace Fortran::runtime::io {
static inline RT_API_ATTRS Cookie NoopUnit(const Terminator &terminator,
int unitNumber, enum Iostat iostat = IostatOk) {
Cookie cookie{&New<NoopStatementState>{terminator}(
terminator.sourceFileName(), terminator.sourceLine(), unitNumber)
.release()
->ioStatementState()};
if (iostat != IostatOk) {
cookie->GetIoErrorHandler().SetPendingError(iostat);
}
return cookie;
}
static inline RT_API_ATTRS ExternalFileUnit *GetOrCreateUnit(int unitNumber,
Direction direction, Fortran::common::optional<bool> isUnformatted,
const Terminator &terminator, Cookie &errorCookie) {
IoErrorHandler handler{terminator};
handler.HasIoStat();
if (ExternalFileUnit *
unit{ExternalFileUnit::LookUpOrCreateAnonymous(
unitNumber, direction, isUnformatted, handler)}) {
errorCookie = nullptr;
return unit;
} else {
auto iostat{static_cast<enum Iostat>(handler.GetIoStat())};
errorCookie = NoopUnit(terminator, unitNumber,
iostat != IostatOk ? iostat : IostatBadUnitNumber);
return nullptr;
}
}
template <Direction DIR, template <Direction> class STATE, typename... A>
RT_API_ATTRS Cookie BeginExternalListIO(
int unitNumber, const char *sourceFile, int sourceLine, A &&...xs) {
Terminator terminator{sourceFile, sourceLine};
Cookie errorCookie{nullptr};
ExternalFileUnit *unit{GetOrCreateUnit(
unitNumber, DIR, false /*!unformatted*/, terminator, errorCookie)};
if (!unit) {
return errorCookie;
}
if (!unit->isUnformatted.has_value()) {
unit->isUnformatted = false;
}
Iostat iostat{IostatOk};
if (*unit->isUnformatted) {
iostat = IostatFormattedIoOnUnformattedUnit;
}
if (ChildIo * child{unit->GetChildIo()}) {
if (iostat == IostatOk) {
iostat = child->CheckFormattingAndDirection(false, DIR);
}
if (iostat == IostatOk) {
return &child->BeginIoStatement<ChildListIoStatementState<DIR>>(
*child, sourceFile, sourceLine);
} else {
return &child->BeginIoStatement<ErroneousIoStatementState>(
iostat, nullptr /* no unit */, sourceFile, sourceLine);
}
} else {
if (iostat == IostatOk && unit->access == Access::Direct) {
iostat = IostatListIoOnDirectAccessUnit;
}
if (iostat == IostatOk) {
iostat = unit->SetDirection(DIR);
}
if (iostat == IostatOk) {
return &unit->BeginIoStatement<STATE<DIR>>(
terminator, std::forward<A>(xs)..., *unit, sourceFile, sourceLine);
} else {
return &unit->BeginIoStatement<ErroneousIoStatementState>(
terminator, iostat, unit, sourceFile, sourceLine);
}
}
}
} // namespace Fortran::runtime::io
#endif // FLANG_RT_RUNTIME_IO_API_COMMON_H_