Re: [ctypes-users] Standards for having strings modified by called functions (and structures)?
Brought to you by:
theller
From: Thomas H. <th...@py...> - 2003-08-27 18:10:14
|
"Mark McMahon" <mar...@eu...> writes: > Hi, > > I have had a quick look at Venster (comdlg.py), the ctypes documentation > (tutorial for version 6.2a), and various other stuff to see if there is > a reasonably standard way to get text from functions (and filled in > structures passed to functions). > > The easiest way seems to be (but the ctypes tutorial gives me the > impression it might be unsafe because python strings are immutable!) > # make the string big enough for the text > #(including nul terminator usually - but depends on the > data/function) > myString = '\0'* lenghtOfString # STEP 1 > > # call the function, myString is modified > FunctionModifyingString(myString) # STEP 2 > Right, Python strings are immutable. In C code, it's impossible to enforce this (unless you use the 'const' attribute). Although I cannot provide an example, I guess all hell breaks lose if you use ctypes (or C code) which violates this. And ctypes doesn't (yet?) have a const sttribute. Thomas > P.S. If you install Py2exe or ctypes you don't get the documentation - > can that be installed aswell? For both, it's included in the source distro. But installing it maybe useful. |