Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5)

Side by Side Diff: Modules/posixmodule.c

Issue 3871: cross and native build of python for mingw32 with distutils
Patch Set: Created 7 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Modules/_multiprocessing/multiprocessing.c ('k') | Modules/python.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* POSIX module implementation */ 2 /* POSIX module implementation */
3 3
4 /* This file is also used for Windows NT/MS-Win and OS/2. In that case the 4 /* This file is also used for Windows NT/MS-Win and OS/2. In that case the
5 module actually calls itself 'nt' or 'os2', not 'posix', and a few 5 module actually calls itself 'nt' or 'os2', not 'posix', and a few
6 functions are either unimplemented or implemented differently. The source 6 functions are either unimplemented or implemented differently. The source
7 assumes that for Windows NT, the macro 'MS_WINDOWS' is defined independent 7 assumes that for Windows NT, the macro 'MS_WINDOWS' is defined independent
8 of the compiler used. Different compilers define their own feature 8 of the compiler used. Different compilers define their own feature
9 test macro, e.g. '__BORLANDC__' or '_MSC_VER'. For OS/2, the compiler 9 test macro, e.g. '__BORLANDC__' or '_MSC_VER'. For OS/2, the compiler
10 independent macro PYOS_OS2 should be defined. On OS/2 the default 10 independent macro PYOS_OS2 should be defined. On OS/2 the default
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 #define HAVE_GETCWD 1 168 #define HAVE_GETCWD 1
169 #define HAVE_GETPPID 1 169 #define HAVE_GETPPID 1
170 #define HAVE_GETLOGIN 1 170 #define HAVE_GETLOGIN 1
171 #define HAVE_SPAWNV 1 171 #define HAVE_SPAWNV 1
172 #define HAVE_EXECV 1 172 #define HAVE_EXECV 1
173 #define HAVE_PIPE 1 173 #define HAVE_PIPE 1
174 #define HAVE_SYSTEM 1 174 #define HAVE_SYSTEM 1
175 #define HAVE_CWAIT 1 175 #define HAVE_CWAIT 1
176 #define HAVE_FSYNC 1 176 #define HAVE_FSYNC 1
177 #define fsync _commit 177 #define fsync _commit
178 #elif defined(__MINGW32__) /* GCC (mingw special) compiler */
179 /*#define HAVE_GETCWD 1 - detected by configure*/
180 #define HAVE_SPAWNV 1
181 #define HAVE_EXECV 1
182 #define HAVE_PIPE 1
183 #define HAVE_POPEN 1
184 #define HAVE_SYSTEM 1
185 #define HAVE_CWAIT 1
186 #define HAVE_FSYNC 1
187 #undef HAVE_FTRUNCATE /* mingw implement it as _chsize. undef to be compatible */
188 #undef HAVE_TRUNCATE /* mingw-w64 implement it. undef to be compatible */
189 #define fsync _commit
190 #include <windows.h>
191 #include <winioctl.h>
192 #ifndef _MAX_ENV
193 #define _MAX_ENV 32767
194 #endif
178 #else 195 #else
179 #if defined(PYOS_OS2) && defined(PYCC_GCC) || defined(__VMS) 196 #if defined(PYOS_OS2) && defined(PYCC_GCC) || defined(__VMS)
180 /* Everything needed is defined in PC/os2emx/pyconfig.h or vms/pyconfig.h */ 197 /* Everything needed is defined in PC/os2emx/pyconfig.h or vms/pyconfig.h */
181 #else /* all other compilers */ 198 #else /* all other compilers */
182 /* Unix functions that the configure script doesn't check for */ 199 /* Unix functions that the configure script doesn't check for */
183 #define HAVE_EXECV 1 200 #define HAVE_EXECV 1
184 #define HAVE_FORK 1 201 #define HAVE_FORK 1
185 #if defined(__USLC__) && defined(__SCO_VERSION__) /* SCO UDK Compiler */ 202 #if defined(__USLC__) && defined(__SCO_VERSION__) /* SCO UDK Compiler */
186 #define HAVE_FORK1 1 203 #define HAVE_FORK1 1
187 #endif 204 #endif
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 #include <sys/ndir.h> 312 #include <sys/ndir.h>
296 #endif 313 #endif
297 #ifdef HAVE_SYS_DIR_H 314 #ifdef HAVE_SYS_DIR_H
298 #include <sys/dir.h> 315 #include <sys/dir.h>
299 #endif 316 #endif
300 #ifdef HAVE_NDIR_H 317 #ifdef HAVE_NDIR_H
301 #include <ndir.h> 318 #include <ndir.h>
302 #endif 319 #endif
303 #endif 320 #endif
304 321
305 #ifdef _MSC_VER 322 #if defined(_MSC_VER) || defined(__MINGW32__)
306 #ifdef HAVE_DIRECT_H 323 #ifdef HAVE_DIRECT_H
307 #include <direct.h> 324 #include <direct.h>
308 #endif 325 #endif
309 #ifdef HAVE_IO_H 326 #ifdef HAVE_IO_H
310 #include <io.h> 327 #include <io.h>
311 #endif 328 #endif
312 #ifdef HAVE_PROCESS_H 329 #ifdef HAVE_PROCESS_H
313 #include <process.h> 330 #include <process.h>
314 #endif 331 #endif
315 #ifndef VOLUME_NAME_DOS 332 #ifndef VOLUME_NAME_DOS
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 #else 904 #else
888 /* dummy version. _PyVerify_fd() is already defined in fileobject.h */ 905 /* dummy version. _PyVerify_fd() is already defined in fileobject.h */
889 #define _PyVerify_fd_dup2(A, B) (1) 906 #define _PyVerify_fd_dup2(A, B) (1)
890 #endif 907 #endif
891 908
892 #ifdef MS_WINDOWS 909 #ifdef MS_WINDOWS
893 /* The following structure was copied from 910 /* The following structure was copied from
894 http://msdn.microsoft.com/en-us/library/ms791514.aspx as the required 911 http://msdn.microsoft.com/en-us/library/ms791514.aspx as the required
895 include doesn't seem to be present in the Windows SDK (at least as included 912 include doesn't seem to be present in the Windows SDK (at least as included
896 with Visual Studio Express). */ 913 with Visual Studio Express). */
914 #ifndef HAVE_REPARSE_DATA_BUFFER
915 /*
916 * REPARSE_DATA_BUFFER is defined in <winnt.h> on mingw.org w32api
917 * instead as is documented in <ntifs.h>. The mingw-w64 API define
918 * it in <ddk/ntifs.h> but we can not include as header like
919 * <ntddk.h> is required instead <ddk/ntddk.h>, i.e. to use mingw-w64
920 * headers user must specify explicitly path to ddk :(.
921 * So lest check at configure time and use MSC hack if not found.
922 */
897 typedef struct _REPARSE_DATA_BUFFER { 923 typedef struct _REPARSE_DATA_BUFFER {
898 ULONG ReparseTag; 924 ULONG ReparseTag;
899 USHORT ReparseDataLength; 925 USHORT ReparseDataLength;
900 USHORT Reserved; 926 USHORT Reserved;
901 union { 927 union {
902 struct { 928 struct {
903 USHORT SubstituteNameOffset; 929 USHORT SubstituteNameOffset;
904 USHORT SubstituteNameLength; 930 USHORT SubstituteNameLength;
905 USHORT PrintNameOffset; 931 USHORT PrintNameOffset;
906 USHORT PrintNameLength; 932 USHORT PrintNameLength;
(...skipping 10 matching lines...) Expand all
917 } MountPointReparseBuffer; 943 } MountPointReparseBuffer;
918 944
919 struct { 945 struct {
920 UCHAR DataBuffer[1]; 946 UCHAR DataBuffer[1];
921 } GenericReparseBuffer; 947 } GenericReparseBuffer;
922 }; 948 };
923 } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER; 949 } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
924 950
925 #define REPARSE_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_DATA_BUFFER,\ 951 #define REPARSE_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_DATA_BUFFER,\
926 GenericReparseBuffer) 952 GenericReparseBuffer)
953 #ifndef MAXIMUM_REPARSE_DATA_BUFFER_SIZE
927 #define MAXIMUM_REPARSE_DATA_BUFFER_SIZE ( 16 * 1024 ) 954 #define MAXIMUM_REPARSE_DATA_BUFFER_SIZE ( 16 * 1024 )
955 #endif
956 #endif /*ndef HAVE_REPARSE_DATA_BUFFER*/
928 957
929 static int 958 static int
930 win32_get_reparse_tag(HANDLE reparse_point_handle, ULONG *reparse_tag) 959 win32_get_reparse_tag(HANDLE reparse_point_handle, ULONG *reparse_tag)
931 { 960 {
932 char target_buffer[MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; 961 char target_buffer[MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
933 REPARSE_DATA_BUFFER *rdb = (REPARSE_DATA_BUFFER *)target_buffer; 962 REPARSE_DATA_BUFFER *rdb = (REPARSE_DATA_BUFFER *)target_buffer;
934 DWORD n_bytes_returned; 963 DWORD n_bytes_returned;
935 964
936 if (0 == DeviceIoControl( 965 if (0 == DeviceIoControl(
937 reparse_point_handle, 966 reparse_point_handle,
(...skipping 12 matching lines...) Expand all
950 979
951 #endif /* MS_WINDOWS */ 980 #endif /* MS_WINDOWS */
952 981
953 /* Return a dictionary corresponding to the POSIX environment table */ 982 /* Return a dictionary corresponding to the POSIX environment table */
954 #ifdef WITH_NEXT_FRAMEWORK 983 #ifdef WITH_NEXT_FRAMEWORK
955 /* On Darwin/MacOSX a shared library or framework has no access to 984 /* On Darwin/MacOSX a shared library or framework has no access to
956 ** environ directly, we must obtain it with _NSGetEnviron(). 985 ** environ directly, we must obtain it with _NSGetEnviron().
957 */ 986 */
958 #include <crt_externs.h> 987 #include <crt_externs.h>
959 static char **environ; 988 static char **environ;
960 #elif !defined(_MSC_VER) && ( !defined(__WATCOMC__) || defined(__QNX__) ) 989 #elif !defined(_MSC_VER) && !defined(__MINGW32__) && ( !defined(__WATCOMC__) || defined(__QNX__) )
961 extern char **environ; 990 extern char **environ;
962 #endif /* !_MSC_VER */ 991 #endif /* !_MSC_VER */
963 992
964 static PyObject * 993 static PyObject *
965 convertenviron(void) 994 convertenviron(void)
966 { 995 {
967 PyObject *d; 996 PyObject *d;
968 #ifdef MS_WINDOWS 997 #ifdef MS_WINDOWS
969 wchar_t **e; 998 wchar_t **e;
970 #else 999 #else
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 Py_DECREF(opath1); 1300 Py_DECREF(opath1);
1272 Py_INCREF(Py_None); 1301 Py_INCREF(Py_None);
1273 return Py_None; 1302 return Py_None;
1274 } 1303 }
1275 1304
1276 1305
1277 #ifdef MS_WINDOWS 1306 #ifdef MS_WINDOWS
1278 static PyObject* 1307 static PyObject*
1279 win32_1str(PyObject* args, char* func, 1308 win32_1str(PyObject* args, char* func,
1280 char* format, BOOL (__stdcall *funcA)(LPCSTR), 1309 char* format, BOOL (__stdcall *funcA)(LPCSTR),
1281 char* wformat, BOOL (__stdcall *funcW)(LPWSTR)) 1310 char* wformat, BOOL (__stdcall *funcW)(LPCWSTR))
1282 { 1311 {
1283 PyObject *uni; 1312 PyObject *uni;
1284 const char *ansi; 1313 const char *ansi;
1285 BOOL result; 1314 BOOL result;
1286 1315
1287 if (PyArg_ParseTuple(args, wformat, &uni)) 1316 if (PyArg_ParseTuple(args, wformat, &uni))
1288 { 1317 {
1289 wchar_t *wstr = PyUnicode_AsUnicode(uni); 1318 wchar_t *wstr = PyUnicode_AsUnicode(uni);
1290 if (wstr == NULL) 1319 if (wstr == NULL)
1291 return NULL; 1320 return NULL;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 int st_rdev; 1427 int st_rdev;
1399 __int64 st_size; 1428 __int64 st_size;
1400 time_t st_atime; 1429 time_t st_atime;
1401 int st_atime_nsec; 1430 int st_atime_nsec;
1402 time_t st_mtime; 1431 time_t st_mtime;
1403 int st_mtime_nsec; 1432 int st_mtime_nsec;
1404 time_t st_ctime; 1433 time_t st_ctime;
1405 int st_ctime_nsec; 1434 int st_ctime_nsec;
1406 }; 1435 };
1407 1436
1408 static __int64 secs_between_epochs = 11644473600; /* Seconds between 1.1.1601 an d 1.1.1970 */ 1437 static __int64 secs_between_epochs = Py_LL(11644473600); /* Seconds between 1.1. 1601 and 1.1.1970 */
1409 1438
1410 static void 1439 static void
1411 FILE_TIME_to_time_t_nsec(FILETIME *in_ptr, time_t *time_out, int* nsec_out) 1440 FILE_TIME_to_time_t_nsec(FILETIME *in_ptr, time_t *time_out, int* nsec_out)
1412 { 1441 {
1413 /* XXX endianness. Shouldn't matter, as all Windows implementations are litt le-endian */ 1442 /* XXX endianness. Shouldn't matter, as all Windows implementations are litt le-endian */
1414 /* Cannot simply cast and dereference in_ptr, 1443 /* Cannot simply cast and dereference in_ptr,
1415 since it might not be aligned properly */ 1444 since it might not be aligned properly */
1416 __int64 in; 1445 __int64 in;
1417 memcpy(&in, in_ptr, sizeof(in)); 1446 memcpy(&in, in_ptr, sizeof(in));
1418 *nsec_out = (int)(in % 10000000) * 100; /* FILETIME is in units of 100 nsec. */ 1447 *nsec_out = (int)(in % 10000000) * 100; /* FILETIME is in units of 100 nsec. */
(...skipping 2276 matching lines...) Expand 10 before | Expand all | Expand 10 after
3695 outbuf, &temp)) { 3724 outbuf, &temp)) {
3696 win32_error("GetFullPathName", path); 3725 win32_error("GetFullPathName", path);
3697 return NULL; 3726 return NULL;
3698 } 3727 }
3699 if (PyUnicode_Check(PyTuple_GetItem(args, 0))) { 3728 if (PyUnicode_Check(PyTuple_GetItem(args, 0))) {
3700 return PyUnicode_Decode(outbuf, strlen(outbuf), 3729 return PyUnicode_Decode(outbuf, strlen(outbuf),
3701 Py_FileSystemDefaultEncoding, NULL); 3730 Py_FileSystemDefaultEncoding, NULL);
3702 } 3731 }
3703 return PyBytes_FromString(outbuf); 3732 return PyBytes_FromString(outbuf);
3704 } /* end of posix__getfullpathname */ 3733 } /* end of posix__getfullpathname */
3705
3706 3734
3707 3735
3708 /* A helper function for samepath on windows */ 3736 /* A helper function for samepath on windows */
3709 static PyObject * 3737 static PyObject *
3710 posix__getfinalpathname(PyObject *self, PyObject *args) 3738 posix__getfinalpathname(PyObject *self, PyObject *args)
3711 { 3739 {
3712 HANDLE hFile; 3740 HANDLE hFile;
3713 int buf_size; 3741 int buf_size;
3714 wchar_t *target_path; 3742 wchar_t *target_path;
3715 int result_length; 3743 int result_length;
(...skipping 7914 matching lines...) Expand 10 before | Expand all | Expand 10 after
11630 if (PyModule_AddIntMacro(d, RTLD_DEEPBIND)) return -1; 11658 if (PyModule_AddIntMacro(d, RTLD_DEEPBIND)) return -1;
11631 #endif 11659 #endif
11632 11660
11633 #if defined(PYOS_OS2) 11661 #if defined(PYOS_OS2)
11634 if (insertvalues(d)) return -1; 11662 if (insertvalues(d)) return -1;
11635 #endif 11663 #endif
11636 return 0; 11664 return 0;
11637 } 11665 }
11638 11666
11639 11667
11640 #if (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !def ined(__QNX__) 11668 #if (defined(_MSC_VER) || defined (__MINGW32__) || defined(__WATCOMC__) || defin ed(__BORLANDC__)) && !defined(__QNX__)
11641 #define INITFUNC PyInit_nt 11669 #define INITFUNC PyInit_nt
11642 #define MODNAME "nt" 11670 #define MODNAME "nt"
11643 11671
11644 #elif defined(PYOS_OS2) 11672 #elif defined(PYOS_OS2)
11645 #define INITFUNC PyInit_os2 11673 #define INITFUNC PyInit_os2
11646 #define MODNAME "os2" 11674 #define MODNAME "os2"
11647 11675
11648 #else 11676 #else
11649 #define INITFUNC PyInit_posix 11677 #define INITFUNC PyInit_posix
11650 #define MODNAME "posix" 11678 #define MODNAME "posix"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
11957 11985
11958 initialized = 1; 11986 initialized = 1;
11959 11987
11960 return m; 11988 return m;
11961 11989
11962 } 11990 }
11963 11991
11964 #ifdef __cplusplus 11992 #ifdef __cplusplus
11965 } 11993 }
11966 #endif 11994 #endif
OLDNEW
« no previous file with comments | « Modules/_multiprocessing/multiprocessing.c ('k') | Modules/python.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+