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

Fix refnanny + test tags

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