(from stdlib-sig) ctypes or struct from an h file

Erik Max Francis max at alcyone.com
Sun Oct 18 23:14:30 CEST 2009


Yuvgoog Greenle wrote:
> I'd like to clarify the use case.
> 
> Lets say you're writing a client and a server, one is in python and
> the other is C. If these 2 programs need to pass binary information
> between them (lets say over a socket) there are 2 options, it could be
> nice if you could only write the struct once (either in python or in
> C) without any Cython or C extension (for portability and ease of
> development's sake).

It's not as simple as that.  You have to know the binary format layouts 
(say, for floating point numbers) and struct padding that's used (since 
it can be inserted arbitrarily) on the C side of things, not to mention 
you have to arrange the whole the to be put into consistent (network) 
byte order.  Both sides have to take care of this, since if the server 
and client are running on different architectures, there's no guarantees 
any of these things will be the same.

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
   Diplomacy and defense are not substitutes for one another. Either
    alone would fail. -- John F. Kennedy, 1917-1963



More information about the Python-list mailing list