[ctypes-users] Re: [Q] How can I realloc() enable?
Brought to you by:
theller
From: Paul M. <pf_...@ya...> - 2003-09-23 19:32:15
|
=?ks_c_5601-1987?B?seggseK/tQ==?= <nta...@ho...> writes: > When I pass 'some python variable;s pointer' to C(.so) using c_char_p > type or pointer()... does it possible that re-size python variable in > .c files(realloc())? > > I tried... but impossible. I would imagine it isn't possible. After all, Python variables aren't "raw" memory created via malloc. > Does anyone success it? I'd guess you should use malloc directly. Something like this (totally untested!!!) might work ptr = cdll.msvcrt.malloc(100) # This is a raw pointer cdll.msvcrt.strcpy(ptr, "Hello, world!") # Fill with raw C functions my_dll_function(ptr) # Call the DLL - no need for pointer() result = (c_char * 200)() # ctypes char array cdll.msvcrt.strcpy(pointer(result), ptr) cdll.msvcrt.free(ptr) That's deep black magic, and I'm *sure* I got it wrong. But you may be able to work from the general principle. Paul -- This signature intentionally left blank |