← Back to team overview

kicad-developers team mailing list archive

Re: Python binding of enums

 

On Thu, Aug 09, 2012 at 10:33:44AM +0200, Miguel Angel Ajo Pelayo wrote:
> As you said, it only checks that it's an "int", and it does an staic cast
> to PCB_FILE_T,

And the static cast for an enum is actually a reinterpret cast... so
nothing is gained, only type compliance

> It won't be a problem in most situations (where user is dependent from the
> ENUMS to know what he's calling),

Well, even with enum the issue stands... both layer number and colors
are enums and btw both address arrays. Other enums (like plot format and
drill mark type, in my case) aren't so critical but may produce
extremely unexpected behaviour.

> but for layer numbers, layer colors, etc, it can be a problem, since user
> can start tweaking the parameters, so
> better do a compare, and throw an exception,

OK, just what I've thougt

> if you tell me what kind of exception you can throw, I could set it up to
> convert the exception back to python-land.
> 
> Do we have some kind of exception for wrong parameters? It could make sense
> now, but not for all situations, only
> scripting-accesible functions, where enums could be used also as numbers
> (layer number, color number, etc..)

Uhmm... kicad at the moment only uses exceptions for the parsing stuff
AFAIK so we have IO_ERROR and its subclass PARSE_ERROR. I don't know why
the inheritance from IO_ERROR and std::exception is commented out (Dick
could answer this).

Without inventing new exception we could use the
std::domain_error/invalid_argument/out_of_range which are expressly
designed for user program.

Since all these are from std::exception a last-chance catch propagating
the what() message could be enough for now (too bad that C++ exceptions
don't snapsnot the call stack, it would be easier to find issues that
way).

-- 
Lorenzo Marcantonio
Logos Srl


References