Skip to content

Commit

Permalink
Merge branch '0.23.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
scoder committed Sep 15, 2015
2 parents a3522a8 + 2c9d175 commit 0f33914
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Other changes
Bugs fixed
----------

* Invalid C code for some builtin methods. This fixes ticket 856 again.

* Incorrect C code in helper functions for PyLong conversion and string
decoding. This fixes ticket 863, ticket 864 and ticket 865.
Original patch by Nikolaus Rath.
Expand Down
4 changes: 4 additions & 0 deletions Cython/Compiler/Optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4212,6 +4212,10 @@ def visit_SimpleCallNode(self, node):
assignment.rhs and not isinstance(assignment.rhs, non_method_nodes)
for assignment in entry.cf_assignments)
if may_be_a_method:
if (node.self and function.is_attribute and
isinstance(function.obj, ExprNodes.CloneNode) and function.obj.arg is node.self):
# function self object was moved into a CloneNode => undo
function.obj = function.obj.arg
node = self.replace(node, ExprNodes.PyMethodCallNode.from_node(
node, function=function, arg_tuple=node.arg_tuple, type=node.type))
return node
Expand Down
34 changes: 28 additions & 6 deletions Cython/Compiler/Visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ def __init__(self, *args):
def visit_CloneNode(self, node):
arg = node.arg
if arg not in self._replacements:
self.visitchildren(node)
arg = node.arg
self.visitchildren(arg)
node.arg = self._replacements.get(arg, arg)
return node

Expand Down Expand Up @@ -679,6 +678,13 @@ def __init__(self, orig_node, new_node):
super(RecursiveNodeReplacer, self).__init__()
self.orig_node, self.new_node = orig_node, new_node

def visit_CloneNode(self, node):
if node is self.orig_node:
return self.new_node
if node.arg is self.orig_node:
node.arg = self.new_node
return node

def visit_Node(self, node):
self.visitchildren(node)
if node is self.orig_node:
Expand Down Expand Up @@ -725,6 +731,7 @@ def replace_node(ptr, value):
else:
getattr(parent, attrname)[listidx] = value


class PrintTree(TreeVisitor):
"""Prints a representation of the tree to standard output.
Subclass and override repr_of to provide more information
Expand Down Expand Up @@ -753,6 +760,25 @@ def __call__(self, tree, phase=None):
# under the parent-node, not displaying the list itself in
# the hierarchy.
def visit_Node(self, node):
self._print_node(node)
self.indent()
self.visitchildren(node)
self.unindent()
return node

def visit_CloneNode(self, node):
self._print_node(node)
self.indent()
line = node.pos[1]
if self._line_range is None or self._line_range[0] <= line <= self._line_range[1]:
print("%s- %s: %s" % (self._indent, 'arg', self.repr_of(node.arg)))
self.indent()
self.visitchildren(node.arg)
self.unindent()
self.unindent()
return node

def _print_node(self, node):
line = node.pos[1]
if self._line_range is None or self._line_range[0] <= line <= self._line_range[1]:
if len(self.access_path) == 0:
Expand All @@ -764,10 +790,6 @@ def visit_Node(self, node):
else:
name = attr
print("%s- %s: %s" % (self._indent, name, self.repr_of(node)))
self.indent()
self.visitchildren(node)
self.unindent()
return node

def repr_of(self, node):
if node is None:
Expand Down

0 comments on commit 0f33914

Please sign in to comment.