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
7f84725f
Commit
7f84725f
authored
May 24, 2016
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reenable rewriting for method-descriptors
parent
0751c27f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
29 deletions
+42
-29
from_cpython/Objects/descrobject.c
from_cpython/Objects/descrobject.c
+6
-0
src/runtime/descr.cpp
src/runtime/descr.cpp
+34
-29
test/tests/methoddescr.py
test/tests/methoddescr.py
+2
-0
No files found.
from_cpython/Objects/descrobject.c
View file @
7f84725f
...
...
@@ -211,6 +211,11 @@ getset_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value)
static
PyObject
*
methoddescr_call
(
PyMethodDescrObject
*
descr
,
PyObject
*
args
,
PyObject
*
kwds
)
{
// Pyston overrides this with an optimized version
assert
(
0
&&
"This shouldn't be getting hit any more"
);
abort
();
#if 0
Py_ssize_t argc;
PyObject *self, *func, *result;
...
...
@@ -250,6 +255,7 @@ methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwds)
Py_DECREF(args);
Py_DECREF(func);
return result;
#endif
}
static
PyObject
*
...
...
src/runtime/descr.cpp
View file @
7f84725f
...
...
@@ -226,14 +226,12 @@ static Box* classmethodGet(Box* self, Box* obj, Box* type) {
return
new
BoxedInstanceMethod
(
type
,
cm
->
cm_callable
,
type
);
}
#if 0
template
<
ExceptionStyle
S
>
Box* BoxedMethodDescriptor::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1,
Box* arg2, Box* arg3, Box** args,
const std::vector<BoxedString*>* keyword_names) noexcept(S == CAPI) {
Box
*
methodDescrTppCall
(
Box
*
_self
,
CallRewriteArgs
*
rewrite_args
,
ArgPassSpec
argspec
,
Box
*
arg1
,
Box
*
arg2
,
Box
*
arg3
,
Box
**
args
,
const
std
::
vector
<
BoxedString
*>*
keyword_names
)
noexcept
(
S
==
CAPI
)
{
if
(
S
==
CAPI
)
{
try
{
return
t
ppCall<CXX>(_self, NULL, argspec, arg1, arg2, arg3, args, keyword_names);
return
methodDescrT
ppCall
<
CXX
>
(
_self
,
NULL
,
argspec
,
arg1
,
arg2
,
arg3
,
args
,
keyword_names
);
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
return
NULL
;
...
...
@@ -242,14 +240,16 @@ Box* BoxedMethodDescriptor::tppCall(Box* _self, CallRewriteArgs* rewrite_args, A
STAT_TIMER
(
t0
,
"us_timer_boxedmethoddescriptor__call__"
,
10
);
assert(_self->cls ==
method_cls
);
BoxedMethodDescriptor* self = static_cast<BoxedMethodDescriptor
*>(_self);
assert
(
_self
->
cls
==
&
PyMethodDescr_Type
||
_self
->
cls
==
&
PyClassMethodDescr_Type
);
PyMethodDescrObject
*
self
=
reinterpret_cast
<
PyMethodDescrObject
*>
(
_self
);
int ml_flags = self->method->ml_flags;
bool
is_classmethod
=
(
_self
->
cls
==
&
PyClassMethodDescr_Type
);
int
ml_flags
=
self
->
d_method
->
ml_flags
;
int
call_flags
=
ml_flags
&
~
(
METH_CLASS
|
METH_COEXIST
|
METH_STATIC
);
if
(
rewrite_args
&&
!
rewrite_args
->
func_guarded
)
{
rewrite_args->obj->addAttrGuard(offsetof(
BoxedMethodDescriptor, method), (intptr_t)self->
method);
rewrite_args
->
obj
->
addAttrGuard
(
offsetof
(
PyMethodDescrObject
,
d_method
),
(
intptr_t
)
self
->
d_
method
);
}
ParamReceiveSpec
paramspec
(
0
,
0
,
false
,
false
);
...
...
@@ -293,16 +293,15 @@ Box* BoxedMethodDescriptor::tppCall(Box* _self, CallRewriteArgs* rewrite_args, A
}
auto
continuation
=
[
=
](
CallRewriteArgs
*
rewrite_args
,
Box
*
arg1
,
Box
*
arg2
,
Box
*
arg3
,
Box
**
args
)
{
if (
ml_flags & METH_CLASS
) {
if
(
is_classmethod
)
{
rewrite_args
=
NULL
;
if
(
!
PyType_Check
(
arg1
))
raiseExcHelper(TypeError, "descriptor '%s' requires a type but received a '%s'",
self->method->ml_name,
getFullTypeName(arg1).c_str());
raiseExcHelper
(
TypeError
,
"descriptor '%s' requires a type but received a '%s'"
,
self
->
d_method
->
ml_name
,
getFullTypeName
(
arg1
).
c_str
());
}
else
{
if (!isSubclass(arg1->cls, self->type))
if
(
!
isSubclass
(
arg1
->
cls
,
self
->
d_
type
))
raiseExcHelper
(
TypeError
,
"descriptor '%s' requires a '%s' arg1 but received a '%s'"
,
self->method->ml_name, getFullNameOfClass(self->type).c_str(),
getFullTypeName(arg1).c_str());
self
->
d_method
->
ml_name
,
self
->
d_type
->
tp_name
,
getFullTypeName
(
arg1
).
c_str
());
}
if
(
rewrite_args
&&
!
arg1_class_guarded
)
{
...
...
@@ -313,57 +312,57 @@ Box* BoxedMethodDescriptor::tppCall(Box* _self, CallRewriteArgs* rewrite_args, A
if
(
call_flags
==
METH_NOARGS
)
{
{
UNAVOIDABLE_STAT_TIMER
(
t0
,
"us_timer_in_builtins"
);
rtn = (Box*)self->method->ml_meth(arg1, NULL);
rtn
=
(
Box
*
)
self
->
d_
method
->
ml_meth
(
arg1
,
NULL
);
}
if
(
rewrite_args
)
rewrite_args
->
out_rtn
= rewrite_args->rewriter->call(true, (void*)self->method->ml_meth, rewrite_args->arg1,
=
rewrite_args
->
rewriter
->
call
(
true
,
(
void
*
)
self
->
d_
method
->
ml_meth
,
rewrite_args
->
arg1
,
rewrite_args
->
rewriter
->
loadConst
(
0
,
Location
::
forArg
(
1
)))
->
setType
(
RefType
::
OWNED
);
}
else
if
(
call_flags
==
METH_VARARGS
)
{
{
UNAVOIDABLE_STAT_TIMER
(
t0
,
"us_timer_in_builtins"
);
rtn = (Box*)self->method->ml_meth(arg1, arg2);
rtn
=
(
Box
*
)
self
->
d_
method
->
ml_meth
(
arg1
,
arg2
);
}
if
(
rewrite_args
)
rewrite_args
->
out_rtn
= rewrite_args->rewriter->call(true, (void*)self->method->ml_meth, rewrite_args->arg1,
=
rewrite_args
->
rewriter
->
call
(
true
,
(
void
*
)
self
->
d_
method
->
ml_meth
,
rewrite_args
->
arg1
,
rewrite_args
->
arg2
)
->
setType
(
RefType
::
OWNED
);
}
else
if
(
call_flags
==
(
METH_VARARGS
|
METH_KEYWORDS
))
{
{
UNAVOIDABLE_STAT_TIMER
(
t0
,
"us_timer_in_builtins"
);
rtn = (Box*)((PyCFunctionWithKeywords)self->method->ml_meth)(arg1, arg2, arg3);
rtn
=
(
Box
*
)((
PyCFunctionWithKeywords
)
self
->
d_
method
->
ml_meth
)(
arg1
,
arg2
,
arg3
);
}
if
(
rewrite_args
)
rewrite_args
->
out_rtn
= rewrite_args->rewriter->call(true, (void*)self->method->ml_meth, rewrite_args->arg1,
=
rewrite_args
->
rewriter
->
call
(
true
,
(
void
*
)
self
->
d_
method
->
ml_meth
,
rewrite_args
->
arg1
,
rewrite_args
->
arg2
,
rewrite_args
->
arg3
)
->
setType
(
RefType
::
OWNED
);
}
else
if
(
call_flags
==
METH_O
)
{
{
UNAVOIDABLE_STAT_TIMER
(
t0
,
"us_timer_in_builtins"
);
rtn = (Box*)self->method->ml_meth(arg1, arg2);
rtn
=
(
Box
*
)
self
->
d_
method
->
ml_meth
(
arg1
,
arg2
);
}
if
(
rewrite_args
)
rewrite_args
->
out_rtn
= rewrite_args->rewriter->call(true, (void*)self->method->ml_meth, rewrite_args->arg1,
=
rewrite_args
->
rewriter
->
call
(
true
,
(
void
*
)
self
->
d_
method
->
ml_meth
,
rewrite_args
->
arg1
,
rewrite_args
->
arg2
)
->
setType
(
RefType
::
OWNED
);
}
else
if
((
call_flags
&
~
(
METH_O3
|
METH_D3
))
==
0
)
{
{
UNAVOIDABLE_STAT_TIMER
(
t0
,
"us_timer_in_builtins"
);
rtn = ((Box * (*)(Box*, Box*, Box*, Box**))self->method->ml_meth)(arg1, arg2, arg3, args);
rtn
=
((
Box
*
(
*
)(
Box
*
,
Box
*
,
Box
*
,
Box
**
))
self
->
d_
method
->
ml_meth
)(
arg1
,
arg2
,
arg3
,
args
);
}
if
(
rewrite_args
)
{
if
(
paramspec
.
totalReceived
()
==
2
)
rewrite_args
->
out_rtn
= rewrite_args->rewriter->call(true, (void*)self->method->ml_meth, rewrite_args->arg1,
=
rewrite_args
->
rewriter
->
call
(
true
,
(
void
*
)
self
->
d_
method
->
ml_meth
,
rewrite_args
->
arg1
,
rewrite_args
->
arg2
)
->
setType
(
RefType
::
OWNED
);
else
if
(
paramspec
.
totalReceived
()
==
3
)
rewrite_args
->
out_rtn
= rewrite_args->rewriter->call(true, (void*)self->method->ml_meth, rewrite_args->arg1,
=
rewrite_args
->
rewriter
->
call
(
true
,
(
void
*
)
self
->
d_
method
->
ml_meth
,
rewrite_args
->
arg1
,
rewrite_args
->
arg2
,
rewrite_args
->
arg3
)
->
setType
(
RefType
::
OWNED
);
else
if
(
paramspec
.
totalReceived
()
>
3
)
rewrite_args
->
out_rtn
= rewrite_args->rewriter->call(true, (void*)self->method->ml_meth, rewrite_args->arg1,
=
rewrite_args
->
rewriter
->
call
(
true
,
(
void
*
)
self
->
d_
method
->
ml_meth
,
rewrite_args
->
arg1
,
rewrite_args
->
arg2
,
rewrite_args
->
arg3
,
rewrite_args
->
args
)
->
setType
(
RefType
::
OWNED
);
else
...
...
@@ -384,10 +383,9 @@ Box* BoxedMethodDescriptor::tppCall(Box* _self, CallRewriteArgs* rewrite_args, A
return
rtn
;
};
return rearrangeArgumentsAndCall(paramspec, NULL, self->method->ml_name, defaults, rewrite_args, argspec, arg1,
return
rearrangeArgumentsAndCall
(
paramspec
,
NULL
,
self
->
d_
method
->
ml_name
,
defaults
,
rewrite_args
,
argspec
,
arg1
,
arg2
,
arg3
,
args
,
keyword_names
,
continuation
);
}
#endif
void
BoxedProperty
::
dealloc
(
Box
*
_self
)
noexcept
{
BoxedProperty
*
self
=
static_cast
<
BoxedProperty
*>
(
_self
);
...
...
@@ -640,7 +638,14 @@ void setupDescr() {
PyWrapperDescr_Type
.
tp_call
=
proxyToTppCall
;
PyType_Ready
(
&
PyWrapperDescr_Type
);
PyMethodDescr_Type
.
tpp_call
.
capi_val
=
methodDescrTppCall
<
CAPI
>
;
PyMethodDescr_Type
.
tpp_call
.
cxx_val
=
methodDescrTppCall
<
CXX
>
;
PyMethodDescr_Type
.
tp_call
=
proxyToTppCall
;
PyType_Ready
(
&
PyMethodDescr_Type
);
PyClassMethodDescr_Type
.
tpp_call
.
capi_val
=
methodDescrTppCall
<
CAPI
>
;
PyClassMethodDescr_Type
.
tpp_call
.
cxx_val
=
methodDescrTppCall
<
CXX
>
;
PyClassMethodDescr_Type
.
tp_call
=
proxyToTppCall
;
PyType_Ready
(
&
PyClassMethodDescr_Type
);
}
}
test/tests/methoddescr.py
0 → 100644
View file @
7f84725f
for
i
in
xrange
(
1000
):
print
float
.
__dict__
[
'fromhex'
](
float
,
"f0.04a"
)
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