Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
weird crash with cdef classes and C++ STL containers
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
David Warde-Farley  
View profile  
 More options Sep 12 2012, 10:56 pm
From: David Warde-Farley <d.warde.far...@gmail.com>
Date: Wed, 12 Sep 2012 22:56:50 -0400
Local: Wed, Sep 12 2012 10:56 pm
Subject: weird crash with cdef classes and C++ STL containers
Hello everyone,

So, shoving cdef classes into C++ STL containers *seems* to work (when
compiling with language='c++' of course) but with some strange side
effects. I'm getting quite a strange crash (seg fault), which only
happens the second time I call the function that does it. It seems to
be related to deque, replacing that with a Python deque is fine.
Replacing it with a C++ STL vector still yields the same problem.

https://gist.github.com/30a62791569666f6447b

This crash is happening with Cython 0.17. Anyone know what's going on?

David


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Bradshaw  
View profile  
 More options Sep 12 2012, 11:17 pm
From: Robert Bradshaw <rober...@gmail.com>
Date: Wed, 12 Sep 2012 20:17:03 -0700
Local: Wed, Sep 12 2012 11:17 pm
Subject: Re: [cython-users] weird crash with cdef classes and C++ STL containers

On Sep 12, 2012 7:56 PM, "David Warde-Farley" <d.warde.far...@gmail.com>
wrote:

> Hello everyone,

> So, shoving cdef classes into C++ STL containers *seems* to work (when
> compiling with language='c++' of course) but with some strange side
> effects. I'm getting quite a strange crash (seg fault), which only
> happens the second time I call the function that does it. It seems to
> be related to deque, replacing that with a Python deque is fine.
> Replacing it with a C++ STL vector still yields the same problem.

> https://gist.github.com/30a62791569666f6447b

> This crash is happening with Cython 0.17. Anyone know what's going on?

> David

Sticking Python objects in c++ containers doesn't work as they don't do
reference counting... This should be a compile error.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Warde-Farley  
View profile  
 More options Sep 12 2012, 11:37 pm
From: David Warde-Farley <d.warde.far...@gmail.com>
Date: Wed, 12 Sep 2012 23:37:44 -0400
Local: Wed, Sep 12 2012 11:37 pm
Subject: Re: [cython-users] weird crash with cdef classes and C++ STL containers

On Wed, Sep 12, 2012 at 11:17 PM, Robert Bradshaw <rober...@gmail.com> wrote:
> Sticking Python objects in c++ containers doesn't work as they don't do
> reference counting... This should be a compile error.

Welp, that explains it. I figured there might be some voodoo going on
that made it possible to refcount cdef classes in STL containers given
that it magically worked (and seems to work without crashing in other
cases).

Thanks!

David


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Bradshaw  
View profile  
 More options Sep 13 2012, 12:03 am
From: Robert Bradshaw <rober...@gmail.com>
Date: Wed, 12 Sep 2012 21:02:57 -0700
Local: Thurs, Sep 13 2012 12:02 am
Subject: Re: [cython-users] weird crash with cdef classes and C++ STL containers
On Wed, Sep 12, 2012 at 8:37 PM, David Warde-Farley

<d.warde.far...@gmail.com> wrote:
> On Wed, Sep 12, 2012 at 11:17 PM, Robert Bradshaw <rober...@gmail.com> wrote:

>> Sticking Python objects in c++ containers doesn't work as they don't do
>> reference counting... This should be a compile error.

> Welp, that explains it. I figured there might be some voodoo going on
> that made it possible to refcount cdef classes in STL containers given
> that it magically worked (and seems to work without crashing in other
> cases).

It's storing borrowed references, so it'll work as long as something
else in Python-space keeps it alive (which is, as evidenced, a rather
precarious situation to be in).

- Robert


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Warde-Farley  
View profile  
 More options Sep 13 2012, 1:26 am
From: David Warde-Farley <d.warde.far...@gmail.com>
Date: Thu, 13 Sep 2012 01:26:45 -0400
Local: Thurs, Sep 13 2012 1:26 am
Subject: Re: [cython-users] weird crash with cdef classes and C++ STL containers

