Ian Henriksen | 17 Jul 04:00 2015
Picon

Variadic functions don't check types of trailing input variables

I discovered this accidentally while investigating
ways to use variadic templates in Cython.
It unintentionally allows a user to pass an arbitrary
number of arguments of arbitrary types to a function
declared to have a variable number of arguments
and is very clearly a bug.
Here's an intriguing basic example that implements
a Python-like variadic printing function.

//variadic_print.hpp
#pragma once
#include <iostream>

template<typename T>
void cpp_print(T value){
  std::cout << value << std::endl;
}

template<typename T, typename... Args>
void cpp_print(T value, Args... args){
  std::cout << value << ", ";
  print(args...);
}


# cpp_print.pyx
# distutils: extra_compile_args = ['-std=c++11']
# distutils: language='c++'

from libcpp.string cimport string

cdef extern from "variadic_print.hpp" nogil:
    void cpp_print[T](T arg, ...)

def test():
    cdef:
        int thing1 = 1
        double thing2 = 2
        long long thing3 = 3
        float thing4 = 4
        string thing5 = "5"
    cpp_print(thing1, thing2, thing3, thing4, thing5)

--

---
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.
bibi21000 | 16 Jul 23:02 2015
Picon

Segfault with latest versbion of python on Ubuntu 64 bits

Hi,
I'm the developper of the python-openzwave library (https://github.com/OpenZWave/python-openzwave), it use cython to wrap the c++ openzwave library.
Everything works fine before the last release of python (on Ubuntu 64bits), but now I've got a segfault when importing the wrapped library :

$ python 
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import libopenzwave
Erreur de segmentation (core dumped)

With this version, it's OK :
$ python

Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.


I can reproduce this on differents release of Ubuntu 64bits : 12.04, 14.04, 15.04

It works fine on ubuntu 32bits (12.04,14.04,  ...), rapsbian, ...

the only difference between 32bits and 64bits when cythoning is this line :

src-lib/libopenzwave/libopenzwave.cpp:441:36: note: in definition of macro ‘__Pyx_PyBool_FromLong’
 #define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
                                    ^
Any idea ?

Thanks in advance

--

---
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.
Yaidel Ferrales | 16 Jul 19:24 2015
Picon

Can't import module

I have an external module (depthsense) and the installation works just fine. After it I can see the module by using the command:

sorted(["%s==%s" % (i.key, i.version) for i in pip.get_installed_distributions()])

<<output

['adium-theme-ubuntu==0.3.4', 'apt-xapian-index==0.45', 'argparse==1.2.1', 'chardet==2.0.1', 'colorama==0.2.5', 'command-not-found==0.3', 'cython==0.22.1', 'debtagshw==0.1', 'decorator==3.4.0', 'defer==1.0.6', 'depthsense==0.1', 'dirspec==13.10', 'duplicity==0.6.23', 'html5lib==0.999', 'httplib2==0.8', 'ipython==1.2.1', 'lockfile==0.8', 'lxml==3.3.3', 'matplotlib==1.3.1', 'numpy==1.8.2', 'oauthlib==0.6.1', 'oneconf==0.3.7', 'pam==0.4.2', 'pexpect==3.1', 'pillow==2.3.0', 'piston-mini-client==0.7.5', 'pycrypto==2.6.1', 'pycups==1.9.66', 'pycurl==7.19.3', 'pygame==1.9.1release', 'pygobject==3.12.0', 'pyopengl==3.0.2', 'pyopenssl==0.13', 'pyparsing==2.0.1', 'pyrex==0.9.8.5', 'pyserial==2.6', 'pysmbc==1.0.14.1', 'python-apt==0.9.3.5', 'python-dateutil==1.5', 'python-debian==0.1.21-nmu2ubuntu2', 'pytz==2012c', 'pyxdg==0.25', 'reportlab==3.0', 'requests==2.2.1', 'scipy==0.13.3', 'sessioninstaller==0.0.0', 'simplegeneric==0.8.1', 'six==1.5.2', 'software-center-aptd-plugins==0.0.0', 'ssh-import-id==3.21', 'system-service==0.1.6', 'twisted-core==13.2.0', 'twisted-web==13.2.0', 'unity-lens-photos==1.0', 'urllib3==1.7.1', 'wsgiref==0.1.2', 'xdiagnose==3.6.3build2', 'zope.interface==4.0.5']

but when I try to import it I can't. The module setup uses distutils and I installed it using the command: python setup.py install.

Thanks in advance

--

---
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.
Eric Reynolds | 16 Jul 17:37 2015
Picon

cython compiler does not complain but produces invalid C code

Hello fellow Cython users,

The C compiler (but not the Cython compiler) is giving me lots of errors (both MSVC and GCC)


# cython_module.pyx

cdef class A:
cdef list x
def __init__(self):
self.x = [1,2,3]
cdef f(self):
pass

