Commit 9ab6e447 authored by Mark Florisson's avatar Mark Florisson

Fix refnanny + test tags

parent fed08a41
......@@ -684,6 +684,7 @@ class MemoryViewSliceTransform(CythonTransform):
copy_template = '''
static __Pyx_memviewslice %(copy_name)s(const __Pyx_memviewslice from_mvs) {
__Pyx_RefNannyDeclarations
int i;
__Pyx_memviewslice new_mvs = {0, 0};
struct __pyx_obj_memoryview *from_memview = from_mvs.memview;
......@@ -694,7 +695,7 @@ static __Pyx_memviewslice %(copy_name)s(const __Pyx_memviewslice from_mvs) {
struct __pyx_obj_memoryview *memview_obj = 0;
char mode[] = "%(mode)s";
__Pyx_SetupRefcountContext("%(copy_name)s");
__Pyx_RefNannySetupContext("%(copy_name)s");
shape_tuple = PyTuple_New((Py_ssize_t)(buf->ndim));
if(unlikely(!shape_tuple)) {
......@@ -746,7 +747,7 @@ no_fail:
__Pyx_GOTREF(temp_int);
__Pyx_XDECREF(temp_int); temp_int = 0;
__Pyx_XDECREF(array_obj); array_obj = 0;
__Pyx_FinishRefcountContext();
__Pyx_RefNannyFinishContext();
return new_mvs;
}
......@@ -763,7 +764,9 @@ spec_constants_code = UtilityCode(proto="""
)
memviewslice_cname = u'__Pyx_memviewslice'
memviewslice_declare_code = UtilityCode(proto="""
memviewslice_declare_code = UtilityCode(
proto_block='utility_code_proto_before_types',
proto="""
/* memoryview slice struct */
......@@ -813,7 +816,8 @@ static int __Pyx_ValidateAndInit_memviewslice(
__Pyx_BufFmt_StackElem stack[],
__Pyx_memviewslice *memviewslice) {
__Pyx_SetupRefcountContext("ValidateAndInit_memviewslice");
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("ValidateAndInit_memviewslice");
Py_buffer *buf = &memview->view;
int stride, i, spec = 0, retval = -1;
......@@ -929,7 +933,7 @@ fail:
retval = -1;
no_fail:
__Pyx_FinishRefcountContext();
__Pyx_RefNannyFinishContext();
return retval;
}
......@@ -937,8 +941,9 @@ static int __Pyx_init_memviewslice(
struct __pyx_obj_memoryview *memview,
int ndim,
__Pyx_memviewslice *memviewslice) {
__Pyx_SetupRefcountContext("init_memviewslice");
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("init_memviewslice");
int i, retval=-1;
Py_buffer *buf = &memview->view;
......@@ -975,7 +980,7 @@ fail:
memviewslice->data = 0;
retval = -1;
no_fail:
__Pyx_FinishRefcountContext();
__Pyx_RefNannyFinishContext();
return retval;
}
""")
......
......@@ -93,24 +93,24 @@ def inject_utility_code_stage_factory(context):
return module_node
return inject_utility_code_stage
#class UseUtilityCodeDefinitions(CythonTransform):
# # Temporary hack to use any utility code in nodes' "utility_code_definitions".
# # This should be moved to the code generation phase of the relevant nodes once
# # it is safe to generate CythonUtilityCode at code generation time.
# def __call__(self, node):
# self.scope = node.scope
# return super(UseUtilityCodeDefinitions, self).__call__(node)
#
# def visit_AttributeNode(self, node):
# if node.entry and node.entry.utility_code_definition:
# self.scope.use_utility_code(node.entry.utility_code_definition)
# return node
#
# def visit_NameNode(self, node):
# for e in (node.entry, node.type_entry):
# if e and e.utility_code_definition:
# self.scope.use_utility_code(e.utility_code_definition)
# return node
class UseUtilityCodeDefinitions(CythonTransform):
# Temporary hack to use any utility code in nodes' "utility_code_definitions".
# This should be moved to the code generation phase of the relevant nodes once
# it is safe to generate CythonUtilityCode at code generation time.
def __call__(self, node):
self.scope = node.scope
return super(UseUtilityCodeDefinitions, self).__call__(node)
def visit_AttributeNode(self, node):
if node.entry and node.entry.utility_code_definition:
self.scope.use_utility_code(node.entry.utility_code_definition)
return node
def visit_NameNode(self, node):
for e in (node.entry, node.type_entry):
if e and e.utility_code_definition:
self.scope.use_utility_code(e.utility_code_definition)
return node
#
# Pipeline factories
......@@ -191,7 +191,7 @@ def create_pipeline(context, mode, exclude_classes=()):
DropRefcountingTransform(),
FinalOptimizePhase(context),
GilCheck(),
# UseUtilityCodeDefinitions(context),
UseUtilityCodeDefinitions(context),
]
filtered_stages = []
for s in stages:
......
......@@ -74,7 +74,7 @@ class CythonUtilityCode(object):
self.prefix = prefix
self.requires = requires or []
def get_tree(self):
def get_tree(self, entries_only=False):
from AnalysedTreeTransforms import AutoTestDictTransform
# The AutoTestDictTransform creates the statement "__test__ = {}",
# which when copied into the main ModuleNode overwrites
......@@ -88,6 +88,15 @@ class CythonUtilityCode(object):
tree = parse_from_strings(self.name, self.pyx, context=context)
pipeline = Pipeline.create_pipeline(context, 'pyx', exclude_classes=excludes)
if entries_only:
p = []
for t in pipeline:
p.append(t)
if isinstance(p, ParseTreeTransforms.AnalyseDeclarationsTransform):
break
pipeline = p
transform = ParseTreeTransforms.CnameDirectivesTransform(context)
# InterpretCompilerDirectives already does a cdef declarator check
#before = ParseTreeTransforms.DecoratorTransform
......@@ -107,9 +116,9 @@ class CythonUtilityCode(object):
Declare all entries from the utility code in dest_scope. Code will only
be included for used entries.
"""
self.tree = self.get_tree()
tree = self.get_tree(entries_only=True)
entries = self.tree.scope.entries
entries = tree.scope.entries
entries.pop('__name__')
entries.pop('__file__')
entries.pop('__builtins__')
......@@ -119,8 +128,8 @@ class CythonUtilityCode(object):
entry.utility_code_definition = self
entry.used = used
dest_scope.merge_in(self.tree.scope, merge_unused=True)
self.tree.scope = dest_scope
dest_scope.merge_in(tree.scope, merge_unused=True)
tree.scope = dest_scope
for dep in self.requires:
if dep.is_cython_utility:
......
# mode: run
u'''
>>> f()
>>> g()
......
# mode: run
u'''
>>> f()
>>> g()
......
# mode: run
# tag: numpy
__test__ = {}
def testcase(func):
......
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