Undefined behavior with structs

21 views
Skip to first unread message

Matthew Gidden

unread,
Apr 2, 2014, 8:59:13 PM4/2/14
to xdress
Hi all,

I'm seeing some undefined behavior with some structs I'm xdressing. My project is on github here. The oddities I'm seeing is that after a purely clean build (removing install and build dirs), I'm getting segfaults from the command line on a simple struct, correct construction with ipython on the same simply struct, and seg faults on both for a more complicated struct

Both my xdress and build commands work without error. 

My ipython calls follow below:
In [1]: from cyclopts.execute import SupplyParams
In [2]: params = SupplyParams()
In [3]: from cyclopts.execute import RequestParams
In [4]: other = RequestParams()
Segmentation fault (core dumped)

And my command line calls are:
19:51 ~$ python -c "from cyclopts.execute import SupplyParams; params = SupplyParams();"
Segmentation fault (core dumped)
19:51 ~$ python -c "from cyclopts.execute import RequestParams; params = RequestParams();"
Segmentation fault (core dumped)

Any help would be appreciated.

--
Matthew Gidden
Ph.D. Candidate, Nuclear Engineering
The University of Wisconsin -- Madison
Ph. 225.892.3192

Matthew McCormick

unread,
Apr 2, 2014, 9:39:24 PM4/2/14
to Matthew Gidden, xdress
Heya Blackbeard,

What tool is being used to parse the C++?

If a default constructor is explicitly added to the C++ declaration,
does it fix the crash?

Cheers,
spidr
> --
> You received this message because you are subscribed to the Google Groups
> "xdress" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/xdress/CAHRdPFyfcDtq45QB3ShAXNURa5p0%3DKG6LqsWd184TSrNgm9KGw%40mail.gmail.com.

Matthew Gidden

unread,
Apr 3, 2014, 8:57:13 AM4/3/14
to Matthew McCormick, xdress
Hi spidr!




On Wed, Apr 2, 2014 at 8:39 PM, Matthew McCormick <matthew.m...@gmail.com> wrote:
Heya Blackbeard,

What tool is being used to parse the C++?
gccxml 

If a default constructor is explicitly added to the C++ declaration,
does it fix the crash?
yes, it does. 

scopz helped me look through some possible issues last night, and we discovered that if you used a class declaration with all public members, seg faults go away. 

the core problem is that  for a struct, its __init__ looks like:
    def __init__(self, ):
        """RequestParams(self, )                                                                                                                      
        """
        self._inst = malloc(sizeof(cpp_execute.RequestParams))
        (<cpp_execute.RequestParams *> self._inst)[0] = cpp_execute.RequestParams()

But a class' __init__ looks like:
    def __init__(self, ):
        """RequestParams(self, )                                                                                                                      
        """
        self._inst = new cpp_execute.RequestParams()

Regards, 
bb

Anthony Scopatz

unread,
Apr 3, 2014, 3:39:34 PM4/3/14
to Matthew Gidden, Matthew McCormick, xdress
For the record, 

I think what is causing the issue is that structs for C++ in cython were being malloc'd rather than new'd.  I suppose that they should be new'd as well. I don't think that this will be a hard fix.  But we should also add a test case for this.

Be Well
Anthony


Reply all
Reply to author
Forward
0 new messages