Ben Booth | 12 Dec 23:14 2014
Picon

[Cython] cygdb bugs when debugging python 3 extensions

I'm trying to figure out how to use cygdb to debug extensions built with python 3. I've tested all the debugger commands listed in http://docs.cython.org/src/userguide/debugging.html when debugging python 2 extensions and everything works great. But some of the commands seem to be broken when debugging python 3 extensions.

Here are the debugger commands that I've confirmed as working with python 3 extensions:

cy break
cy step
cy next
cy run
cy cont
cy down
cy finish .. works but prints error message
cy exec
cy list
cy_lineno()
cy_eval()
cy_cname()

Here are the commands which fail under python 3, and the error message that is given for each:

cy up
    Python Exception <class 'gdb.error'> There is no member named length.:
    Error occurred in Python command: There is no member named length.
cy finish .. works but gives error
    Python Exception <class 'gdb.error'> There is no member named length.:
    Error occurred in Python command: There is no member named length.
cy bt
    Python Exception <class 'gdb.error'> There is no member named length.:
    Error occurred in Python command: There is no member named length.
cy print
    Python Exception <class 'gdb.error'> There is no member named ma_mask.:
    Python Exception <class 'gdb.error'> Error occurred in Python command: There is no member named ma_mask.:
    Error occurred in Python command: Error occurred in Python command: There is no member named ma_mask.
cy set x = 2
    Python Exception <class 'gdb.error'> No symbol "__pyx_v_10helloworld_x" in current context.:
    Error occurred in Python command: No symbol "__pyx_v_10helloworld_x" in current context.
cy locals
    Python Exception <class 'gdb.error'> There is no member named ma_mask.:
    Error occurred in Python command: There is no member named ma_mask.
cy globals
    Python Exception <class 'gdb.error'> There is no member named ma_mask.:
    Error occurred in Python command: There is no member named ma_mask.
cy_cvalue()
    Python Exception <class 'gdb.error'> There is no member named ma_mask.:
    Error occurred in Python convenience function: There is no member named ma_mask.

In summary:
  - The "cy set" and "cy_cname()" commands seem to be giving incorrect C names for cython variables. I did a grep of the generated .c source file for "__pyx_v_10helloworld_x", and didn't get any hits. Luckily, the "cy exec" command works, so I can use that to get the value of variables as a workaround. 
  - Any commands related to viewing or traversing the call stack seem to give an error related to a missing "length" member. 
  - Commands related to printing the value of a variable complain about a missing "ma_mask" member. 

Here are the source files I used for the test:

helloworld.py:
import helloworld

helloworld.pyx:
x = 1
y = "a"
print("Hello World 1")
print("Hello World 2")
print("Hello World 3")
print("Hello World 4")
print("Hello World 5")
print("Hello World 6")
print("Hello World 8")
print("Hello World 9")
print("Hello World 10")

setup.py:
from distutils.core import setup
from Cython.Build import cythonize
from distutils.extension import Extension
extensions = [Extension("helloworld", ["helloworld.pyx"])]
setup(ext_modules=cythonize(extensions, gdb_debug=True, output_dir="."))

To compile I ran:
python setup.py build_ext --inplace

To debug, I ran:
cygdb -vv . -- --args python helloworld.py

Here is my python version:
Python 3.4.2

I used pyenv (https://github.com/yyuu/pyenv) to build and install the latest Python 3 version with debugging symbols enabled.

Ben


<div>I'm trying to figure out how to use cygdb to debug extensions built with python 3. I've tested all the debugger commands listed in&nbsp;<a href="http://docs.cython.org/src/userguide/debugging.html" class="">http://docs.cython.org/src/userguide/debugging.html</a>&nbsp;when debugging python 2 extensions and everything works great. But some of the commands seem to be broken when debugging python 3 extensions.<div class=""><br class=""></div>
<div class="">Here are the debugger commands that I've confirmed as working with python 3 extensions:</div>
<div class=""><br class=""></div>
<div class="">
<div class="">cy break</div>
<div class="">cy step</div>
<div class="">cy next</div>
<div class="">cy run</div>
<div class="">cy cont</div>
<div class="">cy down</div>
<div class="">cy finish .. works but prints error message</div>
<div class="">cy exec</div>
<div class="">cy list</div>
<div class="">cy_lineno()</div>
<div class="">cy_eval()</div>
<div class="">cy_cname()</div>
</div>
<div class=""><br class=""></div>
<div class="">Here are the commands which fail under python 3, and the error message that is given for each:</div>
<div class=""><br class=""></div>
<div class="">
<div class="">cy up</div>
<div class="">&nbsp; &nbsp; Python Exception &lt;class 'gdb.error'&gt; There is no member named length.:</div>
<div class="">&nbsp; &nbsp; Error occurred in Python command: There is no member named length.</div>
<div class="">cy finish .. works but gives error</div>
<div class="">&nbsp; &nbsp; Python Exception &lt;class 'gdb.error'&gt; There is no member named length.:</div>
<div class="">&nbsp; &nbsp; Error occurred in Python command: There is no member named length.</div>
<div class="">cy bt</div>
<div class="">&nbsp; &nbsp; Python Exception &lt;class 'gdb.error'&gt; There is no member named length.:</div>
<div class="">&nbsp; &nbsp; Error occurred in Python command: There is no member named length.</div>
<div class="">cy print</div>
<div class="">&nbsp; &nbsp; Python Exception &lt;class 'gdb.error'&gt; There is no member named ma_mask.:</div>
<div class="">&nbsp; &nbsp; Python Exception &lt;class 'gdb.error'&gt; Error occurred in Python command: There is no member named ma_mask.:</div>
<div class="">&nbsp; &nbsp; Error occurred in Python command: Error occurred in Python command: There is no member named ma_mask.</div>
<div class="">cy set x = 2</div>
<div class="">&nbsp; &nbsp; Python Exception &lt;class 'gdb.error'&gt; No symbol "__pyx_v_10helloworld_x" in current context.:</div>
<div class="">&nbsp; &nbsp; Error occurred in Python command: No symbol "__pyx_v_10helloworld_x" in current context.</div>
<div class="">cy locals</div>
<div class="">&nbsp; &nbsp; Python Exception &lt;class 'gdb.error'&gt; There is no member named ma_mask.:</div>
<div class="">&nbsp; &nbsp; Error occurred in Python command: There is no member named ma_mask.</div>
<div class="">cy globals</div>
<div class="">&nbsp; &nbsp; Python Exception &lt;class 'gdb.error'&gt; There is no member named ma_mask.:</div>
<div class="">&nbsp; &nbsp; Error occurred in Python command: There is no member named ma_mask.</div>
<div class="">cy_cvalue()</div>
<div class="">&nbsp; &nbsp; Python Exception &lt;class 'gdb.error'&gt; There is no member named ma_mask.:</div>
<div class="">&nbsp; &nbsp; Error occurred in Python convenience function: There is no member named ma_mask.</div>
</div>
<div class=""><br class=""></div>
<div class="">In summary:</div>
<div class="">&nbsp; - The "cy set" and "cy_cname()" commands seem to be giving incorrect C names for cython variables. I did a grep of the generated .c source file for "__pyx_v_10helloworld_x", and didn't get any hits. Luckily, the "cy exec" command works, so I can use that to get the value of variables as a workaround.&nbsp;</div>
<div class="">&nbsp; - Any commands related to viewing or traversing the call stack seem to give an error related to a missing "length" member.&nbsp;</div>
<div class="">&nbsp; - Commands related to printing the value of a variable complain about a missing "ma_mask" member.&nbsp;</div>
<div class=""><br class=""></div>
<div class="">Here are the source files I used for the test:</div>
<div class=""><br class=""></div>
<div class="">helloworld.py:</div>
<div class="">import helloworld</div>
<div class=""><br class=""></div>
<div class="">helloworld.pyx:</div>
<div class="">
<div class="">x = 1</div>
<div class="">y = "a"</div>
<div class="">print("Hello World 1")</div>
<div class="">print("Hello World 2")</div>
<div class="">print("Hello World 3")</div>
<div class="">print("Hello World 4")</div>
<div class="">print("Hello World 5")</div>
<div class="">print("Hello World 6")</div>
<div class="">print("Hello World 8")</div>
<div class="">print("Hello World 9")</div>
<div class="">print("Hello World 10")</div>
</div>
<div class=""><br class=""></div>
<div class="">setup.py:</div>
<div class="">
<div class="">from distutils.core import setup</div>
<div class="">from Cython.Build import cythonize</div>
<div class="">from distutils.extension import Extension</div>
<div class="">extensions = [Extension("helloworld", ["helloworld.pyx"])]</div>
<div class="">setup(ext_modules=cythonize(extensions, gdb_debug=True, output_dir="."))</div>
</div>
<div class=""><br class=""></div>
<div class="">To compile I ran:</div>
<div class="">python setup.py build_ext --inplace</div>
<div class=""><br class=""></div>
<div class="">To debug, I ran:</div>
<div class="">cygdb -vv . -- --args python helloworld.py</div>
<div class=""><br class=""></div>
<div class="">Here is my python version:</div>
<div class="">Python 3.4.2</div>
<div class=""><br class=""></div>
<div class="">I used pyenv (<a href="https://github.com/yyuu/pyenv" class="">https://github.com/yyuu/pyenv</a>)&nbsp;to build and install the latest Python 3 version with debugging symbols enabled.</div>
<div class=""><br class=""></div>
<div class="">Ben</div>
<div class=""><br class=""></div>
<div class=""><br class=""></div>
</div>
serge Guelton | 8 Dec 20:52 2014
Picon
Picon

[Cython] Cython <> pythran collaboration

Hi Cython dev,

I am one of the two core developers of the Pythran[0] compiler.
We are planning to start a project where Cython would delegate the
generation of optimized (i.e. parallel / vectorized / without temporary
arrays) numpy expression when it finds one, instead of calling the
native API. Something like the following meaningless example:

    import numpy as np
    cimport numpy as np

    def play_with_arrays(np.ndarray arr):
        cdef int N = arr.shape[0]
        cdef np.ndarray other_arr = np.empty([N], dtype=np.int)

        other_arr = arr ** 2 + 1 # pythran would handle this

        for i in range(N):
            other_arr[i] /=  2 # cython would handle this

        return  other_arr

Everything would live in a pyx file and it should be transparent to a
cython user. Cython would drive the compilation process, using pythran
as a numpy expression optimizer.

Does that look feasible / appealing to you?

[0] http://pythonhosted.org/pythran/
Dave Hirschfeld | 8 Dec 13:22 2014
Picon

[Cython] Can't assign numpy array to memoryview

It appears that you can't assign an ndarray to a memoryview slice? Is 
this correct/expected behaviour?

Whilst there are a couple of possible workarounds it would be nice if 
this just worked as it's a slightly surprising deviation from the 
ndarray behaviour.

Broken example:
```
In [3]: %%cython
   ...: cimport cython
   ...: import numpy as np
   ...: cimport numpy as np
   ...: 
   ...: cpdef np.ndarray[np.float64_t, ndim=2] f():
   ...:     cdef np.ndarray[np.float64_t, ndim=2] x = np.ones([3, 4], 
dtype=np.float64)
   ...:     cdef double[:,:] y = np.zeros([3, 4], dtype=np.float64)
   ...:     cdef np.ndarray[np.float64_t, ndim=1] row
   ...:     cdef int idx
   ...:     for idx, row in enumerate(x):
   ...:         y[idx] = row
   ...:     return np.asarray(y)

In [4]: f()
Traceback (most recent call last):

  File "<ipython-input-4-0ec059b9bfe1>", line 1, in <module>
    f()

  File "_cython_magic_5f2586693ddbf044815dae01d800bc0c.pyx", line 5, in 
_cython_magic_5f2586693ddbf044815dae01d800bc0c.f 
(C:\Users\dhirschfeld\.ipython\cython\_cython_magic_5f2586693ddbf044815d
ae01d800bc0c.c:2086)

  File "_cython_magic_5f2586693ddbf044815dae01d800bc0c.pyx", line 11, in 
_cython_magic_5f2586693ddbf044815dae01d800bc0c.f 
(C:\Users\dhirschfeld\.ipython\cython\_cython_magic_5f2586693ddbf044815d
ae01d800bc0c.c:1935)
```

Workarounds - either:
1. Type both lhs and rhs as ndarray
2. Create a 1D memoryview to use as a temporary container and assign 
that to the memoryview slice

```
In [5]: %%cython
   ...: cimport cython
   ...: import numpy as np
   ...: cimport numpy as np
   ...: 
   ...: cpdef np.ndarray[np.float64_t, ndim=2] f():
   ...:     cdef np.ndarray[np.float64_t, ndim=2] x = np.ones([3, 4], 
dtype=np.float64)
   ...:     cdef np.ndarray[np.float64_t, ndim=2] y = np.zeros([3, 4], 
dtype=np.float64)
   ...:     cdef np.ndarray[np.float64_t, ndim=1] row
   ...:     cdef int idx
   ...:     for idx, row in enumerate(x):
   ...:         y[idx] = row
   ...:     return np.asarray(y)

In [6]: f()
Out[6]: 
array([[ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.]])

In [7]: %%cython
   ...: cimport cython
   ...: import numpy as np
   ...: cimport numpy as np
   ...: 
   ...: cpdef np.ndarray[np.float64_t, ndim=2] f():
   ...:     cdef np.ndarray[np.float64_t, ndim=2] x = np.ones([3, 4], 
dtype=np.float64)
   ...:     cdef double[:,:] y = np.zeros([3, 4], dtype=np.float64)
   ...:     cdef np.ndarray[np.float64_t, ndim=1] row
   ...:     cdef double[:] tmp
   ...:     cdef int idx
   ...:     for idx, row in enumerate(x):
   ...:         tmp = row
   ...:         y[idx] = tmp
   ...:     return np.asarray(y)

In [8]: f()
Out[8]: 
array([[ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.]])
```

Samuele Kaplun | 2 Dec 14:13 2014
Picon
Picon

[Cython] Possible bug (or wrong documentation) WRT "not None"

Hi!

I would like to report what I think is a possible bug (in cython or 
corresponding documentation).

According to:
<http://docs.cython.org/src/userguide/extension_types.html#extension-types-and-none>

[...]
The self parameter of a method of an extension type is guaranteed never to be 
None.
[...]

However given this snippet:
[...]
cdef class test:
    def __sub__(self, test rhs not None):
        print "self is %s" % repr(self), "rhs is %s" % repr(rhs)
[...]

If I then load it python:
In [1]: import test
In [2]: x = test.test()
In [3]: None - x
self is None rhs is <test.test object at 0x7fdd9eeb7410>

Thus showing that in this case "self" was actually initialized with None.

If I explictly add "not None" as in:
[...]
cdef class test:
    def __sub__(self not None, test rhs not None):
        print "self is %s" % repr(self), "rhs is %s" % repr(rhs)
[...]
In [3]: None - x
TypeError: Argument 'self' must not be None
[...]

Which is good.

If I instead add "test self" as in:
[...]
cdef class test:
    def __sub__(test self not None, test rhs not None):
        print "self is %s" % repr(self), "rhs is %s" % repr(rhs)
[...]
In [3]: None - x
TypeError: Argument 'self' has incorrect type (expected test.test, got 
NoneType)
[...]

What's worse is that if I use "test self" (without not None), the same 
TypeError is not raised:
[...]
cdef class test:
    def __sub__(test self, test rhs not None):
        print "self is %s" % repr(self), "rhs is %s" % repr(rhs)
[...]
In [3]: None - x
self is None rhs is <test.test object at 0x7f17b36ff3f0>

Thus we have:
self -> not respecting None-checking (in disagreement with Documentation)
self not None ->  OK
test self -> not respecting type-checking!
test self non None -> OK (respecting type-checking, hence None-checking).

Hope that helps. Cheers,
	Samuele

--

-- 
Samuele Kaplun
Invenio Developer ** <http://invenio-software.org/>

Michael Enßlin | 30 Nov 16:14 2014

[Cython] cython --cplus --embed generates invalid code

Hi,

on my system, --embed does not work with --cplus.

How to reproduce: Any valid pyx file works:

$ rm -f test.pyx; touch test.pyx
$ cython --embed --cplus test.pyx
$ g++ -c test.cpp -I/usr/include/python3.4m
test.cpp: In function ‘wchar_t* __Pyx_char2wchar(char*)’:
test.cpp:945:41: error: invalid conversion from ‘void*’ to ‘wchar_t*’
[-fpermissive]
     res = malloc(argsize*sizeof(wchar_t));
$ clang++ -c test.cpp -I/usr/include/python3.4m
test.cpp:945:9: error: assigning to 'wchar_t *' from incompatible type
'void *'
    res = malloc(argsize*sizeof(wchar_t));

The issue can easily be fixed by manually casting the malloc result to
(wchar_t *).
In C it is not recommended to cast the malloc result, while in C++ it is
required (and malloc is discouraged).

System info:

$ cython --version
Cython version 0.21.1
$ g++ --version
g++ (Debian 4.9.2-2) 4.9.2
$ python3 --version
Python 3.4.2
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux unstable (sid)
Release:	unstable
Codename:	sid

~ Michael

Hi,

on my system, --embed does not work with --cplus.

How to reproduce: Any valid pyx file works:

$ rm -f test.pyx; touch test.pyx
$ cython --embed --cplus test.pyx
$ g++ -c test.cpp -I/usr/include/python3.4m
test.cpp: In function ‘wchar_t* __Pyx_char2wchar(char*)’:
test.cpp:945:41: error: invalid conversion from ‘void*’ to ‘wchar_t*’
[-fpermissive]
     res = malloc(argsize*sizeof(wchar_t));
$ clang++ -c test.cpp -I/usr/include/python3.4m
test.cpp:945:9: error: assigning to 'wchar_t *' from incompatible type
'void *'
    res = malloc(argsize*sizeof(wchar_t));

The issue can easily be fixed by manually casting the malloc result to
(wchar_t *).
In C it is not recommended to cast the malloc result, while in C++ it is
required (and malloc is discouraged).

System info:

$ cython --version
Cython version 0.21.1
$ g++ --version
g++ (Debian 4.9.2-2) 4.9.2
$ python3 --version
Python 3.4.2
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux unstable (sid)
Release:	unstable
Codename:	sid

~ Michael

Favian Contreras | 14 Nov 13:46 2014
Picon

[Cython] Location where extern declarations are parsed

Hello all,

Does anyone know where the (c++) external declarations are parsed? I am specifically looking for where external function pointers are parsed by the compiler. I noticed that all functions are parsed in some way in Symtab.py, but this includes all of the inherited methods from python and the c files within Cython, and I'm thinking there is a more specific place where external function pointers parsed.

Cheers,
Favian Contreras
<div><div dir="ltr">
<div>Hello all,<br><br>
</div>
<div>Does anyone know where the (c++) external declarations are parsed? I am specifically looking for where external function pointers are parsed by the compiler. I noticed that all functions are parsed in some way in Symtab.py, but this includes all of the inherited methods from python and the c files within Cython, and I'm thinking there is a more specific place where external function pointers parsed.<br><br>
</div>
<div>Cheers,<br>
</div>
<div>Favian Contreras<br>
</div>
</div></div>
Rich Leigh | 10 Nov 16:35 2014
Picon

[Cython] Compiler crash in cython 0.21.1 DebugTransform

Hi all - I get the following compiler crash from cython 0.21.1 (from pip) when compiling a C++ module with debugging. It's fine without the --gdb option.

[1/3] Compiling Cython CXX source for [project]...
FAILED: cd [project_build] && cython --cplus -I [project_src] -2 --gdb --output-file [project_build]/[project].cxx [project_src]/[project].pyx

Error compiling Cython file:
------------------------------------------------------------
...

    def merge(self):
        cdef cpp_string ofnametmp = self.ofname + ".tmp"
        merge[cpp_vector[cpp_string]](self.sources, ofnametmp.c_str())
                           ^
------------------------------------------------------------

[project_src]/[project].pyx:241:28: Compiler crash in DebugTransform

ModuleNode.body = StatListNode([project].pyx:1:0)
StatListNode.stats[12] = StatListNode([project].pyx:227:5)
StatListNode.stats[0] = CompilerDirectivesNode([project].pyx:227:5)
CompilerDirectivesNode.body = StatListNode([project].pyx:227:5)
StatListNode.stats[0] = CClassDefNode([project].pyx:227:5,
    as_name = u'Merge',
    class_name = u'Merge',
    decorators = [...]/0,
    module_name = u'',
    visibility = u'private')
CClassDefNode.body = StatListNode([project].pyx:228:4)
StatListNode.stats[1] = DefNode([project].pyx:238:4,
    modifiers = [...]/0,
    module_name = u'[Project]',
    name = u'merge',
    num_required_args = 1,
    py_wrapper_required = True,
    qualname = u'Merge.merge',
    reqd_kw_flags_cname = '0',
    used = True)
DefNode.body = StatListNode([project].pyx:239:8)
StatListNode.stats[0] = ExprStatNode([project].pyx:240:41)
ExprStatNode.expr = SimpleCallNode([project].pyx:240:41,
    analysed = True,
    is_temp = 1,
    use_managed_ref = True)
SimpleCallNode.function = IndexNode([project].pyx:240:17,
    is_called = 1,
    is_subscript = True,
    result_is_used = True,
    type_indices = [...]/1,
    use_managed_ref = True)
IndexNode.index = IndexNode([project].pyx:240:28,
    is_subscript = True,
    result_is_used = True,
    use_managed_ref = True)
IndexNode.base = NameNode([project].pyx:240:28,
    cf_maybe_null = True,
    is_name = True,
    name = u'cpp_vector',
    result_is_used = True,
    use_managed_ref = True)

Compiler crash traceback from this point on:
  File "Cython/Compiler/Visitor.py", line 173, in Cython.Compiler.Visitor.TreeVisitor._visit (cython/Cython/Compiler/Visitor.c:4449)
    return handler_method(obj)
  File "python2.7/site-packages/Cython/Compiler/ParseTreeTransforms.py", line 2937, in visit_NameNode
    node.type.is_cfunction and
AttributeError: 'NoneType' object has no attribute 'is_cfunction'


In my pyx file, cpp_vector and cpp_string are as follows:

from libcpp.vector cimport vector as cpp_vector
from libcpp.string cimport string as cpp_string

and merge (my C++ function, though I've also got the python def above of a method with the same name) has this signature:

   cdef void merge[T](const T&, const char *) except+

I've managed to fix it by turning line 2937 in ParseTreeTransforms.py from

2937:            node.type.is_cfunction and

to

2937:            getattr(node.type, 'is_cfunction', False) and

which seems to do the trick.

I did a quick google to see if anybody else had this issue, but it seems like a fresh bug. Not sure if this is the correct solution though, or whether I've simply buried an underlying issue.




<div><div dir="ltr">
<div class="gmail_quote">
<div dir="ltr">Hi all - I get the following compiler crash from cython 0.21.1 (from pip) when compiling a C++ module with debugging. It's fine without the --gdb option.<br><div>
<br>[1/3] Compiling Cython CXX source for [project]...<br>FAILED: cd [project_build] &amp;&amp; cython --cplus -I [project_src] -2 --gdb --output-file [project_build]/[project].cxx [project_src]/[project].pyx<br><br>Error compiling Cython file:<br>------------------------------------------------------------<br>...<br><br>&nbsp;&nbsp;&nbsp; def merge(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cdef cpp_string ofnametmp = self.ofname + ".tmp"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; merge[cpp_vector[cpp_string]](self.sources, ofnametmp.c_str())<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^<br>------------------------------------------------------------<br><br>[project_src]/[project].pyx:241:28: Compiler crash in DebugTransform<br><br>ModuleNode.body = StatListNode([project].pyx:1:0)<br>StatListNode.stats[12] = StatListNode([project].pyx:227:5)<br>StatListNode.stats[0] = CompilerDirectivesNode([project].pyx:227:5)<br>CompilerDirectivesNode.body = StatListNode([project].pyx:227:5)<br>StatListNode.stats[0] = CClassDefNode([project].pyx:227:5,<br>&nbsp;&nbsp;&nbsp; as_name = u'Merge',<br>&nbsp;&nbsp;&nbsp; class_name = u'Merge',<br>&nbsp;&nbsp;&nbsp; decorators = [...]/0,<br>&nbsp;&nbsp;&nbsp; module_name = u'',<br>&nbsp;&nbsp;&nbsp; visibility = u'private')<br>CClassDefNode.body = StatListNode([project].pyx:228:4)<br>StatListNode.stats[1] = DefNode([project].pyx:238:4,<br>&nbsp;&nbsp;&nbsp; modifiers = [...]/0,<br>&nbsp;&nbsp;&nbsp; module_name = u'[Project]',<br>&nbsp;&nbsp;&nbsp; name = u'merge',<br>&nbsp;&nbsp;&nbsp; num_required_args = 1,<br>&nbsp;&nbsp;&nbsp; py_wrapper_required = True,<br>&nbsp;&nbsp;&nbsp; qualname = u'Merge.merge',<br>&nbsp;&nbsp;&nbsp; reqd_kw_flags_cname = '0',<br>&nbsp;&nbsp;&nbsp; used = True)<br>DefNode.body = StatListNode([project].pyx:239:8)<br>StatListNode.stats[0] = ExprStatNode([project].pyx:240:41)<br>ExprStatNode.expr = SimpleCallNode([project].pyx:240:41,<br>&nbsp;&nbsp;&nbsp; analysed = True,<br>&nbsp;&nbsp;&nbsp; is_temp = 1,<br>&nbsp;&nbsp;&nbsp; use_managed_ref = True)<br>SimpleCallNode.function = IndexNode([project].pyx:240:17,<br>&nbsp;&nbsp;&nbsp; is_called = 1,<br>&nbsp;&nbsp;&nbsp; is_subscript = True,<br>&nbsp;&nbsp;&nbsp; result_is_used = True,<br>&nbsp;&nbsp;&nbsp; type_indices = [...]/1,<br>&nbsp;&nbsp;&nbsp; use_managed_ref = True)<br>IndexNode.index = IndexNode([project].pyx:240:28,<br>&nbsp;&nbsp;&nbsp; is_subscript = True,<br>&nbsp;&nbsp;&nbsp; result_is_used = True,<br>&nbsp;&nbsp;&nbsp; use_managed_ref = True)<br>IndexNode.base = NameNode([project].pyx:240:28,<br>&nbsp;&nbsp;&nbsp; cf_maybe_null = True,<br>&nbsp;&nbsp;&nbsp; is_name = True,<br>&nbsp;&nbsp;&nbsp; name = u'cpp_vector',<br>&nbsp;&nbsp;&nbsp; result_is_used = True,<br>&nbsp;&nbsp;&nbsp; use_managed_ref = True)<br><br>Compiler crash traceback from this point on:<br>&nbsp; File "Cython/Compiler/Visitor.py", line 173, in Cython.Compiler.Visitor.TreeVisitor._visit (cython/Cython/Compiler/Visitor.c:4449)<br>&nbsp;&nbsp;&nbsp; return handler_method(obj)<br>&nbsp; File "python2.7/site-packages/Cython/Compiler/ParseTreeTransforms.py", line 2937, in visit_NameNode<br>&nbsp;&nbsp;&nbsp; node.type.is_cfunction and<br>AttributeError: 'NoneType' object has no attribute 'is_cfunction'<br><br><br>
</div>
<div>In my pyx file, cpp_vector and cpp_string are as follows:<br>
</div>
<div>
<br>from libcpp.vector cimport vector as cpp_vector<br>from libcpp.string cimport string as cpp_string<br><br>
</div>
<div>and merge (my C++ function, though I've also got the python def above of a method with the same name) has this signature:<br><br>&nbsp;&nbsp; cdef void merge[T](const T&amp;, const char *) except+<br><br>
</div>
<div>I've managed to fix it by turning line 2937 in ParseTreeTransforms.py from<br><br>2937:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; node.type.is_cfunction and<br>
</div>
<div><br></div>
<div>to<br>
</div>
<div>
<br>2937: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getattr(node.type, 'is_cfunction', False) and<br><br>
</div>
<div>which seems to do the trick.<br><br>
</div>
<div>I did a quick google to see if anybody else had this issue, but it seems like a fresh bug. Not sure if this is the correct solution though, or whether I've simply buried an underlying issue.<br>
</div>
<div><br></div>
<div>
<br><br>
</div>
</div>
</div>
<br>
</div></div>
Ondrej Certik | 7 Nov 18:13 2014
Picon

[Cython] Cython sometimes fails to build on Travis

Hi,

Cython sometimes fails to build on Travis for various projects. If it
fails, it always ends with this error:

https://gist.github.com/certik/08f16dd572170c17d956

Here are some instances of this failure in other projects:

https://github.com/sympy/csympy/issues/308
https://github.com/scipy/scipy/pull/4126#issuecomment-62162812

Any ideas what is going on?

Thanks,
Ondrej
Robert Bradshaw | 6 Nov 08:34 2014
Picon

[Cython] New function (pointer) syntax.

I'd like to propose a more pythonic way to declare function pointer
types, namelye

    type0 (*[ident])(type1, type2, type3)

would instead become

    (type1, type2, type3) -> type0 [ident]

I have a pull request up at https://github.com/cython/cython/pull/333;
what do people think?

- Robert
Zaxebo Yaxebo | 4 Nov 02:08 2014
Picon

[Cython] [FEATURE REQUEST] VisualBasic "Option Explicit" / Perl "use strict" -- bringing variable pre-declaration to cython optionally

Subject: [FEATURE REQUEST] VisualBasic "Option Explicit" / Perl "use strict" -- bringing variable pre-declaration to cython optionally

===================================================
Background:
already cython supports the following:
   #program1
    a1  = cython.declare(cython.int) # cdef int a1
    a2  = cython.declare(cython.double,0.57721) # cdef double a2 =0.57721
   #end program1
====================================================
The New Feature Request:

but will there be  - a feature in cython, in which - even though we are "not" declaring "data types" of variables, but we are declaring variables themselves. like:
------------
   #program2
   cython.option_strict(True)                                         ## <------- see this statement
    a1  = cython.declare(cython.int) # cdef int a1
    a2  = cython.declare(cython.double,0.57721) # cdef double a2 =0.57721
    a3 = cython.declare(cython.var) #cdef var a3                      ## <------- see this statement
    a4 = cython.declare(cython.var,0.57721) #cdef var a4=0.57721      ## <------- see this statement
   
      
    a3 = 10                 # <----- This statement will not give error
    b1 = 10                 # <----- This statement will give warning/error, as variable b1 was not declared and cython.option_strict() is enabled
   #end program2
---------

Here we have declared the variables a3 and a4 using "cdef var", but we have not declared their data types. For a1 and a2, we have declared their datatypes too.
  But now, as cython.option_strict() is enabled(i.e., true); 

      HENCE "b1=10"  statement will give error when cython compiles, because "b1" variable which was not declared in any sense using "cython.declare(cython.var) or cdef var" .

      But "a3 = 10" statement in above program will not warning/error,as "a3" is already declared var

NOTE: This feature request is analogous to VisualBasic's "Option Explicit" and perl's "use strict"

==================
Here are other people also requesting the similar thing:


Zaxebo1

<div><div dir="ltr">
<div>Subject: [FEATURE REQUEST] VisualBasic "Option Explicit" / Perl "use strict" -- bringing variable pre-declaration to cython optionally<br>
</div>
<div><br></div>
<div>===================================================</div>
<div>Background:</div>
<div>already cython supports the following:</div>
<div>&nbsp; &nbsp;#program1</div>
<div>&nbsp; &nbsp; a1 &nbsp;= cython.declare(<a href="http://cython.int">cython.int</a>) # cdef int a1</div>
<div>&nbsp; &nbsp; a2 &nbsp;= cython.declare(cython.double,0.57721) # cdef double a2 =0.57721</div>
<div>&nbsp; &nbsp;#end program1</div>
<div>====================================================</div>
<div>The New Feature Request:</div>
<div><br></div>
<div>but will there be &nbsp;- a feature in cython, in which - even though we are "not" declaring "data types" of variables, but we are declaring variables themselves. like:</div>
<div>------------</div>
<div>&nbsp; &nbsp;#program2</div>
<div>&nbsp; &nbsp;cython.option_strict(True) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ## &lt;------- see this statement</div>
<div>&nbsp; &nbsp; a1 &nbsp;= cython.declare(<a href="http://cython.int">cython.int</a>) # cdef int a1</div>
<div>&nbsp; &nbsp; a2 &nbsp;= cython.declare(cython.double,0.57721) # cdef double a2 =0.57721</div>
<div>&nbsp; &nbsp; a3 = cython.declare(cython.var) #cdef var a3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;## &lt;------- see this statement</div>
<div>&nbsp; &nbsp; a4 = cython.declare(cython.var,0.57721) #cdef var a4=0.57721 &nbsp; &nbsp; &nbsp;## &lt;------- see this statement</div>
<div>&nbsp; &nbsp;</div>
<div>&nbsp; &nbsp; &nbsp;&nbsp;</div>
<div>&nbsp; &nbsp; a3 = 10 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # &lt;----- This statement will not give error</div>
<div>&nbsp; &nbsp; b1 = 10 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # &lt;----- This statement will give warning/error, as variable b1 was not declared and cython.option_strict() is enabled</div>
<div>&nbsp; &nbsp;#end program2</div>
<div>---------</div>
<div><br></div>
<div>Here we have declared the variables a3 and a4 using "cdef var", but we have not declared their data types. For a1 and a2, we have declared their datatypes too.</div>
<div>&nbsp; But now, as cython.option_strict() is enabled(i.e., true);&nbsp;</div>
<div><br></div>
<div>&nbsp; &nbsp; &nbsp; HENCE "b1=10" &nbsp;statement will give error when cython compiles, because "b1" variable which was not declared in any sense using "cython.declare(cython.var) or cdef var" .</div>
<div><br></div>
<div>&nbsp; &nbsp; &nbsp; But "a3 = 10" statement in above program will not warning/error,as "a3" is already declared var</div>
<div><br></div>
<div>NOTE: This feature request is analogous to VisualBasic's "Option Explicit" and perl's "use strict"</div>
<div><br></div>
<div>==================</div>
<div>Here are other people also requesting the similar thing:</div>
<div><a href="http://stackoverflow.com/questions/613364/is-there-a-need-for-a-use-strict-python-compiler">http://stackoverflow.com/questions/613364/is-there-a-need-for-a-use-strict-python-compiler</a></div>
<div><a href="http://stackoverflow.com/questions/13425715/does-python-have-a-use-strict-and-use-warnings-like-in-perl">http://stackoverflow.com/questions/13425715/does-python-have-a-use-strict-and-use-warnings-like-in-perl</a></div>
<div><a href="http://stevesprogramming.blogspot.in/2013/03/why-python-needs-perls-use-strict.html">http://stevesprogramming.blogspot.in/2013/03/why-python-needs-perls-use-strict.html</a></div>
<div><a href="http://bytes.com/topic/python/answers/632587-python-feature-request-explicit-variable-declarations">http://bytes.com/topic/python/answers/632587-python-feature-request-explicit-variable-declarations</a></div>
<div><br></div>
<div><br></div>
<div>Zaxebo1</div>
<div><br></div>
</div></div>
Daniele Nicolodi | 25 Oct 03:36 2014
Picon

[Cython] [PATCH] explain how to compile C++ extensions up to Cython 0.21

---
 docs/src/userguide/wrapping_CPlusPlus.rst | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/docs/src/userguide/wrapping_CPlusPlus.rst b/docs/src/userguide/wrapping_CPlusPlus.rst
index 59c89a1..5119b63 100644
--- a/docs/src/userguide/wrapping_CPlusPlus.rst
+++ b/docs/src/userguide/wrapping_CPlusPlus.rst
 <at>  <at>  -141,6 +141,21  <at>  <at>  Note that the ``language`` option has no effect on user provided Extension
 objects that are passed into ``cythonize()``.  It is only used for modules
 found by file name (as in the example above).

+The ``cythonize()`` function in Cython versions up to 0.21 does not
+recognize the ``language`` option and it needs to be specified as an
+option to an :class:`Extension` that describes your extension and that
+is then handled by ``cythonize()`` as follows::
+
+   from distutils.core import setup, Extension
+   from Cython.Build import cythonize
+
+   setup(ext_modules = cythonize(Extension(
+              "rect",                                # the extesion name
+              sources=["rect.pyx", "Rectangle.cpp"], # the Cython source and
+                                                     # additional C++ source files
+              language="c++",                        # generate and compile C++ code
+         )))
+
 The options can also be passed directly from the source file, which is
 often preferable (and overrides any global option).  Starting with
 version 0.17, Cython also allows to pass external source files into the
--

-- 
2.1.1


Gmane