Commit Graph

1034 Commits

Author SHA1 Message Date
Giampaolo Rodola c7f02a9659
bpo-33671 / shutil.copyfile: use memoryview() with dynamic size on Windows (#7681)
bpo-33671
* use memoryview() with size == file size on Windows, see https://github.com/python/cpython/pull/7160#discussion_r195405230
* release intermediate (sliced) memoryview immediately
* replace "OSX" occurrences with "macOS"
* add some unittests for copyfileobj()
2018-06-19 08:27:29 -07:00
Pablo Galindo cb970730e3 bpo-33630: Fix using of freed memory in old versions of glicb for posix_spawn(). (GH-7685) 2018-06-19 11:19:50 +03:00
Giampaolo Rodola 4a172ccc73
bpo-33671: efficient zero-copy for shutil.copy* functions (Linux, OSX and Win) (#7160)
* have shutil.copyfileobj use sendfile() if possible

* refactoring: use ctx manager

* add test with non-regular file obj

* emulate case where file size can't be determined

* reference _copyfileobj_sendfile directly

* add test for offset() at certain position

* add test for empty file

* add test for non regular file dst

* small refactoring

* leave copyfileobj() alone in order to not introduce any incompatibility

* minor refactoring

* remove old test

* update docstring

* update docstring; rename exception class

* detect platforms which only support file to socket zero copy

* don't run test on platforms where file-to-file zero copy is not supported

* use tempfiles

* reset verbosity

* add test for smaller chunks

* add big file size test

* add comment

* update doc

* update whatsnew doc

* update doc

* catch Exception

* remove unused import

* add test case for error on second sendfile() call

* turn docstring into comment

* add one more test

* update comment

* add Misc/NEWS entry

* get rid of COPY_BUFSIZE; it belongs to another PR

* update doc

* expose posix._fcopyfile() for OSX

* merge from linux branch

* merge from linux branch

* expose fcopyfile

* arg clinic for the win implementation

* convert path type to path_t

* expose CopyFileW

* fix windows tests

* release GIL

* minor refactoring

* update doc

* update comment

* update docstrings

* rename functions

* rename test classes

* update doc

* update doc

* update docstrings and comments

* avoid do import nt|posix modules if unnecessary

* set nt|posix modules to None if not available

* micro speedup

* update description

* add doc note

* use better wording in doc

* rename function using 'fastcopy' prefix instead of 'zerocopy'

* use :ref: in rst doc

* change wording in doc

* add test to make sure sendfile() doesn't get called aymore in case it doesn't support file to file copies

* move CopyFileW in _winapi and actually expose CopyFileExW instead

* fix line endings

* add tests for mode bits

* add docstring

* remove test file mode class; let's keep it for later when Istart addressing OSX fcopyfile() specific copies

* update doc to reflect new changes

* update doc

* adjust tests on win

* fix argument clinic error

* update doc

* OSX: expose copyfile(3) instead of fcopyfile(3); also expose flags arg to python

* osx / copyfile: use path_t instead of char

* do not set dst name in the OSError exception in order to remain consistent with platforms which cannot do that (e.g. linux)

* add same file test

* add test for same file

* have osx copyfile() pre-emptively check if src and dst are the same, otherwise it will return immedialtey and src file content gets deleted

* turn PermissionError into appropriate SameFileError

* expose ERROR_SHARING_VIOLATION in order to raise more appropriate SameFileError

* honour follow_symlinks arg when using CopyFileEx

* update Misc/NEWS

* expose CreateDirectoryEx mock

* change C type

* CreateDirectoryExW actual implementation

* provide specific makedirs() implementation for win

* fix typo

* skeleton for SetNamedSecurityInfo

* get security info for src path

* finally set security attrs

* add unit tests

* mimick os.makedirs() behavior and raise if dst dir exists

* set 2 paths for OSError object

* set 2 paths for OSError object

* expand windows test

* in case of exception on os.sendfile() set filename and filename2 exception attributes

* set 2 filenames (src, dst) for OSError in case copyfile() fails on OSX

* update doc

* do not use CreateDirectoryEx() in copytree() if source dir is a symlink (breaks test_copytree_symlink_dir); instead just create a plain dir and remain consistent with POSIX implementation

* use bytearray() and readinto()

* use memoryview() with bytearray()

* refactoring + introduce a new _fastcopy_binfileobj() fun

* remove CopyFileEx and other C wrappers

* remove code related to CopyFileEx

* Recognize binary files in copyfileobj()
...and use fastest _fastcopy_binfileobj() when possible

* set 1MB copy bufsize on win; also add a global _COPY_BUFSIZE variable

* use ctx manager for memoryview()

* update doc

* remove outdated doc

* remove last CopyFileEx remnants

* OSX - use fcopyfile(3) instead of copyfile(3)

...as an extra safety measure: in case src/dst are "exotic" files (non
regular or living on a network fs etc.) we better fail on open() instead
of copyfile(3) as we're not quite sure what's gonna happen in that
case.

* update doc
2018-06-12 23:04:50 +02:00
Zackery Spytz 69dccc397a Remove unneeded PyErr_Occurred() check in os_lseek_impl() (GH-7557)
This call became unneeded after the posix module was converted to the
Argument Clinic in 2f93635d34 and should
have been removed as part of that change.
2018-06-10 10:28:01 +03:00
Serhiy Storchaka d54cfb160c
bpo-33441: Make the sigset_t converter available in other modules. (GH-6720)
* Expose the sigset_t converter via private API _Py_Sigset_Converter().
* Use Argument Clinic for parsing sigset_t in signalmodule.c.
* Raise ValueError instead OverflowError for integers out of
  the C long range.

Based on patch by Pablo Galindo Salgado.
2018-05-08 07:48:50 +03:00
Serhiy Storchaka ef347535f2
bpo-20104: Improve error handling and fix a reference leak in os.posix_spawn(). (#6332) 2018-05-01 16:45:04 +03:00
Alexey Izbyshev 3b20d3454e bpo-33016: Fix potential use of uninitialized memory in nt._getfinalpathname (#6010) 2018-03-08 08:03:25 -08:00
Steve Dower 6921e73e33
bpo-33001: Prevent buffer overrun in os.symlink (GH-5989) 2018-03-05 14:26:08 -08:00
Alexey Izbyshev 3e197c7a67 bpo-32903: Fix a memory leak in os.chdir() on Windows (GH-5801) 2018-03-01 17:13:56 +08:00
Steve Dower 23ad6d0d1a
bpo-32556: nt._getfinalpathname, nt._getvolumepathname and nt._getdiskusage now correctly convert from bytes. (GH-5761) 2018-02-22 10:39:10 -08:00
Alexey Izbyshev b3caf388a0 closes bpo-32859: Don't retry dup3() if it is not available at runtime (GH-5708)
os.dup2() tests for dup3() system call availability at runtime,
but doesn't remember the result across calls, repeating
the test on each call with inheritable=False.

Since the caller of os.dup2() is expected to hold the GIL,
fix this by making the variable holding the test result static.
2018-02-19 23:25:46 -08:00
ngie-eign 7745ec4e35 Update comment in posixmodule.c (GH-5681)
A closing parentheses was missing.

Signed-off-by: Ngie Cooper <yaneurabeya@gmail.com>
2018-02-14 11:54:28 -08:00
SSE4 3c34aad4e7 bpo-29248: Fix os.readlink() on Windows (GH-5577)
The PrintNameOffset field of the reparse data buffer
was treated as a number of characters instead of bytes.
2018-02-12 20:10:35 +03:00
oldk aa0735f597 bpo-32747: Remove trailing spaces in docstrings. (GH-5491) 2018-02-02 10:52:55 +02:00
Stéphane Wirtel 3d86e484de bpo-32681: Fix an uninitialized variable in the C implementation of os.dup2 (GH-5346)
See https://bugs.python.org/issue32441 for where this was introduced.
2018-01-29 22:04:36 -08:00
Pablo Galindo 0cd6bca655 bpo-20104: Fix leaks and errors in new os.posix_spawn (GH-5418)
* Fix memory leaks and error handling in posix spawn
* Improve error handling when destroying the file_actions object
* Py_DECREF the result of PySequence_Fast on error
* Handle uninitialized pid
* Use OSError if file actions fails to initialize
* Move _file_actions to outer scope to avoid undefined behaviour
* Remove HAVE_POSIX_SPAWN define in Modules/posixmodule.c
* Unshadow exception and clean error message
2018-01-29 12:34:42 -08:00
Chih-Hsuan Yen 8997f9cd1a bpo-32705: Current Android does not have posix_spawn (#5413) 2018-01-29 10:50:35 +01:00
Pablo Galindo 6c6ddf97c4 bpo-20104: Expose `posix_spawn` in the os module (GH-5109)
Add os.posix_spawn to wrap the low level POSIX API of the same name.

Contributed by Pablo Galindo.
2018-01-28 17:56:10 -08:00
jcea 6c51d51880
bpo-32659: Solaris "stat" should support "st_fstype" (#5307)
* bpo-32659: Solaris "stat" should support "st_fstype"

* Add 'versionadded'
2018-01-28 14:00:08 +01:00
Pablo Galindo 4defba3b95 bpo-31368: Expose preadv and pwritev in the os module (#5239) 2018-01-27 17:16:37 +01:00
Michael Felt 502d551c6d bpo-32390: Fix compilation failure on AIX after f_fsid was added to os.statvfs() (#4972) 2018-01-05 13:01:58 +01:00
Benjamin Peterson bbdb17d19b
return the new file descriptor from os.dup2 (closes bpo-32441) (#5041) 2017-12-29 13:13:06 -08:00
Michael Felt c5ae169e1b bpo-26439 Fix ctypes.util.find_library failure on AIX (#4507)
Implement find_library() support in ctypes/util for AIX.

Add some AIX specific tests.
2017-12-19 13:58:49 +01:00
Giuseppe Scrivano 96a5e50a5d bpo-32143: add f_fsid to os.statvfs() (#4571)
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2017-12-14 17:46:46 -05:00
Anthony Sottile 233ef249cc bpo-32277: Fix exception raised from chmod(..., follow_symlinks=False) (#4797) 2017-12-14 18:57:55 +02:00
Erik Bray 03eb11f0b3 bpo-16135: Cleanup: Code rot left over from OS/2 support (GH-4147)
Remove dangling references to PYCC_VACPP that are not relelvant
since removal of OS/2 support.
2017-10-27 05:27:06 -07:00
Victor Stinner 850a18e03e bpo-30768: Recompute timeout on interrupted lock (GH-4103)
Fix the pthread+semaphore implementation of
PyThread_acquire_lock_timed() when called with timeout > 0 and
intr_flag=0: recompute the timeout if sem_timedwait() is interrupted
by a signal (EINTR).

See also the PEP 475.

The pthread implementation of PyThread_acquire_lock() now fails with
a fatal error if the timeout is larger than PY_TIMEOUT_MAX, as done
in the Windows implementation.

The check prevents any risk of overflow in PyThread_acquire_lock().

Add also PY_DWORD_MAX constant.
2017-10-24 16:53:32 -07:00
Victor Stinner 01b5aab7bf bpo-31827: Remove os.stat_float_times() (GH-4061) 2017-10-24 02:02:00 -07:00
Victor Stinner a99121526a os.startfile(): add a C comment on security (#3877)
LoadLibrary("SHELL32") is not vulnerable to DLL hijacking.
2017-10-13 13:46:57 -07:00
Masayuki Yamamoto 731e189014 bpo-25658: Implement PEP 539 for Thread Specific Storage (TSS) API (GH-1362)
See PEP 539 for details.

Highlights of changes:

- Add Thread Specific Storage (TSS) API
- Document the Thread Local Storage (TLS) API as deprecated
- Update code that used TLS API to use TSS API
2017-10-06 20:41:34 +10:00
Benjamin Peterson 288d1daada remove support for BSD/OS (closes bpo-31624) (#3812) 2017-09-28 22:44:27 -07:00
Antoine Pitrou a6a4dc816d bpo-31370: Remove support for threads-less builds (#3385)
* Remove Setup.config
* Always define WITH_THREAD for compatibility.
2017-09-07 18:56:24 +02:00
Christian Heimes 75b961869a bpo-31343: Include sys/sysmacros.h (#3318)
Include sys/sysmacros.h for major(), minor(), and makedev(). GNU C libray
plans to remove the functions from sys/types.h.

Signed-off-by: Christian Heimes <christian@python.org>
2017-09-05 15:53:09 +02:00
Christopher Wilcox c67bae0478 bpo-30581: Windows: os.cpu_count() returns wrong number of processors (#2934)
* Fixes #30581 by adding a path to use newer GetMaximumProcessorCount API on Windows calls to os.cpu_count()

* Add NEWS.d entry for bpo-30581, os.cpu_count on Windows.

* Tweak NEWS entry
2017-08-30 11:01:08 +02:00
Коренберг Марк d4b93e21c2 bpo-31106: Fix handling of erros in posix_fallocate() and posix_fadvise() (#3000) (#3000) 2017-08-14 06:55:16 -07:00
Ville Skyttä 49b2734bf1 Spelling fixes (#2902) 2017-08-03 09:00:59 +03:00
Serhiy Storchaka 1180e5a518 bpo-30879: os.listdir() and os.scandir() now emit bytes names when (#2634)
called with bytes-like argument.
2017-07-11 06:36:46 +03:00
Serhiy Storchaka f7eae0adfc [security] bpo-13617: Reject embedded null characters in wchar* strings. (#2302)
Based on patch by Victor Stinner.

Add private C API function _PyUnicode_AsUnicode() which is similar to
PyUnicode_AsUnicode(), but checks for null characters.
2017-06-28 08:30:06 +03:00
Eric N. Vander Weele a7874c73c0 bpo-30769: Fix reference leak introduced in 77703942c5 (#2416)
New error condition paths were introduced, which did not decrement
`key2` and `val2` objects.  Therefore, decrement references before
jumping to the error label.

Signed-off-by: Eric N. Vander Weele <ericvw@gmail.com>
2017-06-27 03:35:20 +02:00
Serhiy Storchaka 77703942c5 bpo-30746: Prohibited the '=' character in environment variable names (#2382)
in `os.putenv()` and `os.spawn*()`.
2017-06-25 07:33:01 +03:00
Victor Stinner c8d6ab2e25 bpo-30602: Fix lastarg in os.spawnve() (#2287)
Fix a regression introduced by myself in the commit
526b22657c.
2017-06-23 15:04:46 +02:00
Victor Stinner 8acb4cf2b3 bpo-30602: Fix refleak in os.spawnv() (#2212)
When os.spawnv() fails while handling arguments, free correctly
argvlist: pass lastarg+1 rather than lastarg to free_string_array()
to also free the first item.
2017-06-15 15:30:40 +02:00
Victor Stinner 526b22657c bpo-30602: Fix refleak in os.spawnve() (#2184)
When os.spawnve() fails while handling arguments, free correctly
argvlist: pass lastarg+1 rather than lastarg to free_string_array()
to also free the first item.
2017-06-14 14:26:21 +02:00
messi Liao 0d322181d9 bpo-30650: Fixed a syntax error: missed right parentheses (#2154) 2017-06-13 17:30:43 +03:00
Gregory P. Smith 163468a766 bpo-16500: Don't use string constants for os.register_at_fork() behavior (#1834)
Instead use keyword only arguments to os.register_at_fork for each of the scenarios.
Updates the documentation for clarity.
2017-05-29 10:03:41 -07:00
Antoine Pitrou 346cbd351e bpo-16500: Allow registering at-fork handlers (#1715)
* bpo-16500: Allow registering at-fork handlers

* Address Serhiy's comments

* Add doc for new C API

* Add doc for new Python-facing function

* Add NEWS entry + doc nit
2017-05-27 17:50:54 +02:00
xdegaye 50e86033de bpo-29619: Do not use HAVE_LARGEFILE_SUPPORT for type conversions (GH-1666).
bpo-29619: Do not use HAVE_LARGEFILE_SUPPORT for type conversions (GH-1666).

* Use only the LongLong form for the conversions.
2017-05-22 11:15:08 +02:00
Serhiy Storchaka bf623ae884 bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (#1096)
raised an error.

Replace them with using concrete types API that never fails if appropriate.
2017-04-19 20:03:52 +03:00
Serhiy Storchaka ea720fe7e9 bpo-25996: Added support of file descriptors in os.scandir() on Unix. (#502)
os.fwalk() is sped up by 2 times by using os.scandir().
2017-03-30 09:12:31 +03:00
Victor Stinner 0f6d73343d bpo-29619: Convert st_ino using unsigned integer (#557)
bpo-29619: os.stat() and os.DirEntry.inodeo() now convert inode
(st_ino) using unsigned integers.
2017-03-09 17:34:28 +01:00