Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(8)

Unified Diff: Modules/timemodule.c

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Modules/_ssl.c ('k') | Objects/bytes_methods.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Modules/timemodule.c Tue Jul 26 09:37:46 2011 +0300
+++ b/Modules/timemodule.c Mon Jul 25 09:47:18 2011 -0400
@@ -3,6 +3,8 @@
#include "Python.h"
#include "_time.h"
+#define TZNAME_ENCODING "utf-8"
+
#include <ctype.h>
#ifdef HAVE_SYS_TYPES_H
@@ -43,11 +45,12 @@
#endif /* MS_WINDOWS */
#endif /* !__WATCOMC__ || __QNX__ */
-#if defined(HAVE_MBCS)
-# define TZNAME_ENCODING "mbcs"
-#else
-# define TZNAME_ENCODING "utf-8"
-#endif
+#if defined(MS_WINDOWS) && !defined(__BORLANDC__)
+/* Win32 has better clock replacement; we have our own version below. */
+#undef HAVE_CLOCK
+#undef TZNAME_ENCODING
+#define TZNAME_ENCODING "mbcs"
+#endif /* MS_WINDOWS && !defined(__BORLANDC__) */
#if defined(PYOS_OS2)
#define INCL_DOS
@@ -81,9 +84,25 @@
Return the current time in seconds since the Epoch.\n\
Fractions of a second may be present if the system clock provides them.");
+#ifdef HAVE_CLOCK
+
+#ifndef CLOCKS_PER_SEC
+#ifdef CLK_TCK
+#define CLOCKS_PER_SEC CLK_TCK
+#else
+#define CLOCKS_PER_SEC 1000000
+#endif
+#endif
+
+static PyObject *
+time_clock(PyObject *self, PyObject *unused)
+{
+ return PyFloat_FromDouble(((double)clock()) / CLOCKS_PER_SEC);
+}
+#endif /* HAVE_CLOCK */
+
#if defined(MS_WINDOWS) && !defined(__BORLANDC__)
-/* Win32 has better clock replacement; we have our own version, due to Mark
- Hammond and Tim Peters */
+/* Due to Mark Hammond and Tim Peters */
static PyObject *
time_clock(PyObject *self, PyObject *unused)
{
@@ -108,23 +127,8 @@
return PyFloat_FromDouble(diff / divisor);
}
-#elif defined(HAVE_CLOCK)
-
-#ifndef CLOCKS_PER_SEC
-#ifdef CLK_TCK
-#define CLOCKS_PER_SEC CLK_TCK
-#else
-#define CLOCKS_PER_SEC 1000000
-#endif
-#endif
-
-static PyObject *
-time_clock(PyObject *self, PyObject *unused)
-{
- return PyFloat_FromDouble(((double)clock()) / CLOCKS_PER_SEC);
-}
-#endif /* HAVE_CLOCK */
-
+#define HAVE_CLOCK /* So it gets included in the methods */
+#endif /* MS_WINDOWS && !defined(__BORLANDC__) */
#ifdef HAVE_CLOCK
PyDoc_STRVAR(clock_doc,
@@ -141,11 +145,6 @@
double secs;
if (!PyArg_ParseTuple(args, "d:sleep", &secs))
return NULL;
- if (secs < 0) {
- PyErr_SetString(PyExc_ValueError,
- "sleep length must be non-negative");
- return NULL;
- }
if (floatsleep(secs) != 0)
return NULL;
Py_INCREF(Py_None);
@@ -785,7 +784,7 @@
static PyMethodDef time_methods[] = {
{"time", time_time, METH_NOARGS, time_doc},
-#if (defined(MS_WINDOWS) && !defined(__BORLANDC__)) || defined(HAVE_CLOCK)
+#ifdef HAVE_CLOCK
{"clock", time_clock, METH_NOARGS, clock_doc},
#endif
{"sleep", time_sleep, METH_VARARGS, sleep_doc},
@@ -916,28 +915,23 @@
#if defined(HAVE_SELECT) && !defined(__EMX__)
struct timeval t;
double frac;
- int err;
-
frac = fmod(secs, 1.0);
secs = floor(secs);
t.tv_sec = (long)secs;
t.tv_usec = (long)(frac*1000000.0);
Py_BEGIN_ALLOW_THREADS
- err = select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t);
- Py_END_ALLOW_THREADS
- if (err != 0) {
+ if (select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t) != 0) {
#ifdef EINTR
- if (errno == EINTR) {
- if (PyErr_CheckSignals())
- return -1;
- }
- else
+ if (errno != EINTR) {
+#else
+ if (1) {
#endif
- {
+ Py_BLOCK_THREADS
PyErr_SetFromErrno(PyExc_IOError);
return -1;
}
}
+ Py_END_ALLOW_THREADS
#elif defined(__WATCOMC__) && !defined(__QNX__)
/* XXX Can't interrupt this sleep */
Py_BEGIN_ALLOW_THREADS
« no previous file with comments | « Modules/_ssl.c ('k') | Objects/bytes_methods.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+