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
ff7f428b
Kaydet (Commit)
ff7f428b
authored
Mar 27, 2015
tarafından
Brett Cannon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge
üst
781692ff
992c43fe
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
7 deletions
+38
-7
pytime.h
Include/pytime.h
+6
-3
test_time.py
Lib/test/test_time.py
+0
-0
_testcapimodule.c
Modules/_testcapimodule.c
+17
-0
timemodule.c
Modules/timemodule.c
+1
-1
pytime.c
Python/pytime.c
+14
-3
No files found.
Include/pytime.h
Dosyayı görüntüle @
ff7f428b
...
@@ -121,15 +121,18 @@ typedef PY_INT64_T _PyTime_t;
...
@@ -121,15 +121,18 @@ typedef PY_INT64_T _PyTime_t;
/* Convert a Python float or int to a timetamp.
/* Convert a Python float or int to a timetamp.
Raise an exception and return -1 on error, return 0 on success. */
Raise an exception and return -1 on error, return 0 on success. */
PyAPI_FUNC
(
int
)
_PyTime_FromObject
(
_PyTime_t
*
t
,
PyAPI_FUNC
(
int
)
_PyTime_From
Seconds
Object
(
_PyTime_t
*
t
,
PyObject
*
obj
,
PyObject
*
obj
,
_PyTime_round_t
round
);
_PyTime_round_t
round
);
/* Convert timestamp to a number of milliseconds (10^-3 seconds). */
/* Convert timestamp to a number of milliseconds (10^-3 seconds). */
PyAPI_FUNC
(
_PyTime_t
)
PyAPI_FUNC
(
_PyTime_t
)
_PyTime_AsMilliseconds
(
_PyTime_t
t
,
_PyTime_AsMilliseconds
(
_PyTime_t
t
,
_PyTime_round_t
round
);
_PyTime_round_t
round
);
/* Convert timestamp to a number of nanoseconds (10^-9 seconds) as a Python int
object. */
PyAPI_FUNC
(
PyObject
*
)
_PyTime_AsNanosecondsObject
(
_PyTime_t
t
);
/* Convert a timestamp to a timeval structure. */
/* Convert a timestamp to a timeval structure. */
PyAPI_FUNC
(
int
)
_PyTime_AsTimeval
(
_PyTime_t
t
,
PyAPI_FUNC
(
int
)
_PyTime_AsTimeval
(
_PyTime_t
t
,
struct
timeval
*
tv
,
struct
timeval
*
tv
,
...
...
Lib/test/test_time.py
Dosyayı görüntüle @
ff7f428b
This diff is collapsed.
Click to expand it.
Modules/_testcapimodule.c
Dosyayı görüntüle @
ff7f428b
...
@@ -3378,6 +3378,22 @@ return_result_with_error(PyObject *self, PyObject *args)
...
@@ -3378,6 +3378,22 @@ return_result_with_error(PyObject *self, PyObject *args)
Py_RETURN_NONE
;
Py_RETURN_NONE
;
}
}
static
PyObject
*
test_pytime_fromsecondsobject
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
obj
;
int
round
;
_PyTime_t
ts
;
if
(
!
PyArg_ParseTuple
(
args
,
"Oi"
,
&
obj
,
&
round
))
return
NULL
;
if
(
check_time_rounding
(
round
)
<
0
)
return
NULL
;
if
(
_PyTime_FromSecondsObject
(
&
ts
,
obj
,
round
)
==
-
1
)
return
NULL
;
return
_PyTime_AsNanosecondsObject
(
ts
);
}
static
PyMethodDef
TestMethods
[]
=
{
static
PyMethodDef
TestMethods
[]
=
{
{
"raise_exception"
,
raise_exception
,
METH_VARARGS
},
{
"raise_exception"
,
raise_exception
,
METH_VARARGS
},
...
@@ -3541,6 +3557,7 @@ static PyMethodDef TestMethods[] = {
...
@@ -3541,6 +3557,7 @@ static PyMethodDef TestMethods[] = {
return_null_without_error
,
METH_NOARGS
},
return_null_without_error
,
METH_NOARGS
},
{
"return_result_with_error"
,
{
"return_result_with_error"
,
return_result_with_error
,
METH_NOARGS
},
return_result_with_error
,
METH_NOARGS
},
{
"pytime_fromsecondsobject"
,
test_pytime_fromsecondsobject
,
METH_VARARGS
},
{
NULL
,
NULL
}
/* sentinel */
{
NULL
,
NULL
}
/* sentinel */
};
};
...
...
Modules/timemodule.c
Dosyayı görüntüle @
ff7f428b
...
@@ -221,7 +221,7 @@ static PyObject *
...
@@ -221,7 +221,7 @@ static PyObject *
time_sleep
(
PyObject
*
self
,
PyObject
*
obj
)
time_sleep
(
PyObject
*
self
,
PyObject
*
obj
)
{
{
_PyTime_t
secs
;
_PyTime_t
secs
;
if
(
_PyTime_FromObject
(
&
secs
,
obj
,
_PyTime_ROUND_UP
))
if
(
_PyTime_From
Seconds
Object
(
&
secs
,
obj
,
_PyTime_ROUND_UP
))
return
NULL
;
return
NULL
;
if
(
secs
<
0
)
{
if
(
secs
<
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
PyErr_SetString
(
PyExc_ValueError
,
...
...
Python/pytime.c
Dosyayı görüntüle @
ff7f428b
...
@@ -424,7 +424,7 @@ _PyTime_FromTimespec(_PyTime_t *tp, struct timespec *ts)
...
@@ -424,7 +424,7 @@ _PyTime_FromTimespec(_PyTime_t *tp, struct timespec *ts)
#endif
#endif
int
int
_PyTime_FromObject
(
_PyTime_t
*
t
,
PyObject
*
obj
,
_PyTime_round_t
round
)
_PyTime_From
Seconds
Object
(
_PyTime_t
*
t
,
PyObject
*
obj
,
_PyTime_round_t
round
)
{
{
if
(
PyFloat_Check
(
obj
))
{
if
(
PyFloat_Check
(
obj
))
{
double
d
,
err
;
double
d
,
err
;
...
@@ -433,8 +433,7 @@ _PyTime_FromObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t round)
...
@@ -433,8 +433,7 @@ _PyTime_FromObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t round)
d
=
PyFloat_AsDouble
(
obj
);
d
=
PyFloat_AsDouble
(
obj
);
d
*=
1e9
;
d
*=
1e9
;
/* FIXME: use sign */
if
((
round
==
_PyTime_ROUND_UP
)
^
(
d
<
0
))
if
(
round
==
_PyTime_ROUND_UP
)
d
=
ceil
(
d
);
d
=
ceil
(
d
);
else
else
d
=
floor
(
d
);
d
=
floor
(
d
);
...
@@ -471,6 +470,18 @@ _PyTime_FromObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t round)
...
@@ -471,6 +470,18 @@ _PyTime_FromObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t round)
}
}
}
}
PyObject
*
_PyTime_AsNanosecondsObject
(
_PyTime_t
t
)
{
#ifdef HAVE_LONG_LONG
assert
(
sizeof
(
PY_LONG_LONG
)
>=
sizeof
(
_PyTime_t
));
return
PyLong_FromLongLong
((
PY_LONG_LONG
)
t
);
#else
assert
(
sizeof
(
long
)
>=
sizeof
(
_PyTime_t
));
return
PyLong_FromLong
((
long
)
t
);
#endif
}
static
_PyTime_t
static
_PyTime_t
_PyTime_Multiply
(
_PyTime_t
t
,
unsigned
int
multiply
,
_PyTime_round_t
round
)
_PyTime_Multiply
(
_PyTime_t
t
,
unsigned
int
multiply
,
_PyTime_round_t
round
)
{
{
...
...
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