← Back to team overview

kicad-developers team mailing list archive

Re: Python binding of enums


On Thu, Aug 09, 2012 at 04:14:37PM +0200, Miguel Angel Ajo Pelayo wrote:
> Dick, what we're proposing is not that bad, I mean, it's parameter checking
> into C++ functions,
> for functions that can cause trouble. This is something good (unless inside
> of functions that can cause
> high CPU load).

More than cpu load, frequent calls since it's a check on the boundary...
Maybe I wouldn't do it in the 'cursor move' event, but no problem in the
autorouter entry function. And anyway these would be all easy checks
(nothing different than checking malloc result...)

Since you can't trust stuff coming from the python side you have to be
paranoid. perl has the whole 'tainting' system, where an outside value
is 'unsafe' until cleaned (the definition of 'cleaned' is a point of
debate itself)

> now), but, In my opinion, that
> can be worse, as that means that if you increase the enum type one day, you
> will have to go to the
> renamed function and change the check.

It's called "maintaining the library bindings" :D

> Example:
> obj->fn(x)   (x>10 will crash)
> class obj:
>     def fn(x):
>          if x>10: throw exception
>          else:  self._fn(x)

Exactly the facade pattern I was talking about in the other mail. I'm
not 100% sure, I'm not very strong with patterns...

Lorenzo Marcantonio
Logos Srl