From 98bf58f1c61a1d6d8a21f75527c8ad7a7d47ef67 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 18 Oct 2001 20:34:25 +0000 Subject: SF patch #462296: Add attributes to os.stat results; by Nick Mathewson. This is a big one, touching lots of files. Some of the platforms aren't tested yet. Briefly, this changes the return value of the os/posix functions stat(), fstat(), statvfs(), fstatvfs(), and the time functions localtime(), gmtime(), and strptime() from tuples into pseudo-sequences. When accessed as a sequence, they behave exactly as before. But they also have attributes like st_mtime or tm_year. The stat return value, moreover, has a few platform-specific attributes that are not available through the sequence interface (because everybody expects the sequence to have a fixed length, these couldn't be added there). If your platform's struct stat doesn't define st_blksize, st_blocks or st_rdev, they won't be accessible from Python either. (Still missing is a documentation update.) --- Include/structseq.h | 39 ++++++ Lib/test/test_os.py | 121 +++++++++++++++- Mac/Modules/macmodule.c | 159 ++++++++++++++++----- Makefile.pre.in | 2 + Misc/NEWS | 12 +- Modules/posixmodule.c | 246 +++++++++++++++++++++++--------- Modules/timemodule.c | 59 ++++++-- RISCOS/Modules/riscosmodule.c | 88 +++++++++--- configure | 316 ++++++++++++++++++++++++++++-------------- configure.in | 3 + pyconfig.h.in | 9 ++ 11 files changed, 814 insertions(+), 240 deletions(-) create mode 100644 Include/structseq.h diff --git a/Include/structseq.h b/Include/structseq.h new file mode 100644 index 0000000..b08f04e --- /dev/null +++ b/Include/structseq.h @@ -0,0 +1,39 @@ + +/* Tuple object interface */ + +#ifndef Py_STRUCTSEQ_H +#define Py_STRUCTSEQ_H +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyStructSequence_Field { + char *name; + char *doc; +} PyStructSequence_Field; + +typedef struct PyStructSequence_Desc { + char *name; + char *doc; + struct PyStructSequence_Field *fields; + int n_in_sequence; +} PyStructSequence_Desc; + +extern DL_IMPORT(void) PyStructSequence_InitType(PyTypeObject *type, + PyStructSequence_Desc *desc); + +extern DL_IMPORT(PyObject *) PyStructSequence_New(PyTypeObject* type); + +typedef struct { + PyObject_VAR_HEAD + PyObject *ob_item[1]; +} PyStructSequence; + +/* Macro, *only* to be used to fill in brand new objects */ +#define PyStructSequence_SET_ITEM(op, i, v) \ + (((PyStructSequence *)(op))->ob_item[i] = v) + +#ifdef __cplusplus +} +#endif +#endif /* !Py_STRUCTSEQ_H */ diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 3f26f2f..bec3b90 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -11,7 +11,6 @@ warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning, __name__) from test_support import TESTFN, run_unittest - class TemporaryFileTests(unittest.TestCase): def setUp(self): self.files = [] @@ -61,10 +60,128 @@ class TemporaryFileTests(unittest.TestCase): "test_os") self.check_tempfile(os.tmpnam()) +# Test attributes on return values from os.*stat* family. +class StatAttributeTests(unittest.TestCase): + def setUp(self): + os.mkdir(TESTFN) + self.fname = os.path.join(TESTFN, "f1") + f = open(self.fname, 'wb') + f.write("ABC") + f.close() + + def tearDown(self): + os.unlink(self.fname) + os.rmdir(TESTFN) + + def test_stat_attributes(self): + if not hasattr(os, "stat"): + return + + import stat + result = os.stat(self.fname) + + # Make sure direct access works + self.assertEquals(result[stat.ST_SIZE], 3) + self.assertEquals(result.st_size, 3) + + import sys + + # Make sure all the attributes are there + members = dir(result) + for name in dir(stat): + if name[:3] == 'ST_': + attr = name.lower() + self.assertEquals(getattr(result, attr), + result[getattr(stat, name)]) + self.assert_(attr in members) + + try: + result[200] + self.fail("No exception thrown") + except IndexError: + pass + + # Make sure that assignment fails + try: + result.st_mode = 1 + self.fail("No exception thrown") + except TypeError: + pass + + try: + result.st_rdev = 1 + self.fail("No exception thrown") + except TypeError: + pass + + try: + result.parrot = 1 + self.fail("No exception thrown") + except AttributeError: + pass + + # Use the stat_result constructor with a too-short tuple. + try: + result2 = os.stat_result((10,)) + self.fail("No exception thrown") + except TypeError: + pass + + # Use the constructr with a too-long tuple. + try: + result2 = os.stat_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)) + except TypeError: + pass + + + def test_statvfs_attributes(self): + if not hasattr(os, "statvfs"): + return + + import statvfs + result = os.statvfs(self.fname) + + # Make sure direct access works + self.assertEquals(result.f_bfree, result[statvfs.F_BFREE]) + + # Make sure all the attributes are there + members = dir(result) + for name in dir(statvfs): + if name[:2] == 'F_': + attr = name.lower() + self.assertEquals(getattr(result, attr), + result[getattr(statvfs, name)]) + self.assert_(attr in members) + + # Make sure that assignment really fails + try: + result.f_bfree = 1 + self.fail("No exception thrown") + except TypeError: + pass + + try: + result.parrot = 1 + self.fail("No exception thrown") + except AttributeError: + pass + + # Use the constructor with a too-short tuple. + try: + result2 = os.statvfs_result((10,)) + self.fail("No exception thrown") + except TypeError: + pass + + # Use the constructr with a too-long tuple. + try: + result2 = os.statvfs_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)) + except TypeError: + pass def test_main(): run_unittest(TemporaryFileTests) - + run_unittest(StatAttributeTests) if __name__ == "__main__": test_main() diff --git a/Mac/Modules/macmodule.c b/Mac/Modules/macmodule.c index 766722f..3606b93 100644 --- a/Mac/Modules/macmodule.c +++ b/Mac/Modules/macmodule.c @@ -25,6 +25,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* Mac module implementation */ #include "Python.h" +#include "structseq.h" #include "ceval.h" #include @@ -460,11 +461,119 @@ mac_rmdir(self, args) return mac_1str(args, rmdir); } +static char stat_result__doc__[] = +"stat_result: Result from stat or lstat.\n\n\ +This object may be accessed either as a tuple of\n\ + (mode,ino,dev,nlink,uid,gid,size,atime,mtime,ctime)\n\ +or via the attributes st_mode, st_ino, st_dev, st_nlink, st_uid, and so on.\n\ +\n\ +Macintosh: The fields st_rsize, st_creator, and st_type are available from\n\ +os.xstat.\n\ +\n\ +See os.stat for more information.\n"; + +#define COMMON_STAT_RESULT_FIELDS \ + { "st_mode", "protection bits" }, \ + { "st_ino", "inode" }, \ + { "st_dev", "device" }, \ + { "st_nlink", "number of hard links" }, \ + { "st_uid", "user ID of owner" }, \ + { "st_gid", "group ID of owner" }, \ + { "st_size", "total size, in bytes" }, \ + { "st_atime", "time of last access" }, \ + { "st_mtime", "time of last modification" }, \ + { "st_ctime", "time of last change" }, + + + +static PyStructSequence_Field stat_result_fields[] = { + COMMON_STAT_RESULT_FIELDS + {0} +}; + +static PyStructSequence_Desc stat_result_desc = { + "stat_result", + stat_result__doc__, + stat_result_fields, + 10 +}; + +static PyTypeObject StatResultType; + +#ifdef TARGET_API_MAC_OS8 +static PyStructSequence_Field xstat_result_fields[] = { + COMMON_XSTAT_RESULT_FIELDS + { "st_rsize" }, + { "st_creator" }, + { "st_type "}, + {0} +}; + +static PyStructSequence_Desc xstat_result_desc = { + "xstat_result", + stat_result__doc__, + xstat_result_fields, + 13 +}; + +static PyTypeObject XStatResultType; +#endif + +static PyObject * +_pystat_from_struct_stat(struct stat st, void* _mst) +{ + PyObject *v; + +#if TARGET_API_MAC_OS8 + struct macstat *mst; + + if (_mst != NULL) + v = PyStructSequence_New(&XStatResultType); + else +#endif + v = PyStructSequence_New(&StatResultType); + PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long)st.st_mode)); + PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long)st.st_ino)); + PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long)st.st_dev)); + PyStructSequence_SET_ITEM(v, 3, PyInt_FromLong((long)st.st_nlink)); + PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long)st.st_uid)); + PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long)st.st_gid)); + PyStructSequence_SET_ITEM(v, 6, PyInt_FromLong((long)st.st_size)); + PyStructSequence_SET_ITEM(v, 7, + PyFloat_FromDouble((double)st.st_atime)); + PyStructSequence_SET_ITEM(v, 8, + PyFloat_FromDouble((double)st.st_mtime)); + PyStructSequence_SET_ITEM(v, 9, + PyFloat_FromDouble((double)st.st_ctime)); +#if TARGET_API_MAC_OS8 + if (_mst != NULL) { + mst = (struct macstat *) _mst; + PyStructSequence_SET_ITEM(v, 10, + PyInt_FromLong((long)mst->st_rsize)); + PyStructSequence_SET_ITEM(v, 11, + PyString_FromStringAndSize(mst->st_creator, + 4)); + PyStructSequence_SET_ITEM(v, 12, + PyString_FromStringAndSize(mst->st_type, + 4)); + } +#endif + + if (PyErr_Occurred()) { + Py_DECREF(v); + return NULL; + } + + return v; +} + + static PyObject * mac_stat(self, args) PyObject *self; PyObject *args; { + PyObject *v; struct stat st; char *path; int res; @@ -475,17 +584,8 @@ mac_stat(self, args) Py_END_ALLOW_THREADS if (res != 0) return mac_error(); - return Py_BuildValue("(lllllllddd)", - (long)st.st_mode, - (long)st.st_ino, - (long)st.st_dev, - (long)st.st_nlink, - (long)st.st_uid, - (long)st.st_gid, - (long)st.st_size, - (double)st.st_atime, - (double)st.st_mtime, - (double)st.st_ctime); + + return _pystat_from_struct_stat(st, NULL); } #ifdef WEHAVE_FSTAT @@ -504,17 +604,8 @@ mac_fstat(self, args) Py_END_ALLOW_THREADS if (res != 0) return mac_error(); - return Py_BuildValue("(lllllllddd)", - (long)st.st_mode, - (long)st.st_ino, - (long)st.st_dev, - (long)st.st_nlink, - (long)st.st_uid, - (long)st.st_gid, - (long)st.st_size, - (double)st.st_atime, - (double)st.st_mtime, - (double)st.st_ctime); + + return _pystat_from_struct_stat(st, NULL); } #endif /* WEHAVE_FSTAT */ @@ -545,20 +636,8 @@ mac_xstat(self, args) Py_END_ALLOW_THREADS if (res != 0) return mac_error(); - return Py_BuildValue("(llllllldddls#s#)", - (long)st.st_mode, - (long)st.st_ino, - (long)st.st_dev, - (long)st.st_nlink, - (long)st.st_uid, - (long)st.st_gid, - (long)st.st_size, - (double)st.st_atime, - (double)st.st_mtime, - (double)st.st_ctime, - (long)mst.st_rsize, - mst.st_creator, 4, - mst.st_type, 4); + + return _pystat_from_struct_stat(st, (void*) &mst); } #endif @@ -766,4 +845,12 @@ initmac() /* Initialize mac.error exception */ MacError = PyErr_NewException("mac.error", NULL, NULL); PyDict_SetItemString(d, "error", MacError); + + PyStructSequence_InitType(&StatResultType, &stat_result_desc); + PyDict_SetItemString(d, "stat_result", (PyObject*) &StatResultType); + +#if TARGET_API_MAC_OS8 + PyStructSequence_InitType(&XStatResultType, &xstat_result_desc); + PyDict_SetItemString(d, "xstat_result", (PyObject*) &XStatResultType); +#endif } diff --git a/Makefile.pre.in b/Makefile.pre.in index b9bbeb5..5cb7b31 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -263,6 +263,7 @@ OBJECT_OBJS= \ Objects/rangeobject.o \ Objects/sliceobject.o \ Objects/stringobject.o \ + Objects/structseq.o \ Objects/tupleobject.o \ Objects/typeobject.o \ Objects/weakrefobject.o \ @@ -465,6 +466,7 @@ PYTHON_HEADERS= \ Include/rangeobject.h \ Include/sliceobject.h \ Include/stringobject.h \ + Include/structseq.h \ Include/structmember.h \ Include/symtable.h \ Include/sysmodule.h \ diff --git a/Misc/NEWS b/Misc/NEWS index 6d6c659..257546d 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -48,7 +48,17 @@ Extension modules - readline now supports setting the startup_hook and the pre_event_hook. -- posix supports chroot and setgroups where available. +- os and posix supports chroot() and setgroups() where available. The + stat(), fstat(), statvfs() and fstatvfs() functions now return + "pseudo-sequences" -- the various fields can now be accessed as + attributes (e.g. os.stat("/").st_mtime) but for backwards + compatibility they also behave as a fixed-length sequence. Some + platform-specific fields (e.g. st_rdev) are only accessible as + attributes. + +- time: localtime(), gmtime() and strptime() now return a + pseudo-sequence similar to the os.stat() return value, with + attributes like tm_year etc. - Decompression objects in the zlib module now accept an optional second parameter to decompress() that specifies the maximum amount diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 346de54..f0c93aa 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -17,6 +17,7 @@ disguised Unix interface). Refer to the library manual and\n\ corresponding Unix manual entries for more information on calls."; #include "Python.h" +#include "structseq.h" #if defined(PYOS_OS2) #define INCL_DOS @@ -516,42 +517,152 @@ posix_2str(PyObject *args, char *format, return Py_None; } +static char stat_result__doc__[] = +"stat_result: Result from stat or lstat.\n\n\ +This object may be accessed either as a tuple of\n\ + (mode,ino,dev,nlink,uid,gid,size,atime,mtime,ctime)\n\ +or via the attributes st_mode, st_ino, st_dev, st_nlink, st_uid, and so on.\n\ +\n\ +Posix/windows: If your platform supports st_blksize, st_blocks, or st_rdev, +they are available as attributes only.\n\ +\n\ +See os.stat for more information.\n"; + +static PyStructSequence_Field stat_result_fields[] = { + {"st_mode", "protection bits"}, + {"st_ino", "inode"}, + {"st_dev", "device"}, + {"st_nlink", "number of hard links"}, + {"st_uid", "user ID of owner"}, + {"st_gid", "group ID of owner"}, + {"st_size", "total size, in bytes"}, + {"st_atime", "time of last access"}, + {"st_mtime", "time of last modification"}, + {"st_ctime", "time of last change"}, +#ifdef HAVE_ST_BLKSIZE + {"st_blksize", "blocksize for filesystem I/O"}, +#endif +#ifdef HAVE_ST_BLOCKS + {"st_blocks", "number of blocks allocated"}, +#endif +#ifdef HAVE_ST_RDEV + {"st_rdev", "device type (if inode device)"}, +#endif + {0} +}; + +#ifdef HAVE_ST_BLKSIZE +#define ST_BLKSIZE_IDX 10 +#else +#define ST_BLKSIZE_IDX 9 +#endif + +#ifdef HAVE_ST_BLOCKS +#define ST_BLOCKS_IDX (ST_BLKSIZE_IDX+1) +#else +#define ST_BLOCKS_IDX ST_BLKSIZE_IDX +#endif + +#ifdef HAVE_ST_RDEV +#define ST_RDEV_IDX (ST_BLOCKS_IDX+1) +#else +#define ST_RDEV_IDX ST_BLOCKS_IDX +#endif + +static PyStructSequence_Desc stat_result_desc = { + "stat_result", /* name */ + stat_result__doc__, /* doc */ + stat_result_fields, + 10 +}; + +static char statvfs_result__doc__[] = +"statvfs_result: Result from statvfs or fstatvfs.\n\n\ +This object may be accessed either as a tuple of\n\ + (bsize,frsize,blocks,bfree,bavail,files,ffree,favail,flag,namemax), +or via the attributes f_bsize, f_frsize, f_blocks, f_bfree, and so on. +\n\ +See os.statvfs for more information.\n"; + +static PyStructSequence_Field statvfs_result_fields[] = { + {"f_bsize", }, + {"f_frsize", }, + {"f_blocks", }, + {"f_bfree", }, + {"f_bavail", }, + {"f_files", }, + {"f_ffree", }, + {"f_favail", }, + {"f_flag", }, + {"f_namemax",}, + {0} +}; + +static PyStructSequence_Desc statvfs_result_desc = { + "statvfs_result", /* name */ + statvfs_result__doc__, /* doc */ + statvfs_result_fields, + 10 +}; + +static PyTypeObject StatResultType; +static PyTypeObject StatVFSResultType; + /* pack a system stat C structure into the Python stat tuple (used by posix_stat() and posix_fstat()) */ static PyObject* _pystat_fromstructstat(STRUCT_STAT st) { - PyObject *v = PyTuple_New(10); + PyObject *v = PyStructSequence_New(&StatResultType); if (v == NULL) return NULL; - PyTuple_SetItem(v, 0, PyInt_FromLong((long)st.st_mode)); + PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long)st.st_mode)); #ifdef HAVE_LARGEFILE_SUPPORT - PyTuple_SetItem(v, 1, PyLong_FromLongLong((LONG_LONG)st.st_ino)); + PyStructSequence_SET_ITEM(v, 1, + PyLong_FromLongLong((LONG_LONG)st.st_ino)); #else - PyTuple_SetItem(v, 1, PyInt_FromLong((long)st.st_ino)); + PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long)st.st_ino)); #endif #if defined(HAVE_LONG_LONG) && !defined(MS_WINDOWS) - PyTuple_SetItem(v, 2, PyLong_FromLongLong((LONG_LONG)st.st_dev)); + PyStructSequence_SET_ITEM(v, 2, + PyLong_FromLongLong((LONG_LONG)st.st_dev)); #else - PyTuple_SetItem(v, 2, PyInt_FromLong((long)st.st_dev)); + PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long)st.st_dev)); #endif - PyTuple_SetItem(v, 3, PyInt_FromLong((long)st.st_nlink)); - PyTuple_SetItem(v, 4, PyInt_FromLong((long)st.st_uid)); - PyTuple_SetItem(v, 5, PyInt_FromLong((long)st.st_gid)); + PyStructSequence_SET_ITEM(v, 3, PyInt_FromLong((long)st.st_nlink)); + PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long)st.st_uid)); + PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long)st.st_gid)); #ifdef HAVE_LARGEFILE_SUPPORT - PyTuple_SetItem(v, 6, PyLong_FromLongLong((LONG_LONG)st.st_size)); + PyStructSequence_SET_ITEM(v, 6, + PyLong_FromLongLong((LONG_LONG)st.st_size)); #else - PyTuple_SetItem(v, 6, PyInt_FromLong(st.st_size)); + PyStructSequence_SET_ITEM(v, 6, PyInt_FromLong(st.st_size)); #endif #if SIZEOF_TIME_T > SIZEOF_LONG - PyTuple_SetItem(v, 7, PyLong_FromLongLong((LONG_LONG)st.st_atime)); - PyTuple_SetItem(v, 8, PyLong_FromLongLong((LONG_LONG)st.st_mtime)); - PyTuple_SetItem(v, 9, PyLong_FromLongLong((LONG_LONG)st.st_ctime)); + PyStructSequence_SET_ITEM(v, 7, + PyLong_FromLongLong((LONG_LONG)st.st_atime)); + PyStructSequence_SET_ITEM(v, 8, + PyLong_FromLongLong((LONG_LONG)st.st_mtime)); + PyStructSequence_SET_ITEM(v, 9, + PyLong_FromLongLong((LONG_LONG)st.st_ctime)); #else - PyTuple_SetItem(v, 7, PyInt_FromLong((long)st.st_atime)); - PyTuple_SetItem(v, 8, PyInt_FromLong((long)st.st_mtime)); - PyTuple_SetItem(v, 9, PyInt_FromLong((long)st.st_ctime)); + PyStructSequence_SET_ITEM(v, 7, PyInt_FromLong((long)st.st_atime)); + PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long)st.st_mtime)); + PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long)st.st_ctime)); +#endif + +#ifdef HAVE_ST_BLKSIZE + PyStructSequence_SET_ITEM(v, ST_BLKSIZE_IDX, + PyInt_FromLong((long)st.st_blksize)); +#endif +#ifdef HAVE_ST_BLOCKS + PyStructSequence_SET_ITEM(v, ST_BLOCKS_IDX, + PyInt_FromLong((long)st.st_blocks)); +#endif +#ifdef HAVE_ST_RDEV + PyStructSequence_SET_ITEM(v, ST_RDEV_IDX, + PyInt_FromLong((long)st.st_rdev)); #endif if (PyErr_Occurred()) { @@ -562,7 +673,6 @@ _pystat_fromstructstat(STRUCT_STAT st) return v; } - static PyObject * posix_do_stat(PyObject *self, PyObject *args, char *format, int (*statfunc)(const char *, STRUCT_STAT *)) @@ -4173,6 +4283,45 @@ posix_WSTOPSIG(PyObject *self, PyObject *args) #endif #include +static PyObject* +_pystatvfs_fromstructstatvfs(struct statvfs st) { + PyObject *v = PyStructSequence_New(&StatVFSResultType); + if (v == NULL) + return NULL; + +#if !defined(HAVE_LARGEFILE_SUPPORT) + PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long) st.f_bsize)); + PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long) st.f_frsize)); + PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long) st.f_blocks)); + PyStructSequence_SET_ITEM(v, 3, PyInt_FromLong((long) st.f_bfree)); + PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long) st.f_bavail)); + PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long) st.f_files)); + PyStructSequence_SET_ITEM(v, 6, PyInt_FromLong((long) st.f_ffree)); + PyStructSequence_SET_ITEM(v, 7, PyInt_FromLong((long) st.f_favail)); + PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long) st.f_flag)); + PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long) st.f_namemax)); +#else + PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long) st.f_bsize)); + PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long) st.f_frsize)); + PyStructSequence_SET_ITEM(v, 2, + PyLong_FromLongLong((LONG_LONG) st.f_blocks)); + PyStructSequence_SET_ITEM(v, 3, + PyLong_FromLongLong((LONG_LONG) st.f_bfree)); + PyStructSequence_SET_ITEM(v, 4, + PyLong_FromLongLong((LONG_LONG) st.f_bavail)); + PyStructSequence_SET_ITEM(v, 5, + PyLong_FromLongLong((LONG_LONG) st.f_files)); + PyStructSequence_SET_ITEM(v, 6, + PyLong_FromLongLong((LONG_LONG) st.f_ffree)); + PyStructSequence_SET_ITEM(v, 7, + PyLong_FromLongLong((LONG_LONG) st.f_favail)); + PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long) st.f_flag)); + PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long) st.f_namemax)); +#endif + + return v; +} + static char posix_fstatvfs__doc__[] = "fstatvfs(fd) -> \n\ (bsize, frsize, blocks, bfree, bavail, files, ffree, favail, flag, namemax)\n\ @@ -4183,6 +4332,7 @@ posix_fstatvfs(PyObject *self, PyObject *args) { int fd, res; struct statvfs st; + if (!PyArg_ParseTuple(args, "i:fstatvfs", &fd)) return NULL; Py_BEGIN_ALLOW_THREADS @@ -4190,31 +4340,8 @@ posix_fstatvfs(PyObject *self, PyObject *args) Py_END_ALLOW_THREADS if (res != 0) return posix_error(); -#if !defined(HAVE_LARGEFILE_SUPPORT) - return Py_BuildValue("(llllllllll)", - (long) st.f_bsize, - (long) st.f_frsize, - (long) st.f_blocks, - (long) st.f_bfree, - (long) st.f_bavail, - (long) st.f_files, - (long) st.f_ffree, - (long) st.f_favail, - (long) st.f_flag, - (long) st.f_namemax); -#else - return Py_BuildValue("(llLLLLLLll)", - (long) st.f_bsize, - (long) st.f_frsize, - (LONG_LONG) st.f_blocks, - (LONG_LONG) st.f_bfree, - (LONG_LONG) st.f_bavail, - (LONG_LONG) st.f_files, - (LONG_LONG) st.f_ffree, - (LONG_LONG) st.f_favail, - (long) st.f_flag, - (long) st.f_namemax); -#endif + + return _pystatvfs_fromstructstatvfs(st); } #endif /* HAVE_FSTATVFS */ @@ -4240,31 +4367,8 @@ posix_statvfs(PyObject *self, PyObject *args) Py_END_ALLOW_THREADS if (res != 0) return posix_error_with_filename(path); -#if !defined(HAVE_LARGEFILE_SUPPORT) - return Py_BuildValue("(llllllllll)", - (long) st.f_bsize, - (long) st.f_frsize, - (long) st.f_blocks, - (long) st.f_bfree, - (long) st.f_bavail, - (long) st.f_files, - (long) st.f_ffree, - (long) st.f_favail, - (long) st.f_flag, - (long) st.f_namemax); -#else /* HAVE_LARGEFILE_SUPPORT */ - return Py_BuildValue("(llLLLLLLll)", - (long) st.f_bsize, - (long) st.f_frsize, - (LONG_LONG) st.f_blocks, - (LONG_LONG) st.f_bfree, - (LONG_LONG) st.f_bavail, - (LONG_LONG) st.f_files, - (LONG_LONG) st.f_ffree, - (LONG_LONG) st.f_favail, - (long) st.f_flag, - (long) st.f_namemax); -#endif + + return _pystatvfs_fromstructstatvfs(st); } #endif /* HAVE_STATVFS */ @@ -5825,4 +5929,10 @@ INITFUNC(void) if (posix_putenv_garbage == NULL) posix_putenv_garbage = PyDict_New(); #endif + + PyStructSequence_InitType(&StatResultType, &stat_result_desc); + PyDict_SetItemString(d, "stat_result", (PyObject*) &StatResultType); + + PyStructSequence_InitType(&StatVFSResultType, &statvfs_result_desc); + PyDict_SetItemString(d, "statvfs_result", (PyObject*) &StatResultType); } diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 2834738..bb7f358 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -2,6 +2,7 @@ /* Time module */ #include "Python.h" +#include "structseq.h" #include @@ -210,19 +211,53 @@ static char sleep_doc[] = Delay execution for a given number of seconds. The argument may be\n\ a floating point number for subsecond precision."; +static PyStructSequence_Field struct_time_type_fields[] = { + {"tm_year", NULL}, + {"tm_mon", NULL}, + {"tm_mday", NULL}, + {"tm_hour", NULL}, + {"tm_min", NULL}, + {"tm_sec", NULL}, + {"tm_wday", NULL}, + {"tm_yday", NULL}, + {"tm_isdst", NULL}, + {0} +}; + +static PyStructSequence_Desc struct_time_type_desc = { + "struct_time", + NULL, + struct_time_type_fields, + 9, +}; + +static PyTypeObject StructTimeType; + static PyObject * tmtotuple(struct tm *p) { - return Py_BuildValue("(iiiiiiiii)", - p->tm_year + 1900, - p->tm_mon + 1, /* Want January == 1 */ - p->tm_mday, - p->tm_hour, - p->tm_min, - p->tm_sec, - (p->tm_wday + 6) % 7, /* Want Monday == 0 */ - p->tm_yday + 1, /* Want January, 1 == 1 */ - p->tm_isdst); + PyObject *v = PyStructSequence_New(&StructTimeType); + if (v == NULL) + return NULL; + +#define SET(i,val) PyStructSequence_SET_ITEM(v, i, PyInt_FromLong((long) val)) + + SET(0, p->tm_year + 1900); + SET(1, p->tm_mon + 1); /* Want January == 1 */ + SET(2, p->tm_mday); + SET(3, p->tm_hour); + SET(4, p->tm_min); + SET(5, p->tm_sec); + SET(6, (p->tm_wday + 6) % 7); /* Want Monday == 0 */ + SET(7, p->tm_yday + 1); /* Want January, 1 == 1 */ + SET(8, p->tm_isdst); +#undef SET + if (PyErr_Occurred()) { + Py_XDECREF(v); + return NULL; + } + + return v; } static PyObject * @@ -674,6 +709,9 @@ inittime(void) ins(d, "tzname", Py_BuildValue("(zz)", _tzname[0], _tzname[1])); #endif /* __CYGWIN__ */ #endif /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/ + + PyStructSequence_InitType(&StructTimeType, &struct_time_type_desc); + PyDict_SetItemString(d, "struct_time", (PyObject*) &StructTimeType); } @@ -852,5 +890,6 @@ floatsleep(double secs) #endif /* !__WATCOMC__ || __QNX__ */ #endif /* !macintosh */ #endif /* !HAVE_SELECT */ + return 0; } diff --git a/RISCOS/Modules/riscosmodule.c b/RISCOS/Modules/riscosmodule.c index d378eba..d5cdd94 100644 --- a/RISCOS/Modules/riscosmodule.c +++ b/RISCOS/Modules/riscosmodule.c @@ -113,8 +113,46 @@ static PyObject *riscos_listdir(PyObject *self,PyObject *args) return d; } +static char stat_result__doc__[] = +"stat_result: Result from stat or lstat.\n\n\ +This object may be accessed either as a tuple of\n\ + (mode,ino,dev,nlink,uid,gid,size,atime,mtime,ctime)\n\ +or via the attributes st_mode, st_ino, st_dev, st_nlink, st_uid, and so on.\n\ +\n\ +RiscOS: The fields st_ftype, st_attrs, and st_obtype are also available.\n\ +\n\ +See os.stat for more information.\n"; + +static PyStructSequence_Field stat_result_fields[] = { + { "st_mode", "protection bits" }, + { "st_ino", "inode" }, + { "st_dev", "device" }, + { "st_nlink", "number of hard links" }, + { "st_uid", "user ID of owner" }, + { "st_gid", "group ID of owner" }, + { "st_size", "total size, in bytes" }, + { "st_atime", "time of last access" }, + { "st_mtime", "time of last modification" }, + { "st_ctime", "time of last change" }, + { "st_ftype", "file type" }, + { "st_attrs", "attributes" }, + { "st_obtype", "object type" } + { 0 } +}; + +static PyStructSequence_Desc stat_result_desc = { + "stat_result", + stat_result__doc__, + stat_result_fields, + 13 +}; + +static PyTypeObject StatResultType; + static PyObject *riscos_stat(PyObject *self,PyObject *args) -{ char *path; +{ + PyObject *v; + char *path; int ob,len; bits t=0; bits ld,ex,at,ft,mode; @@ -130,21 +168,34 @@ static PyObject *riscos_stat(PyObject *self,PyObject *args) if(ft!=-1) t=unixtime(ld,ex); mode|=(at&7)<<6; mode|=((at&112)*9)>>4; - return Py_BuildValue("(lllllllllllll)", - (long)mode,/*st_mode*/ - 0,/*st_ino*/ - 0,/*st_dev*/ - 0,/*st_nlink*/ - 0,/*st_uid*/ - 0,/*st_gid*/ - (long)len,/*st_size*/ - (long)t,/*st_atime*/ - (long)t,/*st_mtime*/ - (long)t,/*st_ctime*/ - (long)ft,/*file type*/ - (long)at,/*attributes*/ - (long)ob/*object type*/ - ); + + v = PyStructSequence_New(&StatResultType); + + PyStructSequence_SET_ITEM(v, 0, + PyInt_FromLong((long) mode)); /*st_mode*/ + PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long) 0)); /*st_ino*/ + PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long) 0)); /*st_dev*/ + PyStructSequence_SET_ITEM(v, 3, PyInt_FromLong((long) 0)); /*st_nlink*/ + PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long) 0)); /*st_uid*/ + PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long) 0)); /*st_gid*/ + PyStructSequence_SET_ITEM(v, 6, + PyInt_FromLong((long) len)); /*st_size*/ + PyStructSequence_SET_ITEM(v, 7, PyInt_FromLong((long) t)); /*st_atime*/ + PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long) t)); /*st_mtime*/ + PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long) t)); /*st_ctime*/ + PyStructSequence_SET_ITEM(v, 10, + PyInt_FromLong((long) ft)); /*file type*/ + PyStructSequence_SET_ITEM(v, 11, + PyInt_FromLong((long) at)); /*attributes*/ + PyStructSequence_SET_ITEM(v, 12, + PyInt_FromLong((long) ot)); /*object type*/ + + if (PyErr_Occurred()) { + Py_DECREF(v); + return NULL; + } + + return v; } static PyObject *riscos_chmod(PyObject *self,PyObject *args) @@ -271,7 +322,7 @@ static PyMethodDef riscos_methods[] = { void initriscos() { - PyObject *m, *d; + PyObject *m, *d, *stat_m; m = Py_InitModule("riscos", riscos_methods); d = PyModule_GetDict(m); @@ -280,4 +331,7 @@ initriscos() RiscosError = PyString_FromString("riscos.error"); if (RiscosError == NULL || PyDict_SetItemString(d, "error", RiscosError) != 0) Py_FatalError("can't define riscos.error"); + + PyStructSequence_InitType(&StatResultType, &stat_result_desc); + PyDict_SetItemString(d, "stat_result", (PyObject*) &StatResultType); } diff --git a/configure b/configure index 3ad3727..d85057d 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh -# From configure.in Revision: 1.272 +# From configure.in Revision: 1.273 # Guess values for system-dependent variables and create Makefiles. # Generated automatically using autoconf version 2.13 @@ -5783,21 +5783,125 @@ EOF fi fi +echo $ac_n "checking for st_rdev in struct stat""... $ac_c" 1>&6 +echo "configure:5788: checking for st_rdev in struct stat" >&5 +if eval "test \"`echo '$''{'ac_cv_struct_st_rdev'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext < +#include +int main() { +struct stat s; s.st_rdev; +; return 0; } +EOF +if { (eval echo configure:5801: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_struct_st_rdev=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_struct_st_rdev=no +fi +rm -f conftest* +fi + +echo "$ac_t""$ac_cv_struct_st_rdev" 1>&6 +if test $ac_cv_struct_st_rdev = yes; then + cat >> confdefs.h <<\EOF +#define HAVE_ST_RDEV 1 +EOF + +fi + +echo $ac_n "checking for st_blksize in struct stat""... $ac_c" 1>&6 +echo "configure:5822: checking for st_blksize in struct stat" >&5 +if eval "test \"`echo '$''{'ac_cv_struct_st_blksize'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext < +#include +int main() { +struct stat s; s.st_blksize; +; return 0; } +EOF +if { (eval echo configure:5835: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_struct_st_blksize=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_struct_st_blksize=no +fi +rm -f conftest* +fi + +echo "$ac_t""$ac_cv_struct_st_blksize" 1>&6 +if test $ac_cv_struct_st_blksize = yes; then + cat >> confdefs.h <<\EOF +#define HAVE_ST_BLKSIZE 1 +EOF + +fi + +echo $ac_n "checking for st_blocks in struct stat""... $ac_c" 1>&6 +echo "configure:5856: checking for st_blocks in struct stat" >&5 +if eval "test \"`echo '$''{'ac_cv_struct_st_blocks'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext < +#include +int main() { +struct stat s; s.st_blocks; +; return 0; } +EOF +if { (eval echo configure:5869: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_struct_st_blocks=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_struct_st_blocks=no +fi +rm -f conftest* +fi + +echo "$ac_t""$ac_cv_struct_st_blocks" 1>&6 +if test $ac_cv_struct_st_blocks = yes; then + cat >> confdefs.h <<\EOF +#define HAVE_ST_BLOCKS 1 +EOF + +else + LIBOBJS="$LIBOBJS fileblocks.${ac_objext}" +fi + echo $ac_n "checking for time.h that defines altzone""... $ac_c" 1>&6 -echo "configure:5789: checking for time.h that defines altzone" >&5 +echo "configure:5893: checking for time.h that defines altzone" >&5 if eval "test \"`echo '$''{'ac_cv_header_time_altzone'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < int main() { return altzone; ; return 0; } EOF -if { (eval echo configure:5801: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:5905: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_header_time_altzone=yes else @@ -5819,9 +5923,9 @@ fi was_it_defined=no echo $ac_n "checking whether sys/select.h and sys/time.h may both be included""... $ac_c" 1>&6 -echo "configure:5823: checking whether sys/select.h and sys/time.h may both be included" >&5 +echo "configure:5927: checking whether sys/select.h and sys/time.h may both be included" >&5 cat > conftest.$ac_ext < @@ -5832,7 +5936,7 @@ int main() { ; ; return 0; } EOF -if { (eval echo configure:5836: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:5940: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* cat >> confdefs.h <<\EOF #define SYS_SELECT_WITH_SYS_TIME 1 @@ -5846,12 +5950,12 @@ rm -f conftest* echo "$ac_t""$was_it_defined" 1>&6 echo $ac_n "checking for addrinfo""... $ac_c" 1>&6 -echo "configure:5850: checking for addrinfo" >&5 +echo "configure:5954: checking for addrinfo" >&5 if eval "test \"`echo '$''{'ac_cv_struct_addrinfo'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < @@ -5859,7 +5963,7 @@ int main() { struct addrinfo a ; return 0; } EOF -if { (eval echo configure:5863: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:5967: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_struct_addrinfo=yes else @@ -5880,12 +5984,12 @@ EOF fi echo $ac_n "checking for sockaddr_storage""... $ac_c" 1>&6 -echo "configure:5884: checking for sockaddr_storage" >&5 +echo "configure:5988: checking for sockaddr_storage" >&5 if eval "test \"`echo '$''{'ac_cv_struct_sockaddr_storage'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < @@ -5894,7 +5998,7 @@ int main() { struct sockaddr_storage s ; return 0; } EOF -if { (eval echo configure:5898: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6002: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_struct_sockaddr_storage=yes else @@ -5917,14 +6021,14 @@ fi # checks for compiler characteristics echo $ac_n "checking whether char is unsigned""... $ac_c" 1>&6 -echo "configure:5921: checking whether char is unsigned" >&5 +echo "configure:6025: checking whether char is unsigned" >&5 if eval "test \"`echo '$''{'ac_cv_c_char_unsigned'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test "$GCC" = yes; then # GCC predefines this symbol on systems where it applies. cat > conftest.$ac_ext <&2; exit 1; } else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:6064: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_c_char_unsigned=yes else @@ -5980,12 +6084,12 @@ EOF fi echo $ac_n "checking for working const""... $ac_c" 1>&6 -echo "configure:5984: checking for working const" >&5 +echo "configure:6088: checking for working const" >&5 if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6142: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_const=yes else @@ -6057,16 +6161,16 @@ fi works=no echo $ac_n "checking for working volatile""... $ac_c" 1>&6 -echo "configure:6061: checking for working volatile" >&5 +echo "configure:6165: checking for working volatile" >&5 cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6174: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* works=yes else @@ -6083,16 +6187,16 @@ echo "$ac_t""$works" 1>&6 works=no echo $ac_n "checking for working signed char""... $ac_c" 1>&6 -echo "configure:6087: checking for working signed char" >&5 +echo "configure:6191: checking for working signed char" >&5 cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6200: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* works=yes else @@ -6109,16 +6213,16 @@ echo "$ac_t""$works" 1>&6 have_prototypes=no echo $ac_n "checking for prototypes""... $ac_c" 1>&6 -echo "configure:6113: checking for prototypes" >&5 +echo "configure:6217: checking for prototypes" >&5 cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6226: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* cat >> confdefs.h <<\EOF #define HAVE_PROTOTYPES 1 @@ -6133,9 +6237,9 @@ echo "$ac_t""$have_prototypes" 1>&6 works=no echo $ac_n "checking for variable length prototypes and stdarg.h""... $ac_c" 1>&6 -echo "configure:6137: checking for variable length prototypes and stdarg.h" >&5 +echo "configure:6241: checking for variable length prototypes and stdarg.h" >&5 cat > conftest.$ac_ext < @@ -6152,7 +6256,7 @@ int main() { return foo(10, "", 3.14); ; return 0; } EOF -if { (eval echo configure:6156: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6260: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* cat >> confdefs.h <<\EOF #define HAVE_STDARG_PROTOTYPES 1 @@ -6168,16 +6272,16 @@ echo "$ac_t""$works" 1>&6 if test "$have_prototypes" = yes; then bad_prototypes=no echo $ac_n "checking for bad exec* prototypes""... $ac_c" 1>&6 -echo "configure:6172: checking for bad exec* prototypes" >&5 +echo "configure:6276: checking for bad exec* prototypes" >&5 cat > conftest.$ac_ext < int main() { char **t;execve("@",t,t); ; return 0; } EOF -if { (eval echo configure:6181: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6285: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then : else echo "configure: failed program was:" >&5 @@ -6194,9 +6298,9 @@ fi # check if sockaddr has sa_len member echo $ac_n "checking if sockaddr has sa_len member""... $ac_c" 1>&6 -echo "configure:6198: checking if sockaddr has sa_len member" >&5 +echo "configure:6302: checking if sockaddr has sa_len member" >&5 cat > conftest.$ac_ext < #include @@ -6205,7 +6309,7 @@ struct sockaddr x; x.sa_len = 0; ; return 0; } EOF -if { (eval echo configure:6209: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6313: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 cat >> confdefs.h <<\EOF @@ -6221,7 +6325,7 @@ fi rm -f conftest* echo $ac_n "checking for bad static forward""... $ac_c" 1>&6 -echo "configure:6225: checking for bad static forward" >&5 +echo "configure:6329: checking for bad static forward" >&5 if eval "test \"`echo '$''{'ac_cv_bad_static_forward'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -6229,7 +6333,7 @@ else ac_cv_bad_static_forward=no else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:6352: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_bad_static_forward=no else @@ -6269,9 +6373,9 @@ fi va_list_is_array=no echo $ac_n "checking whether va_list is an array""... $ac_c" 1>&6 -echo "configure:6273: checking whether va_list is an array" >&5 +echo "configure:6377: checking whether va_list is an array" >&5 cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6392: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then : else echo "configure: failed program was:" >&5 @@ -6300,12 +6404,12 @@ echo "$ac_t""$va_list_is_array" 1>&6 # sigh -- gethostbyname_r is a mess; it can have 3, 5 or 6 arguments :-( echo $ac_n "checking for gethostbyname_r""... $ac_c" 1>&6 -echo "configure:6304: checking for gethostbyname_r" >&5 +echo "configure:6408: checking for gethostbyname_r" >&5 if eval "test \"`echo '$''{'ac_cv_func_gethostbyname_r'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:6436: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_gethostbyname_r=yes" else @@ -6348,11 +6452,11 @@ if eval "test \"`echo '$ac_cv_func_'gethostbyname_r`\" = yes"; then EOF echo $ac_n "checking gethostbyname_r with 6 args""... $ac_c" 1>&6 -echo "configure:6352: checking gethostbyname_r with 6 args" >&5 +echo "configure:6456: checking gethostbyname_r with 6 args" >&5 OLD_CFLAGS=$CFLAGS CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS" cat > conftest.$ac_ext < @@ -6369,7 +6473,7 @@ int main() { ; return 0; } EOF -if { (eval echo configure:6373: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6477: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* cat >> confdefs.h <<\EOF @@ -6389,9 +6493,9 @@ else echo "$ac_t""no" 1>&6 echo $ac_n "checking gethostbyname_r with 5 args""... $ac_c" 1>&6 -echo "configure:6393: checking gethostbyname_r with 5 args" >&5 +echo "configure:6497: checking gethostbyname_r with 5 args" >&5 cat > conftest.$ac_ext < @@ -6408,7 +6512,7 @@ int main() { ; return 0; } EOF -if { (eval echo configure:6412: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6516: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* cat >> confdefs.h <<\EOF @@ -6428,9 +6532,9 @@ else echo "$ac_t""no" 1>&6 echo $ac_n "checking gethostbyname_r with 3 args""... $ac_c" 1>&6 -echo "configure:6432: checking gethostbyname_r with 3 args" >&5 +echo "configure:6536: checking gethostbyname_r with 3 args" >&5 cat > conftest.$ac_ext < @@ -6445,7 +6549,7 @@ int main() { ; return 0; } EOF -if { (eval echo configure:6449: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6553: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* cat >> confdefs.h <<\EOF @@ -6481,12 +6585,12 @@ else for ac_func in gethostbyname do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:6485: checking for $ac_func" >&5 +echo "configure:6589: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:6617: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -6547,12 +6651,12 @@ fi # Linux requires this for correct f.p. operations echo $ac_n "checking for __fpu_control""... $ac_c" 1>&6 -echo "configure:6551: checking for __fpu_control" >&5 +echo "configure:6655: checking for __fpu_control" >&5 if eval "test \"`echo '$''{'ac_cv_func___fpu_control'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:6683: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func___fpu_control=yes" else @@ -6593,7 +6697,7 @@ if eval "test \"`echo '$ac_cv_func_'__fpu_control`\" = yes"; then else echo "$ac_t""no" 1>&6 echo $ac_n "checking for __fpu_control in -lieee""... $ac_c" 1>&6 -echo "configure:6597: checking for __fpu_control in -lieee" >&5 +echo "configure:6701: checking for __fpu_control in -lieee" >&5 ac_lib_var=`echo ieee'_'__fpu_control | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -6601,7 +6705,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lieee $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:6720: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -6645,7 +6749,7 @@ fi # Check for --with-fpectl echo $ac_n "checking for --with-fpectl""... $ac_c" 1>&6 -echo "configure:6649: checking for --with-fpectl" >&5 +echo "configure:6753: checking for --with-fpectl" >&5 # Check whether --with-fpectl or --without-fpectl was given. if test "${with_fpectl+set}" = set; then withval="$with_fpectl" @@ -6670,7 +6774,7 @@ BeOS) ;; *) LIBM=-lm esac echo $ac_n "checking for --with-libm=STRING""... $ac_c" 1>&6 -echo "configure:6674: checking for --with-libm=STRING" >&5 +echo "configure:6778: checking for --with-libm=STRING" >&5 # Check whether --with-libm or --without-libm was given. if test "${with_libm+set}" = set; then withval="$with_libm" @@ -6691,7 +6795,7 @@ fi # check for --with-libc=... echo $ac_n "checking for --with-libc=STRING""... $ac_c" 1>&6 -echo "configure:6695: checking for --with-libc=STRING" >&5 +echo "configure:6799: checking for --with-libc=STRING" >&5 # Check whether --with-libc or --without-libc was given. if test "${with_libc+set}" = set; then withval="$with_libc" @@ -6715,12 +6819,12 @@ LIBS="$LIBS $LIBM" for ac_func in hypot do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:6719: checking for $ac_func" >&5 +echo "configure:6823: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:6851: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -6773,7 +6877,7 @@ LIBS=$LIBS_SAVE # check whether malloc(0) returns NULL or not echo $ac_n "checking what malloc(0) returns""... $ac_c" 1>&6 -echo "configure:6777: checking what malloc(0) returns" >&5 +echo "configure:6881: checking what malloc(0) returns" >&5 if eval "test \"`echo '$''{'ac_cv_malloc_zero'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -6781,7 +6885,7 @@ else ac_cv_malloc_zero=nonnull else cat > conftest.$ac_ext < #ifdef HAVE_STDLIB @@ -6800,7 +6904,7 @@ main() { exit(0); } EOF -if { (eval echo configure:6804: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:6908: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_malloc_zero=nonnull else @@ -6826,17 +6930,17 @@ fi # check for wchar.h ac_safe=`echo "wchar.h" | sed 'y%./+-%__p_%'` echo $ac_n "checking for wchar.h""... $ac_c" 1>&6 -echo "configure:6830: checking for wchar.h" >&5 +echo "configure:6934: checking for wchar.h" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:6840: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:6944: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -6867,7 +6971,7 @@ fi if test "$wchar_h" = yes then echo $ac_n "checking size of wchar_t""... $ac_c" 1>&6 -echo "configure:6871: checking size of wchar_t" >&5 +echo "configure:6975: checking size of wchar_t" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_wchar_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -6875,7 +6979,7 @@ else ac_cv_sizeof_wchar_t=4 else cat > conftest.$ac_ext < main() @@ -6886,7 +6990,7 @@ main() exit(0); } EOF -if { (eval echo configure:6890: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:6994: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_wchar_t=`cat conftestval` else @@ -6908,7 +7012,7 @@ EOF fi echo $ac_n "checking what type to use for unicode""... $ac_c" 1>&6 -echo "configure:6912: checking what type to use for unicode" >&5 +echo "configure:7016: checking what type to use for unicode" >&5 # Check whether --enable-unicode or --disable-unicode was given. if test "${enable_unicode+set}" = set; then enableval="$enable_unicode" @@ -6983,14 +7087,14 @@ fi # check for endianness echo $ac_n "checking whether byte ordering is bigendian""... $ac_c" 1>&6 -echo "configure:6987: checking whether byte ordering is bigendian" >&5 +echo "configure:7091: checking whether byte ordering is bigendian" >&5 if eval "test \"`echo '$''{'ac_cv_c_bigendian'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_cv_c_bigendian=unknown # See if sys/param.h defines the BYTE_ORDER macro. cat > conftest.$ac_ext < #include @@ -7001,11 +7105,11 @@ int main() { #endif ; return 0; } EOF -if { (eval echo configure:7005: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:7109: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* # It does; now see whether it defined to BIG_ENDIAN or not. cat > conftest.$ac_ext < #include @@ -7016,7 +7120,7 @@ int main() { #endif ; return 0; } EOF -if { (eval echo configure:7020: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:7124: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_bigendian=yes else @@ -7036,7 +7140,7 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:7157: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_c_bigendian=no else @@ -7076,7 +7180,7 @@ fi # Check whether right shifting a negative integer extends the sign bit # or fills with zeros (like the Cray J90, according to Tim Peters). echo $ac_n "checking whether right shift extends the sign bit""... $ac_c" 1>&6 -echo "configure:7080: checking whether right shift extends the sign bit" >&5 +echo "configure:7184: checking whether right shift extends the sign bit" >&5 if eval "test \"`echo '$''{'ac_cv_rshift_extends_sign'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -7085,7 +7189,7 @@ if test "$cross_compiling" = yes; then ac_cv_rshift_extends_sign=yes else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:7202: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_rshift_extends_sign=yes else @@ -7119,13 +7223,13 @@ fi # check for getc_unlocked and related locking functions echo $ac_n "checking for getc_unlocked() and friends""... $ac_c" 1>&6 -echo "configure:7123: checking for getc_unlocked() and friends" >&5 +echo "configure:7227: checking for getc_unlocked() and friends" >&5 if eval "test \"`echo '$''{'ac_cv_have_getc_unlocked'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < int main() { @@ -7137,7 +7241,7 @@ int main() { ; return 0; } EOF -if { (eval echo configure:7141: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:7245: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* ac_cv_have_getc_unlocked=yes else @@ -7160,7 +7264,7 @@ fi # check for readline 4.0 echo $ac_n "checking for rl_pre_input_hook in -lreadline""... $ac_c" 1>&6 -echo "configure:7164: checking for rl_pre_input_hook in -lreadline" >&5 +echo "configure:7268: checking for rl_pre_input_hook in -lreadline" >&5 ac_lib_var=`echo readline'_'rl_pre_input_hook | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -7168,7 +7272,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lreadline -ltermcap $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:7287: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -7205,7 +7309,7 @@ fi # check for readline 4.2 echo $ac_n "checking for rl_completion_matches in -lreadline""... $ac_c" 1>&6 -echo "configure:7209: checking for rl_completion_matches in -lreadline" >&5 +echo "configure:7313: checking for rl_completion_matches in -lreadline" >&5 ac_lib_var=`echo readline'_'rl_completion_matches | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -7213,7 +7317,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lreadline -ltermcap $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:7332: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -7249,7 +7353,7 @@ fi echo $ac_n "checking for broken nice()""... $ac_c" 1>&6 -echo "configure:7253: checking for broken nice()" >&5 +echo "configure:7357: checking for broken nice()" >&5 if eval "test \"`echo '$''{'ac_cv_broken_nice'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -7258,7 +7362,7 @@ if test "$cross_compiling" = yes; then ac_cv_broken_nice=no else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:7378: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_broken_nice=yes else @@ -7301,12 +7405,12 @@ cat >> confdefs.h <<\EOF #endif EOF echo $ac_n "checking for socklen_t""... $ac_c" 1>&6 -echo "configure:7305: checking for socklen_t" >&5 +echo "configure:7409: checking for socklen_t" >&5 if eval "test \"`echo '$''{'ac_cv_type_socklen_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #if STDC_HEADERS @@ -7355,7 +7459,7 @@ done SRCDIRS="Parser Grammar Objects Python Modules" echo $ac_n "checking for build directories""... $ac_c" 1>&6 -echo "configure:7359: checking for build directories" >&5 +echo "configure:7463: checking for build directories" >&5 for dir in $SRCDIRS; do if test ! -d $dir; then mkdir $dir diff --git a/configure.in b/configure.in index ed8698a..a578527 100644 --- a/configure.in +++ b/configure.in @@ -1534,6 +1534,9 @@ AC_CHECK_FUNCS(getnameinfo) AC_HEADER_TIME AC_STRUCT_TM AC_STRUCT_TIMEZONE +AC_STRUCT_ST_RDEV +AC_STRUCT_ST_BLKSIZE +AC_STRUCT_ST_BLOCKS AC_MSG_CHECKING(for time.h that defines altzone) AC_CACHE_VAL(ac_cv_header_time_altzone, diff --git a/pyconfig.h.in b/pyconfig.h.in index fe8d262..0edfcb2 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -18,6 +18,15 @@ /* Define to `int' if doesn't define. */ #undef gid_t +/* Define if your struct stat has st_blksize. */ +#undef HAVE_ST_BLKSIZE + +/* Define if your struct stat has st_blocks. */ +#undef HAVE_ST_BLOCKS + +/* Define if your struct stat has st_rdev. */ +#undef HAVE_ST_RDEV + /* Define if your struct tm has tm_zone. */ #undef HAVE_TM_ZONE -- cgit v0.12