Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read-only memoryview fields in a cdef class lead to AssertionError #2251

Closed
zhanghjumich opened this issue May 9, 2018 · 5 comments
Closed

Comments

@zhanghjumich
Copy link

zhanghjumich commented May 9, 2018

Hi,

I am using Cython 0.28.2 from Anaconda and noticed that the following code will lead to AssertionError during Cython compilation:

cdef struct B:
    int a
    int b

cdef class A:
    cdef const B[:] c
% cythonize test.pyx
Compiling test.pyx because it changed.
[1/1] Cythonizing test.pyx
Traceback (most recent call last):
  File "/home/zhanghj/.local/opt/conda/bin/cythonize", line 11, in <module>
    sys.exit(main())
  File "/home/zhanghj/.local/opt/conda/lib/python3.6/site-packages/Cython/Build/Cythonize.py", line 196, in main
    cython_compile(path, options)
  File "/home/zhanghj/.local/opt/conda/lib/python3.6/site-packages/Cython/Build/Cythonize.py", line 90, in cython_compile
    **options.options)
  File "/home/zhanghj/.local/opt/conda/lib/python3.6/site-packages/Cython/Build/Dependencies.py", line 1026, in cythonize
    cythonize_one(*args)
  File "/home/zhanghj/.local/opt/conda/lib/python3.6/site-packages/Cython/Build/Dependencies.py", line 1129, in cythonize_one
    result = compile_single(pyx_file, options, full_module_name=full_module_name)
  File "/home/zhanghj/.local/opt/conda/lib/python3.6/site-packages/Cython/Compiler/Main.py", line 649, in compile_single
    return run_pipeline(source, options, full_module_name)
  File "/home/zhanghj/.local/opt/conda/lib/python3.6/site-packages/Cython/Compiler/Main.py", line 499, in run_pipeline
    err, enddata = Pipeline.run_pipeline(pipeline, source)
  File "/home/zhanghj/.local/opt/conda/lib/python3.6/site-packages/Cython/Compiler/Pipeline.py", line 354, in run_pipeline
    data = run(phase, data)
  File "/home/zhanghj/.local/opt/conda/lib/python3.6/site-packages/Cython/Compiler/Pipeline.py", line 334, in run
    return phase(data)
  File "/home/zhanghj/.local/opt/conda/lib/python3.6/site-packages/Cython/Compiler/Pipeline.py", line 52, in generate_pyx_code_stage
    module_node.process_implementation(options, result)
  File "/home/zhanghj/.local/opt/conda/lib/python3.6/site-packages/Cython/Compiler/ModuleNode.py", line 142, in process_implementation
    self.generate_c_code(env, options, result)
  File "/home/zhanghj/.local/opt/conda/lib/python3.6/site-packages/Cython/Compiler/ModuleNode.py", line 397, in generate_c_code
    globalstate.use_utility_code(utilcode)
  File "Cython/Compiler/Code.py", line 1601, in Cython.Compiler.Code.GlobalState.use_utility_code
  File "Cython/Compiler/Code.py", line 674, in Cython.Compiler.Code.LazyUtilityCode.put_code
  File "/home/zhanghj/.local/opt/conda/lib/python3.6/site-packages/Cython/Compiler/PyrexTypes.py", line 888, in lazy_utility_callback
    context['dtype_typeinfo'] = Buffer.get_type_information_cname(code, self.dtype)
  File "/home/zhanghj/.local/opt/conda/lib/python3.6/site-packages/Cython/Compiler/Buffer.py", line 674, in get_type_information_cname
    assert len(fields) > 0
AssertionError

% cython --version
Cython version 0.28.2

Thank you

@brhumphe
Copy link

This is still an issue on 0.29.14. Attempting to assign anything to the memory view definition also generates the same error:

from struct import pack

cdef packed struct B:
    int a
    int b
    
cdef const B[:] c

cdef bytes data = pack('ii', 1, 2)
# Adding this line will cause the assertion error. Any type of assignment seems to do it.
c = data

@franklsf95
Copy link

franklsf95 commented Nov 5, 2020

+1 also observed on 0.29.21. Any fix?

@scoder
Copy link
Contributor

scoder commented Nov 5, 2020

Does this also fail in Cython 3.0?

@franklsf95
Copy link

@scoder yes, just tested on Cython 3.0a6:

❯ cython --version
Cython version 3.0a6
❯ cython -3 a.pyx
Traceback (most recent call last):
  File "/Users/lsf/miniconda3/envs/cython-test/bin/cython", line 8, in <module>
    sys.exit(setuptools_main())
  File "/Users/lsf/miniconda3/envs/cython-test/lib/python3.9/site-packages/Cython/Compiler/Main.py", line 711, in setuptools_main
    return main(command_line = 1)
  File "/Users/lsf/miniconda3/envs/cython-test/lib/python3.9/site-packages/Cython/Compiler/Main.py", line 729, in main
    result = compile(sources, options)
  File "/Users/lsf/miniconda3/envs/cython-test/lib/python3.9/site-packages/Cython/Compiler/Main.py", line 628, in compile
    return compile_multiple(source, options)
  File "/Users/lsf/miniconda3/envs/cython-test/lib/python3.9/site-packages/Cython/Compiler/Main.py", line 605, in compile_multiple
    result = run_pipeline(source, options, context=context)
  File "/Users/lsf/miniconda3/envs/cython-test/lib/python3.9/site-packages/Cython/Compiler/Main.py", line 503, in run_pipeline
    err, enddata = Pipeline.run_pipeline(pipeline, source)
  File "/Users/lsf/miniconda3/envs/cython-test/lib/python3.9/site-packages/Cython/Compiler/Pipeline.py", line 356, in run_pipeline
    data = run(phase, data)
  File "/Users/lsf/miniconda3/envs/cython-test/lib/python3.9/site-packages/Cython/Compiler/Pipeline.py", line 336, in run
    return phase(data)
  File "/Users/lsf/miniconda3/envs/cython-test/lib/python3.9/site-packages/Cython/Compiler/Pipeline.py", line 52, in generate_pyx_code_stage
    module_node.process_implementation(options, result)
  File "/Users/lsf/miniconda3/envs/cython-test/lib/python3.9/site-packages/Cython/Compiler/ModuleNode.py", line 167, in process_implementation
    self.generate_c_code(env, options, result)
  File "/Users/lsf/miniconda3/envs/cython-test/lib/python3.9/site-packages/Cython/Compiler/ModuleNode.py", line 469, in generate_c_code
    globalstate.use_utility_code(utilcode)
  File "/Users/lsf/miniconda3/envs/cython-test/lib/python3.9/site-packages/Cython/Compiler/Code.py", line 1713, in use_utility_code
    utility_code.put_code(self)
  File "/Users/lsf/miniconda3/envs/cython-test/lib/python3.9/site-packages/Cython/Compiler/Code.py", line 684, in put_code
    utility = self.callback(globalstate.rootwriter)
  File "/Users/lsf/miniconda3/envs/cython-test/lib/python3.9/site-packages/Cython/Compiler/PyrexTypes.py", line 936, in lazy_utility_callback
    context['dtype_typeinfo'] = Buffer.get_type_information_cname(code, self.dtype)
  File "/Users/lsf/miniconda3/envs/cython-test/lib/python3.9/site-packages/Cython/Compiler/Buffer.py", line 675, in get_type_information_cname
    assert len(fields) > 0
AssertionError

@scoder scoder closed this as completed in a23cffe Nov 7, 2020
@scoder
Copy link
Contributor

scoder commented Nov 7, 2020

Thanks for the short reproducer and for testing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants