[Spice-devel] [PATCH spice-common] Remove extra self parameter from member function

Frediano Ziglio fziglio at redhat.com
Wed Apr 11 09:13:14 UTC 2018


> 
> When testing out some experimental protocol changes, I managed to
> trigger the following error:
> 
>   GEN      generated_client_demarshallers.c
> Traceback (most recent call last):
>   File "../../../spice-common/spice_codegen.py", line 267, in <module>
>     demarshal.write_protocol_parser(writer, proto, True)
>   File "/home/jjongsma/work/spice/spice-common/python_modules/demarshal.py",
>   line 1270, in write_protocol_parser
>     parsers[channel.value] = (channel.channel_type,
>     write_channel_parser(writer, channel.channel_type, is_server))
>   File "/home/jjongsma/work/spice/spice-common/python_modules/demarshal.py",
>   line 1163, in write_channel_parser
>     func = write_msg_parser(helpers, ids[i].message_type)
>   File "/home/jjongsma/work/spice/spice-common/python_modules/demarshal.py",
>   line 1061, in write_msg_parser
>     num_pointers = message.get_num_pointers()
>   File "/home/jjongsma/work/spice/spice-common/python_modules/ptypes.py",
>   line 855, in get_num_pointers
>     count = count + m.get_num_pointers()
>   File "/home/jjongsma/work/spice/spice-common/python_modules/ptypes.py",
>   line 662, in get_num_pointers
>     return self.member_type.get_num_pointers()
>   File "/home/jjongsma/work/spice/spice-common/python_modules/ptypes.py",
>   line 507, in get_num_pointers
>     if self.is_constant_length(self):
> TypeError: is_constant_length() takes exactly 1 argument (2 given)
> 
> Calling a member function will implicitly pass 'self' as the first
> argument, but we were also explicitly passing it as an argument
> (self.is_constant_length(self)). This resulted in the above error.
> ---
>  python_modules/ptypes.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py
> index 63a7a2f..d29c97a 100644
> --- a/python_modules/ptypes.py
> +++ b/python_modules/ptypes.py
> @@ -504,7 +504,7 @@ class ArrayType(Type):
>          element_count = self.element_type.get_num_pointers()
>          if element_count  == 0:
>              return 0
> -        if self.is_constant_length(self):
> +        if self.is_constant_length():
>              return element_count * self.size
>          raise Exception("Pointers in dynamic arrays not supported")
>  

Sure correct fix.

Off topic following.
I'm wondering why this was never used. It seems you are attempting to
have an array of pointers to something. Given however that dynamic size
element are not supported why not instead having a pointer to an array
or even just an array?
Why not having a test for this syntax?
Why we don't use pylint?
$ pylint -E python_modules/ptypes.py
No config file found, using default configuration
************* Module python_modules.ptypes
E:185,31: Instance of 'Type' has no 'c_type' member (no-member)
E:303,27: Instance of 'EnumBaseType' has no 'bits' member (no-member)
E:306,29: Instance of 'EnumBaseType' has no 'bits' member (no-member)
E:312,39: Instance of 'EnumBaseType' has no 'names' member; maybe 'name'? (no-member)
E:323,15: Instance of 'EnumBaseType' has no 'bits' member (no-member)
E:330,22: Instance of 'EnumBaseType' has no 'names' member; maybe 'name'? (no-member)
E:335,41: Instance of 'EnumBaseType' has no 'names' member; maybe 'name'? (no-member)
E:507,11: Too many positional arguments for method call (too-many-function-args)
E:581,40: Instance of 'Containee' has no 'member_type' member (no-member)
E:584,40: Instance of 'Containee' has no 'member_type' member (no-member)
E:587,40: Instance of 'Containee' has no 'member_type' member (no-member)
E:590,40: Instance of 'Containee' has no 'member_type' member (no-member)
E:894,19: Instance of 'ContainerType' has no 'members_by_name' member (no-member)
E:895,21: Instance of 'ContainerType' has no 'members_by_name' member (no-member)
(see error at line 507)

Frediano


More information about the Spice-devel mailing list