Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Remove Interop.ReadDir.cs #34274

Merged
merged 3 commits into from
Dec 31, 2018
Merged

Remove Interop.ReadDir.cs #34274

merged 3 commits into from
Dec 31, 2018

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Dec 29, 2018

Since TimeZoneInfo was switched to FileSystem's Interop.ReadDir.cs in dotnet/coreclr#21622 we can now remove the old Interop.ReadDir.cs

ReadBufferSize property was removed (see dotnet/coreclr#21622 (comment))

/cc @jkotas

int result = Interop.Sys.ReadDir(_directoryHandle, buffer, ref _entry);
switch (result)
if (_entryBuffer == null)
return;
Copy link
Member Author

@EgorBo EgorBo Dec 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this. The old code used Span<byte>.Empty in case of null _entryBuffer. Then that empty span was used in ReadDir where it could crash with NullReferenceException because of ref MemoryMarshal.GetReference.
Perhaps we should throw some kind of an error here?

Copy link
Member

@jkotas jkotas Dec 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then that empty span was used in ReadDir where it could crash with NullReferenceException

Why do you think it could crash? ref MemoryMarshal.GetReference handles null just fine.

This if (_entryBuffer == null) return; should be deleted, and null check should be added to _entryBuffer.Length a few lines below.

Notice that when this method is called there is always MoveNext() on the stack that has a dummy fixed (byte* _ = _entryBuffer) to keep the buffer pinned. Ideally, the pointer to the buffer pinned by MoveNext() would be passed along and this would just use that pointer instead of doing another redundant fixed. Unfortunately, it cannot be done easily given how to code is factored.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, indeed! It doesn't throw NRE. I refactored a bit FindNextEntry for cases where it's possible to pass a pointer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored a bit FindNextEntry for cases where it's possible to pass a pointer.

I am not sure whether this refactoring is an improvement. It would be an improvement if it is always possible to pass a pointer. Performance-wise, it is probably a tiny loss (the redundant fixed is very cheap).

…numerator.Unix.cs

Co-Authored-By: EgorBo <egorbo@gmail.com>
@jkotas
Copy link
Member

jkotas commented Dec 30, 2018

@dotnet-bot test Linux arm64 Release Build please
@dotnet-bot test Packaging All Configurations x64 Debug Build please

@danmoseley
Copy link
Member

Unrelated existing test issue

@danmoseley danmoseley merged commit 9158933 into dotnet:master Dec 31, 2018
@karelz karelz added this to the 3.0 milestone Mar 18, 2019
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Remove Interop.ReadDir.cs

* pass bufferPtr to FindNextEntry

* Update src/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Unix.cs

Co-Authored-By: EgorBo <egorbo@gmail.com>


Commit migrated from dotnet/corefx@9158933
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants