mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Issue #23753: Python doesn't support anymore platforms without stat() or
fstat(), these functions are always required. Remove HAVE_STAT and HAVE_FSTAT defines, and stop supporting DONT_HAVE_STAT and DONT_HAVE_FSTAT.
This commit is contained in:
parent
551350a79f
commit
f329878e74
7 changed files with 4 additions and 73 deletions
|
@ -15,14 +15,11 @@ PyAPI_FUNC(char*) Py_EncodeLocale(
|
||||||
const wchar_t *text,
|
const wchar_t *text,
|
||||||
size_t *error_pos);
|
size_t *error_pos);
|
||||||
|
|
||||||
#if defined(HAVE_STAT) && !defined(MS_WINDOWS)
|
|
||||||
PyAPI_FUNC(int) _Py_wstat(
|
PyAPI_FUNC(int) _Py_wstat(
|
||||||
const wchar_t* path,
|
const wchar_t* path,
|
||||||
struct stat *buf);
|
struct stat *buf);
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef Py_LIMITED_API
|
#ifndef Py_LIMITED_API
|
||||||
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
|
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
struct _Py_stat_struct {
|
struct _Py_stat_struct {
|
||||||
|
@ -49,14 +46,11 @@ struct _Py_stat_struct {
|
||||||
PyAPI_FUNC(int) _Py_fstat(
|
PyAPI_FUNC(int) _Py_fstat(
|
||||||
int fd,
|
int fd,
|
||||||
struct _Py_stat_struct *stat);
|
struct _Py_stat_struct *stat);
|
||||||
#endif /* HAVE_FSTAT || MS_WINDOWS */
|
|
||||||
#endif /* Py_LIMITED_API */
|
#endif /* Py_LIMITED_API */
|
||||||
|
|
||||||
#ifdef HAVE_STAT
|
|
||||||
PyAPI_FUNC(int) _Py_stat(
|
PyAPI_FUNC(int) _Py_stat(
|
||||||
PyObject *path,
|
PyObject *path,
|
||||||
struct stat *statbuf);
|
struct stat *statbuf);
|
||||||
#endif /* HAVE_STAT */
|
|
||||||
|
|
||||||
#ifndef Py_LIMITED_API
|
#ifndef Py_LIMITED_API
|
||||||
PyAPI_FUNC(int) _Py_open(
|
PyAPI_FUNC(int) _Py_open(
|
||||||
|
|
|
@ -357,28 +357,6 @@ typedef int Py_ssize_clean_t;
|
||||||
* stat() and fstat() fiddling *
|
* stat() and fstat() fiddling *
|
||||||
*******************************/
|
*******************************/
|
||||||
|
|
||||||
/* We expect that stat and fstat exist on most systems.
|
|
||||||
* It's confirmed on Unix, Mac and Windows.
|
|
||||||
* If you don't have them, add
|
|
||||||
* #define DONT_HAVE_STAT
|
|
||||||
* and/or
|
|
||||||
* #define DONT_HAVE_FSTAT
|
|
||||||
* to your pyconfig.h. Python code beyond this should check HAVE_STAT and
|
|
||||||
* HAVE_FSTAT instead.
|
|
||||||
* Also
|
|
||||||
* #define HAVE_SYS_STAT_H
|
|
||||||
* if <sys/stat.h> exists on your platform, and
|
|
||||||
* #define HAVE_STAT_H
|
|
||||||
* if <stat.h> does.
|
|
||||||
*/
|
|
||||||
#ifndef DONT_HAVE_STAT
|
|
||||||
#define HAVE_STAT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DONT_HAVE_FSTAT
|
|
||||||
#define HAVE_FSTAT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_SYS_STAT_H
|
#ifdef HAVE_SYS_STAT_H
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#elif defined(HAVE_STAT_H)
|
#elif defined(HAVE_STAT_H)
|
||||||
|
|
|
@ -10,6 +10,9 @@ Release date: 2015-03-28
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #23753: Python doesn't support anymore platforms without stat() or
|
||||||
|
fstat(), these functions are always required.
|
||||||
|
|
||||||
- Issue #23681: The -b option now affects comparisons of bytes with int.
|
- Issue #23681: The -b option now affects comparisons of bytes with int.
|
||||||
|
|
||||||
- Issue #23632: Memoryviews now allow tuple indexing (including for
|
- Issue #23632: Memoryviews now allow tuple indexing (including for
|
||||||
|
@ -29,7 +32,7 @@ Library
|
||||||
|
|
||||||
- Issue #23657: Avoid explicit checks for str in zipapp, adding support
|
- Issue #23657: Avoid explicit checks for str in zipapp, adding support
|
||||||
for pathlib.Path objects as arguments.
|
for pathlib.Path objects as arguments.
|
||||||
|
|
||||||
- Issue #23688: Added support of arbitrary bytes-like objects and avoided
|
- Issue #23688: Added support of arbitrary bytes-like objects and avoided
|
||||||
unnecessary copying of memoryview in gzip.GzipFile.write().
|
unnecessary copying of memoryview in gzip.GzipFile.write().
|
||||||
Original patch by Wolfgang Maier.
|
Original patch by Wolfgang Maier.
|
||||||
|
|
|
@ -180,7 +180,6 @@ fileio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
static int
|
static int
|
||||||
check_fd(int fd)
|
check_fd(int fd)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
|
|
||||||
struct _Py_stat_struct buf;
|
struct _Py_stat_struct buf;
|
||||||
if (_Py_fstat(fd, &buf) < 0 &&
|
if (_Py_fstat(fd, &buf) < 0 &&
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
|
@ -197,7 +196,6 @@ check_fd(int fd)
|
||||||
Py_XDECREF(exc);
|
Py_XDECREF(exc);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,9 +226,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
|
||||||
#elif !defined(MS_WINDOWS)
|
#elif !defined(MS_WINDOWS)
|
||||||
int *atomic_flag_works = NULL;
|
int *atomic_flag_works = NULL;
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
|
|
||||||
struct _Py_stat_struct fdfstat;
|
struct _Py_stat_struct fdfstat;
|
||||||
#endif
|
|
||||||
int async_err = 0;
|
int async_err = 0;
|
||||||
|
|
||||||
assert(PyFileIO_Check(oself));
|
assert(PyFileIO_Check(oself));
|
||||||
|
@ -427,7 +423,6 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
|
||||||
}
|
}
|
||||||
|
|
||||||
self->blksize = DEFAULT_BUFFER_SIZE;
|
self->blksize = DEFAULT_BUFFER_SIZE;
|
||||||
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
|
|
||||||
if (_Py_fstat(self->fd, &fdfstat) < 0) {
|
if (_Py_fstat(self->fd, &fdfstat) < 0) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -446,7 +441,6 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
|
||||||
if (fdfstat.st_blksize > 1)
|
if (fdfstat.st_blksize > 1)
|
||||||
self->blksize = fdfstat.st_blksize;
|
self->blksize = fdfstat.st_blksize;
|
||||||
#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
|
#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
|
||||||
#endif /* HAVE_FSTAT || MS_WINDOWS */
|
|
||||||
|
|
||||||
#if defined(MS_WINDOWS) || defined(__CYGWIN__)
|
#if defined(MS_WINDOWS) || defined(__CYGWIN__)
|
||||||
/* don't translate newlines (\r\n <=> \n) */
|
/* don't translate newlines (\r\n <=> \n) */
|
||||||
|
@ -597,8 +591,6 @@ fileio_readinto(fileio *self, PyObject *args)
|
||||||
return PyLong_FromSsize_t(n);
|
return PyLong_FromSsize_t(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
|
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
new_buffersize(fileio *self, size_t currentsize)
|
new_buffersize(fileio *self, size_t currentsize)
|
||||||
{
|
{
|
||||||
|
@ -702,18 +694,6 @@ fileio_readall(fileio *self)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
fileio_readall(fileio *self)
|
|
||||||
{
|
|
||||||
_Py_IDENTIFIER(readall);
|
|
||||||
return _PyObject_CallMethodId((PyObject*)&PyRawIOBase_Type,
|
|
||||||
&PyId_readall, "O", self);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* HAVE_FSTAT || MS_WINDOWS */
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
fileio_read(fileio *self, PyObject *args)
|
fileio_read(fileio *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1112,9 +1112,7 @@ _GetMapSize(PyObject *o, const char* param)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
|
new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_FSTAT
|
|
||||||
struct _Py_stat_struct st;
|
struct _Py_stat_struct st;
|
||||||
#endif
|
|
||||||
mmap_object *m_obj;
|
mmap_object *m_obj;
|
||||||
PyObject *map_size_obj = NULL;
|
PyObject *map_size_obj = NULL;
|
||||||
Py_ssize_t map_size;
|
Py_ssize_t map_size;
|
||||||
|
@ -1179,7 +1177,6 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
(void)fcntl(fd, F_FULLFSYNC);
|
(void)fcntl(fd, F_FULLFSYNC);
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_FSTAT
|
|
||||||
if (fd != -1 && _Py_fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
|
if (fd != -1 && _Py_fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
|
||||||
if (map_size == 0) {
|
if (map_size == 0) {
|
||||||
if (st.st_size == 0) {
|
if (st.st_size == 0) {
|
||||||
|
@ -1204,7 +1201,6 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
m_obj = (mmap_object *)type->tp_alloc(type, 0);
|
m_obj = (mmap_object *)type->tp_alloc(type, 0);
|
||||||
if (m_obj == NULL) {return NULL;}
|
if (m_obj == NULL) {return NULL;}
|
||||||
m_obj->data = NULL;
|
m_obj->data = NULL;
|
||||||
|
|
|
@ -519,17 +519,8 @@ Py_EncodeLocale(const wchar_t *text, size_t *error_pos)
|
||||||
#endif /* __APPLE__ */
|
#endif /* __APPLE__ */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In principle, this should use HAVE__WSTAT, and _wstat
|
|
||||||
should be detected by autoconf. However, no current
|
|
||||||
POSIX system provides that function, so testing for
|
|
||||||
it is pointless.
|
|
||||||
Not sure whether the MS_WINDOWS guards are necessary:
|
|
||||||
perhaps for cygwin/mingw builds?
|
|
||||||
*/
|
|
||||||
#if defined(HAVE_STAT) && !defined(MS_WINDOWS)
|
|
||||||
|
|
||||||
/* Get file status. Encode the path to the locale encoding. */
|
/* Get file status. Encode the path to the locale encoding. */
|
||||||
|
|
||||||
int
|
int
|
||||||
_Py_wstat(const wchar_t* path, struct stat *buf)
|
_Py_wstat(const wchar_t* path, struct stat *buf)
|
||||||
{
|
{
|
||||||
|
@ -544,11 +535,8 @@ _Py_wstat(const wchar_t* path, struct stat *buf)
|
||||||
PyMem_Free(fname);
|
PyMem_Free(fname);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
|
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
static __int64 secs_between_epochs = 11644473600; /* Seconds between 1.1.1601 and 1.1.1970 */
|
static __int64 secs_between_epochs = 11644473600; /* Seconds between 1.1.1601 and 1.1.1970 */
|
||||||
|
|
||||||
|
@ -679,10 +667,8 @@ _Py_fstat(int fd, struct _Py_stat_struct *result)
|
||||||
return fstat(fd, result);
|
return fstat(fd, result);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif /* HAVE_FSTAT || MS_WINDOWS */
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_STAT
|
|
||||||
/* Call _wstat() on Windows, or encode the path to the filesystem encoding and
|
/* Call _wstat() on Windows, or encode the path to the filesystem encoding and
|
||||||
call stat() otherwise. Only fill st_mode attribute on Windows.
|
call stat() otherwise. Only fill st_mode attribute on Windows.
|
||||||
|
|
||||||
|
@ -715,8 +701,6 @@ _Py_stat(PyObject *path, struct stat *statbuf)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* HAVE_STAT */
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
get_inheritable(int fd, int raise)
|
get_inheritable(int fd, int raise)
|
||||||
|
|
|
@ -1481,7 +1481,6 @@ PyMarshal_ReadLongFromFile(FILE *fp)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
|
|
||||||
/* Return size of file in bytes; < 0 if unknown or INT_MAX if too big */
|
/* Return size of file in bytes; < 0 if unknown or INT_MAX if too big */
|
||||||
static off_t
|
static off_t
|
||||||
getfilesize(FILE *fp)
|
getfilesize(FILE *fp)
|
||||||
|
@ -1496,7 +1495,6 @@ getfilesize(FILE *fp)
|
||||||
else
|
else
|
||||||
return (off_t)st.st_size;
|
return (off_t)st.st_size;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* If we can get the size of the file up-front, and it's reasonably small,
|
/* If we can get the size of the file up-front, and it's reasonably small,
|
||||||
* read it in one gulp and delegate to ...FromString() instead. Much quicker
|
* read it in one gulp and delegate to ...FromString() instead. Much quicker
|
||||||
|
@ -1509,7 +1507,6 @@ PyMarshal_ReadLastObjectFromFile(FILE *fp)
|
||||||
{
|
{
|
||||||
/* REASONABLE_FILE_LIMIT is by defn something big enough for Tkinter.pyc. */
|
/* REASONABLE_FILE_LIMIT is by defn something big enough for Tkinter.pyc. */
|
||||||
#define REASONABLE_FILE_LIMIT (1L << 18)
|
#define REASONABLE_FILE_LIMIT (1L << 18)
|
||||||
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
|
|
||||||
off_t filesize;
|
off_t filesize;
|
||||||
filesize = getfilesize(fp);
|
filesize = getfilesize(fp);
|
||||||
if (filesize > 0 && filesize <= REASONABLE_FILE_LIMIT) {
|
if (filesize > 0 && filesize <= REASONABLE_FILE_LIMIT) {
|
||||||
|
@ -1522,7 +1519,6 @@ PyMarshal_ReadLastObjectFromFile(FILE *fp)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
/* We don't have fstat, or we do but the file is larger than
|
/* We don't have fstat, or we do but the file is larger than
|
||||||
* REASONABLE_FILE_LIMIT or malloc failed -- read a byte at a time.
|
* REASONABLE_FILE_LIMIT or malloc failed -- read a byte at a time.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue