ctypes - c_buffer

Roman Yakovenko romany at actimize.com
Tue May 6 02:00:32 EDT 2003


	Good morning. I am using ctypes 0.6.0 library and I think I
found small defect in it.
The problem is - there is no simple way to find out the length of null
terminated string. 
If I wrong correct me please.

Consider next situation:
C function:
	 void dosmth( const char *from, char *to ); //this function
writes smth into to

In Python:
	x = c_buffer('\000', 128)
	dosmth( "Hello world", x )
	
Now the only way to know length of x as string is

str_x = []
for i in x.value:
    str_x.append(i)
    if not i:
        break
str_x = ''.join(str_x)

After this you may take the length of the string. 
This way is not too bad for C, but I write my programs in Python.

So the question is: Am I wrong or missed smth?

Roman








More information about the Python-list mailing list