Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-14 Thread Jach Fong
Gregory Ewing at 2018/4/15 PM 08:20 wrote: Jach Fong wrote:  >>> pvoid = ctypes.c_void_p(ctypes.addressof(buf0))  >>> pvoid.contents Traceback (most recent call last):   File "", line 1, in AttributeError: 'c_void_p' object has no attribute 'contents' I think the 'contents' attribute only

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-14 Thread Gregory Ewing
Jach Fong wrote: >>> pvoid = ctypes.c_void_p(ctypes.addressof(buf0)) >>> pvoid.contents Traceback (most recent call last): File "", line 1, in AttributeError: 'c_void_p' object has no attribute 'contents' I think the 'contents' attribute only applies to pointers that are pointing at part

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-13 Thread eryk sun
On Sat, Apr 14, 2018 at 1:57 AM, Jach Fong wrote: > eryk sun at 2018/4/14 PM 05:27 wrote: > >> The simple types c_void_p, c_char_p, and c_wchar_p are pointers. >> However, since they subclass _SimpleCData instead of _Pointer, they >> inherit the behavior of simple types. > >

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-13 Thread Jach Fong
eryk sun at 2018/4/14 PM 05:27 wrote: On Fri, Apr 13, 2018 at 8:44 AM, Jach Fong wrote: After studying the example you explained in your previous post replied to Gregory Ewing, I had noticed that until today I was totally misunderstand the meaning of the c_char_p. I

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-13 Thread eryk sun
On Fri, Apr 13, 2018 at 8:44 AM, Jach Fong wrote: > > After studying the example you explained in your previous post replied to > Gregory Ewing, I had noticed that until today I was totally misunderstand > the meaning of the c_char_p. I always think it "is" a pointer, but

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-13 Thread Jach Fong
eryk sun at 2018/4/13 PM 12:16 wrote: On Fri, Apr 13, 2018 at 12:38 AM, Jach Fong wrote: Gregory Ewing at 2018/4/13 上午 07:25 wrote: To get around this, you may need to declare the return type as POINTER(c_char) instead: For a general character pointer that may also

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread eryk sun
On Fri, Apr 13, 2018 at 12:38 AM, Jach Fong wrote: > Gregory Ewing at 2018/4/13 上午 07:25 wrote: > >> To get around this, you may need to declare the return type >> as POINTER(c_char) instead: >> >>> For a general character pointer that may also point to binary data, >> >> >

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread Jach Fong
Gregory Ewing at 2018/4/13 上午 07:25 wrote: On Thu, Apr 12, 2018 at 2:16 PM,  wrote: This C function returns a buffer which I declared it as a ctypes.c_char_p. The buffer has size 0x1 bytes long and the valid data may vary from a few bytes to the whole size. I think

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread eryk sun
On Thu, Apr 12, 2018 at 11:25 PM, Gregory Ewing wrote: > > To get around this, you may need to declare the return type > as POINTER(c_char) instead: > >> For a general character pointer that may also point to binary data, > >> POINTER(c_char) must be used. > > I'm not

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread Cameron Simpson
On 12Apr2018 16:11, Jach Fong wrote: This is the first time I am using python-list to interact with comp.lang.python forum (because there are so many spam when using browser to view it) so forgive me if something goes wrong. Python already treat the returned buffer as

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread Gregory Ewing
On Thu, Apr 12, 2018 at 2:16 PM, wrote: This C function returns a buffer which I declared it as a ctypes.c_char_p. The buffer has size 0x1 bytes long and the valid data may vary from a few bytes to the whole size. I think we need to see the code you're using to call

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread Albert-Jan Roskam
On Apr 12, 2018 09:39, jf...@ms4.hinet.net wrote: > > Chris Angelico於 2018年4月12日星期四 UTC+8下午1時31分35秒寫道: > > On Thu, Apr 12, 2018 at 2:16 PM, wrote: > > > This C function returns a buffer which I declared it as a > > > ctypes.c_char_p. The buffer has size 0x1 bytes long

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread Jach Fong
This is the first time I am using python-list to interact with comp.lang.python forum (because there are so many spam when using browser to view it) so forgive me if something goes wrong. Python already treat the returned buffer as 'bytes'. The problem is Python don't know its size (or

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread jfong
Chris Angelico於 2018年4月12日星期四 UTC+8下午4時05分29秒寫道: > On Thu, Apr 12, 2018 at 4:20 PM, wrote: > > Chris Angelico於 2018年4月12日星期四 UTC+8下午1時31分35秒寫道: > >> On Thu, Apr 12, 2018 at 2:16 PM, wrote: > >> > This C function returns a buffer which I declared it as

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread Cameron Simpson
On 11Apr2018 21:16, jf...@ms4.hinet.net wrote: This C function returns a buffer which I declared it as a ctypes.c_char_p. The buffer has size 0x1 bytes long and the valid data may vary from a few bytes to the whole size. Could you show us the function? In every

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread Chris Angelico
On Thu, Apr 12, 2018 at 4:20 PM, wrote: > Chris Angelico於 2018年4月12日星期四 UTC+8下午1時31分35秒寫道: >> On Thu, Apr 12, 2018 at 2:16 PM, wrote: >> > This C function returns a buffer which I declared it as a ctypes.c_char_p. >> > The buffer has size 0x1

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread jfong
Chris Angelico於 2018年4月12日星期四 UTC+8下午1時31分35秒寫道: > On Thu, Apr 12, 2018 at 2:16 PM, wrote: > > This C function returns a buffer which I declared it as a ctypes.c_char_p. > > The buffer has size 0x1 bytes long and the valid data may vary from a > > few bytes to the

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-11 Thread Chris Angelico
On Thu, Apr 12, 2018 at 2:16 PM, wrote: > This C function returns a buffer which I declared it as a ctypes.c_char_p. > The buffer has size 0x1 bytes long and the valid data may vary from a few > bytes to the whole size. > > In every call I know how much the valid data

How to write partial of a buffer which was returned from a C function to a file?

2018-04-11 Thread jfong
This C function returns a buffer which I declared it as a ctypes.c_char_p. The buffer has size 0x1 bytes long and the valid data may vary from a few bytes to the whole size. In every call I know how much the valid data size is, but I suppose I can't use slice to get it because there may be