Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
1bd18ba9
Kaydet (Commit)
1bd18ba9
authored
Mar 29, 2015
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #22117: Cleanup pytime.c/.h
üst
09e5cf28
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
44 deletions
+42
-44
pytime.h
Include/pytime.h
+37
-37
pytime.c
Python/pytime.c
+5
-7
No files found.
Include/pytime.h
Dosyayı görüntüle @
1bd18ba9
...
@@ -13,13 +13,16 @@ functions and constants
...
@@ -13,13 +13,16 @@ functions and constants
extern
"C"
{
extern
"C"
{
#endif
#endif
/* Structure used by time.get_clock_info() */
#ifdef PY_INT64_T
typedef
struct
{
/* _PyTime_t: Python timestamp with subsecond precision. It can be used to
const
char
*
implementation
;
store a duration, and so indirectly a date (related to another date, like
int
monotonic
;
UNIX epoch). */
int
adjustable
;
typedef
PY_INT64_T
_PyTime_t
;
double
resolution
;
#define _PyTime_MIN PY_LLONG_MIN
}
_Py_clock_info_t
;
#define _PyTime_MAX PY_LLONG_MAX
#else
# error "_PyTime_t need signed 64-bit integer type"
#endif
typedef
enum
{
typedef
enum
{
/* Round towards zero. */
/* Round towards zero. */
...
@@ -32,12 +35,6 @@ typedef enum {
...
@@ -32,12 +35,6 @@ typedef enum {
_PyTime_ROUND_FLOOR
_PyTime_ROUND_FLOOR
}
_PyTime_round_t
;
}
_PyTime_round_t
;
/* Convert a number of seconds, int or float, to time_t. */
PyAPI_FUNC
(
int
)
_PyTime_ObjectToTime_t
(
PyObject
*
obj
,
time_t
*
sec
,
_PyTime_round_t
);
/* Convert a time_t to a PyLong. */
/* Convert a time_t to a PyLong. */
PyAPI_FUNC
(
PyObject
*
)
_PyLong_FromTime_t
(
PyAPI_FUNC
(
PyObject
*
)
_PyLong_FromTime_t
(
time_t
sec
);
time_t
sec
);
...
@@ -46,6 +43,12 @@ PyAPI_FUNC(PyObject *) _PyLong_FromTime_t(
...
@@ -46,6 +43,12 @@ PyAPI_FUNC(PyObject *) _PyLong_FromTime_t(
PyAPI_FUNC
(
time_t
)
_PyLong_AsTime_t
(
PyAPI_FUNC
(
time_t
)
_PyLong_AsTime_t
(
PyObject
*
obj
);
PyObject
*
obj
);
/* Convert a number of seconds, int or float, to time_t. */
PyAPI_FUNC
(
int
)
_PyTime_ObjectToTime_t
(
PyObject
*
obj
,
time_t
*
sec
,
_PyTime_round_t
);
/* Convert a number of seconds, int or float, to a timeval structure.
/* Convert a number of seconds, int or float, to a timeval structure.
usec is in the range [0; 999999] and rounded towards zero.
usec is in the range [0; 999999] and rounded towards zero.
For example, -1.2 is converted to (-2, 800000). */
For example, -1.2 is converted to (-2, 800000). */
...
@@ -64,22 +67,6 @@ PyAPI_FUNC(int) _PyTime_ObjectToTimespec(
...
@@ -64,22 +67,6 @@ PyAPI_FUNC(int) _PyTime_ObjectToTimespec(
long
*
nsec
,
long
*
nsec
,
_PyTime_round_t
);
_PyTime_round_t
);
/* Initialize time.
Return 0 on success, raise an exception and return -1 on error. */
PyAPI_FUNC
(
int
)
_PyTime_Init
(
void
);
/****************** NEW _PyTime_t API **********************/
#ifdef PY_INT64_T
/* _PyTime_t: Python timestamp with subsecond precision. It can be used to
store a duration, and so indirectly a date (related to another date, like
UNIX epoch). */
typedef
PY_INT64_T
_PyTime_t
;
#define _PyTime_MIN PY_LLONG_MIN
#define _PyTime_MAX PY_LLONG_MAX
#else
# error "_PyTime_t need signed 64-bit integer type"
#endif
/* Create a timestamp from a number of nanoseconds (C long). */
/* Create a timestamp from a number of nanoseconds (C long). */
PyAPI_FUNC
(
_PyTime_t
)
_PyTime_FromNanoseconds
(
PY_LONG_LONG
ns
);
PyAPI_FUNC
(
_PyTime_t
)
_PyTime_FromNanoseconds
(
PY_LONG_LONG
ns
);
...
@@ -125,14 +112,6 @@ PyAPI_FUNC(int) _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts);
...
@@ -125,14 +112,6 @@ PyAPI_FUNC(int) _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts);
works. */
works. */
PyAPI_FUNC
(
_PyTime_t
)
_PyTime_GetSystemClock
(
void
);
PyAPI_FUNC
(
_PyTime_t
)
_PyTime_GetSystemClock
(
void
);
/* Get the current time from the system clock.
* Fill clock information if info is not NULL.
* Raise an exception and return -1 on error, return 0 on success.
*/
PyAPI_FUNC
(
int
)
_PyTime_GetSystemClockWithInfo
(
_PyTime_t
*
t
,
_Py_clock_info_t
*
info
);
/* Get the time of a monotonic clock, i.e. a clock that cannot go backwards.
/* Get the time of a monotonic clock, i.e. a clock that cannot go backwards.
The clock is not affected by system clock updates. The reference point of
The clock is not affected by system clock updates. The reference point of
the returned value is undefined, so that only the difference between the
the returned value is undefined, so that only the difference between the
...
@@ -142,6 +121,23 @@ PyAPI_FUNC(int) _PyTime_GetSystemClockWithInfo(
...
@@ -142,6 +121,23 @@ PyAPI_FUNC(int) _PyTime_GetSystemClockWithInfo(
is available and works. */
is available and works. */
PyAPI_FUNC
(
_PyTime_t
)
_PyTime_GetMonotonicClock
(
void
);
PyAPI_FUNC
(
_PyTime_t
)
_PyTime_GetMonotonicClock
(
void
);
/* Structure used by time.get_clock_info() */
typedef
struct
{
const
char
*
implementation
;
int
monotonic
;
int
adjustable
;
double
resolution
;
}
_Py_clock_info_t
;
/* Get the current time from the system clock.
* Fill clock information if info is not NULL.
* Raise an exception and return -1 on error, return 0 on success.
*/
PyAPI_FUNC
(
int
)
_PyTime_GetSystemClockWithInfo
(
_PyTime_t
*
t
,
_Py_clock_info_t
*
info
);
/* Get the time of a monotonic clock, i.e. a clock that cannot go backwards.
/* Get the time of a monotonic clock, i.e. a clock that cannot go backwards.
The clock is not affected by system clock updates. The reference point of
The clock is not affected by system clock updates. The reference point of
the returned value is undefined, so that only the difference between the
the returned value is undefined, so that only the difference between the
...
@@ -155,6 +151,10 @@ PyAPI_FUNC(int) _PyTime_GetMonotonicClockWithInfo(
...
@@ -155,6 +151,10 @@ PyAPI_FUNC(int) _PyTime_GetMonotonicClockWithInfo(
_Py_clock_info_t
*
info
);
_Py_clock_info_t
*
info
);
/* Initialize time.
Return 0 on success, raise an exception and return -1 on error. */
PyAPI_FUNC
(
int
)
_PyTime_Init
(
void
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
Python/pytime.c
Dosyayı görüntüle @
1bd18ba9
...
@@ -151,8 +151,6 @@ _PyTime_ObjectToTimeval(PyObject *obj, time_t *sec, long *usec,
...
@@ -151,8 +151,6 @@ _PyTime_ObjectToTimeval(PyObject *obj, time_t *sec, long *usec,
return
_PyTime_ObjectToDenominator
(
obj
,
sec
,
usec
,
1e6
,
round
);
return
_PyTime_ObjectToDenominator
(
obj
,
sec
,
usec
,
1e6
,
round
);
}
}
/****************** NEW _PyTime_t API **********************/
static
void
static
void
_PyTime_overflow
(
void
)
_PyTime_overflow
(
void
)
{
{
...
@@ -161,7 +159,7 @@ _PyTime_overflow(void)
...
@@ -161,7 +159,7 @@ _PyTime_overflow(void)
}
}
int
int
_PyTime_RoundTowards
Infinity
(
int
is_neg
,
_PyTime_round_t
round
)
_PyTime_RoundTowards
PosInf
(
int
is_neg
,
_PyTime_round_t
round
)
{
{
if
(
round
==
_PyTime_ROUND_FLOOR
)
if
(
round
==
_PyTime_ROUND_FLOOR
)
return
0
;
return
0
;
...
@@ -196,7 +194,7 @@ _PyTime_FromTimespec(_PyTime_t *tp, struct timespec *ts, int raise)
...
@@ -196,7 +194,7 @@ _PyTime_FromTimespec(_PyTime_t *tp, struct timespec *ts, int raise)
*
tp
=
t
;
*
tp
=
t
;
return
res
;
return
res
;
}
}
#el
se
#el
if !defined(MS_WINDOWS)
static
int
static
int
_PyTime_FromTimeval
(
_PyTime_t
*
tp
,
struct
timeval
*
tv
,
int
raise
)
_PyTime_FromTimeval
(
_PyTime_t
*
tp
,
struct
timeval
*
tv
,
int
raise
)
{
{
...
@@ -227,7 +225,7 @@ _PyTime_FromSecondsObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t round)
...
@@ -227,7 +225,7 @@ _PyTime_FromSecondsObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t round)
d
=
PyFloat_AsDouble
(
obj
);
d
=
PyFloat_AsDouble
(
obj
);
d
*=
1e9
;
d
*=
1e9
;
if
(
_PyTime_RoundTowards
Infinity
(
d
<
0
,
round
))
if
(
_PyTime_RoundTowards
PosInf
(
d
<
0
,
round
))
d
=
ceil
(
d
);
d
=
ceil
(
d
);
else
else
d
=
floor
(
d
);
d
=
floor
(
d
);
...
@@ -293,7 +291,7 @@ _PyTime_Multiply(_PyTime_t t, unsigned int multiply, _PyTime_round_t round)
...
@@ -293,7 +291,7 @@ _PyTime_Multiply(_PyTime_t t, unsigned int multiply, _PyTime_round_t round)
_PyTime_t
k
;
_PyTime_t
k
;
if
(
multiply
<
SEC_TO_NS
)
{
if
(
multiply
<
SEC_TO_NS
)
{
k
=
SEC_TO_NS
/
multiply
;
k
=
SEC_TO_NS
/
multiply
;
if
(
_PyTime_RoundTowards
Infinity
(
t
<
0
,
round
))
if
(
_PyTime_RoundTowards
PosInf
(
t
<
0
,
round
))
return
(
t
+
k
-
1
)
/
k
;
return
(
t
+
k
-
1
)
/
k
;
else
else
return
t
/
k
;
return
t
/
k
;
...
@@ -353,7 +351,7 @@ _PyTime_AsTimeval(_PyTime_t t, struct timeval *tv, _PyTime_round_t round)
...
@@ -353,7 +351,7 @@ _PyTime_AsTimeval(_PyTime_t t, struct timeval *tv, _PyTime_round_t round)
res
=
-
1
;
res
=
-
1
;
#endif
#endif
if
(
_PyTime_RoundTowards
Infinity
(
tv
->
tv_sec
<
0
,
round
))
if
(
_PyTime_RoundTowards
PosInf
(
tv
->
tv_sec
<
0
,
round
))
tv
->
tv_usec
=
(
int
)((
ns
+
US_TO_NS
-
1
)
/
US_TO_NS
);
tv
->
tv_usec
=
(
int
)((
ns
+
US_TO_NS
-
1
)
/
US_TO_NS
);
else
else
tv
->
tv_usec
=
(
int
)(
ns
/
US_TO_NS
);
tv
->
tv_usec
=
(
int
)(
ns
/
US_TO_NS
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment