Diogo Alves | 23 Aug 14:49 2015
Picon

Cython for Visual Studio 2015 to deploy on Windows 10 IoT Core

Hi

I am currently trying to port an application I have working on raspbian to Windows 10 IoT Core.

My project uses a module called python-openzwave that strongly rely on cython.

I don't have a big knoledge in cython so I decided that the first step to successfully port everything would be make it run on a windows 10 computer


So far I installed VS2015 I loaded the source code I have in there and installed cython using "pip install cython"

Everything goes well, but now I am strugling to build the project

I will post here the configuration of setup-lib.py and the output:

if os_name == 'win32' or os_name=='nt':
    ext_modules = [Extension("libopenzwave",
                             sources=["src-lib/libopenzwave/libopenzwave.cpp"],
                             libraries=['setupapi', 'msvc'],
                             language="c++",
                             extra_objects=['openzwave/libopenzwave.a'],
                             include_dirs=['openzwave/cpp/src', 'openzwave/cpp/src/value_classes', 'openzwave/cpp/src/platform', 'openzwave/cpp/build/windows', "src-lib/libopenzwave" , "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include"]
    )]




And here is the output of the build:


running build
running build_ext
cythoning src-lib/libopenzwave/libopenzwave.pyx to src-lib/libopenzwave\libopenzwave.cpp
building 'libopenzwave' extension
creating build
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
creating build\temp.win-amd64-2.7\Release\src-lib
creating build\temp.win-amd64-2.7\Release\src-lib\libopenzwave
C:\Users\Diogo Alves\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Iopenzwave/cpp/src -Iopenzwave/cpp/src/value_classes -Iopenzwave/cpp/src/platform -Iopenzwave/cpp/build/windows -Isrc-lib/libopenzwave "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include" -IC:\Python27\include -IC:\Python27\PC /Tpsrc-lib/libopenzwave\libopenzwave.cpp /Fobuild\temp.win-amd64-2.7\Release\src-lib/libopenzwave\libopenzwave.objlibopenzwave.cpp
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vadefs.h(127) : error C3168: 'bool' : illegal underlying type for enum
        C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vadefs.h(128) : see reference to class template instantiation '__vcrt_va_list_is_reference<_Ty>' being compiled
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vadefs.h(133) : error C3168: 'bool' : illegal underlying type for enum
        C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vadefs.h(134) : see reference to class template instantiation '__vcrt_va_list_is_reference<_Ty&>' being compiled
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vadefs.h(137) : error C2143: syntax error : missing ',' before '&&'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vadefs.h(138) : error C2143: syntax error : missing ';' before '{'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vadefs.h(139) : error C2143: syntax error : missing ';' before '{'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vadefs.h(140) : error C2143: syntax error : missing ';' before '}'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vadefs.h(144) : error C2143: syntax error : missing ';' before '{'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vadefs.h(146) : error C2143: syntax error : missing ';' before '}'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vadefs.h(147) : error C2143: syntax error : missing ';' before '}'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vcruntime.h(81) : error C2143: syntax error : missing ';' before '{'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vcruntime.h(238): error C2143: syntax error : missing ';' before '{'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vcruntime.h(243): error C2143: syntax error : missing ';' before '}'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vcruntime.h(307): error C2143: syntax error : missing ';' before '}'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\crtdefs.h(10) : fatal error C1083: Cannot open include file: 'corecrt.h': No such file or directory


Anyone knows if what I am trying to do is possible and if possible how to solve this issue?

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Simon King | 23 Aug 10:19 2015
Picon
Picon

cmp of integers with nogil

Hi!

I try to speed-up some code using "with nogil", and found that  
comparison of integers by cmp(i,j) requires gil. Is there a function  
(e.g. from cpython), say,
cmp_int, that compares two <int> and does not require gil?

Best regards,
Simon

--

-- 

--- 
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Antony Lee | 23 Aug 05:51 2015
Picon

Debugging a Cython extension for Python3 using cygdb

I am trying to debug Python3 extensions with cygdb.  Currently, whether I run

    $ python2 `which cygdb` . -vv -- --args /usr/bin/python3 run.py

or

    $ python3 `which cygdb` . -vv -- --args /usr/bin/python3 run.py

(where run.py is a file that invokes an intentionally crashing cython extension), calling `cy bt` at the gdb CLI results in the following error:

    (gdb) cy bt
    Python Exception <class 'gdb.error'> Cannot convert value to int.:
    Error occurred in Python command: Cannot convert value to int.

Setting `python print-stack` to `full` shows that the error actually happens in the call to `PyObjectPtr.is_null` (in `Cython.Debugger.libpython`); `int` is called on an object of type `gdb.Value` (I cannot locate where this class is defined).

Note that at that point, regardless of the invocation of cygdb, the Python interpreter used by gdb is Python2.

Any help would be welcome.

This is on Arch Linux with gdb 7.9.1, python3 3.4.1, python2 2.7.10, cython{2,3} 0.23.

cross-posted to stackoverflow

Antony Lee

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Antony Lee | 23 Aug 05:47 2015
Picon

Bug: Offset lines in cygdb

Trying debugging the following with cygdb:

    from libc.stdlib cimport free

    def main():
        cdef int i
        free(&i)

(built with no flags passed to gcc in setup.py) results in

    (gdb) run
    Starting program: /usr/bin/python2 run.py # run is a wrapper that calls main
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/usr/lib/libthread_db.so.1".

    Program received signal SIGSEGV, Segmentation fault.
    0x00007ffff67b8140 in __pyx_pw_7invalid_1main ()
    from /home/antony/tests/bug-cygdb2/invalid.so
    (gdb) cy bt
    #9  0x00007ffff67b8140 in main() at /home/antony/tests/bug-cygdb2/invalid.pyx:0
            1    from libc.stdlib cimport free(gdb)

The error is reported at an incorrect line.  Additionally, an extra newline at the end of the listing would be a minor improvement.

Antony

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Antony Lee | 23 Aug 00:58 2015
Picon

is cython_debug/interpreter necessary?

Currently, when compiling a cython module for debugging, a `cython_debug/interpreter` file is written next to the xml info file; it contains the path to the interpreter.
The problem is that this prevents debugging a module that is intended both for Python2 and Python3 usage -- especially as the file is not overwritten when rebuilding the extension with the "other" interpreter.
I would guess that the actual interpreter could just be obtained from the "file" argument to gdb?

Antony

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Matthew Seal | 22 Aug 19:33 2015
Picon

Detecting compiler before defining extensions

I'm working on a cython project where I need to pass different flags based on the compiler. Normally I inject into the cmdclass arg to setuptool's setup method and wrap the install or build_ext commands to check internal state. But in this case I have to cythonize the extension modules before I reach the wrappers. Is there some simple way to read the chosen compiler when it's not supplied to setup.py as an argument before extensions need to be defined?

I posted a bounty question on SO trying to get an answer, but no luck so far.

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stefan Behnel | 22 Aug 17:55 2015
Picon

Cython 0.23.1 released

Hi everyone,

based on the feedback for the recent 0.23 release, here is a bug-fix-only
release that repairs several problems and regressions.

https://pypi.python.org/pypi/Cython/0.23.1

Complete changelog follows below. Upgrading is generally recommended.

You can get the signed release from here:

http://cython.org/

http://cython.org/release/Cython-0.23.1.tar.gz

http://cython.org/release/Cython-0.23.1.zip

SHA1 sums:
2ff0f863d3b996d2265d0bf06e567e5dd23d004d  Cython-0.23.1.tar.gz
42943dd9b1355015ec5d630419f93a91f4f118cb  Cython-0.23.1.zip

Have fun,

Stefan

0.23.1 (2015-08-22)
===================

Bugs fixed
----------

* Invalid C code for generators.  This fixes ticket 858.

* Invalid C code for some builtin methods.  This fixes ticket 856.

* Invalid C code for unused local buffer variables.
  This fixes ticket 154.

* Test failures on 32bit systems.  This fixes ticket 857.

* Code that uses "from xyz import *" and global C struct/union/array
  variables could fail to compile due to missing helper functions.
  This fixes ticket 851.

