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
0a8385c9
Commit
0a8385c9
authored
Sep 01, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #880 from undingen/wrapper
BoxedWrapper optimizations
parents
8a1b2e08
aacf932f
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
227 additions
and
231 deletions
+227
-231
from_cpython/Include/descrobject.h
from_cpython/Include/descrobject.h
+4
-0
src/capi/typeobject.cpp
src/capi/typeobject.cpp
+180
-227
src/runtime/descr.cpp
src/runtime/descr.cpp
+41
-4
src/runtime/types.cpp
src/runtime/types.cpp
+2
-0
No files found.
from_cpython/Include/descrobject.h
View file @
0a8385c9
...
...
@@ -24,6 +24,8 @@ typedef PyObject *(*wrapperfunc)(PyObject *self, PyObject *args,
typedef
PyObject
*
(
*
wrapperfunc_kwds
)(
PyObject
*
self
,
PyObject
*
args
,
void
*
wrapped
,
PyObject
*
kwds
);
typedef
PyObject
*
(
*
wrapperfunc_1arg
)(
PyObject
*
self
,
void
*
wrapped
);
struct
wrapperbase
{
char
*
name
;
int
offset
;
...
...
@@ -38,6 +40,8 @@ struct wrapperbase {
#define PyWrapperFlag_KEYWORDS 1
/* wrapper function takes keyword args */
#define PyWrapperFlag_PYSTON 2
/* wrapper function is a Pyston function */
#define PyWrapperFlag_BOOL 4
/* not really a wrapper, just set a bool field */
#define PyWrapperFlag_1ARG 8
/* wrapper function takes 1 argument */
#define PyWrapperFlag_2ARG 16
/* wrapper function takes 2 arguments */
/* Various kinds of descriptor objects */
...
...
src/capi/typeobject.cpp
View file @
0a8385c9
This diff is collapsed.
Click to expand it.
src/runtime/descr.cpp
View file @
0a8385c9
...
...
@@ -519,6 +519,17 @@ Box* BoxedWrapperObject::__call__(BoxedWrapperObject* self, Box* args, Box* kwds
rtn
=
(
*
wk
)(
self
->
obj
,
args
,
self
->
descr
->
wrapped
,
kwds
);
}
else
if
(
flags
==
PyWrapperFlag_PYSTON
||
flags
==
0
)
{
rtn
=
(
*
wrapper
)(
self
->
obj
,
args
,
self
->
descr
->
wrapped
);
}
else
if
(
flags
==
PyWrapperFlag_1ARG
)
{
if
(
PyTuple_GET_SIZE
(
args
)
!=
0
)
raiseExcHelper
(
TypeError
,
"%s() takes exactly 1 arguments (%ld given)"
,
self
->
descr
->
wrapper
->
name
.
data
(),
PyTuple_GET_SIZE
(
args
)
+
1
);
wrapperfunc_1arg
wrapper_1arg
=
(
wrapperfunc_1arg
)
wrapper
;
rtn
=
(
*
wrapper_1arg
)(
self
->
obj
,
self
->
descr
->
wrapped
);
}
else
if
(
flags
==
PyWrapperFlag_2ARG
)
{
if
(
PyTuple_GET_SIZE
(
args
)
!=
1
)
raiseExcHelper
(
TypeError
,
"%s() takes exactly 2 arguments (%ld given)"
,
self
->
descr
->
wrapper
->
name
.
data
(),
PyTuple_GET_SIZE
(
args
)
+
1
);
rtn
=
(
*
wrapper
)(
self
->
obj
,
PyTuple_GET_ITEM
(
args
,
0
),
self
->
descr
->
wrapped
);
}
else
{
RELEASE_ASSERT
(
0
,
"%d"
,
flags
);
}
...
...
@@ -559,6 +570,10 @@ Box* BoxedWrapperObject::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgP
paramspec
=
ParamReceiveSpec
(
0
,
0
,
true
,
true
);
}
else
if
(
flags
==
PyWrapperFlag_PYSTON
||
flags
==
0
)
{
paramspec
=
ParamReceiveSpec
(
0
,
0
,
true
,
false
);
}
else
if
(
flags
==
PyWrapperFlag_1ARG
)
{
paramspec
=
ParamReceiveSpec
(
0
,
0
,
false
,
false
);
}
else
if
(
flags
==
PyWrapperFlag_2ARG
)
{
paramspec
=
ParamReceiveSpec
(
1
,
0
,
false
,
false
);
}
else
{
RELEASE_ASSERT
(
0
,
"%d"
,
flags
);
}
...
...
@@ -569,10 +584,8 @@ Box* BoxedWrapperObject::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgP
rearrangeArguments
(
paramspec
,
NULL
,
self
->
descr
->
wrapper
->
name
.
data
(),
NULL
,
rewrite_args
,
rewrite_success
,
argspec
,
arg1
,
arg2
,
arg3
,
args
,
oargs
,
keyword_names
);
if
(
paramspec
.
takes_varargs
)
assert
(
arg1
&&
arg1
->
cls
==
tuple_cls
);
if
(
!
paramspec
.
takes_kwargs
)
assert
(
arg2
==
NULL
);
assert
(
arg3
==
NULL
);
if
(
!
rewrite_success
)
rewrite_args
=
NULL
;
...
...
@@ -594,6 +607,30 @@ Box* BoxedWrapperObject::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgP
}
else
if
(
flags
==
PyWrapperFlag_PYSTON
||
flags
==
0
)
{
rtn
=
(
*
wrapper
)(
self
->
obj
,
arg1
,
self
->
descr
->
wrapped
);
if
(
rewrite_args
)
{
auto
rewriter
=
rewrite_args
->
rewriter
;
auto
r_obj
=
rewrite_args
->
obj
->
getAttr
(
offsetof
(
BoxedWrapperObject
,
obj
),
Location
::
forArg
(
0
));
rewrite_args
->
out_rtn
=
rewriter
->
call
(
true
,
(
void
*
)
wrapper
,
r_obj
,
rewrite_args
->
arg1
,
rewriter
->
loadConst
((
intptr_t
)
self
->
descr
->
wrapped
,
Location
::
forArg
(
2
)));
rewrite_args
->
rewriter
->
checkAndThrowCAPIException
(
rewrite_args
->
out_rtn
);
rewrite_args
->
out_success
=
true
;
}
}
else
if
(
flags
==
PyWrapperFlag_1ARG
)
{
wrapperfunc_1arg
wrapper_1arg
=
(
wrapperfunc_1arg
)
wrapper
;
rtn
=
(
*
wrapper_1arg
)(
self
->
obj
,
self
->
descr
->
wrapped
);
if
(
rewrite_args
)
{
auto
rewriter
=
rewrite_args
->
rewriter
;
auto
r_obj
=
rewrite_args
->
obj
->
getAttr
(
offsetof
(
BoxedWrapperObject
,
obj
),
Location
::
forArg
(
0
));
rewrite_args
->
out_rtn
=
rewriter
->
call
(
true
,
(
void
*
)
wrapper
,
r_obj
,
rewriter
->
loadConst
((
intptr_t
)
self
->
descr
->
wrapped
,
Location
::
forArg
(
1
)));
rewrite_args
->
rewriter
->
checkAndThrowCAPIException
(
rewrite_args
->
out_rtn
);
rewrite_args
->
out_success
=
true
;
}
}
else
if
(
flags
==
PyWrapperFlag_2ARG
)
{
rtn
=
(
*
wrapper
)(
self
->
obj
,
arg1
,
self
->
descr
->
wrapped
);
if
(
rewrite_args
)
{
auto
rewriter
=
rewrite_args
->
rewriter
;
auto
r_obj
=
rewrite_args
->
obj
->
getAttr
(
offsetof
(
BoxedWrapperObject
,
obj
),
Location
::
forArg
(
0
));
...
...
src/runtime/types.cpp
View file @
0a8385c9
...
...
@@ -3353,6 +3353,8 @@ static void setupDefaultClassGCParticipation() {
// hundreds of thousands of unicode strings.
setTypeGCNone
(
unicode_cls
);
unicode_cls
->
gc_visit
=
unicode_visit
;
unicode_cls
->
is_constant
=
true
;
unicode_cls
->
is_user_defined
=
false
;
for
(
BoxedClass
*
cls
:
exception_types
)
{
setTypeGCNone
(
cls
);
...
...
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