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
f75e8ea3
Commit
f75e8ea3
authored
Mar 04, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'django'
parents
88606baf
4c7c0a05
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
151 additions
and
19 deletions
+151
-19
from_cpython/Include/intobject.h
from_cpython/Include/intobject.h
+1
-1
from_cpython/Include/longobject.h
from_cpython/Include/longobject.h
+1
-1
from_cpython/Lib/_abcoll.py
from_cpython/Lib/_abcoll.py
+0
-3
from_cpython/Lib/collections.py
from_cpython/Lib/collections.py
+2
-2
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+3
-0
src/runtime/classobj.cpp
src/runtime/classobj.cpp
+12
-2
src/runtime/classobj.h
src/runtime/classobj.h
+2
-0
src/runtime/int.cpp
src/runtime/int.cpp
+99
-10
src/runtime/long.cpp
src/runtime/long.cpp
+4
-0
test/tests/intmethods.py
test/tests/intmethods.py
+12
-0
test/tests/oldstyle_classes.py
test/tests/oldstyle_classes.py
+14
-0
test/tests/userlist_test.py
test/tests/userlist_test.py
+1
-0
No files found.
from_cpython/Include/intobject.h
View file @
f75e8ea3
...
...
@@ -45,7 +45,7 @@ PyAPI_FUNC(bool) _PyInt_Check(PyObject*) PYSTON_NOEXCEPT;
#endif
#define PyInt_CheckExact(op) (Py_TYPE(op) == &PyInt_Type)
PyAPI_FUNC
(
PyObject
*
)
PyInt_FromString
(
char
*
,
char
**
,
int
)
PYSTON_NOEXCEPT
;
PyAPI_FUNC
(
PyObject
*
)
PyInt_FromString
(
c
onst
c
har
*
,
char
**
,
int
)
PYSTON_NOEXCEPT
;
#ifdef Py_USING_UNICODE
PyAPI_FUNC
(
PyObject
*
)
PyInt_FromUnicode
(
Py_UNICODE
*
,
Py_ssize_t
,
int
)
PYSTON_NOEXCEPT
;
#endif
...
...
from_cpython/Include/longobject.h
View file @
f75e8ea3
...
...
@@ -69,7 +69,7 @@ PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *) PYST
PyAPI_FUNC
(
PY_LONG_LONG
)
PyLong_AsLongLongAndOverflow
(
PyObject
*
,
int
*
)
PYSTON_NOEXCEPT
;
#endif
/* HAVE_LONG_LONG */
PyAPI_FUNC
(
PyObject
*
)
PyLong_FromString
(
char
*
,
char
**
,
int
)
PYSTON_NOEXCEPT
;
PyAPI_FUNC
(
PyObject
*
)
PyLong_FromString
(
c
onst
c
har
*
,
char
**
,
int
)
PYSTON_NOEXCEPT
;
#ifdef Py_USING_UNICODE
PyAPI_FUNC
(
PyObject
*
)
PyLong_FromUnicode
(
Py_UNICODE
*
,
Py_ssize_t
,
int
)
PYSTON_NOEXCEPT
;
#endif
...
...
from_cpython/Lib/_abcoll.py
View file @
f75e8ea3
# Copyright 2007 Google, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
# Pyston change: disable using the _abcoll module for now.
raise
NotImplementedError
()
"""Abstract Base Classes (ABCs) for collections, according to PEP 3119.
DON'T USE THIS MODULE DIRECTLY! The classes here should be imported
...
...
from_cpython/Lib/collections.py
View file @
f75e8ea3
...
...
@@ -2,8 +2,8 @@ __all__ = ['Counter', 'deque', 'defaultdict', 'namedtuple', 'OrderedDict']
# For bootstrapping reasons, the collection ABCs are defined in _abcoll.py.
# They should however be considered an integral part of collections.py.
# Pyston change: disable using the _abcoll module for now.
#
from _abcoll import *
#
import _abcoll
from
_abcoll
import
*
import
_abcoll
# __all__ += _abcoll.__all__
from
_collections
import
deque
,
defaultdict
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
f75e8ea3
...
...
@@ -1138,5 +1138,8 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"classmethod"
,
classmethod_cls
);
builtins_module
->
giveAttr
(
"eval"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
eval
,
UNKNOWN
,
1
,
0
,
false
,
false
),
"eval"
));
BoxedClass
*
buffer_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
NULL
,
0
,
0
,
sizeof
(
Box
),
false
,
"buffer"
);
builtins_module
->
giveAttr
(
"buffer"
,
buffer_cls
);
}
}
src/runtime/classobj.cpp
View file @
f75e8ea3
...
...
@@ -269,11 +269,20 @@ Box* instanceSetitem(Box* _inst, Box* key, Box* value) {
return
runtimeCall
(
setitem_func
,
ArgPassSpec
(
2
),
key
,
value
,
NULL
,
NULL
,
NULL
);
}
Box
*
instanceDelitem
(
Box
*
_inst
,
Box
*
key
)
{
RELEASE_ASSERT
(
_inst
->
cls
==
instance_cls
,
""
);
BoxedInstance
*
inst
=
static_cast
<
BoxedInstance
*>
(
_inst
);
Box
*
delitem_func
=
_instanceGetattribute
(
inst
,
boxStrConstant
(
"__delitem__"
),
true
);
return
runtimeCall
(
delitem_func
,
ArgPassSpec
(
1
),
key
,
NULL
,
NULL
,
NULL
,
NULL
);
}
void
setupClassobj
()
{
classobj_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
BoxedClassobj
::
gcHandler
,
offsetof
(
BoxedClassobj
,
attrs
),
0
,
sizeof
(
BoxedClassobj
),
false
,
"classobj"
);
instance_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
BoxedInstance
::
gcHandler
,
offsetof
(
BoxedInstance
,
attrs
),
0
,
sizeof
(
BoxedInstance
),
false
,
"instance"
);
instance_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
BoxedInstance
::
gcHandler
,
offsetof
(
BoxedInstance
,
attrs
),
offsetof
(
BoxedInstance
,
weakreflist
),
sizeof
(
BoxedInstance
),
false
,
"instance"
);
classobj_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
classobjNew
,
UNKNOWN
,
4
,
0
,
false
,
false
)));
...
...
@@ -294,6 +303,7 @@ void setupClassobj() {
instance_cls
->
giveAttr
(
"__len__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceLen
,
UNKNOWN
,
1
)));
instance_cls
->
giveAttr
(
"__getitem__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceGetitem
,
UNKNOWN
,
2
)));
instance_cls
->
giveAttr
(
"__setitem__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceSetitem
,
UNKNOWN
,
3
)));
instance_cls
->
giveAttr
(
"__delitem__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceDelitem
,
UNKNOWN
,
2
)));
instance_cls
->
freeze
();
}
...
...
src/runtime/classobj.h
View file @
f75e8ea3
...
...
@@ -54,6 +54,8 @@ public:
BoxedClassobj
*
inst_cls
;
Box
**
weakreflist
;
BoxedInstance
(
BoxedClassobj
*
inst_cls
)
:
inst_cls
(
inst_cls
)
{}
DEFAULT_CLASS
(
instance_cls
);
...
...
src/runtime/int.cpp
View file @
f75e8ea3
...
...
@@ -82,6 +82,68 @@ extern "C" int _PyInt_AsInt(PyObject* obj) noexcept {
return
(
int
)
result
;
}
extern
"C"
PyObject
*
PyInt_FromString
(
const
char
*
s
,
char
**
pend
,
int
base
)
noexcept
{
char
*
end
;
long
x
;
Py_ssize_t
slen
;
PyObject
*
sobj
,
*
srepr
;
if
((
base
!=
0
&&
base
<
2
)
||
base
>
36
)
{
PyErr_SetString
(
PyExc_ValueError
,
"int() base must be >= 2 and <= 36"
);
return
NULL
;
}
while
(
*
s
&&
isspace
(
Py_CHARMASK
(
*
s
)))
s
++
;
errno
=
0
;
if
(
base
==
0
&&
s
[
0
]
==
'0'
)
{
x
=
(
long
)
strtoul
(
s
,
&
end
,
base
);
if
(
x
<
0
)
return
PyLong_FromString
(
s
,
pend
,
base
);
}
else
x
=
strtoul
(
s
,
&
end
,
base
);
if
(
end
==
s
||
!
isalnum
(
Py_CHARMASK
(
end
[
-
1
])))
goto
bad
;
while
(
*
end
&&
isspace
(
Py_CHARMASK
(
*
end
)))
end
++
;
if
(
*
end
!=
'\0'
)
{
bad:
slen
=
strlen
(
s
)
<
200
?
strlen
(
s
)
:
200
;
sobj
=
PyString_FromStringAndSize
(
s
,
slen
);
if
(
sobj
==
NULL
)
return
NULL
;
srepr
=
PyObject_Repr
(
sobj
);
Py_DECREF
(
sobj
);
if
(
srepr
==
NULL
)
return
NULL
;
PyErr_Format
(
PyExc_ValueError
,
"invalid literal for int() with base %d: %s"
,
base
,
PyString_AS_STRING
(
srepr
));
Py_DECREF
(
srepr
);
return
NULL
;
}
else
if
(
errno
!=
0
)
return
PyLong_FromString
(
s
,
pend
,
base
);
if
(
pend
)
*
pend
=
end
;
return
PyInt_FromLong
(
x
);
}
#ifdef Py_USING_UNICODE
PyObject
*
PyInt_FromUnicode
(
Py_UNICODE
*
s
,
Py_ssize_t
length
,
int
base
)
noexcept
{
PyObject
*
result
;
char
*
buffer
=
(
char
*
)
PyMem_MALLOC
(
length
+
1
);
if
(
buffer
==
NULL
)
return
PyErr_NoMemory
();
if
(
PyUnicode_EncodeDecimal
(
s
,
length
,
buffer
,
NULL
))
{
PyMem_FREE
(
buffer
);
return
NULL
;
}
result
=
PyInt_FromString
(
buffer
,
NULL
,
base
);
PyMem_FREE
(
buffer
);
return
result
;
}
#endif
BoxedInt
*
interned_ints
[
NUM_INTERNED_INTS
];
// If we don't have fast overflow-checking builtins, provide some slow variants:
...
...
@@ -751,23 +813,50 @@ extern "C" Box* intOct(BoxedInt* self) {
return
new
BoxedString
(
std
::
string
(
buf
,
len
));
}
Box
*
_intNew
(
Box
*
val
)
{
static
Box
*
_intNew
(
Box
*
val
,
Box
*
base
)
{
if
(
isSubclass
(
val
->
cls
,
int_cls
))
{
RELEASE_ASSERT
(
!
base
,
""
);
BoxedInt
*
n
=
static_cast
<
BoxedInt
*>
(
val
);
if
(
val
->
cls
==
int_cls
)
return
n
;
return
new
BoxedInt
(
n
->
n
);
}
else
if
(
val
->
cls
==
str_cls
)
{
int
base_n
;
if
(
!
base
)
base_n
=
10
;
else
{
RELEASE_ASSERT
(
base
->
cls
==
int_cls
,
""
);
base_n
=
static_cast
<
BoxedInt
*>
(
base
)
->
n
;
}
BoxedString
*
s
=
static_cast
<
BoxedString
*>
(
val
);
std
::
istringstream
ss
(
s
->
s
);
int64_t
n
;
ss
>>
n
;
return
new
BoxedInt
(
n
);
RELEASE_ASSERT
(
s
->
s
.
size
()
==
strlen
(
s
->
s
.
c_str
()),
""
);
Box
*
r
=
PyInt_FromString
(
s
->
s
.
c_str
(),
NULL
,
base_n
);
if
(
!
r
)
throwCAPIException
();
assert
(
r
);
return
r
;
}
else
if
(
val
->
cls
==
unicode_cls
)
{
int
base_n
;
if
(
!
base
)
base_n
=
10
;
else
{
RELEASE_ASSERT
(
base
->
cls
==
int_cls
,
""
);
base_n
=
static_cast
<
BoxedInt
*>
(
base
)
->
n
;
}
Box
*
r
=
PyInt_FromUnicode
(
PyUnicode_AS_UNICODE
(
val
),
PyUnicode_GET_SIZE
(
val
),
base_n
);
if
(
!
r
)
throwCAPIException
();
assert
(
r
);
return
r
;
}
else
if
(
val
->
cls
==
float_cls
)
{
RELEASE_ASSERT
(
!
base
,
""
);
double
d
=
static_cast
<
BoxedFloat
*>
(
val
)
->
d
;
return
new
BoxedInt
(
d
);
}
else
{
RELEASE_ASSERT
(
!
base
,
""
);
static
const
std
::
string
int_str
(
"__int__"
);
Box
*
r
=
callattr
(
val
,
&
int_str
,
CallattrFlags
({.
cls_only
=
true
,
.
null_on_nonexistent
=
true
}),
ArgPassSpec
(
0
),
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
...
...
@@ -784,7 +873,7 @@ Box* _intNew(Box* val) {
}
}
extern
"C"
Box
*
intNew
(
Box
*
_cls
,
Box
*
val
)
{
extern
"C"
Box
*
intNew
(
Box
*
_cls
,
Box
*
val
,
Box
*
base
)
{
if
(
!
isSubclass
(
_cls
->
cls
,
type_cls
))
raiseExcHelper
(
TypeError
,
"int.__new__(X): X is not a type object (%s)"
,
getTypeName
(
_cls
));
...
...
@@ -794,9 +883,9 @@ extern "C" Box* intNew(Box* _cls, Box* val) {
getNameOfClass
(
cls
));
if
(
cls
==
int_cls
)
return
_intNew
(
val
);
return
_intNew
(
val
,
base
);
BoxedInt
*
n
=
(
BoxedInt
*
)
_intNew
(
val
);
BoxedInt
*
n
=
(
BoxedInt
*
)
_intNew
(
val
,
base
);
if
(
n
->
cls
==
long_cls
)
{
if
(
cls
==
int_cls
)
return
n
;
...
...
@@ -882,8 +971,8 @@ void setupInt() {
int_cls
->
giveAttr
(
"__hex__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
intHex
,
STR
,
1
)));
int_cls
->
giveAttr
(
"__oct__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
intOct
,
STR
,
1
)));
int_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
intNew
,
UNKNOWN
,
2
,
1
,
false
,
false
),
{
boxInt
(
0
)
}));
int_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
intNew
,
UNKNOWN
,
3
,
2
,
false
,
false
),
{
boxInt
(
0
),
NULL
}));
int_cls
->
giveAttr
(
"__init__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
intInit
,
NONE
,
2
,
1
,
true
,
false
),
{
boxInt
(
0
)
}));
...
...
src/runtime/long.cpp
View file @
f75e8ea3
...
...
@@ -90,6 +90,10 @@ extern "C" PY_LONG_LONG PyLong_AsLongLong(PyObject* vv) noexcept {
Py_FatalError
(
"unimplemented"
);
}
extern
"C"
PyObject
*
PyLong_FromString
(
const
char
*
str
,
char
**
pend
,
int
base
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
int64_t
asSignedLong
(
BoxedLong
*
self
)
{
assert
(
self
->
cls
==
long_cls
);
if
(
!
mpz_fits_slong_p
(
self
->
n
))
...
...
test/tests/intmethods.py
View file @
f75e8ea3
...
...
@@ -60,3 +60,15 @@ class L(object):
def
__int__
(
self
):
return
1L
print
type
(
int
(
L
()))
print
int
(
u'123'
)
for
b
in
range
(
26
):
try
:
print
int
(
'123'
,
b
)
except
ValueError
as
e
:
print
e
try
:
print
int
(
u'123'
,
b
)
except
ValueError
as
e
:
print
e
test/tests/oldstyle_classes.py
View file @
f75e8ea3
...
...
@@ -126,3 +126,17 @@ print g.b
print
g
.
__class__
print
g
.
__dict__
.
items
()
print
bool
(
g
)
class
MappingTest
:
def
__getitem__
(
self
,
key
):
print
"getitem"
,
key
return
1
def
__setitem__
(
self
,
key
,
value
):
print
"setitem"
,
key
,
value
def
__delitem__
(
self
,
key
):
print
"delitem"
,
key
m
=
MappingTest
()
m
[
1
]
=
2
del
m
[
2
]
print
m
[
3
]
test/tests/userlist_test.py
0 → 100644
View file @
f75e8ea3
import
UserList
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