You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MSSpectrum::get...DataArrayByName segfaults if name not found #3002
first some context, this was implemented and discussed here #2847 and then here #2855 . @timosachsenberg@hendrikweisser should we implement has...DataArrayWithName() functions? would that help?
I am not sure how the iterator solution is a good idea as it exposes the internal workings to the user and at this point we might as well give the user raw access to the data structure and ask them to use find themselves. I suggest the interface should be
void hasIntegerDataArray(const String& name);
// may throw InvalidArgumentException, you need to check hasIntegerDataArray first
IntegerDataArray& getIntegerDataArray(const String& name);
what would the alternative interface look like?
// may return invalid iterator, you need to compare against getIntegerDataArrayEndIterator
IntegerDataArray::iterator getIntegerDataArray(const String& name);
IntegerDataArray::iterator getIntegerDataArrayEndIterator(const String& name);
now I think the first interface is clearer and it is easier to check that people adhere to it.
I am not sure how the iterator solution is a good idea as it exposes the internal workings to the user and at this point we might as well give the user raw access to the data structure and ask them to use find themselves. I suggest the interface should be
void hasIntegerDataArray(const String& name);
// may throw InvalidArgumentException, you need to check hasIntegerDataArray first
IntegerDataArray& getIntegerDataArray(const String& name);
what would the alternative interface look like?
// may return invalid iterator, you need to compare against getIntegerDataArrayEndIterator
IntegerDataArray::iterator getIntegerDataArray(const String& name);
IntegerDataArray::iterator getIntegerDataArrayEndIterator(const String& name);
now I think the first interface is clearer and it is easier to check that people adhere to it. In either case, the current interface is pretty messy and contains multiple ways to access the data, either by getting a single array or by getting all of them ...
void hasIntegerDataArray(const String& name);
// may throw InvalidArgumentException, you need to check hasIntegerDataArray first
IntegerDataArray& getIntegerDataArray(const String& name);
The problem that I have with this is that the look-up has to happen twice - first to check if the name exists, then again to return the array. What's wrong with returning an iterator and then checking? if (spectrum.getIntegerDataArrayByName(name) != spectrum.getIntegerDataArrays().end())
The pointer has the nice property that it could also be passed to (e.g. scoring) methods that may use this information (e.g., an annotated charge array).
Downside is, that reallocation invalidates these pointers.
Another alternative would be returning an index or -1
Resolved on develop: commit 61cd113 removed the unsafe MSSpectrum::get*DataArrayByName getters, so a missing name can no longer be dereferenced through this API. The current API exposes the data-array containers for explicit checked lookup. Closing as completed.
Activity
enetz commentedon Nov 13, 2017
first some context, this was implemented and discussed here #2847 and then here #2855 .
@timosachsenberg @hendrikweisser should we implement
has...DataArrayWithName()functions? would that help?hroest commentedon Nov 13, 2017
I am not sure how the iterator solution is a good idea as it exposes the internal workings to the user and at this point we might as well give the user raw access to the data structure and ask them to use find themselves. I suggest the interface should be
what would the alternative interface look like?
now I think the first interface is clearer and it is easier to check that people adhere to it.
hroest commentedon Nov 13, 2017
I am not sure how the iterator solution is a good idea as it exposes the internal workings to the user and at this point we might as well give the user raw access to the data structure and ask them to use find themselves. I suggest the interface should be
what would the alternative interface look like?
now I think the first interface is clearer and it is easier to check that people adhere to it. In either case, the current interface is pretty messy and contains multiple ways to access the data, either by getting a single array or by getting all of them ...
hendrikweisser commentedon Nov 13, 2017
The problem that I have with this is that the look-up has to happen twice - first to check if the name exists, then again to return the array. What's wrong with returning an iterator and then checking?
if (spectrum.getIntegerDataArrayByName(name) != spectrum.getIntegerDataArrays().end())hendrikweisser commentedon Nov 13, 2017
Or we could be old-school and return a pointer that may be zero...
timosachsenberg commentedon Nov 13, 2017
The pointer has the nice property that it could also be passed to (e.g. scoring) methods that may use this information (e.g., an annotated charge array).
Downside is, that reallocation invalidates these pointers.
Another alternative would be returning an index or -1
timosachsenberg commentedon Jul 14, 2026
Resolved on
develop: commit 61cd113 removed the unsafeMSSpectrum::get*DataArrayByNamegetters, so a missing name can no longer be dereferenced through this API. The current API exposes the data-array containers for explicit checked lookup. Closing as completed.61cd11352b