Re: [cython-users] ambiguous overloaded method

541 views
Skip to first unread message

Stefan Behnel

unread,
Aug 30, 2012, 7:01:22 AM8/30/12
to cython...@googlegroups.com
bibi21000, 29.08.2012 21:38:
> Hi all
> I try to update python-openzwave and I've got some problems. The first is
> an ambiguous overloaded method when trying to compile
> I try to compile it on 0.14 (oneiric) and 0.15 (precise)
> Here is the pyx :
>
> if values_map.find(id) != values_map.end():
> datatype = PyValueTypes[values_map.at(id).GetType()]
>
> if datatype == "Bool":
> type_bool = value
> self.manager.SetValue(values_map.at(id), type_bool)
> elif datatype == "Byte":
> type_byte = value
> self.manager.SetValue(values_map.at(id),
> type_byte)
> elif datatype == "Decimal":
> type_float = value
> self.manager.SetValue(values_map.at(id), type_float)
> # TODO: this gives me an "ambiguous overloaded method", I don't
> understand why.
> elif datatype == "Int":
> type_int = value
> self.manager.SetValue(values_map.at(id), type_int)
> #elif datatype == "Short":
> # type_short = value
> # self.manager.SetValue(values_map.at(id), type_short)
> elif datatype == "String":
> type_string = string(value)
> self.manager.SetValue(values_map.at(id), type_string)
>
> The C headers
> bool SetValue( ValueID const& _id, bool const _value );
> bool SetValue( ValueID const& _id, uint8 const _value );
> bool SetValue( ValueID const& _id, float const _value );
> bool SetValue( ValueID const& _id, int32 const _value );
> bool SetValue( ValueID const& _id, int16 const _value );
> bool SetValue( ValueID const& _id, string const& _value );
>
> And the result of the compilation :
>
> Error compiling Cython file:
> ------------------------------------------------------------
> ...
> type_float = value
> self.manager.SetValue(values_map.at(id), type_float)
> # TODO: this gives me an "ambiguous overloaded method", I don't
> understand why.
> elif datatype == "Int":
> type_int = value
> self.manager.SetValue(values_map.at(id), type_int)
> ^
> ------------------------------------------------------------
>
> openzwave.pyx:1229:37: ambiguous overloaded method

Apparently, the author(s) had the same problem:

https://github.com/maartendamen/py-openzwave/blob/master/openzwave.pyx#L1134

It's based on these declarations further above in the file:

bint SetValue(ValueID& valueid, bint value)
bint SetValue(ValueID& valueid, uint8 value)
bint SetValue(ValueID& valueid, float value)
bint SetValue(ValueID& valueid, int32 value)
bint SetValue(ValueID& valueid, int16 value)
bint SetValue(ValueID& valueid, string value)

Note that the first parameter that is passed into the method is not a C++
reference type but the plain value type. Just a guess, but that might lead
to a slight difference in the signature matching that prevents an exact
match. IMHO, it shouldn't.

As a work-around, use the github version of their code.

Stefan

Stefan Behnel

unread,
Aug 30, 2012, 3:22:39 PM8/30/12
to cython...@googlegroups.com
bibi21000, 30.08.2012 20:55:
> Le jeudi 30 août 2012 13:01:25 UTC+2, Stefan Behnel a écrit :
>> bibi21000, 29.08.2012 21:38:
> Yes. As I've said in the previous post, I try to update it.
> You've surely seen that it is no longer maintained. It use an very old
> release of openzwave which have a poor set of functions and doesn't compile
> on recent distribs (precise for example)
>
>>
>> It's based on these declarations further above in the file:
>>
>> bint SetValue(ValueID& valueid, bint value)
>> bint SetValue(ValueID& valueid, uint8 value)
>> bint SetValue(ValueID& valueid, float value)
>> bint SetValue(ValueID& valueid, int32 value)
>> bint SetValue(ValueID& valueid, int16 value)
>> bint SetValue(ValueID& valueid, string value)
>>
>> Note that the first parameter that is passed into the method is not a C++
>> reference type but the plain value type. Just a guess, but that might lead
>> to a slight difference in the signature matching that prevents an exact
>> match. IMHO, it shouldn't.
>>
>> yes but it find the right methods for bint, unit8, float and string. The
> problem only appears with int32 and int16
>
> From cython documentation :
>
>
> 1.
>
> If the header file uses typedef names such as word to refer to
> platform-dependent flavours of numeric types, you will need a corresponding
> ctypedef<http://docs.cython.org/src/userguide/language_basics.html#ctypedef>statement, but you don’t need to match the type exactly, just use something
> of the right general kind (int, float, etc). For example,:
>
> ctypedef int word
>
> will work okay whatever the actual size of a word is (provided the
> header file defines it correctly). Conversion to and from Python types, if
> any, will also be used for this new type
>
> Sould it be the problem ?
> cython uses the same type to map int16 and "int32" so it couldn't find the
> right method after that ?