cdef class B(A):
cdef f(self):
z = tuple(None for y in self.x)

# run.py

import pyximport
pyximport.install()

import cython_module



Is this a bug?

Thanks, regards,

Eric

--

---
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.
Giuseppe Attardi | 16 Jul 12:24 2015
Picon

deprecated conversion from string constant

Compiling cython 0.2.1 using g++ I get this warning:

 warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

due to a missing const specifier in the generated code:

static char* __pyx_import_star_type_names[] = {
  "AffixExtractor",
  ...
};

--

---
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.
Himanshu Mishra | 16 Jul 10:25 2015
Picon

How can I install with --no-cython-compile?

On my CI environment, I install Cython using `pip install Cython` but I have seen that using --no-cython-compile is recommended by Stefan. But I'm confused how can I do that?

I don't think he means
$ pip install Cython --no-cython-compile

because it can't work

--

---
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.
Yaidel Ferrales | 15 Jul 17:39 2015
Picon

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Hello, I'm trying to build a wrapper for a DepthSense SDK writen Cython but when I run the command python setup.py install this is the output I get:

running install
running build
running build_ext
skipping 'Depthsense.cpp' Cython extension (up-to-date)
building 'depthsense' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/opt/softkinetic/DepthSenseSDK/include -I/usr/include/python2.7 -c Depthsense.cpp -o build/temp.linux-x86_64-2.7/Depthsense.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
In file included from /usr/include/python2.7/numpy/ndarraytypes.h:1761:0,
                 from /usr/include/python2.7/numpy/ndarrayobject.h:17,
                 from /usr/include/python2.7/numpy/arrayobject.h:4,
                 from Depthsense.cpp:263:
/usr/include/python2.7/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it by " \
  ^
Depthsense.cpp: In function ‘PyObject* __pyx_pf_10depthsense_11dsDepthNode_20captureConfiguration___get__(__pyx_obj_10depthsense_dsDepthNode*)’:
Depthsense.cpp:5778:103: error: invalid conversion from ‘uint32_t* {aka unsigned int*}’ to ‘int32_t* {aka int*}’ [-fpermissive]
   DepthSense::FrameFormat_toResolution(__pyx_v_config.frameFormat, (&__pyx_v_width), (&__pyx_v_height));
                                                                                                       ^
In file included from Depthsense.cpp:266:0:
/opt/softkinetic/DepthSenseSDK/include/DepthSense.hxx:285:9: error:   initializing argument 2 of ‘void DepthSense::FrameFormat_toResolution(DepthSense::FrameFormat, int32_t*, int32_t*)’ [-fpermissive]
         FrameFormat_toResolution (FrameFormat frameFormat, int32_t* width, int32_t* height);
         ^
Depthsense.cpp:5778:103: error: invalid conversion from ‘uint32_t* {aka unsigned int*}’ to ‘int32_t* {aka int*}’ [-fpermissive]
   DepthSense::FrameFormat_toResolution(__pyx_v_config.frameFormat, (&__pyx_v_width), (&__pyx_v_height));
                                                                                                       ^
In file included from Depthsense.cpp:266:0:
/opt/softkinetic/DepthSenseSDK/include/DepthSense.hxx:285:9: error:   initializing argument 3 of ‘void DepthSense::FrameFormat_toResolution(DepthSense::FrameFormat, int32_t*, int32_t*)’ [-fpermissive]
         FrameFormat_toResolution (FrameFormat frameFormat, int32_t* width, int32_t* height);
         ^
In file included from /usr/include/python2.7/numpy/ndarrayobject.h:26:0,
                 from /usr/include/python2.7/numpy/arrayobject.h:4,
                 from Depthsense.cpp:263:
/usr/include/python2.7/numpy/__multiarray_api.h: At global scope:
/usr/include/python2.7/numpy/__multiarray_api.h:1629:1: warning: ‘int _import_array()’ defined but not used [-Wunused-function]
 _import_array(void)
 ^
In file included from /usr/include/python2.7/numpy/ufuncobject.h:327:0,
                 from Depthsense.cpp:264:
/usr/include/python2.7/numpy/__ufunc_api.h:241:1: warning: ‘int _import_umath()’ defined but not used [-Wunused-function]
 _import_umath(void)
 ^
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

My setup.py looks like this:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext


ext = Extension (
'depthsense', # extension name
['Depthsense.pyx'], # cython source
language = 'c++', # make a c++ file
include_dirs = ['/opt/softkinetic/DepthSenseSDK/include'],
libraries = ['DepthSense'],
library_dirs = ['/opt/softkinetic/DepthSenseSDK/lib/'],
extra_link_args=['-Wl,-rpath=/opt/softkinetic/DepthSenseSDK/lib/'],
)

