Skip to content

[FIX] fix return a reference to local variable. - #2855

Merged
timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:fix/dataarrayname
Aug 14, 2017
Merged

timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:fix/dataarrayname

Conversation

@timosachsenberg

Copy link
Copy Markdown
Contributor

this fixes the build issue so I would like to merge this quickly. @enetz it currently doesn't check for the presence of the name and if it is missing we probably get a segfault. Best way would probably be to return the iterator but then the function is not easily wrapped with pyOpenMS.

@timosachsenberg
timosachsenberg merged commit 4816a2c into OpenMS:develop Aug 14, 2017
@cbielow

cbielow commented Aug 15, 2017

Copy link
Copy Markdown
Contributor

mhh.. both solutions are illegal C++ if the name is not found :/ (segfault as you mentioned)

Why not use the iterator and provide another (less efficient) interface for pyOpenMS? Or would Raw pointers be any better?
Alternatively, throw an exception if the array is not found -- but I guess sometimes its expected that it does not exist, so exception is not warranted.

@timosachsenberg

Copy link
Copy Markdown
Contributor Author

@hroest is there any way we could use the iterator solution? would this mean that autowrap needs to be extended or only some addon file for pyOpenMS

@timosachsenberg

timosachsenberg commented Aug 15, 2017 •

Copy link
Copy Markdown
Contributor Author

(another (bad) solution would be to return a reference to a static instance of an empty vector. Not really though as changing it will surprise the user...)
Another way would be to create the dataarray and return a reference to it

@timosachsenberg
timosachsenberg deleted the fix/dataarrayname branch August 15, 2017 08:24
@cbielow

cbielow commented Aug 15, 2017

Copy link
Copy Markdown
Contributor

since the return value is not const, how does the user tell if he got the real array or the 'does not exist' dummy version? People might even start to fill in data... this gets messy quickly...

@timosachsenberg

Copy link
Copy Markdown
Contributor Author

Yep. These are no real solutions. Iterator would be best or we need a has/get combination

@hroest

hroest commented Aug 18, 2017

Copy link
Copy Markdown
Contributor

there are ways to get an iterator, but its quite ugly and also there is a chance that it will point to an invalid end() element which cannot be tested in Python. See https://github.com/OpenMS/OpenMS/blob/develop/src/pyOpenMS/pxds/MSChromatogram.pxd#L46 for examples, so libcpp_vector[Klass].iterator works as return value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants