Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 52f57e8

Browse files
committed
Respond to PR feedback
* Rename shims to match their underlying platform API names * Update guidelines * Add errno conversion TODO * Account for OS X in run-test.sh
1 parent e35129f commit 52f57e8

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

Documentation/coding-guidelines/interop-guidelines.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,10 @@ rather than the underlying integral type.
254254

255255
Often, various UNIX flavors offer the same API from the point-of-view of compatibility
256256
with C/C++ source code, but they do not have the same ABI. e.g. Fields can be laid out
257-
differently, constants can have different numeric values, etc. Even the exports can
258-
be named differently.
257+
differently, constants cn have different numeric values, exports can
258+
be named differently, etc. There are not only differences between operating systems
259+
(Mac OS X vs. Ubuntu vs. FreeBSD), but also differences related to the underlying
260+
processor architecture (x64 vs. x86 vs. ARM).
259261

260262
This leaves us with a situation where we can't write portable P/Invoke declarations
261263
that will work on all flavors, and writing separate declarations per flavor is quite
@@ -267,10 +269,6 @@ a P/Invoke to a C++ lib written specifically for corefx. These libs -- System.*.
267269
Generally, they are not there to add any significant abstraction, but to create a
268270
stable ABI such that the same IL assembly can work across UNIX flavors.
269271

270-
At this time, these shims are compiled in the dotnet/coreclr repository under the corefx
271-
folder. This is temporary (issue #2301) until we add necessary infrastructure to build them
272-
in this repository.
273-
274272
Guidelines for shim C++ API:
275273

276274
- Keep them as "thin"/1:1 as possible.
@@ -279,12 +277,14 @@ Guidelines for shim C++ API:
279277
easy to assume something is safe/guaranteed when it isn't.
280278
- Don't cheat and take advantage of coincidental agreement between
281279
one flavor's ABI and the shim's ABI.
282-
- Use PascalCase and spell things out in a style closer to Win32 than libc.
283-
- At first, it seemed that we'd want to use 1:1 names for the shims, but it
284-
turns out there are many cases where being strictly 1:1 isn't practical. As such,
285-
the libraries will end up looking more self-consistent if we give them their
286-
own style with which to express themselves.
287-
- Stick to data types which are guaranteed not to vary in size across flavors. (Pointers
288-
and size_t variance across bitness is OK.)
289-
- e.g. use int32_t, int64_t from stdint.h and not int, long.
280+
- Use PascalCase in a style closer to Win32 than libc.
281+
- If an export point has a 1:1 correspondence to the platform API, then name
282+
it after the platform API in PascalCase (e.g. stat -> Stat, fstat -> FStat).
283+
- If an export is not 1:1, then spell things out as we typically would in
284+
CoreFX code (i.e. don't use abbreviations unless they come from the underlying
285+
API.
286+
- At first, it seemed that we'd want to use 1:1 names throughout, but it
287+
turns out there are many cases where being strictly 1:1 isn't practical.
288+
- Stick to data types which are guaranteed not to vary in size across flavors.
289+
- e.g. use int32_t, int64_t from stdint.h and not int, long.
290290

run-test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ create_test_overlay()
129129
fi
130130
find $CoreFxBins -name '*.dll' -exec cp '{}' "$OverlayDir" ";"
131131

132-
# Then the native linux CoreFX binaries
132+
# Then the native CoreFX binaries
133133
#
134134
# TODO: Currently, CI does not build the native CoreFX components so build them here
135135
# in the test phase for now.
136-
( $ProjectRoot/src/Native/build.sh && cp $ProjectRoot/bin/$OS.x64.$Configuration/Native/*.so $OverlayDir ) || exit 1
136+
( $ProjectRoot/src/Native/build.sh && cp $ProjectRoot/bin/$OS.x64.$Configuration/Native/* $OverlayDir ) || exit 1
137137
}
138138

139139
copy_test_overlay()

src/Common/src/Interop/Unix/System.IO.Native/Interop.NativeIO.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ internal enum FileStatsFlags
3939
}
4040

4141
[DllImport(Libraries.IOInterop, SetLastError = true)]
42-
internal static extern int GetFileStatsFromDescriptor(int fileDescriptor, out FileStats output);
42+
internal static extern int FStat(int fileDescriptor, out FileStats output);
4343

4444
[DllImport(Libraries.IOInterop, SetLastError = true)]
45-
internal static extern int GetFileStatsFromPath(string path, out FileStats output);
45+
internal static extern int Stat(string path, out FileStats output);
4646
}
4747
}

src/Native/System.IO.Native/nativeio.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void ConvertFileStats(const struct stat_& src, FileStats* dst)
3333

3434
extern "C"
3535
{
36-
int32_t GetFileStatsFromPath(const char* path, struct FileStats* output)
36+
int32_t Stat(const char* path, struct FileStats* output)
3737
{
3838
struct stat_ result;
3939
int ret = stat_(path, &result);
@@ -43,10 +43,10 @@ extern "C"
4343
ConvertFileStats(result, output);
4444
}
4545

46-
return ret;
46+
return ret; // TODO: errno conversion
4747
}
4848

49-
int32_t GetFileStatsFromDescriptor(int32_t fileDescriptor, FileStats* output)
49+
int32_t FStat(int32_t fileDescriptor, FileStats* output)
5050
{
5151
struct stat_ result;
5252
int ret = fstat_(fileDescriptor, &result);
@@ -56,6 +56,6 @@ extern "C"
5656
ConvertFileStats(result, output);
5757
}
5858

59-
return ret;
59+
return ret; // TODO: errno conversion
6060
}
6161
}

src/Native/System.IO.Native/nativeio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ extern "C"
3333
*
3434
* Returns 0 for success, -1 for failure. Sets errno on failure.
3535
*/
36-
int32_t GetFileStatsFromDescriptor(int32_t fileDescriptor, FileStats* output);
36+
int32_t FStat(int32_t fileDescriptor, FileStats* output);
3737

3838
/**
3939
* Get file stats from a full path. Implemented as shim to stat(2).
4040
*
4141
* Returns 0 for success, -1 for failure. Sets errno on failure.
4242
*/
43-
int32_t GetFileStatsFromPath(const char* path, FileStats* output);
43+
int32_t Stat(const char* path, FileStats* output);
4444
}
4545

src/System.Console/src/System/ConsolePal.Unix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ internal UnixConsoleStream(string devPath, FileAccess access)
380380
_handle.DangerousAddRef(ref gotFd);
381381
Interop.NativeIO.FileStats buf;
382382
_handleType =
383-
Interop.NativeIO.GetFileStatsFromDescriptor((int)_handle.DangerousGetHandle(), out buf) == 0 ?
383+
Interop.NativeIO.FStat((int)_handle.DangerousGetHandle(), out buf) == 0 ?
384384
(buf.Mode & Interop.NativeIO.FileTypes.S_IFMT) :
385385
Interop.NativeIO.FileTypes.S_IFREG; // if something goes wrong, don't fail, just say it's a regular file
386386
}

0 commit comments

Comments
 (0)