Ah, right - I missed this on first sight:

"""
ctypedef unsigned int uint32
ctypedef unsigned long uint64
ctypedef int int32
ctypedef int int16
ctypedef unsigned char uint8
"""

Sure, this is wrong. Change the int16 ctypedef from int to short and it
should work.


>> As a work-around, use the github version of their code.
> ?

... instead of a release version. But even better, fix the above and send
them a pull request.

Stefan

Stefan Behnel

unread,
Aug 30, 2012, 5:03:50 PM8/30/12
to cython...@googlegroups.com
bibi21000, 30.08.2012 22:40:
> Thanks a lot
> That works :)

You're welcome. If you want to do it really right, get rid of the above
declarations all together and use cimports from the libc.stdint module instead.

https://github.com/cython/cython/blob/master/Cython/Includes/libc/stdint.pxd

Bon courage,

Stefan

bibi21000

unread,
Sep 18, 2012, 5:51:35 PM9/18/12
to cython...@googlegroups.com, stef...@behnel.de
Me again.
Everything works fine on cython 0.14.1 but does not compile on cython 0.16.

The full code is here :
http://code.google.com/p/python-openzwave/source/browse/lib/libopenzwave.pyx

  1. running build_ext
  2. cythoning lib/libopenzwave.pyx to lib/libopenzwave.cpp
  1.  
  2. Error compiling Cython file:
  3. ------------------------------------------------------------
  4. ...
  1.         if values_map.find(id) != values_map.end():
  2.             datatype = PyValueTypes[values_map.at(id).GetType()]
  3.  
  4.             if datatype == "Bool":
  5.                 type_bool = value
  1.                 cret = self.manager.SetValue(values_map.at(id), type_bool)
  2.                                            ^
  3. ------------------------------------------------------------
  4.  
  5. lib/libopenzwave.pyx:1584:44: ambiguous overloaded method
  1.  
  2. Error compiling Cython file:
  3. ------------------------------------------------------------
  4. ...
  1.                 type_bool = value
  2.                 cret = self.manager.SetValue(values_map.at(id), type_bool)
  3.                 ret = 1 if cret else 0
  1.             elif datatype == "Byte":
  2.                 type_byte = value
  1.                 cret = self.manager.SetValue(values_map.at(id), type_byte)
  2.                                            ^
  3. ------------------------------------------------------------
  4.  
  5. lib/libopenzwave.pyx:1588:44: ambiguous overloaded method
  1.  
  2. Error compiling Cython file:
  3. ------------------------------------------------------------
  4. ...
  5.                 type_float = value
  1.                 cret = self.manager.SetValue(values_map.at(id), type_float)
  2.                 ret = 1 if cret else 0
  1.             elif datatype == "Int":
  2.                 type_int = value
  1.                 cret = self.manager.SetValue(values_map.at(id), type_int)
  2.                                            ^
  3. ------------------------------------------------------------
  4.  
  5. lib/libopenzwave.pyx:1596:44: ambiguous overloaded method
  1.  
  2. Error compiling Cython file:
  3. ------------------------------------------------------------
  4. ...
  1.                 type_int = value
  2.                 cret = self.manager.SetValue(values_map.at(id), type_int)
  3.                 ret = 1 if cret else 0
  4.             elif datatype == "Short":
  5.                 type_short = value
  6.                 cret = self.manager.SetValue(values_map.at(id), type_short)
  7.                                            ^
  8. ------------------------------------------------------------
  9.  
  10. lib/libopenzwave.pyx:1600:44: ambiguous overloaded method

I've moved all ctype declaration in a separate pxd file : http://code.google.com/p/python-openzwave/source/browse/lib/mylibc.pxd

So I can use the standard https://github.com/cython/cython/blob/master/Cython/Includes/libc/stdint.pxd simply now. Will it solve my problem ?



Le vendredi 31 août 2012 21:31:35 UTC+2, bibi21000 a écrit :
I'll take a look at this

Bon courage,
Merci

Stefan

bibi

bibi21000

unread,
Sep 27, 2012, 8:58:26 AM9/27/12
to cython...@googlegroups.com
well, I try to use the standard integer types (exact match size) but doesn't compile with 0.16
one user reports that compilation is ok with 0.15
any idea ?
Reply all
Reply to author
Forward
0 new messages