Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 9 additions & 5 deletions flang/runtime/io-stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,15 @@ int ExternalIoStatementBase::EndIoStatement() {
CompleteOperation();
auto result{IoStatementBase::EndIoStatement()};
#if !defined(RT_USE_PSEUDO_FILE_UNIT)
auto unitNumber{unit_.unitNumber()};
unit_.EndIoStatement(); // annihilates *this in unit_.u_
if (destroy_) {
if (ExternalFileUnit *
toClose{ExternalFileUnit::LookUpForClose(unitNumber)}) {
toClose->Close(CloseStatus::Delete, *this);
toClose->DestroyClosed();
}
}
#else
// Fetch the unit pointer before *this disappears.
ExternalFileUnit *unitPtr{&unit_};
Expand Down Expand Up @@ -329,11 +337,7 @@ void OpenStatementState::CompleteOperation() {
}
if (!wasExtant_ && InError()) {
// Release the new unit on failure
if (ExternalFileUnit *
toClose{unit().LookUpForClose(unit().unitNumber())}) {
toClose->Close(CloseStatus::Delete, *this);
toClose->DestroyClosed();
}
set_destroy();
}
IoStatementBase::CompleteOperation();
}
Expand Down
2 changes: 2 additions & 0 deletions flang/runtime/io-stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ class ExternalIoStatementBase : public IoStatementBase {
RT_API_ATTRS MutableModes &mutableModes();
RT_API_ATTRS ConnectionState &GetConnectionState();
RT_API_ATTRS int asynchronousID() const { return asynchronousID_; }
RT_API_ATTRS void set_destroy(bool yes = true) { destroy_ = yes; }
RT_API_ATTRS int EndIoStatement();
RT_API_ATTRS ExternalFileUnit *GetExternalFileUnit() const { return &unit_; }
RT_API_ATTRS void SetAsynchronous();
Expand All @@ -463,6 +464,7 @@ class ExternalIoStatementBase : public IoStatementBase {
private:
ExternalFileUnit &unit_;
int asynchronousID_{-1};
bool destroy_{false};
};

template <Direction DIR>
Expand Down
Loading