On Thu, Sep 13, 2012 at 12:02 AM, Robert Bradshaw <rober...@gmail.com> wrote:
> It's storing borrowed references, so it'll work as long as something
> else in Python-space keeps it alive (which is, as evidenced, a rather
> precarious situation to be in).

Indeed. I'm confused, though: in the example I've given, all 4 nodes
have references not only to each other but in the method scope of
test_dfs. It's unclear to me how or why they'd be garbage collected
(or decref'd to 0) before test_dfs() finished (since it's a call in
the last line of test_dfs where the crash takes place).

David


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dag Sverre Seljebotn  
View profile  
 More options Sep 13 2012, 4:58 am
From: Dag Sverre Seljebotn <d.s.seljeb...@astro.uio.no>
Date: Thu, 13 Sep 2012 10:58:02 +0200
Local: Thurs, Sep 13 2012 4:58 am
Subject: Re: [cython-users] weird crash with cdef classes and C++ STL containers
On 09/13/2012 07:26 AM, David Warde-Farley wrote:

> On Thu, Sep 13, 2012 at 12:02 AM, Robert Bradshaw <rober...@gmail.com> wrote:

>> It's storing borrowed references, so it'll work as long as something
>> else in Python-space keeps it alive (which is, as evidenced, a rather
>> precarious situation to be in).

> Indeed. I'm confused, though: in the example I've given, all 4 nodes
> have references not only to each other but in the method scope of
> test_dfs. It's unclear to me how or why they'd be garbage collected
> (or decref'd to 0) before test_dfs() finished (since it's a call in
> the last line of test_dfs where the crash takes place).

If you want to do this, write an auto_ptr-like class, a class
overloading operator* and operator->, let's call it pyptr, which has a
PyObject* member but does INCREF on construction and DECREF on destruction.

Then simply create std::vector<pyptr> rather than std::vector<PyObject*>.

This *should* work, but to my knowledge there isn't any code available
already, so please report back if you do this and perhaps we can include
the pyptr class with Cython.

Dag Sverre


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dag Sverre Seljebotn  
View profile  
 More options Sep 13 2012, 4:59 am
From: Dag Sverre Seljebotn <d.s.seljeb...@astro.uio.no>
Date: Thu, 13 Sep 2012 10:59:17 +0200
Local: Thurs, Sep 13 2012 4:59 am
Subject: Re: [cython-users] weird crash with cdef classes and C++ STL containers
On 09/13/2012 10:58 AM, Dag Sverre Seljebotn wrote:

In fact, once std::vector<pyptr> works really well, it should be rather
easy to build it into Cython and support "std::vector<object>" as a
syntax for it. Not volunteering though.

Dag Sverre


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Bradshaw  
View profile  
 More options Sep 13 2012, 11:59 am
From: Robert Bradshaw <rober...@gmail.com>
Date: Thu, 13 Sep 2012 08:59:11 -0700
Local: Thurs, Sep 13 2012 11:59 am
Subject: Re: [cython-users] weird crash with cdef classes and C++ STL containers
On Thu, Sep 13, 2012 at 1:58 AM, Dag Sverre Seljebotn

I was about to suggest exactly this. Syntax is a good question though,
but perhaps  "std::vector<object>" would be sufficient.

- Robert


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bradley Froehle  
View profile  
 More options Sep 13 2012, 12:22 pm
From: Bradley Froehle <brad.froe...@gmail.com>
Date: Thu, 13 Sep 2012 09:22:44 -0700 (PDT)
Local: Thurs, Sep 13 2012 12:22 pm
Subject: Re: [cython-users] weird crash with cdef classes and C++ STL containers

A quick search turned up a lot of smart pointer adapters for `PyObject*`s.
 For
example, http://code.activestate.com/recipes/577985-automatic-python-pyobject-...

-Brad


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stefan Behnel  
View profile  
 More options Sep 15 2012, 1:47 am
From: Stefan Behnel <stefan...@behnel.de>
Date: Sat, 15 Sep 2012 07:47:08 +0200
Local: Sat, Sep 15 2012 1:47 am
Subject: Re: [cython-users] weird crash with cdef classes and C++ STL containers
Bradley Froehle, 13.09.2012 18:22:

+1 for supporting this in Cython. Any volunteering to make this work as in
"std::vector<object>" is definitely appreciated.

Stefan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »