mark florisson, 26.04.2011 17:18:
On 26 April 2011 16:43, Stefan Behnel wrote:
mark florisson, 26.04.2011 16:23:

I've been working a bit on fused types
(http://wiki.cython.org/enhancements/fusedtypes), and I've got it to
generate code for every permutation of specific types. Currently it
only works for cdef functions. Now in SimpleCallNode I'm trying to use
PyrexTypes.best_match() to find the function with the best signature,
but it doesn't seem to take care of coercions, e.g. it calls
'assignable_from' on the dst_type (e.g. char *), but for
BuiltinObjectType (a str) this returns false.

Which is correct. "char*" cannot coerce from/to "str". It can coerce to
"bytes", though.

http://wiki.cython.org/enhancements/stringliterals

Right, I see, so the thing is that I was using string literals which
should be inferred as the bytes type when they are assigned to a char
*. The thing is that because the type is fused, the argument may be
anything, so I was hoping best_match would figure it out for me.
Apparently it doesn't, and indeed, this example doesn't work:

cdef extern from "Foo.h":
     cdef cppclass Foo:
         Foo(char *)
         Foo(int)

cdef char *foo = "foo"
cdef Foo* foo = new Foo("foo") #<- this doesn't work ("no suitable
method found")
cdef Foo* bar = new Foo(foo)   #<- this works

So that's pretty lame, I think I should fix that.

Well, I assume it's less lame when you use b"foo". But given the current auto-coerce semantics for unprefixed string literals in Cython, I agree that it should also auto-coerce here.

Stefan
_______________________________________________
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel

Reply via email to