Meador Inge <[email protected]> added the comment:
This is busted for plain old assignment too:
Python 3.3.0a0 (default:6374b4ffe00c, Sep 2 2011, 23:50:39)
[GCC 4.6.0 20110603 (Red Hat 4.6.0-10)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> buff = create_string_buffer(b'foo')
>>> p = c_char_p()
>>> p.value = addressof(buff)
>>> print(p.value)
b'foo'
>>> p.value = buff.value
>>> print(p.value)
b'foo'
>>> p.value = buff
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: string or integer address expected instead of c_char_Array_4 instance
I think having the conversion is an entirely reasonable request. It is the
equivalent of:
char buff[128] = "foo";
char *p = buff;
in C. I imagine a lot of C programmers would expect this behavior.
Also, 'ctypes' already does this type of conversion for function parameters.
Consider a function exported from a shared library 'libfoo' called
'print_string':
void print_string (char *str)
{
printf ("%s\n", str);
}
The following all work fine:
>>> libfoo = CDLL("./libfoo.so.1.0")
>>> buff = create_string_buffer("foo")
>>> libfoo.print_string(buff)
foo
>>> libfoo.print_string("foo")
foo
>>> libfoo.print_string(addressof(buff))
foo
I am working on a patch for this. I will post it soon.
----------
assignee: theller ->
nosy: +amaury.forgeotdarc, belopolsky, meadori -theller
stage: test needed -> needs patch
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue5149>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com