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
82e9cdcd
Commit
82e9cdcd
authored
Aug 18, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #847 from kmod/format_fix
descriptor/format fix
parents
97c47267
e497a265
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
54 deletions
+35
-54
src/capi/typeobject.cpp
src/capi/typeobject.cpp
+7
-2
src/runtime/descr.cpp
src/runtime/descr.cpp
+4
-4
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+18
-47
src/runtime/types.h
src/runtime/types.h
+1
-1
test/tests/builtins.py
test/tests/builtins.py
+2
-0
test/tests/float.py
test/tests/float.py
+3
-0
No files found.
src/capi/typeobject.cpp
View file @
82e9cdcd
...
...
@@ -1888,8 +1888,13 @@ static const slotdef* update_one_slot(BoxedClass* type, const slotdef* p) noexce
point out a bug in this reasoning a beer. */
}
else
if
(
offset
==
offsetof
(
BoxedClass
,
tp_descr_get
)
&&
descr
->
cls
==
function_cls
&&
static_cast
<
BoxedFunction
*>
(
descr
)
->
f
->
always_use_version
)
{
type
->
tpp_descr_get
=
(
descrgetfunc
)
static_cast
<
BoxedFunction
*>
(
descr
)
->
f
->
always_use_version
->
code
;
specific
=
(
void
*
)
slot_tp_tpp_descr_get
;
CompiledFunction
*
cf
=
static_cast
<
BoxedFunction
*>
(
descr
)
->
f
->
always_use_version
;
if
(
cf
->
exception_style
==
CXX
)
{
type
->
tpp_descr_get
=
(
descrgetfunc
)
cf
->
code
;
specific
=
(
void
*
)
slot_tp_tpp_descr_get
;
}
else
{
specific
=
cf
->
code
;
}
}
else
if
(
descr
==
Py_None
&&
ptr
==
(
void
**
)
&
type
->
tp_hash
)
{
/* We specifically allow __hash__ to be set to None
to prevent inheritance of the default
...
...
src/runtime/descr.cpp
View file @
82e9cdcd
...
...
@@ -407,7 +407,7 @@ static Box* methodRepr(Box* _o) {
return
PyString_FromFormat
(
"<method '%s' of '%s' objects>"
,
name
,
getNameOfClass
(
md
->
type
));
}
Box
*
BoxedMethodDescriptor
::
__get__
(
BoxedMethodDescriptor
*
self
,
Box
*
inst
,
Box
*
owner
)
{
Box
*
BoxedMethodDescriptor
::
descr_get
(
BoxedMethodDescriptor
*
self
,
Box
*
inst
,
Box
*
owner
)
noexcept
{
RELEASE_ASSERT
(
self
->
cls
==
method_cls
,
""
);
// CPython handles this differently: they create the equivalent of different BoxedMethodDescriptor
...
...
@@ -420,7 +420,7 @@ Box* BoxedMethodDescriptor::__get__(BoxedMethodDescriptor* self, Box* inst, Box*
if
(
self
->
method
->
ml_flags
&
METH_COEXIST
)
Py_FatalError
(
"unimplemented"
);
if
(
inst
==
N
one
)
if
(
inst
==
N
ULL
)
return
self
;
else
return
boxInstanceMethod
(
inst
,
self
,
self
->
type
);
...
...
@@ -653,8 +653,8 @@ void setupDescr() {
"__get__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
classmethodGet
,
UNKNOWN
,
3
,
1
,
false
,
false
),
{
None
}));
classmethod_cls
->
freeze
();
method_cls
->
giveAttr
(
"__get__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedMethodDescriptor
::
__get__
,
UNKNOWN
,
3
)));
method_cls
->
giveAttr
(
"__get__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedMethodDescriptor
::
descr_get
,
UNKNOWN
,
3
,
ParamNames
::
empty
(),
CAPI
)));
CLFunction
*
method_call_cl
=
boxRTFunction
((
void
*
)
BoxedMethodDescriptor
::
__call__
,
UNKNOWN
,
2
,
0
,
true
,
true
);
method_cls
->
giveAttr
(
"__call__"
,
new
BoxedFunction
(
method_call_cl
));
method_cls
->
tpp_call
.
capi_val
=
BoxedMethodDescriptor
::
tppCall
<
CAPI
>
;
...
...
src/runtime/objmodel.cpp
View file @
82e9cdcd
...
...
@@ -1764,63 +1764,34 @@ Box* getattrInternalGeneric(Box* obj, BoxedString* attr, GetattrRewriteArgs* rew
}
// Lookup __get__
RewriterVar
*
r_get
=
NULL
;
Box
*
local_get
;
descrgetfunc
local_get
=
val
->
cls
->
tp_descr_get
;
if
(
rewrite_args
)
{
RewriterVar
*
r_val_cls
=
r_val
->
getAttr
(
offsetof
(
Box
,
cls
),
Location
::
any
());
GetattrRewriteArgs
grewrite_args
(
rewrite_args
->
rewriter
,
r_val_cls
,
Location
::
any
());
local_get
=
typeLookup
(
val
->
cls
,
get_str
,
&
grewrite_args
);
if
(
!
grewrite_args
.
out_success
)
{
rewrite_args
=
NULL
;
}
else
if
(
local_get
)
{
r_get
=
grewrite_args
.
out_rtn
;
}
}
else
{
local_get
=
typeLookup
(
val
->
cls
,
get_str
,
NULL
);
RewriterVar
*
r_cls
=
r_val
->
getAttr
(
offsetof
(
Box
,
cls
));
r_cls
->
addAttrGuard
(
offsetof
(
BoxedClass
,
tp_descr_get
),
(
intptr_t
)
local_get
);
}
// Call __get__(val, None, obj)
if
(
local_get
)
{
Box
*
res
;
if
(
for_call
)
{
#if STAT_CALLATTR_DESCR_ABORTS
if
(
rewrite_args
)
{
std
::
string
attr_name
=
"num_callattr_descr_abort"
;
Stats
::
log
(
Stats
::
getStatCounter
(
attr_name
));
logByCurrentPythonLine
(
attr_name
);
}
#endif
rewrite_args
=
NULL
;
REWRITE_ABORTED
(
""
);
}
if
(
!
local_get
)
{
if
(
rewrite_args
)
{
CallRewriteArgs
crewrite_args
(
rewrite_args
->
rewriter
,
r_get
,
rewrite_args
->
destination
);
crewrite_args
.
arg1
=
r_val
;
crewrite_args
.
arg2
=
rewrite_args
->
rewriter
->
loadConst
((
intptr_t
)
None
,
Location
::
any
());
crewrite_args
.
arg3
=
rewrite_args
->
obj
;
res
=
runtimeCallInternal
<
CXX
>
(
local_get
,
&
crewrite_args
,
ArgPassSpec
(
3
),
val
,
None
,
obj
,
NULL
,
NULL
);
if
(
!
crewrite_args
.
out_success
)
{
rewrite_args
=
NULL
;
}
else
{
rewrite_args
->
out_success
=
true
;
rewrite_args
->
out_rtn
=
crewrite_args
.
out_rtn
;
}
}
else
{
res
=
runtimeCallInternal
<
CXX
>
(
local_get
,
NULL
,
ArgPassSpec
(
3
),
val
,
None
,
obj
,
NULL
,
NULL
);
rewrite_args
->
out_rtn
=
r_val
;
rewrite_args
->
out_success
=
true
;
}
return
res
;
return
val
;
}
// If there was no local __get__, just return val
// Call __get__(val, None, obj)
Box
*
r
=
local_get
(
val
,
NULL
,
obj
);
if
(
!
r
)
throwCAPIException
();
if
(
rewrite_args
)
{
rewrite_args
->
out_rtn
=
r_val
;
rewrite_args
->
out_rtn
=
rewrite_args
->
rewriter
->
call
(
true
,
(
void
*
)
local_get
,
r_val
,
rewrite_args
->
rewriter
->
loadConst
(
0
,
Location
::
forArg
(
1
)),
rewrite_args
->
obj
);
rewrite_args
->
rewriter
->
checkAndThrowCAPIException
(
rewrite_args
->
out_rtn
);
rewrite_args
->
out_success
=
true
;
}
return
val
;
return
r
;
}
}
}
...
...
src/runtime/types.h
View file @
82e9cdcd
...
...
@@ -1017,7 +1017,7 @@ public:
DEFAULT_CLASS
(
method_cls
);
static
Box
*
__get__
(
BoxedMethodDescriptor
*
self
,
Box
*
inst
,
Box
*
owner
)
;
static
Box
*
descr_get
(
BoxedMethodDescriptor
*
self
,
Box
*
inst
,
Box
*
owner
)
noexcept
;
static
Box
*
__call__
(
BoxedMethodDescriptor
*
self
,
Box
*
obj
,
BoxedTuple
*
varargs
,
Box
**
_args
);
template
<
ExceptionStyle
S
>
static
Box
*
tppCall
(
Box
*
_self
,
CallRewriteArgs
*
rewrite_args
,
ArgPassSpec
argspec
,
Box
*
arg1
,
Box
*
arg2
,
Box
*
arg3
,
...
...
test/tests/builtins.py
View file @
82e9cdcd
...
...
@@ -123,3 +123,5 @@ print apply(sorted, [l], { "reverse" : True })
print
format
(
5.0
,
'+'
)
print
format
(
5.011111111111
,
'+.6'
)
print
format
(
"abc"
,
''
)
print
'{n}'
.
format
(
n
=
None
)
test/tests/float.py
View file @
82e9cdcd
...
...
@@ -105,3 +105,6 @@ for lhs in all_args:
print
pow
(
lhs
,
rhs
,
mod
)
except
Exception
as
e
:
print
type
(
e
),
e
import
sys
print
sys
.
float_info
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