|
| <prev next> |
__swig__slots__ on shadowed Python classes?: msg#00188programming.swig
Dear all, I'd like to have something like __slots__ on the shadow Python classes being generated by swig. Suppose you have: struct foo { char bar[MAX_BAR]; } FOO; and you swig it with -shadow, and in Python you do: f = FOO() f.baz = '123' then this assignment will blissfully go ahead, but your C library, when being passed f, will not do what you want. This error is sometimes amazingly hard to find (between Python modules, its a nuisance, but between a Python modules and other people's C libraries, it can become taxing - today, I had to revert to an ISDN D-channel protocol analyzer to get me back on track. And the last time I made the same error, it also took me a long time). Performing a check whether the attribute exists in the underlying C structure seems simple[1] to implement and I can volunteer a patch if it has any chance of being accepted. I'd be happy if the behaviour I described could be turned on with an additional commandline argument to swig, like -strict (only valid in conjunction with -shadow) or -shadow-strict. I'd be really pleased, of course, if this would be made default behaviour. The behaviour could even be turned on/off for individual classes, but this seems complete overkill. I'd appreciate any feedback. - Lars [1]: I rewrote _swig_setattr to: def _swig_setattr(self,class_type,name,value): if (name == "this"): if isinstance(value, class_type): self.__dict__[name] = value.this if hasattr(value,"thisown"): self.__dict__["thisown"] = value.thisown del value.thisown return if name not in ['this', 'thisown', '__class__'] and \ name not in class_type.__swig_slots__: raise AttributeError, name method = class_type.__swig_setmethods__.get(name,None) if method: return method(self,value) self.__dict__[name] = value and (manually) added __swig_slots__ to the wrapper classes. _______________________________________________ Swig maillist - Swig@xxxxxxxxxxxxxxx http://mailman.cs.uchicago.edu/mailman/listinfo/swig |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: naive question about passing in a NULL via Python: 00188, Gerald S. Williams |
|---|---|
| Previous by Thread: | [Newbie]:swig wrappers for bootstrapped classesi: 00188, Sharma K M |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |