Skip to content

WIP: Improve EventContext::getExtension error checking

Gerhard Raven requested to merge graven/Gaudi:getExtension into master

The current EventContext::getExtension always returns a pointer to the extension.

In case the type does not match, or there is no extension, this implies that a nullptr is returned. Looking at Atlas LXR getExtension is typically used without any checking on the return value, and the returned pointer is blindly dereferenced. So in case of error, the result is a SEGV. If instead of doing an any_cast on a pointer to the any, the any_cast it would have been done on the any itself, an error would instead generate an exception.

This MR changes the interface of getExtension slightly in a backwards incompatible way: if the 'old' behavior is required, one has to provide a pointer type. In case a non-pointer is provided, a plain any_cast is done.

As a result, code which currently does eg.

const std::string* contextName = context.getExtension<std::string>();

has to be changed into:

const std::string* contextName = context.getExtension<std::string*>();

On the other hand, one can now also do:

const std::string& contextName = context.getExtension<std::string>();

which either succeeds, or throws -- so this is a much more 'safe' interface. However, the problem is that of course this change is not backwards compatible. Now, as a migration, one could first introduce add the possibility to do

const std::string* contextName = context.getExtension<std::string*>();

without changing the behavior of getExtension<T> where T is not a pointer, and then in a next release change that function...

Given that fact that this is backwards incompatible, I leave this MR as WIP.

Merge request reports