setup (
name = 'depthsense',
version = '0.1',
ext_package = 'depthsense',
ext_modules = [ext],
cmdclass = {'build_ext' : build_ext}
)

Thanks in advance.

--

---
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.
Ryan Houlette | 15 Jul 16:13 2015
Picon

Memory leak with typed memoryviews and CPython arrays?

Hi folks. I've run into what seems to be a memory leak when I use typed memoryviews with CPython arrays.

Here's a repro (using Python 2.7.5 and Cython 0.22).

cdef cython_memory_leak_repro():
    cdef
:
       
double[:] memview


    lst
= [3.14] * 1000


   
for i in range(100000):
        arr
= array('d', lst)
        memview
= arr

Running this snippet grows the process memory permanently by ~900MB. If I comment out the last line (the memoryview assignment), memory usage does not grow.

Looking at the generated C code, it looks like the problem might be in this line:
https://github.com/cython/cython/blob/6254fcc6f9e2e8739e043ef1d89ac502496a61a9/Cython/Utility/Buffer.c#L133

which renders for the above example as:

static void __Pyx_ReleaseBuffer(Py_buffer *view) {
   
PyObject *obj = view->obj;
   
if (!obj) return;
   
if (PyObject_CheckBuffer(obj)) {
       
PyBuffer_Release(view);
       
return;
   
}
       
if (PyObject_TypeCheck(obj, __pyx_ptype_7cpython_5array_array)) { __pyx_pw_7cpython_5array_5array_3__releasebuffer__(obj, view); return; }
   
Py_DECREF(obj);
    view
->obj = NULL;
}


__pyx_pw_7cpython_5array_5array_3__releasebuffer_() is invoked and then the method returns without decrementing the reference count for obj (the CPython array). Those arrays thus never get deallocated. Profiling with valgrind massif confirms that the heap usage is due to the CPython arrays.

It seems like the "return" call in the PyObject_TypeCheck() line above is incorrect, and the flow should continue through to the following two lines to decrement the reference and zero out the pointer.

Can anyone confirm that this is indeed a bug, or am I just doing something wrong?

Thanks!
Ryan

--

---
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.
Eric Reynolds | 15 Jul 13:05 2015
Picon

Python object type 'A' cannot be used as a template argument

Hello everyone,

Here's my code:

# vector.pyx
from libcpp.vector cimport vector

cdef class A:
    cdef int x
  
cdef vector[A] vect

This doesn't compile under 0.22.1, in fact `cython --cplus vector.pyx` gives the following error:

Error compiling Cython file:
------------------------------------------------------------
...
from libcpp.vector cimport vector

cdef class A:
    cdef int x

cdef vector[A] vect
           ^
------------------------------------------------------------

vector.pyx:6:12: Python object type 'A' cannot be used as a template argument

But this worked perfectly in earlier versions of Cython (I have checked using 0.15.1), and generated the statically typed C++ code I would have expected it to generate.

Is this intentional or is it a bug?

Thanks, regards,

Eric

--

---
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.
Anthony Scopatz | 15 Jul 03:59 2015
Picon

ANN: "Effective Computation in Physics" Released, 50% Off until Friday July 17th

Hello All!

We are ecstatic to announce the release of the first edition of Effective Computation in Physics - Field Guide to Research with Python, published by O'Reilly Media.

You (or your students and colleagues) can even get a 50% discount if you grab it before July 17th using the code: WKPYDP.

This book was heavily inspired by Software Carpentry. Though it draws on many examples from the physical sciences, many of the topics and  chapters are broadly applicable to all of scientific computing. We hope that you'll find it useful even if your domain is biological, chemical, or mathematical in nature!

For more information, please check out:
Don't hesitate to contact us via email at authors <at> physics.codes or on twitter <at> physics_codes with any questions or concerns that you have.

Accompanying Jupyter Notebooks for all of the code in the book can be found on GitHub at https://github.com/physics-codes/examples released under the CC0 license.

Please remember to review the book and give feedback online once you have finished reading it. We truly appreciate it, no matter what you say.

Sorry if you received this announcement multiple times. We promise this will be the only time we ever send out such an announcement.

We couldn't have done it without you!
Katy Huff & Anthony Scopatz

--

---
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.
David Warde-Farley | 14 Jul 21:40 2015
Picon

Lots of compiler warnings on OS X re: numpy?

Hello,

I'm seeing a lot of NumPy-related compiler warnings using NumPy 1.9.x
and Cython 0.22.1.

In the gist below are the errors and some minimal source code:

https://gist.github.com/dwf/36accf3f88cf9eb9a1ab

I suppose that I only really need NumPy for the sake of npy_intp. Is
there a preferred way to interact with NumPy from Cython that doesn't
incur all of this noise? Is there a reliable alternative to importing
npy_intp that maintains compatibility?

Thanks,
David

--

-- 

--- 
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