Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Therning <niklas@therning.org>2016-11-17 15:34:09 +0300
committerNiklas Therning <niklas@therning.org>2016-11-17 16:10:49 +0300
commit3df6f5c3f3ba949f5cb144be3d70c7ec60a70660 (patch)
tree5f4f33d9aff8afdc48cae47cd84308ee65dc6110 /support
parentb34a3d6b7833f662c69bbc88a3e226096a1c8289 (diff)
Fix Mono.Posix tests on Windows
Cleaned up Mono_Posix_FromSeekFlags() in support/map.c. It didn't properly handle the case when L_INCR, L_SET, L_XTND aren't available, like on Windows. Added Mono_Posix_Stdlib_GetLastError() to support/errno.c and changed Stdlib.GetlastError() use it. Without this Stdlib.GetlastError() wouldn't take errno in the C runtime used by libMonoPosixHelper.dll into account. On Windows the Syscall class failed to initialize due to missing functions, e.g. Mono_Posix_Syscall_get_at_fdcwd(), in libMonoPosixHelper.dll. Those readonly static fields which were initialized at class initialization have now been converted to static readonly properties so that the Syscall class can be initialized despite those functions not being defined. Cleaned up temp file handling in StdioFileStreamTest to avoid failures due to sharing violations on Windows. Fixed a bug in the StdioFileStreamTest.Write() test method when reading back the batch of bytes written in the second part of the test. Enabled the Mono.Posix test suite to run on PR builds. This test suite should from now on be green.
Diffstat (limited to 'support')
-rw-r--r--support/errno.c6
-rw-r--r--support/map.c40
-rw-r--r--support/map.h1
-rw-r--r--support/stdio.c16
4 files changed, 34 insertions, 29 deletions
diff --git a/support/errno.c b/support/errno.c
index 74c2fdf5648..b066d462b16 100644
--- a/support/errno.c
+++ b/support/errno.c
@@ -10,6 +10,12 @@
G_BEGIN_DECLS
+int
+Mono_Posix_Stdlib_GetLastError (void)
+{
+ return errno;
+}
+
void
Mono_Posix_Stdlib_SetLastError (int error_number)
{
diff --git a/support/map.c b/support/map.c
index 92fca755371..615584889df 100644
--- a/support/map.c
+++ b/support/map.c
@@ -4716,52 +4716,36 @@ int Mono_Posix_ToPosixMadviseAdvice (int x, int *r)
int Mono_Posix_FromSeekFlags (short x, short *r)
{
*r = 0;
- if (x == Mono_Posix_SeekFlags_L_INCR)
#ifdef L_INCR
+ if (x == Mono_Posix_SeekFlags_L_INCR)
{*r = L_INCR; return 0;}
-#else /* def L_INCR */
- {errno = EINVAL; return -1;}
-#endif /* ndef L_INCR */
- if (x == Mono_Posix_SeekFlags_L_SET)
+#endif /* def L_INCR */
#ifdef L_SET
+ if (x == Mono_Posix_SeekFlags_L_SET)
{*r = L_SET; return 0;}
-#else /* def L_SET */
- {errno = EINVAL; return -1;}
-#endif /* ndef L_SET */
- if (x == Mono_Posix_SeekFlags_L_XTND)
+#endif /* def L_SET */
#ifdef L_XTND
+ if (x == Mono_Posix_SeekFlags_L_XTND)
{*r = L_XTND; return 0;}
-#else /* def L_XTND */
- {errno = EINVAL; return -1;}
-#endif /* ndef L_XTND */
- if (x == Mono_Posix_SeekFlags_SEEK_CUR)
+#endif /* def L_XTND */
#ifdef SEEK_CUR
+ if (x == Mono_Posix_SeekFlags_SEEK_CUR)
{*r = SEEK_CUR; return 0;}
-#else /* def SEEK_CUR */
- {errno = EINVAL; return -1;}
-#endif /* ndef SEEK_CUR */
- if (x == Mono_Posix_SeekFlags_SEEK_END)
+#endif /* def SEEK_CUR */
#ifdef SEEK_END
+ if (x == Mono_Posix_SeekFlags_SEEK_END)
{*r = SEEK_END; return 0;}
-#else /* def SEEK_END */
- {errno = EINVAL; return -1;}
-#endif /* ndef SEEK_END */
- if (x == Mono_Posix_SeekFlags_SEEK_SET)
+#endif /* def SEEK_END */
#ifdef SEEK_SET
+ if (x == Mono_Posix_SeekFlags_SEEK_SET)
{*r = SEEK_SET; return 0;}
-#else /* def SEEK_SET */
- {errno = EINVAL; return -1;}
-#endif /* ndef SEEK_SET */
- if (x == 0)
- return 0;
+#endif /* def SEEK_SET */
errno = EINVAL; return -1;
}
int Mono_Posix_ToSeekFlags (short x, short *r)
{
*r = 0;
- if (x == 0)
- return 0;
#ifdef L_INCR
if (x == L_INCR)
{*r = Mono_Posix_SeekFlags_L_INCR; return 0;}
diff --git a/support/map.h b/support/map.h
index 8c6ef5000f2..cf6213c8c56 100644
--- a/support/map.h
+++ b/support/map.h
@@ -2184,6 +2184,7 @@ void* Mono_Posix_Stdlib_realloc (void* ptr, guint64 size);
void Mono_Posix_Stdlib_free (void* p);
int Mono_Posix_Stdlib_rewind (void* stream);
int Mono_Posix_Stdlib_setbuf (void* stream, void* buf);
+int Mono_Posix_Stdlib_GetLastError (void);
void Mono_Posix_Stdlib_SetLastError (int error);
int Mono_Posix_Stdlib_setvbuf (void* stream, void* buf, int mode, guint64 size);
void* Mono_Posix_Stdlib_fopen (char* path, char* mode);
diff --git a/support/stdio.c b/support/stdio.c
index b914dfdb1d0..22ce6077de9 100644
--- a/support/stdio.c
+++ b/support/stdio.c
@@ -49,7 +49,21 @@ Mono_Posix_Stdlib_fwrite (unsigned char *ptr, mph_size_t size, mph_size_t nmemb,
mph_return_if_size_t_overflow (size);
mph_return_if_size_t_overflow (nmemb);
- return fwrite (ptr, (size_t) size, (size_t) nmemb, (FILE*) stream);
+ size_t ret = fwrite (ptr, (size_t) size, (size_t) nmemb, (FILE*) stream);
+#ifdef HOST_WIN32
+ // Workaround for a particular weirdness on Windows triggered by the
+ // StdioFileStreamTest.Write() test method. The test writes 15 bytes to a
+ // file, then rewinds the file pointer and reads the same bytes. It then
+ // writes 15 additional bytes to the file. This second write fails on
+ // Windows with 0 returned from fwrite(). Calling fseek() followed by a retry
+ // of fwrite() like we do here fixes the issue.
+ if (ret != nmemb)
+ {
+ fseek (stream, 0, SEEK_CUR);
+ ret = fwrite (ptr + (ret * nmemb), (size_t) size, (size_t) nmemb - ret, (FILE*) stream);
+ }
+#endif
+ return ret;
}
#ifdef HAVE_VSNPRINTF