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
3fc72257
Commit
3fc72257
authored
Oct 06, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #954 from undingen/perf_new4
Use callattr inside PyObject_CallMethod*
parents
270cbee1
c9eed4a1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
66 deletions
+51
-66
src/capi/abstract.cpp
src/capi/abstract.cpp
+51
-66
No files found.
src/capi/abstract.cpp
View file @
3fc72257
...
@@ -527,21 +527,7 @@ extern "C" PyObject* PyObject_CallFunctionObjArgs(PyObject* callable, ...) noexc
...
@@ -527,21 +527,7 @@ extern "C" PyObject* PyObject_CallFunctionObjArgs(PyObject* callable, ...) noexc
}
}
extern
"C"
PyObject
*
PyObject_CallObject
(
PyObject
*
obj
,
PyObject
*
args
)
noexcept
{
extern
"C"
PyObject
*
PyObject_CallObject
(
PyObject
*
obj
,
PyObject
*
args
)
noexcept
{
// TODO do something like this? not sure if this is safe; will people expect that calling into a known function
return
PyEval_CallObjectWithKeywords
(
obj
,
args
,
NULL
);
// won't end up doing a GIL check?
// threading::GLDemoteRegion _gil_demote;
try
{
Box
*
r
;
if
(
args
)
r
=
runtimeCall
(
obj
,
ArgPassSpec
(
0
,
0
,
true
,
false
),
args
,
NULL
,
NULL
,
NULL
,
NULL
);
else
r
=
runtimeCall
(
obj
,
ArgPassSpec
(
0
,
0
,
false
,
false
),
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
return
r
;
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
return
NULL
;
}
}
}
extern
"C"
int
PyObject_AsCharBuffer
(
PyObject
*
obj
,
const
char
**
buffer
,
Py_ssize_t
*
buffer_len
)
noexcept
{
extern
"C"
int
PyObject_AsCharBuffer
(
PyObject
*
obj
,
const
char
**
buffer
,
Py_ssize_t
*
buffer_len
)
noexcept
{
...
@@ -657,36 +643,26 @@ static PyObject* call_function_tail(PyObject* callable, PyObject* args) {
...
@@ -657,36 +643,26 @@ static PyObject* call_function_tail(PyObject* callable, PyObject* args) {
extern
"C"
PyObject
*
PyObject_CallMethod
(
PyObject
*
o
,
const
char
*
name
,
const
char
*
format
,
...)
noexcept
{
extern
"C"
PyObject
*
PyObject_CallMethod
(
PyObject
*
o
,
const
char
*
name
,
const
char
*
format
,
...)
noexcept
{
va_list
va
;
va_list
va
;
PyObject
*
args
;
PyObject
*
args
=
NULL
;
PyObject
*
func
=
NULL
;
PyObject
*
retval
=
NULL
;
PyObject
*
retval
=
NULL
;
if
(
o
==
NULL
||
name
==
NULL
)
if
(
o
==
NULL
||
name
==
NULL
)
return
null_error
();
return
null_error
();
func
=
PyObject_GetAttrString
(
o
,
name
);
ArgPassSpec
argspec
(
0
,
0
,
true
,
false
);
if
(
func
==
NULL
)
{
PyErr_SetString
(
PyExc_AttributeError
,
name
);
return
0
;
}
if
(
!
PyCallable_Check
(
func
))
{
type_error
(
"attribute of type '%.200s' is not callable"
,
func
);
goto
exit
;
}
if
(
format
&&
*
format
)
{
if
(
format
&&
*
format
)
{
va_start
(
va
,
format
);
va_start
(
va
,
format
);
args
=
Py_VaBuildValue
(
format
,
va
);
args
=
Py_VaBuildValue
(
format
,
va
);
va_end
(
va
);
va_end
(
va
);
}
else
args
=
PyTuple_New
(
0
);
retval
=
call_function_tail
(
func
,
args
);
if
(
!
PyTuple_Check
(
args
))
argspec
=
ArgPassSpec
(
1
);
exit:
}
else
/* args gets consumed in call_function_tail */
argspec
=
ArgPassSpec
(
0
);
Py_XDECREF
(
func
);
retval
=
callattrInternal
<
ExceptionStyle
::
CAPI
,
NOT_REWRITABLE
>
(
o
,
internStringMortal
(
name
),
CLASS_OR_INST
,
NULL
,
argspec
,
args
,
NULL
,
NULL
,
NULL
,
NULL
);
if
(
!
retval
&&
!
PyErr_Occurred
())
PyErr_SetString
(
PyExc_AttributeError
,
name
);
return
retval
;
return
retval
;
}
}
...
@@ -698,10 +674,6 @@ extern "C" PyObject* PyObject_CallMethodObjArgs(PyObject* callable, PyObject* na
...
@@ -698,10 +674,6 @@ extern "C" PyObject* PyObject_CallMethodObjArgs(PyObject* callable, PyObject* na
if
(
callable
==
NULL
||
name
==
NULL
)
if
(
callable
==
NULL
||
name
==
NULL
)
return
null_error
();
return
null_error
();
callable
=
PyObject_GetAttr
(
callable
,
name
);
if
(
callable
==
NULL
)
return
NULL
;
/* count the args */
/* count the args */
va_start
(
vargs
,
name
);
va_start
(
vargs
,
name
);
args
=
objargs_mktuple
(
vargs
);
args
=
objargs_mktuple
(
vargs
);
...
@@ -710,7 +682,27 @@ extern "C" PyObject* PyObject_CallMethodObjArgs(PyObject* callable, PyObject* na
...
@@ -710,7 +682,27 @@ extern "C" PyObject* PyObject_CallMethodObjArgs(PyObject* callable, PyObject* na
Py_DECREF
(
callable
);
Py_DECREF
(
callable
);
return
NULL
;
return
NULL
;
}
}
tmp
=
PyObject_Call
(
callable
,
args
,
NULL
);
BoxedString
*
attr
=
(
BoxedString
*
)
name
;
if
(
!
PyString_Check
(
attr
))
{
if
(
PyUnicode_Check
(
attr
))
{
attr
=
(
BoxedString
*
)
_PyUnicode_AsDefaultEncodedString
(
attr
,
NULL
);
if
(
attr
==
NULL
)
return
NULL
;
}
else
{
PyErr_Format
(
TypeError
,
"attribute name must be string, not '%.200s'"
,
Py_TYPE
(
attr
)
->
tp_name
);
return
NULL
;
}
}
internStringMortalInplace
(
attr
);
tmp
=
callattrInternal
<
ExceptionStyle
::
CAPI
,
NOT_REWRITABLE
>
(
callable
,
attr
,
CLASS_OR_INST
,
NULL
,
ArgPassSpec
(
0
,
0
,
true
,
false
),
args
,
NULL
,
NULL
,
NULL
,
NULL
);
if
(
!
tmp
&&
!
PyErr_Occurred
())
PyErr_Format
(
PyExc_AttributeError
,
"'%.50s' object has no attribute '%.400s'"
,
callable
->
cls
->
tp_name
,
PyString_AS_STRING
(
attr
));
Py_DECREF
(
args
);
Py_DECREF
(
args
);
Py_DECREF
(
callable
);
Py_DECREF
(
callable
);
...
@@ -719,42 +711,35 @@ extern "C" PyObject* PyObject_CallMethodObjArgs(PyObject* callable, PyObject* na
...
@@ -719,42 +711,35 @@ extern "C" PyObject* PyObject_CallMethodObjArgs(PyObject* callable, PyObject* na
extern
"C"
PyObject
*
_PyObject_CallMethod_SizeT
(
PyObject
*
o
,
const
char
*
name
,
const
char
*
format
,
...)
noexcept
{
extern
"C"
PyObject
*
_PyObject_CallMethod_SizeT
(
PyObject
*
o
,
const
char
*
name
,
const
char
*
format
,
...)
noexcept
{
// TODO it looks like this could be made much more efficient by calling our callattr(), but
PyObject
*
args
=
NULL
,
*
tmp
;
// I haven't taken the time to verify that that has the same behavior
va_list
vargs
;
va_list
va
;
PyObject
*
args
;
PyObject
*
func
=
NULL
;
PyObject
*
retval
=
NULL
;
if
(
o
==
NULL
||
name
==
NULL
)
if
(
o
==
NULL
||
name
==
NULL
)
return
null_error
();
return
null_error
();
func
=
PyObject_GetAttrString
(
o
,
name
);
ArgPassSpec
argspec
(
0
,
0
,
true
,
false
);
if
(
func
==
NULL
)
{
PyErr_SetString
(
PyExc_AttributeError
,
name
);
return
0
;
}
if
(
!
PyCallable_Check
(
func
))
{
type_error
(
"attribute of type '%.200s' is not callable"
,
func
);
goto
exit
;
}
/* count the args */
if
(
format
&&
*
format
)
{
if
(
format
&&
*
format
)
{
va_start
(
va
,
format
);
va_start
(
vargs
,
format
);
args
=
_Py_VaBuildValue_SizeT
(
format
,
va
);
args
=
_Py_VaBuildValue_SizeT
(
format
,
vargs
);
va_end
(
va
);
va_end
(
vargs
);
if
(
!
PyTuple_Check
(
args
))
argspec
=
ArgPassSpec
(
1
);
}
else
}
else
args
=
PyTuple_New
(
0
);
args
pec
=
ArgPassSpec
(
0
);
retval
=
call_function_tail
(
func
,
args
);
tmp
=
callattrInternal
<
ExceptionStyle
::
CAPI
,
NOT_REWRITABLE
>
(
o
,
internStringMortal
(
name
),
CLASS_OR_INST
,
NULL
,
argspec
,
args
,
NULL
,
NULL
,
NULL
,
NULL
);
if
(
!
tmp
&&
!
PyErr_Occurred
())
PyErr_Format
(
PyExc_AttributeError
,
"'%.50s' object has no attribute '%.400s'"
,
o
->
cls
->
tp_name
,
name
);
exit:
/* args gets consumed in call_function_tail */
Py_XDECREF
(
func
);
return
retval
;
Py_DECREF
(
args
);
Py_DECREF
(
o
);
return
tmp
;
}
}
extern
"C"
Py_ssize_t
PyObject_Size
(
PyObject
*
o
)
noexcept
{
extern
"C"
Py_ssize_t
PyObject_Size
(
PyObject
*
o
)
noexcept
{
...
...
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