Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f329878

Browse files
committed
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.
1 parent 551350a commit f329878

7 files changed

Lines changed: 4 additions & 73 deletions

File tree

Include/fileutils.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ PyAPI_FUNC(char*) Py_EncodeLocale(
1515
const wchar_t *text,
1616
size_t *error_pos);
1717

18-
#if defined(HAVE_STAT) && !defined(MS_WINDOWS)
1918
PyAPI_FUNC(int) _Py_wstat(
2019
const wchar_t* path,
2120
struct stat *buf);
22-
#endif
2321

2422
#ifndef Py_LIMITED_API
25-
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
2623

2724
#ifdef MS_WINDOWS
2825
struct _Py_stat_struct {
@@ -49,14 +46,11 @@ struct _Py_stat_struct {
4946
PyAPI_FUNC(int) _Py_fstat(
5047
int fd,
5148
struct _Py_stat_struct *stat);
52-
#endif /* HAVE_FSTAT || MS_WINDOWS */
5349
#endif /* Py_LIMITED_API */
5450

55-
#ifdef HAVE_STAT
5651
PyAPI_FUNC(int) _Py_stat(
5752
PyObject *path,
5853
struct stat *statbuf);
59-
#endif /* HAVE_STAT */
6054

6155
#ifndef Py_LIMITED_API
6256
PyAPI_FUNC(int) _Py_open(

Include/pyport.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -357,28 +357,6 @@ typedef int Py_ssize_clean_t;
357357
* stat() and fstat() fiddling *
358358
*******************************/
359359

360-
/* We expect that stat and fstat exist on most systems.
361-
* It's confirmed on Unix, Mac and Windows.
362-
* If you don't have them, add
363-
* #define DONT_HAVE_STAT
364-
* and/or
365-
* #define DONT_HAVE_FSTAT
366-
* to your pyconfig.h. Python code beyond this should check HAVE_STAT and
367-
* HAVE_FSTAT instead.
368-
* Also
369-
* #define HAVE_SYS_STAT_H
370-
* if <sys/stat.h> exists on your platform, and
371-
* #define HAVE_STAT_H
372-
* if <stat.h> does.
373-
*/
374-
#ifndef DONT_HAVE_STAT
375-
#define HAVE_STAT
376-
#endif
377-
378-
#ifndef DONT_HAVE_FSTAT
379-
#define HAVE_FSTAT
380-
#endif
381-
382360
#ifdef HAVE_SYS_STAT_H
383361
#include <sys/stat.h>
384362
#elif defined(HAVE_STAT_H)

Misc/NEWS

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: 2015-03-28
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #23753: Python doesn't support anymore platforms without stat() or
14+
fstat(), these functions are always required.
15+
1316
- Issue #23681: The -b option now affects comparisons of bytes with int.
1417

1518
- Issue #23632: Memoryviews now allow tuple indexing (including for
@@ -29,7 +32,7 @@ Library
2932

3033
- Issue #23657: Avoid explicit checks for str in zipapp, adding support
3134
for pathlib.Path objects as arguments.
32-
35+
3336
- Issue #23688: Added support of arbitrary bytes-like objects and avoided
3437
unnecessary copying of memoryview in gzip.GzipFile.write().
3538
Original patch by Wolfgang Maier.

Modules/_io/fileio.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ fileio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
180180
static int
181181
check_fd(int fd)
182182
{
183-
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
184183
struct _Py_stat_struct buf;
185184
if (_Py_fstat(fd, &buf) < 0 &&
186185
#ifdef MS_WINDOWS
@@ -197,7 +196,6 @@ check_fd(int fd)
197196
Py_XDECREF(exc);
198197
return -1;
199198
}
200-
#endif
201199
return 0;
202200
}
203201

@@ -228,9 +226,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
228226
#elif !defined(MS_WINDOWS)
229227
int *atomic_flag_works = NULL;
230228
#endif
231-
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
232229
struct _Py_stat_struct fdfstat;
233-
#endif
234230
int async_err = 0;
235231

236232
assert(PyFileIO_Check(oself));
@@ -427,7 +423,6 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
427423
}
428424

429425
self->blksize = DEFAULT_BUFFER_SIZE;
430-
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
431426
if (_Py_fstat(self->fd, &fdfstat) < 0) {
432427
PyErr_SetFromErrno(PyExc_OSError);
433428
goto error;
@@ -446,7 +441,6 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
446441
if (fdfstat.st_blksize > 1)
447442
self->blksize = fdfstat.st_blksize;
448443
#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
449-
#endif /* HAVE_FSTAT || MS_WINDOWS */
450444

451445
#if defined(MS_WINDOWS) || defined(__CYGWIN__)
452446
/* don't translate newlines (\r\n <=> \n) */
@@ -597,8 +591,6 @@ fileio_readinto(fileio *self, PyObject *args)
597591
return PyLong_FromSsize_t(n);
598592
}
599593

600-
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
601-
602594
static size_t
603595
new_buffersize(fileio *self, size_t currentsize)
604596
{
@@ -702,18 +694,6 @@ fileio_readall(fileio *self)
702694
return result;
703695
}
704696

705-
#else
706-
707-
static PyObject *
708-
fileio_readall(fileio *self)
709-
{
710-
_Py_IDENTIFIER(readall);
711-
return _PyObject_CallMethodId((PyObject*)&PyRawIOBase_Type,
712-
&PyId_readall, "O", self);
713-
}
714-
715-
#endif /* HAVE_FSTAT || MS_WINDOWS */
716-
717697
static PyObject *
718698
fileio_read(fileio *self, PyObject *args)
719699
{

Modules/mmapmodule.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,9 +1112,7 @@ _GetMapSize(PyObject *o, const char* param)
11121112
static PyObject *
11131113
new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
11141114
{
1115-
#ifdef HAVE_FSTAT
11161115
struct _Py_stat_struct st;
1117-
#endif
11181116
mmap_object *m_obj;
11191117
PyObject *map_size_obj = NULL;
11201118
Py_ssize_t map_size;
@@ -1179,7 +1177,6 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
11791177
if (fd != -1)
11801178
(void)fcntl(fd, F_FULLFSYNC);
11811179
#endif
1182-
#ifdef HAVE_FSTAT
11831180
if (fd != -1 && _Py_fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
11841181
if (map_size == 0) {
11851182
if (st.st_size == 0) {
@@ -1204,7 +1201,6 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
12041201
return NULL;
12051202
}
12061203
}
1207-
#endif
12081204
m_obj = (mmap_object *)type->tp_alloc(type, 0);
12091205
if (m_obj == NULL) {return NULL;}
12101206
m_obj->data = NULL;

Python/fileutils.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,8 @@ Py_EncodeLocale(const wchar_t *text, size_t *error_pos)
519519
#endif /* __APPLE__ */
520520
}
521521

522-
/* In principle, this should use HAVE__WSTAT, and _wstat
523-
should be detected by autoconf. However, no current
524-
POSIX system provides that function, so testing for
525-
it is pointless.
526-
Not sure whether the MS_WINDOWS guards are necessary:
527-
perhaps for cygwin/mingw builds?
528-
*/
529-
#if defined(HAVE_STAT) && !defined(MS_WINDOWS)
530522

531523
/* Get file status. Encode the path to the locale encoding. */
532-
533524
int
534525
_Py_wstat(const wchar_t* path, struct stat *buf)
535526
{
@@ -544,11 +535,8 @@ _Py_wstat(const wchar_t* path, struct stat *buf)
544535
PyMem_Free(fname);
545536
return err;
546537
}
547-
#endif
548538

549539

550-
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
551-
552540
#ifdef MS_WINDOWS
553541
static __int64 secs_between_epochs = 11644473600; /* Seconds between 1.1.1601 and 1.1.1970 */
554542

@@ -679,10 +667,8 @@ _Py_fstat(int fd, struct _Py_stat_struct *result)
679667
return fstat(fd, result);
680668
#endif
681669
}
682-
#endif /* HAVE_FSTAT || MS_WINDOWS */
683670

684671

685-
#ifdef HAVE_STAT
686672
/* Call _wstat() on Windows, or encode the path to the filesystem encoding and
687673
call stat() otherwise. Only fill st_mode attribute on Windows.
688674
@@ -715,8 +701,6 @@ _Py_stat(PyObject *path, struct stat *statbuf)
715701
#endif
716702
}
717703

718-
#endif /* HAVE_STAT */
719-
720704

721705
static int
722706
get_inheritable(int fd, int raise)

Python/marshal.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,6 @@ PyMarshal_ReadLongFromFile(FILE *fp)
14811481
return res;
14821482
}
14831483

1484-
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
14851484
/* Return size of file in bytes; < 0 if unknown or INT_MAX if too big */
14861485
static off_t
14871486
getfilesize(FILE *fp)
@@ -1496,7 +1495,6 @@ getfilesize(FILE *fp)
14961495
else
14971496
return (off_t)st.st_size;
14981497
}
1499-
#endif
15001498

15011499
/* If we can get the size of the file up-front, and it's reasonably small,
15021500
* read it in one gulp and delegate to ...FromString() instead. Much quicker
@@ -1509,7 +1507,6 @@ PyMarshal_ReadLastObjectFromFile(FILE *fp)
15091507
{
15101508
/* REASONABLE_FILE_LIMIT is by defn something big enough for Tkinter.pyc. */
15111509
#define REASONABLE_FILE_LIMIT (1L << 18)
1512-
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
15131510
off_t filesize;
15141511
filesize = getfilesize(fp);
15151512
if (filesize > 0 && filesize <= REASONABLE_FILE_LIMIT) {
@@ -1522,7 +1519,6 @@ PyMarshal_ReadLastObjectFromFile(FILE *fp)
15221519
}
15231520

15241521
}
1525-
#endif
15261522
/* We don't have fstat, or we do but the file is larger than
15271523
* REASONABLE_FILE_LIMIT or malloc failed -- read a byte at a time.
15281524
*/

0 commit comments

Comments
 (0)