Ticket #545 (new defect)
Opened 3 years ago
Compiler crash with C++ templates/buffers
| Reported by: | robertwb | Owned by: | dagss |
|---|---|---|---|
| Priority: | major | Milestone: | wishlist |
| Component: | Buffers | Keywords: | |
| Cc: |
Description
My bad,
the error actually goes away when I change to void *:
- the return type of myFactory
- the ptr local variable of myFactory
- the ptr local variable of called_by_python
I also must explicit the template argument of myTemplateObject when doing the "new", like so:
ptr = new cxx.myTemplateObject[float](<float *>stuff.data)
Sorry about that,
Lionel
2010/6/18 Lionel Data <lionel.data@gmail.com>
Hi,
The C++ wrapper in Cython makes a pretty good job, even when using template variables. However I came across a strange error, and I don't know if I'm the one messing with cython too much, or if it is an actual bug. (I pulled the cython repository yesterday, changeset: 3394:37d40646533e)
So here it is (I hope you'll be able to reproduce it):
cimport mycppDecl as cxx # <- this is my .px file containing the declarations
cimport numpy as np
cdef myFactory(np.ndarray stuff):
cxx.myTemplateObject[T] * ptr
if stuff.dtype == np.dtype(np.float32): # Is it the best way to do this btw ?
ptr = new cxx.myTemplateObject(<float *>stuff.data)
else:
ptr = new cxx.myTemplateObject(<double *>stuff.data)
return ptr
def called_by_python(np.ndarray stuff):
cxx.myTemplateObject[T] * ptr # Error goes away with void * here
ptr = myFactory(stuff)
This code produces an exception when cython tries to parse it (I think). It goes away when I change the type of ptr to void * in called_by_python().
here is the output of the error:
Traceback (most recent call last):
File "./setup.py", line 25, in <module>
ext_modules = ext_modules
File "/home/lionel/work/ets/python26/lib/python2.6/distutils/core.py", line 152, in setup
dist.run_commands()
File "/home/lionel/work/ets/python26/lib/python2.6/distutils/dist.py", line 975, in run_commands
self.run_command(cmd)
File "/home/lionel/work/ets/python26/lib/python2.6/distutils/dist.py", line 995, in run_command
cmd_obj.run()
File "/home/lionel/work/ets/python26/lib/python2.6/distutils/command/build_ext.py", line 345, in run
self.build_extensions()
File "/home/lionel/work/cython/cython-devel/Cython/Distutils/build_ext.py", line 75, in build_extensions
ext.sources = self.cython_sources(ext.sources, ext)
File "/home/lionel/work/cython/cython-devel/Cython/Distutils/build_ext.py", line 197, in cython_sources
full_module_name=module_name)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/Main.py", line 749, in compile
return compile_single(source, options, full_module_name)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/Main.py", line 696, in compile_single
return run_pipeline(source, options, full_module_name)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/Main.py", line 593, in run_pipeline
err, enddata = context.run_pipeline(pipeline, source)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/Main.py", line 234, in run_pipeline
data = phase(data)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/ParseTreeTransforms.py", line 965, in __call__
return super(AnalyseDeclarationsTransform, self).__call__(root)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/Visitor.py", line 276, in __call__
return super(CythonTransform, self).__call__(node)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/Visitor.py", line 259, in __call__
return self.visit(root)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/Visitor.py", line 28, in visit
return handler_method(obj)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/ParseTreeTransforms.py", line 973, in visit_ModuleNode
node.analyse_declarations(self.env_stack[-1])
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/ModuleNode.py", line 63, in analyse_declarations
self.body.analyse_declarations(env)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/Nodes.py", line 341, in analyse_declarations
stat.analyse_declarations(env)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/Nodes.py", line 341, in analyse_declarations
stat.analyse_declarations(env)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/Nodes.py", line 1515, in analyse_declarations
base_type = self.base_type.analyse(env)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/Nodes.py", line 836, in analyse
self.type = base_type.specialize_here(self.pos, template_types)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/PyrexTypes.py", line 1924, in specialize_here
return self.specialize(dict(zip(self.templates, template_values)))
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/PyrexTypes.py", line 1940, in specialize
specialized.scope = self.scope.specialize(values)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/Symtab.py", line 1605, in specialize
entry.cname)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/Symtab.py", line 350, in declare_type
entry = self.declare(name, cname, type, pos, visibility)
File "/home/lionel/work/cython/cython-devel/Cython/Compiler/Symtab.py", line 306, in declare
if type.is_buffer and not isinstance(self, LocalScope):
AttributeError: 'NoneType' object has no attribute 'is_buffer'
Note: See
TracTickets for help on using
tickets.
