Commit e1a4ad15 authored by Stefan Behnel's avatar Stefan Behnel

make buffer auxilary variables anonymous and keep anonymous variables from...

make buffer auxilary variables anonymous and keep anonymous variables from appearing in locals() and cyfunction.func_code.varnames
parent 689b3f61
...@@ -65,14 +65,14 @@ class IntroduceBufferAuxiliaryVars(CythonTransform): ...@@ -65,14 +65,14 @@ class IntroduceBufferAuxiliaryVars(CythonTransform):
# Declare auxiliary vars # Declare auxiliary vars
cname = scope.mangle(Naming.bufstruct_prefix, name) cname = scope.mangle(Naming.bufstruct_prefix, name)
bufinfo = scope.declare_var(name="$%s" % cname, cname=cname, bufinfo = scope.declare_var(name=None, cname=cname,
type=PyrexTypes.c_py_buffer_type, pos=node.pos) type=PyrexTypes.c_py_buffer_type, pos=node.pos)
if entry.is_arg: if entry.is_arg:
bufinfo.used = True # otherwise, NameNode will mark whether it is used bufinfo.used = True # otherwise, NameNode will mark whether it is used
def var(prefix, idx, initval): def var(prefix, idx, initval):
cname = scope.mangle(prefix, "%d_%s" % (idx, name)) cname = scope.mangle(prefix, "%d_%s" % (idx, name))
result = scope.declare_var("$%s" % cname, PyrexTypes.c_py_ssize_t_type, result = scope.declare_var(None, PyrexTypes.c_py_ssize_t_type,
node.pos, cname=cname, is_cdef=True) node.pos, cname=cname, is_cdef=True)
result.init = initval result.init = initval
......
...@@ -5270,7 +5270,7 @@ class CodeObjectNode(ExprNode): ...@@ -5270,7 +5270,7 @@ class CodeObjectNode(ExprNode):
if def_node.starstar_arg: if def_node.starstar_arg:
args.append(def_node.starstar_arg) args.append(def_node.starstar_arg)
local_vars = [ arg for arg in def_node.local_scope.var_entries local_vars = [ arg for arg in def_node.local_scope.var_entries
if arg.name and arg.type.is_pyobject ] if arg.name ]
self.varnames = TupleNode( self.varnames = TupleNode(
def_node.pos, def_node.pos,
args = [ IdentifierStringNode(arg.pos, unicode_value=arg.name, args = [ IdentifierStringNode(arg.pos, unicode_value=arg.name,
......
...@@ -2258,6 +2258,7 @@ class TransformBuiltinMethods(EnvTransform): ...@@ -2258,6 +2258,7 @@ class TransformBuiltinMethods(EnvTransform):
# not the builtin # not the builtin
return node return node
pos = node.pos pos = node.pos
local_names = [ var.name for var in lenv.entries.values() if var.name ]
if func_name in ('locals', 'vars'): if func_name in ('locals', 'vars'):
if func_name == 'locals' and len(node.args) > 0: if func_name == 'locals' and len(node.args) > 0:
error(self.pos, "Builtin 'locals()' called with wrong number of args, expected 0, got %d" error(self.pos, "Builtin 'locals()' called with wrong number of args, expected 0, got %d"
...@@ -2270,9 +2271,9 @@ class TransformBuiltinMethods(EnvTransform): ...@@ -2270,9 +2271,9 @@ class TransformBuiltinMethods(EnvTransform):
if len(node.args) > 0: if len(node.args) > 0:
return node # nothing to do return node # nothing to do
items = [ ExprNodes.DictItemNode(pos, items = [ ExprNodes.DictItemNode(pos,
key=ExprNodes.StringNode(pos, value=var), key=ExprNodes.IdentifierStringNode(pos, value=var),
value=ExprNodes.NameNode(pos, name=var, allow_null=True)) value=ExprNodes.NameNode(pos, name=var, allow_null=True))
for var in lenv.entries ] for var in local_names ]
return ExprNodes.DictNode(pos, key_value_pairs=items, exclude_null_values=True) return ExprNodes.DictNode(pos, key_value_pairs=items, exclude_null_values=True)
else: # dir() else: # dir()
if len(node.args) > 1: if len(node.args) > 1:
...@@ -2281,7 +2282,8 @@ class TransformBuiltinMethods(EnvTransform): ...@@ -2281,7 +2282,8 @@ class TransformBuiltinMethods(EnvTransform):
if len(node.args) > 0: if len(node.args) > 0:
# optimised in Builtin.py # optimised in Builtin.py
return node return node
items = [ ExprNodes.StringNode(pos, value=var) for var in lenv.entries ] items = [ ExprNodes.IdentifierStringNode(pos, value=var)
for var in local_names ]
return ExprNodes.ListNode(pos, args=items) return ExprNodes.ListNode(pos, args=items)
def visit_SimpleCallNode(self, node): def visit_SimpleCallNode(self, node):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment