[clam-devel] ipyclam: trouble with ProcessingConfigs

David García Garzón david.garcia at barcelonamedia.org
Fri May 27 05:12:16 PDT 2011


On Friday 27 May 2011 12:27:13 Xavier Serra Román wrote:
> On May 27, 2011, at 11:47 AM, David García Garzón wrote:
> > Xavi, Pau, you didn't notice but you were sending catalan bable to the
> > list ;-) I am not able to reproduce the error neither. It looks like
> > typeid does not work as it should. Maybe a dangling library in testfarm.
> > Who knows
> 
> I'll keep the conflicting tests commented untill we figure out more.
> 
> > .
> > 
> > Xavi, i took a look to the setAttribute implementation and i see some
> > flaws. In order to choose the type you rely on the type of the new
> > value. But if that value is not the correct one for the attribute you
> > force the assignement which could lead to memory corruption.
> > 
> > The proper solution is to check first the attribute type, then check the
> > value is of a compatible type, raising an exception if not, then setting
> > the attribute.
> > 
> > if ( config.attributeType(index) == typeid(bool) )
> > {
> > 
> > 	if (not PyBool_Check(value) )
> > 	
> > 		raise TypeError // Translate to C
> > 	
> > 	bool boolvalue = value==Py_True;
> > 	config.setAttributeValue<bool>(index, boolvalue);
> > 	return;
> > 
> > }
> 
> Yes, I know. That is going to be the next step. First was setting
> attributes trusting that the user passes the correct value, then making a
> test passing the incorrect type and expecting an exception.

Notice that beside the error report there is an inversion of control. Instead 
of relying on the passed value type to chose the attribute type, you rely on 
the type of the attribute to choose the conversion to apply to the incoming 
value. In either case you can do the type check ans exception handling or not.






More information about the clam-devel mailing list