* Misnamed PEP 492 coroutine property ``cr_yieldfrom`` renamed to
  ``cr_await`` to match CPython.

* Missing deallocation code for C++ object attributes in certain
  extension class hierarchies.

* Crash when async coroutine was not awaited.

* Compiler crash on ``yield`` in signature annotations and default
  argument values.  Both are forbidden now.

* Compiler crash on certain constructs in ``finally`` clauses.

* Cython failed to build when CPython's pgen is installed.

--

-- 

--- 
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

smbat.makiyan | 21 Aug 15:38 2015

Cython generates wrong dealloc for classes in come cases

Hi all,

I am using cython in C++ workflow (not C), and I expect C++-like behavior from Cython generated code.

I hit a case that cause a memory leak.

I have cython class Base and two derived classes DerivedClass and DerivedClassWithMember (see sources in attach)
DerivedClassWithMember also contains AdditionalMember instance inited in __cinit__, and cython generates proper tp_dealloc where destroys every member.

But in case of DerivedClass tp_dealloc is not generated and it uses Base class tp_dealloc.

In other (C++) words constructor for DerivedClass is called, but destructor is not. At the same time DerivedClassWithMember is destroyed properly.

This is output from example.py :

CBase constructor
cython Base constructor
CDerived constructor
cython DerivedClass constructor
CBase constructor
cython Base constructor
CDerived constructor
cython DerivedClassWithMember constructor
CMember constructor
cython AdditionalMember constructor
job is done
CDerived destructor
CMember destructor
CBase destructor
CBase destructor

Is this a bug or expected behavior? How do I write my code so that all objects are destroyed properly?

My command line code for cython code generation python -m cython --cplus mem_leak.pyx -o mem_leak.cpp

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Attachment (cython_mem_leak.zip): application/zip, 23 KiB
Antony Lee | 21 Aug 10:23 2015
Picon

cygdb documentation issues

A few notes regarding the "Debugging your Cython program" doc page:

- The example build script has an incorrect first line `from distutils.code import setup`: right now there is no `distutils.code` neither in Python 2.7.10 not in Python 3.4.3.

- The example invocation `$ cygdb . --args python-dbg mainscript.py` is incorrect and fails, I assume the correct invocation is `cygdb . -- --args ...`

Antony

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Simon King | 21 Aug 01:33 2015
Picon
Picon

How to create functions of a given signature depending on parameters?

Hi!

It could be that my question is vaguely related with this question, but I couldn't find an answer to my problem there or elsewhere.

I have, for example,
ctypedef str (*functype)(str, int)

Now I want to create functions of type functype that depend on "parameters". By that, I mean something like a bound method, for example as follows
cdef class MyCaller:
    cdef
int start
   
def __init__(self, start):
       
self.start = start
    cdef str the_call
(self, str s, int end):
       
return s[self.start:end]

I expected that I would be able to do
cdef functype f
cdef
MyCaller M = MyCaller(3)
f
= M.the_call
However, "M.the_call" still has the additional argument "self", making it incompatible with "functype". Thus, "M.the_call" doesn't behave like a bound method and can't be assigned to "f".

Then, I expected that I would be able to use a closure instead of a bound method, doing
cdef functype creator(start):
    cdef str
out(str s, int end):
       
return s[start:end]
   
return out
cdef functype f
= creator(3)
But cython doesn't accept that either.

Something like a Cython version of "functools.partial" would also provide a solution, but I guess such thing doesn't exist. Or does it?

I guess creating functions of a prescribed signature but depending on parameters is a common problem that has a solution in Cython. But how?

Best regards,
Simon

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
houbaastef . | 20 Aug 23:56 2015
Picon

wrapping pthread

Hello folks,

i need to call some functions from the pthread library.

eg : int pthread_mutex_init (pthread_mutex_t *__mutex, const pthread_mutexattr_t *__mutexattr)

so i have to declare the opaque pthread_mutex_t and pthread_mutexattr_t

by reading some headers, pthread_mutex_t looks implemented as a struct on OSX, as a union on Linux, and maybe as pointers on some BSDs.

Is there a way to properly declare that in cython, without explicite and painful conditional compilation for each system ?

Thank you,
Stephane

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gmane