mirror of
https://github.com/python/cpython.git
synced 2025-11-11 22:55:08 +00:00
New hacks for include files to get time_t in the most portable way.
Added Turbo C milli functions (courtesy Mark Anacker) Disable THINK C sleep for 4.0
This commit is contained in:
parent
753e2bfbbf
commit
80c9d88cbf
1 changed files with 54 additions and 10 deletions
|
|
@ -33,13 +33,30 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
|
||||||
#ifdef __STDC__
|
/* What happens here is not trivial.
|
||||||
#include <time.h>
|
The BSD_TIME code needs <sys/time.h> (for struct timeval).
|
||||||
#else /* !__STDC__ */
|
The rest of the code needs only time_t, except some MS-DOS
|
||||||
typedef unsigned long time_t;
|
code which needs clock_t as well.
|
||||||
extern time_t time();
|
Standard C says that time_t is defined in <time.h>, and
|
||||||
#endif /* !__STDC__ */
|
does not have <sys/types.h>; THINK C agrees (MS-DOS too?).
|
||||||
|
What's worse, in pure 4.3 BSD, older SunOS versions, and
|
||||||
|
probably everything derived from BSD, you can't #include
|
||||||
|
both <time.h> and <sys/time.h> in the same file, since
|
||||||
|
<sys/time.h> includes <time.h> without any protection,
|
||||||
|
and <time.h> contains a typedef, which can't be parsed twice!
|
||||||
|
So on traditional UNIX systems we include <sys/types.h>
|
||||||
|
and <sys/time.h> and hope this implies <time.h> and time_t,
|
||||||
|
while on other systems, including conforming Standard C
|
||||||
|
systems (where 'unix' can't be defined), we rely on <time.h>.
|
||||||
|
Still one problem: BSD_TIME won't work with strict Standard C...
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef unix
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/time.h> /* Implies <time.h> everywhere, as far as I know */
|
||||||
|
#else /* !unix */
|
||||||
|
#include <time.h>
|
||||||
|
#endif /* !unix */
|
||||||
|
|
||||||
/* Time methods */
|
/* Time methods */
|
||||||
|
|
||||||
|
|
@ -51,7 +68,7 @@ time_time(self, args)
|
||||||
time_t secs;
|
time_t secs;
|
||||||
if (!getnoarg(args))
|
if (!getnoarg(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
secs = time((time_t *)NULL);
|
time(&secs);
|
||||||
#ifdef THINK_C
|
#ifdef THINK_C
|
||||||
#ifndef THINK_C_3_0
|
#ifndef THINK_C_3_0
|
||||||
/* Difference in origin between Mac and Unix clocks: */
|
/* Difference in origin between Mac and Unix clocks: */
|
||||||
|
|
@ -109,6 +126,10 @@ extern long sys_milli();
|
||||||
#define DO_MILLI
|
#define DO_MILLI
|
||||||
#endif /* BSD_TIME */
|
#endif /* BSD_TIME */
|
||||||
|
|
||||||
|
#ifdef TURBO_C
|
||||||
|
#define DO_MILLI
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DO_MILLI
|
#ifdef DO_MILLI
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
|
|
@ -172,6 +193,7 @@ inittime()
|
||||||
|
|
||||||
#define MacTicks (* (long *)0x16A)
|
#define MacTicks (* (long *)0x16A)
|
||||||
|
|
||||||
|
#ifdef THINK_C_3_0
|
||||||
sleep(msecs)
|
sleep(msecs)
|
||||||
int msecs;
|
int msecs;
|
||||||
{
|
{
|
||||||
|
|
@ -183,6 +205,7 @@ sleep(msecs)
|
||||||
sleep_catcher(SIGINT);
|
sleep_catcher(SIGINT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
millisleep(msecs)
|
millisleep(msecs)
|
||||||
long msecs;
|
long msecs;
|
||||||
|
|
@ -207,9 +230,6 @@ millitimer()
|
||||||
|
|
||||||
#ifdef BSD_TIME
|
#ifdef BSD_TIME
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
long
|
long
|
||||||
millitimer()
|
millitimer()
|
||||||
{
|
{
|
||||||
|
|
@ -232,3 +252,27 @@ millisleep(msecs)
|
||||||
|
|
||||||
#endif /* BSD_TIME */
|
#endif /* BSD_TIME */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef TURBO_C /* Maybe also for MS-DOS? */
|
||||||
|
|
||||||
|
#ifndef CLOCKS_PER_SEC
|
||||||
|
#define CLOCKS_PER_SEC 55 /* 54.945 msec per tick (18.2 HZ clock) */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static
|
||||||
|
millisleep(msecs)
|
||||||
|
long msecs;
|
||||||
|
{
|
||||||
|
delay(msecs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static long
|
||||||
|
millitimer()
|
||||||
|
{
|
||||||
|
clock_t ticks;
|
||||||
|
|
||||||
|
ticks = clock(); /* ticks since program start */
|
||||||
|
return ticks * CLOCKS_PER_SEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* TURBO_C */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue