Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
338af286
Commit
338af286
authored
Jan 08, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic datetime support
parent
f250404f
Changes
14
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
484 additions
and
64 deletions
+484
-64
Makefile
Makefile
+1
-1
from_cpython/CMakeLists.txt
from_cpython/CMakeLists.txt
+1
-1
from_cpython/Include/datetime.h
from_cpython/Include/datetime.h
+241
-0
from_cpython/Include/intobject.h
from_cpython/Include/intobject.h
+1
-1
from_cpython/Include/stringobject.h
from_cpython/Include/stringobject.h
+1
-1
from_cpython/Include/timefuncs.h
from_cpython/Include/timefuncs.h
+28
-0
src/capi/abstract.cpp
src/capi/abstract.cpp
+4
-0
src/capi/object.cpp
src/capi/object.cpp
+5
-0
src/capi/typeobject.cpp
src/capi/typeobject.cpp
+160
-57
src/runtime/builtin_modules/time.cpp
src/runtime/builtin_modules/time.cpp
+23
-0
src/runtime/long.cpp
src/runtime/long.cpp
+3
-1
src/runtime/str.cpp
src/runtime/str.cpp
+7
-2
src/runtime/types.cpp
src/runtime/types.cpp
+2
-0
test/tests/datetime_test.py
test/tests/datetime_test.py
+7
-0
No files found.
Makefile
View file @
338af286
...
...
@@ -290,7 +290,7 @@ SRCS := $(MAIN_SRCS) $(STDLIB_SRCS)
STDLIB_OBJS
:=
stdlib.bc.o stdlib.stripped.bc.o
STDLIB_RELEASE_OBJS
:=
stdlib.release.bc.o
STDMODULE_SRCS
:=
errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c pwdmodule.c posixmodule.c _struct.c
$(EXTRA_STDMODULE_SRCS)
STDMODULE_SRCS
:=
errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c pwdmodule.c posixmodule.c _struct.c
datetimemodule.c
$(EXTRA_STDMODULE_SRCS)
STDOBJECT_SRCS
:=
structseq.c capsule.c stringobject.c
$(EXTRA_STDOBJECT_SRCS)
STDPYTHON_SRCS
:=
pyctype.c getargs.c formatter_string.c pystrtod.c dtoa.c
$(EXTRA_STDPYTHON_SRCS)
FROM_CPYTHON_SRCS
:=
$(
addprefix
from_cpython/Modules/,
$(STDMODULE_SRCS)
)
$(
addprefix
from_cpython/Objects/,
$(STDOBJECT_SRCS)
)
$(
addprefix
from_cpython/Python/,
$(STDPYTHON_SRCS)
)
...
...
from_cpython/CMakeLists.txt
View file @
338af286
...
...
@@ -15,7 +15,7 @@ endforeach(STDLIB_FILE)
add_custom_target
(
copy_stdlib ALL DEPENDS
${
STDLIB_TARGETS
}
)
# compile specified files in from_cpython/Modules
file
(
GLOB_RECURSE STDMODULE_SRCS Modules errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c pwdmodule.c posixmodule.c _struct.c
)
file
(
GLOB_RECURSE STDMODULE_SRCS Modules errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c pwdmodule.c posixmodule.c _struct.c
datetimemodule.c
)
# compile specified files in from_cpython/Objects
file
(
GLOB_RECURSE STDOBJECT_SRCS Objects structseq.c capsule.c stringobject.c
)
...
...
from_cpython/Include/datetime.h
0 → 100644
View file @
338af286
// This file is originally from CPython 2.7, with modifications for Pyston
/* datetime.h
*/
#ifndef DATETIME_H
#define DATETIME_H
#ifdef __cplusplus
extern
"C"
{
#endif
/* Fields are packed into successive bytes, each viewed as unsigned and
* big-endian, unless otherwise noted:
*
* byte offset
* 0 year 2 bytes, 1-9999
* 2 month 1 byte, 1-12
* 3 day 1 byte, 1-31
* 4 hour 1 byte, 0-23
* 5 minute 1 byte, 0-59
* 6 second 1 byte, 0-59
* 7 usecond 3 bytes, 0-999999
* 10
*/
/* # of bytes for year, month, and day. */
#define _PyDateTime_DATE_DATASIZE 4
/* # of bytes for hour, minute, second, and usecond. */
#define _PyDateTime_TIME_DATASIZE 6
/* # of bytes for year, month, day, hour, minute, second, and usecond. */
#define _PyDateTime_DATETIME_DATASIZE 10
typedef
struct
{
PyObject_HEAD
long
hashcode
;
/* -1 when unknown */
int
days
;
/* -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS */
int
seconds
;
/* 0 <= seconds < 24*3600 is invariant */
int
microseconds
;
/* 0 <= microseconds < 1000000 is invariant */
}
PyDateTime_Delta
;
typedef
struct
{
PyObject_HEAD
/* a pure abstract base class */
}
PyDateTime_TZInfo
;
/* The datetime and time types have hashcodes, and an optional tzinfo member,
* present if and only if hastzinfo is true.
*/
#define _PyTZINFO_HEAD \
PyObject_HEAD \
long hashcode; \
char hastzinfo;
/* boolean flag */
/* No _PyDateTime_BaseTZInfo is allocated; it's just to have something
* convenient to cast to, when getting at the hastzinfo member of objects
* starting with _PyTZINFO_HEAD.
*/
typedef
struct
{
_PyTZINFO_HEAD
}
_PyDateTime_BaseTZInfo
;
/* All time objects are of PyDateTime_TimeType, but that can be allocated
* in two ways, with or without a tzinfo member. Without is the same as
* tzinfo == None, but consumes less memory. _PyDateTime_BaseTime is an
* internal struct used to allocate the right amount of space for the
* "without" case.
*/
#define _PyDateTime_TIMEHEAD \
_PyTZINFO_HEAD \
unsigned char data[_PyDateTime_TIME_DATASIZE];
typedef
struct
{
_PyDateTime_TIMEHEAD
}
_PyDateTime_BaseTime
;
/* hastzinfo false */
typedef
struct
{
_PyDateTime_TIMEHEAD
PyObject
*
tzinfo
;
}
PyDateTime_Time
;
/* hastzinfo true */
/* All datetime objects are of PyDateTime_DateTimeType, but that can be
* allocated in two ways too, just like for time objects above. In addition,
* the plain date type is a base class for datetime, so it must also have
* a hastzinfo member (although it's unused there).
*/
typedef
struct
{
_PyTZINFO_HEAD
unsigned
char
data
[
_PyDateTime_DATE_DATASIZE
];
}
PyDateTime_Date
;
#define _PyDateTime_DATETIMEHEAD \
_PyTZINFO_HEAD \
unsigned char data[_PyDateTime_DATETIME_DATASIZE];
typedef
struct
{
_PyDateTime_DATETIMEHEAD
}
_PyDateTime_BaseDateTime
;
/* hastzinfo false */
typedef
struct
{
_PyDateTime_DATETIMEHEAD
PyObject
*
tzinfo
;
}
PyDateTime_DateTime
;
/* hastzinfo true */
/* Apply for date and datetime instances. */
#define PyDateTime_GET_YEAR(o) ((((PyDateTime_Date*)o)->data[0] << 8) | \
((PyDateTime_Date*)o)->data[1])
#define PyDateTime_GET_MONTH(o) (((PyDateTime_Date*)o)->data[2])
#define PyDateTime_GET_DAY(o) (((PyDateTime_Date*)o)->data[3])
#define PyDateTime_DATE_GET_HOUR(o) (((PyDateTime_DateTime*)o)->data[4])
#define PyDateTime_DATE_GET_MINUTE(o) (((PyDateTime_DateTime*)o)->data[5])
#define PyDateTime_DATE_GET_SECOND(o) (((PyDateTime_DateTime*)o)->data[6])
#define PyDateTime_DATE_GET_MICROSECOND(o) \
((((PyDateTime_DateTime*)o)->data[7] << 16) | \
(((PyDateTime_DateTime*)o)->data[8] << 8) | \
((PyDateTime_DateTime*)o)->data[9])
/* Apply for time instances. */
#define PyDateTime_TIME_GET_HOUR(o) (((PyDateTime_Time*)o)->data[0])
#define PyDateTime_TIME_GET_MINUTE(o) (((PyDateTime_Time*)o)->data[1])
#define PyDateTime_TIME_GET_SECOND(o) (((PyDateTime_Time*)o)->data[2])
#define PyDateTime_TIME_GET_MICROSECOND(o) \
((((PyDateTime_Time*)o)->data[3] << 16) | \
(((PyDateTime_Time*)o)->data[4] << 8) | \
((PyDateTime_Time*)o)->data[5])
/* Define structure for C API. */
typedef
struct
{
/* type objects */
PyTypeObject
*
DateType
;
PyTypeObject
*
DateTimeType
;
PyTypeObject
*
TimeType
;
PyTypeObject
*
DeltaType
;
PyTypeObject
*
TZInfoType
;
/* constructors */
PyObject
*
(
*
Date_FromDate
)(
int
,
int
,
int
,
PyTypeObject
*
);
PyObject
*
(
*
DateTime_FromDateAndTime
)(
int
,
int
,
int
,
int
,
int
,
int
,
int
,
PyObject
*
,
PyTypeObject
*
);
PyObject
*
(
*
Time_FromTime
)(
int
,
int
,
int
,
int
,
PyObject
*
,
PyTypeObject
*
);
PyObject
*
(
*
Delta_FromDelta
)(
int
,
int
,
int
,
int
,
PyTypeObject
*
);
/* constructors for the DB API */
PyObject
*
(
*
DateTime_FromTimestamp
)(
PyObject
*
,
PyObject
*
,
PyObject
*
);
PyObject
*
(
*
Date_FromTimestamp
)(
PyObject
*
,
PyObject
*
);
}
PyDateTime_CAPI
;
#define PyDateTime_CAPSULE_NAME "datetime.datetime_CAPI"
/* "magic" constant used to partially protect against developer mistakes. */
#define DATETIME_API_MAGIC 0x414548d5
#ifdef Py_BUILD_CORE
/* Macros for type checking when building the Python core. */
#define PyDate_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateType)
#define PyDate_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateType)
#define PyDateTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateTimeType)
#define PyDateTime_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateTimeType)
#define PyTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeType)
#define PyTime_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TimeType)
#define PyDelta_Check(op) PyObject_TypeCheck(op, &PyDateTime_DeltaType)
#define PyDelta_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DeltaType)
#define PyTZInfo_Check(op) PyObject_TypeCheck(op, &PyDateTime_TZInfoType)
#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TZInfoType)
#else
/* Define global variable for the C API and a macro for setting it. */
static
PyDateTime_CAPI
*
PyDateTimeAPI
=
NULL
;
#define PyDateTime_IMPORT \
PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0)
/* Macros for type checking when not building the Python core. */
#define PyDate_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateType)
#define PyDate_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DateType)
#define PyDateTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateTimeType)
#define PyDateTime_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DateTimeType)
#define PyTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TimeType)
#define PyTime_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->TimeType)
#define PyDelta_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DeltaType)
#define PyDelta_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DeltaType)
#define PyTZInfo_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TZInfoType)
#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->TZInfoType)
/* Macros for accessing constructors in a simplified fashion. */
#define PyDate_FromDate(year, month, day) \
PyDateTimeAPI->Date_FromDate(year, month, day, PyDateTimeAPI->DateType)
#define PyDateTime_FromDateAndTime(year, month, day, hour, min, sec, usec) \
PyDateTimeAPI->DateTime_FromDateAndTime(year, month, day, hour, \
min, sec, usec, Py_None, PyDateTimeAPI->DateTimeType)
#define PyTime_FromTime(hour, minute, second, usecond) \
PyDateTimeAPI->Time_FromTime(hour, minute, second, usecond, \
Py_None, PyDateTimeAPI->TimeType)
#define PyDelta_FromDSU(days, seconds, useconds) \
PyDateTimeAPI->Delta_FromDelta(days, seconds, useconds, 1, \
PyDateTimeAPI->DeltaType)
/* Macros supporting the DB API. */
#define PyDateTime_FromTimestamp(args) \
PyDateTimeAPI->DateTime_FromTimestamp( \
(PyObject*) (PyDateTimeAPI->DateTimeType), args, NULL)
#define PyDate_FromTimestamp(args) \
PyDateTimeAPI->Date_FromTimestamp( \
(PyObject*) (PyDateTimeAPI->DateType), args)
#endif
/* Py_BUILD_CORE */
#ifdef __cplusplus
}
#endif
#endif
from_cpython/Include/intobject.h
View file @
338af286
...
...
@@ -38,7 +38,7 @@ PyAPI_DATA(PyTypeObject*) int_cls;
// Pyston changes: these aren't direct macros any more [they potentially could be though]
PyAPI_FUNC
(
bool
)
_PyInt_Check
(
PyObject
*
)
PYSTON_NOEXCEPT
;
#define PyInt_Check(op) _PyInt_Check((PyObject*)
op
)
#define PyInt_Check(op) _PyInt_Check((PyObject*)
(op)
)
#if 0
#define PyInt_Check(op) \
PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_INT_SUBCLASS)
...
...
from_cpython/Include/stringobject.h
View file @
338af286
...
...
@@ -66,7 +66,7 @@ PyAPI_DATA(PyTypeObject*) str_cls;
// Pyston changes: these aren't direct macros any more [they potentially could be though]
PyAPI_FUNC
(
bool
)
_PyString_Check
(
PyObject
*
)
PYSTON_NOEXCEPT
;
#define PyString_Check(op) _PyString_Check((PyObject*)
op
)
#define PyString_Check(op) _PyString_Check((PyObject*)
(op)
)
#if 0
#define PyString_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS)
...
...
from_cpython/Include/timefuncs.h
0 → 100644
View file @
338af286
// This file is originally from CPython 2.7, with modifications for Pyston
/* timefuncs.h
*/
/* Utility function related to timemodule.c. */
#ifndef TIMEFUNCS_H
#define TIMEFUNCS_H
#ifdef __cplusplus
extern
"C"
{
#endif
/* Cast double x to time_t, but raise ValueError if x is too large
* to fit in a time_t. ValueError is set on return iff the return
* value is (time_t)-1 and PyErr_Occurred().
*/
PyAPI_FUNC
(
time_t
)
_PyTime_DoubleToTimet
(
double
x
)
PYSTON_NOEXCEPT
;
/* Get the current time since the epoch in seconds */
PyAPI_FUNC
(
double
)
_PyTime_FloatTime
(
void
)
PYSTON_NOEXCEPT
;
#ifdef __cplusplus
}
#endif
#endif
/* TIMEFUNCS_H */
src/capi/abstract.cpp
View file @
338af286
...
...
@@ -353,4 +353,8 @@ extern "C" int PyObject_IsSubclass(PyObject* derived, PyObject* cls) noexcept {
}
return
recursive_issubclass
(
derived
,
cls
);
}
extern
"C"
PyObject
*
_PyObject_CallFunction_SizeT
(
PyObject
*
callable
,
char
*
format
,
...)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
}
src/capi/object.cpp
View file @
338af286
...
...
@@ -123,4 +123,9 @@ extern "C" int PyObject_RichCompareBool(PyObject* v, PyObject* w, int op) noexce
Py_DECREF
(
res
);
return
ok
;
}
// I'm not sure how we can support this one:
extern
"C"
PyObject
**
_PyObject_GetDictPtr
(
PyObject
*
obj
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
}
src/capi/typeobject.cpp
View file @
338af286
This diff is collapsed.
Click to expand it.
src/runtime/builtin_modules/time.cpp
View file @
338af286
...
...
@@ -26,6 +26,29 @@ namespace pyston {
BoxedModule
*
time_module
;
/* Exposed in timefuncs.h. */
extern
"C"
time_t
_PyTime_DoubleToTimet
(
double
x
)
noexcept
{
time_t
result
;
double
diff
;
result
=
(
time_t
)
x
;
/* How much info did we lose? time_t may be an integral or
* floating type, and we don't know which. If it's integral,
* we don't know whether C truncates, rounds, returns the floor,
* etc. If we lost a second or more, the C rounding is
* unreasonable, or the input just doesn't fit in a time_t;
* call it an error regardless. Note that the original cast to
* time_t can cause a C error too, but nothing we can do to
* worm around that.
*/
diff
=
x
-
(
double
)
result
;
if
(
diff
<=
-
1.0
||
diff
>=
1.0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"timestamp out of range for platform time_t"
);
result
=
(
time_t
)
-
1
;
}
return
result
;
}
Box
*
timeTime
()
{
struct
timeval
now
;
gettimeofday
(
&
now
,
NULL
);
...
...
src/runtime/long.cpp
View file @
338af286
...
...
@@ -144,7 +144,9 @@ extern "C" PyAPI_FUNC(PyObject*) _PyLong_Format(PyObject* aa, int base, int addL
}
extern
"C"
PyObject
*
PyLong_FromDouble
(
double
v
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
BoxedLong
*
rtn
=
new
BoxedLong
();
mpz_init_set_d
(
rtn
->
n
,
v
);
return
rtn
;
}
extern
"C"
PyObject
*
PyLong_FromLong
(
long
ival
)
noexcept
{
...
...
src/runtime/str.cpp
View file @
338af286
...
...
@@ -1716,7 +1716,12 @@ extern "C" int _PyString_Resize(PyObject** pv, Py_ssize_t newsize) noexcept {
return
0
;
}
static
Py_ssize_t
string_buffer_getreadbuf
(
PyObject
*
self
,
Py_ssize_t
index
,
const
void
**
ptr
)
{
extern
"C"
void
PyString_ConcatAndDel
(
register
PyObject
**
pv
,
register
PyObject
*
w
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
Py_ssize_t
string_buffer_getreadbuf
(
PyObject
*
self
,
Py_ssize_t
index
,
const
void
**
ptr
)
noexcept
{
RELEASE_ASSERT
(
index
==
0
,
""
);
// I think maybe this can just be a non-release assert? shouldn't be able to call this with
// the wrong type
...
...
@@ -1727,7 +1732,7 @@ static Py_ssize_t string_buffer_getreadbuf(PyObject* self, Py_ssize_t index, con
return
s
->
s
.
size
();
}
static
Py_ssize_t
string_buffer_getsegcount
(
PyObject
*
o
,
Py_ssize_t
*
lenp
)
{
static
Py_ssize_t
string_buffer_getsegcount
(
PyObject
*
o
,
Py_ssize_t
*
lenp
)
noexcept
{
RELEASE_ASSERT
(
lenp
==
NULL
,
""
);
RELEASE_ASSERT
(
o
->
cls
==
str_cls
,
""
);
...
...
src/runtime/types.cpp
View file @
338af286
...
...
@@ -48,6 +48,7 @@ extern "C" void initbinascii();
extern
"C"
void
initpwd
();
extern
"C"
void
initposix
();
extern
"C"
void
init_struct
();
extern
"C"
void
initdatetime
();
namespace
pyston
{
...
...
@@ -1137,6 +1138,7 @@ void setupRuntime() {
initpwd
();
initposix
();
init_struct
();
initdatetime
();
setupSysEnd
();
...
...
test/tests/datetime_test.py
0 → 100644
View file @
338af286
# Simple datetime test
# Doesn't test much of the functionality, but even importing the module is tough:
import
datetime
print
repr
(
datetime
.
time
())
print
datetime
.
datetime
.
__base__
print
repr
(
datetime
.
datetime
(
1
,
2
,
3
))
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