[Python-checkins] python/dist/src/Modules posixmodule.c,2.267,2.268

loewis@users.sourceforge.net loewis@users.sourceforge.net
Wed, 16 Oct 2002 11:27:41 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv7316/Modules

Modified Files:
	posixmodule.c 
Log Message:
Add PyStructSequence_UnnamedField. Add stat_float_times.
Use integers in stat tuple, optionally floats in named fields.


Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.267
retrieving revision 2.268
diff -C2 -d -r2.267 -r2.268
*** posixmodule.c	16 Oct 2002 16:52:11 -0000	2.267
--- posixmodule.c	16 Oct 2002 18:27:38 -0000	2.268
***************
*** 679,682 ****
--- 679,686 ----
  	{"st_gid",     "group ID of owner"},
  	{"st_size",    "total size, in bytes"},
+ 	/* The NULL is replaced with PyStructSequence_UnnamedField later. */
+ 	{NULL,   "integer time of last access"},
+ 	{NULL,   "integer time of last modification"},
+ 	{NULL,   "integer time of last change"},
  	{"st_atime",   "time of last access"},
  	{"st_mtime",   "time of last modification"},
***************
*** 695,701 ****
  
  #ifdef HAVE_ST_BLKSIZE
! #define ST_BLKSIZE_IDX 10
  #else
! #define ST_BLKSIZE_IDX 9
  #endif
  
--- 699,705 ----
  
  #ifdef HAVE_ST_BLKSIZE
! #define ST_BLKSIZE_IDX 13
  #else
! #define ST_BLKSIZE_IDX 12
  #endif
  
***************
*** 750,760 ****
  static PyTypeObject StatResultType;
  static PyTypeObject StatVFSResultType;
  
  static void
  fill_time(PyObject *v, int index, time_t sec, unsigned long nsec)
  {
! 	PyObject *val;
!         val = PyFloat_FromDouble(sec + 1e-9*nsec);
! 	PyStructSequence_SET_ITEM(v, index, val);
  }
  
--- 754,824 ----
  static PyTypeObject StatResultType;
  static PyTypeObject StatVFSResultType;
+ static newfunc structseq_new;
+ 
+ static PyObject *
+ statresult_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+ {
+ 	PyStructSequence *result;
+ 	int i;
+ 
+ 	result = (PyStructSequence*)structseq_new(type, args, kwds);
+ 	if (!result)
+ 		return NULL;
+ 	/* If we have been initialized from a tuple,
+ 	   st_?time might be set to None. Initialize it
+ 	   from the int slots.  */
+ 	for (i = 7; i <= 9; i++) {
+ 		if (result->ob_item[i+3] == Py_None) {
+ 			Py_DECREF(Py_None);
+ 			Py_INCREF(result->ob_item[i]);
+ 			result->ob_item[i+3] = result->ob_item[i];
+ 		}
+ 	}
+ 	return (PyObject*)result;
+ }
+ 
+ 
+ 
+ /* If true, st_?time is float. */
+ static int _stat_float_times = 0;
+ 
+ PyDoc_STRVAR(stat_float_times__doc__,
+ "stat_float_times([newval]) -> oldval\n\n\
+ Determine whether os.[lf]stat represents time stamps as float objects.\n\
+ If newval is True, future calls to stat() return floats, if it is False,\n\
+ future calls return ints. \n\
+ If newval is omitted, return the current setting.\n");
+ 
+ static PyObject*
+ stat_float_times(PyObject* self, PyObject *args)
+ {
+ 	int newval = -1;
+ 	if (!PyArg_ParseTuple(args, "|i:stat_float_times", &newval))
+ 		return NULL;
+ 	if (newval == -1)
+ 		/* Return old value */
+ 		return PyBool_FromLong(_stat_float_times);
+ 	_stat_float_times = newval;
+ 	Py_INCREF(Py_None);
+ 	return Py_None;
+ }
  
  static void
  fill_time(PyObject *v, int index, time_t sec, unsigned long nsec)
  {
! 	PyObject *fval,*ival;
! #if SIZEOF_TIME_T > SIZEOF_LONG
! 	ival = PyLong_FromLongLong((LONG_LONG)sec);
! #else
! 	ival = PyInt_FromLong((long)sec);
! #endif
! 	if (_stat_float_times) {
! 		fval = PyFloat_FromDouble(sec + 1e-9*nsec);
! 	} else {
! 		fval = ival;
! 		Py_INCREF(fval);
! 	}
! 	PyStructSequence_SET_ITEM(v, index, ival);
! 	PyStructSequence_SET_ITEM(v, index+3, fval);
  }
  
***************
*** 6803,6806 ****
--- 6867,6871 ----
  	{"rmdir",	posix_rmdir, METH_VARARGS, posix_rmdir__doc__},
  	{"stat",	posix_stat, METH_VARARGS, posix_stat__doc__},
+ 	{"stat_float_times", stat_float_times, METH_VARARGS, stat_float_times__doc__},
  #ifdef HAVE_SYMLINK
  	{"symlink",	posix_symlink, METH_VARARGS, posix_symlink__doc__},
***************
*** 7297,7301 ****
--- 7362,7371 ----
  
  	stat_result_desc.name = MODNAME ".stat_result";
+ 	stat_result_desc.fields[7].name = PyStructSequence_UnnamedField;
+ 	stat_result_desc.fields[8].name = PyStructSequence_UnnamedField;
+ 	stat_result_desc.fields[9].name = PyStructSequence_UnnamedField;
  	PyStructSequence_InitType(&StatResultType, &stat_result_desc);
+ 	structseq_new = StatResultType.tp_new;
+ 	StatResultType.tp_new = statresult_new;
  	Py_INCREF((PyObject*) &StatResultType);
  	PyModule_AddObject(m, "stat_result", (PyObject*) &StatResultType);