Differences between revisions 1 and 2
Revision 1 as of 2007-03-09 16:53:53
Size: 169
Editor: CameronLaird
Comment:
Revision 2 as of 2007-07-13 17:11:56
Size: 761
Editor: 209
Comment: add memmove FAQs
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:

=== CTypes FAQs ===

'''FAQ: How do I copy bytes to Python from a ctypes.Structure?'''

def send(self):
 return buffer(self)[:]

'''FAQ: How do I copy bytes to a ctypes.Structure from Python?'''

def receiveSome(self, bytes):
 ctypes.memmove(ctypes.addressof(self), bytes, ctypes.sizeof(self))

'''FAQ: Why should I fear using ctypes.memmove?'''

ctypes.memmove emulates the memmove of C with complete faithfulness. If you tell memmove to copy more bytes than sizeof(self), you will overwrite memory that you do not own, with indeterminate consequences, arbitrarily delayed.

"ctypes is an advanced ["ffi"] ... package for Python ...", according to its [http://www.python.net/crew/theller/ctypes/ home page]. ["Python 2.5"] includes ctypes.

CTypes FAQs

FAQ: How do I copy bytes to Python from a ctypes.Structure?

def send(self):

  • return buffer(self)[:]

FAQ: How do I copy bytes to a ctypes.Structure from Python?

def receiveSome(self, bytes):

  • ctypes.memmove(ctypes.addressof(self), bytes, ctypes.sizeof(self))

FAQ: Why should I fear using ctypes.memmove?

ctypes.memmove emulates the memmove of C with complete faithfulness. If you tell memmove to copy more bytes than sizeof(self), you will overwrite memory that you do not own, with indeterminate consequences, arbitrarily delayed.

ctypes (last edited 2011-11-30 00:28:21 by webproxy3)

Unable to edit the page? See the FrontPage for instructions.