Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
a85eea00
Commit
a85eea00
authored
Sep 22, 2008
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
isinstance uses PyObject_TypeCheck when second argument is a type
parent
e92a6012
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
9 deletions
+37
-9
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+2
-1
Cython/Compiler/Main.py
Cython/Compiler/Main.py
+2
-2
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+28
-1
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+4
-4
Cython/Includes/python_object.pxd
Cython/Includes/python_object.pxd
+1
-1
No files found.
Cython/Compiler/Builtin.py
View file @
a85eea00
...
...
@@ -181,7 +181,8 @@ def init_builtins():
init_builtin_funcs
()
init_builtin_types
()
init_builtin_structs
()
global
list_type
,
tuple_type
,
dict_type
,
unicode_type
global
list_type
,
tuple_type
,
dict_type
,
unicode_type
,
type_type
type_type
=
builtin_scope
.
lookup
(
'type'
).
type
list_type
=
builtin_scope
.
lookup
(
'list'
).
type
tuple_type
=
builtin_scope
.
lookup
(
'tuple'
).
type
dict_type
=
builtin_scope
.
lookup
(
'dict'
).
type
...
...
Cython/Compiler/Main.py
View file @
a85eea00
...
...
@@ -81,7 +81,7 @@ class Context:
from
ParseTreeTransforms
import
CreateClosureClasses
,
MarkClosureVisitor
,
DecoratorTransform
from
ParseTreeTransforms
import
InterpretCompilerDirectives
from
AutoDocTransforms
import
EmbedSignature
from
Optimize
import
FlattenInListTransform
,
SwitchTransform
,
OptimizeRefcounting
from
Optimize
import
FlattenInListTransform
,
SwitchTransform
,
FinalOptimizePhase
from
Buffer
import
IntroduceBufferAuxiliaryVars
from
ModuleNode
import
check_c_classes
...
...
@@ -106,7 +106,7 @@ class Context:
_check_c_classes
,
AnalyseExpressionsTransform
(
self
),
SwitchTransform
(),
OptimizeRefcounting
(
self
),
FinalOptimizePhase
(
self
),
# SpecialFunctions(self),
# CreateClosureClasses(context),
]
...
...
Cython/Compiler/Optimize.py
View file @
a85eea00
...
...
@@ -140,7 +140,15 @@ class FlattenInListTransform(Visitor.VisitorTransform):
return
node
class
OptimizeRefcounting
(
Visitor
.
CythonTransform
):
class
FinalOptimizePhase
(
Visitor
.
CythonTransform
):
"""
This visitor handles several commuting optimizations, and is run
just before the C code generation phase.
The optimizations currently implemented in this class are:
- Eliminate None assignment and refcounting for first assignment.
- isinstance -> typecheck for cdef types
"""
def
visit_SingleAssignmentNode
(
self
,
node
):
if
node
.
first
:
lhs
=
node
.
lhs
...
...
@@ -152,3 +160,22 @@ class OptimizeRefcounting(Visitor.CythonTransform):
lhs
.
skip_assignment_decref
=
True
return
node
def
visit_SimpleCallNode
(
self
,
node
):
self
.
visitchildren
(
node
)
if
node
.
function
.
type
.
is_cfunction
:
if
node
.
function
.
name
==
'isinstance'
:
type_arg
=
node
.
args
[
1
]
if
type_arg
.
type
.
is_builtin_type
and
type_arg
.
type
.
name
==
'type'
:
object_module
=
self
.
context
.
find_module
(
'python_object'
)
node
.
function
.
entry
=
object_module
.
lookup
(
'PyObject_TypeCheck'
)
node
.
function
.
type
=
node
.
function
.
entry
.
type
PyTypeObjectPtr
=
PyrexTypes
.
CPtrType
(
object_module
.
lookup
(
'PyTypeObject'
).
type
)
node
.
args
[
1
]
=
ExprNodes
.
CastNode
(
node
.
args
[
1
],
PyTypeObjectPtr
)
# Remove when result_code stuff is put in its proper place...
node
.
function
.
result_code
=
node
.
function
.
entry
.
cname
node
.
args
[
1
].
result_code
=
node
.
args
[
1
].
arg
.
result_as
(
PyTypeObjectPtr
)
if
node
.
is_temp
:
node
.
allocate_temp
(
None
,
node
.
result_code
)
else
:
node
.
allocate_temp
(
None
)
return
node
Cython/Compiler/Symtab.py
View file @
a85eea00
...
...
@@ -6,8 +6,7 @@ import re
from
Cython
import
Utils
from
Errors
import
warning
,
error
,
InternalError
from
StringEncoding
import
EncodedString
import
Options
import
Naming
import
Options
,
Naming
import
PyrexTypes
from
PyrexTypes
import
py_object_type
import
TypeSlots
...
...
@@ -711,7 +710,7 @@ class BuiltinScope(Scope):
entry = self.declare_type(name, type, None, visibility='extern')
var_entry = Entry(name = entry.name,
type =
py_object_type,
type =
self.lookup('type').type, # make sure "
type
" is the first type declared...
pos = entry.pos,
cname = "
((
PyObject
*
)
%
s
)
" % entry.type.typeptr_cname)
var_entry.is_variable = 1
...
...
@@ -1110,8 +1109,9 @@ class ModuleScope(Scope):
# variable entry attached to it. For the variable entry,
# we use a read-only C global variable whose name is an
# expression that refers to the type object.
import Builtin
var_entry = Entry(name = entry.name,
type =
py_object
_type,
type =
Builtin.type
_type,
pos = entry.pos,
cname = "((PyObject*)%s)" % entry.type.typeptr_cname)
var_entry.is_variable = 1
...
...
Cython/Includes/python_object.pxd
View file @
a85eea00
...
...
@@ -233,7 +233,7 @@ cdef extern from "Python.h":
# pointer of type PyTypeObject*, except when the incremented
# reference count is needed.
bint
PyObject_TypeCheck
(
object
o
,
object
type
)
# object o,
PyTypeObject *type)
bint
PyObject_TypeCheck
(
object
o
,
PyTypeObject
*
type
)
# Return true if the object o is of type type or a subtype of
# type. Both parameters must be non-NULL.
...
...
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