hoe to build a patched socketmodule.c

J

jacopo mondi

Hi all, I need to patch socketmodule.c (the _socket module) in order to
add support to an experimental socket family.

I'm guessing about the patched module build process: does a stand alone
build script using distutils makes sense, or have I to patch
sockmodule.c, eventualy rename it, modify setup.py inside python sources
to let it know about the new module, and then rebuild whole python?
I think the latter makes more sense, because I suppose socketmodule
could not be build stand alone, but need the whole python build system,
in order to have right definition specified by a Makefile generated by
autotools from inside python sources.
Or maybe distutils is able to retreive the whole build system? I don't
think so, because there are no requirement about having python source
tree installed.

If I have to go for the second way, then how could I distribuite the
patched _socket module? I could not use distutils, have I to distribuite
the already built .so with only a script to install it, and the source
code in another directory?

Thanks a lot
jacopo

PS correct my english please, is the only way I have to improve it!
 
R

Roger Binns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

jacopo said:
Hi all, I need to patch socketmodule.c (the _socket module) in order to
add support to an experimental socket family.

You may find it considerably easier to use ctypes since that will avoid
the need for any patching. You'll also be able to control how read and
write are done (eg read vs recvfrom vs recvmsg vs readv). You can use
os.fdopen to convert your raw file descriptor into a Python file object
if appropriate.

If you do use ctypes then you'll only need to distribute pure Python
source code.

Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkpWpCAACgkQmOOfHg372QQq0QCbB+rslUqK/AuUu0gA6N4m01Jo
C8IAn3EkzFKCyt/K5WiuCnw3jzORBQh5
=JCv+
-----END PGP SIGNATURE-----
 
J

jacopo mondi

Roger said:
You may find it considerably easier to use ctypes since that will avoid
the need for any patching. You'll also be able to control how read and
write are done (eg read vs recvfrom vs recvmsg vs readv). You can use
os.fdopen to convert your raw file descriptor into a Python file object
if appropriate.

If you do use ctypes then you'll only need to distribute pure Python
source code.

Roger
Thanks a lot, I'll give it a try..

cheers
jacopo
 
J

jacopo mondi

Roger said:
You may find it considerably easier to use ctypes since that will avoid
the need for any patching. You'll also be able to control how read and
write are done (eg read vs recvfrom vs recvmsg vs readv). You can use
os.fdopen to convert your raw file descriptor into a Python file object
if appropriate.

If you do use ctypes then you'll only need to distribute pure Python
source code.

Roger

Wait a minute, am I confused or ctypes seems to be unusless for my needs?
Ctypes wraps a system shared object (as libc is) and gives you the
possibility to access its functions. What have I to wrap? the
fuctionalities I need to use are those exposed by the kernel via
sys/socket.h haeder (socket, bind, connect etc.).
Maybe I could wrapp _socket.so (I think it's possible) but seems to be
unuseless because I need to modify, for example, the parameters that
_socket.so passes to the socket() function in order to create a socket
owned by the new socket family I'm actualy experimenting.
Hope it's clear what I'm trying to explain...

Thanks anyway, but ctypes doen't seem to fit my needs..

cheers
jacopo
 
J

jacopo mondi

Scott said:
The typical Python way of dealing with this is an additional module, not
a modified module placed back in the library. So, take the sources and
edit, but change the module name. Even better is figure out how to
use _socket.pyd, to create a smaller _socketexpmodule.c and use that.

--Scott David Daniels
(e-mail address removed)
Thanks a lot Scott.
If I'll write a new module, with a new name, based on socketmodule.c I
will not be able to ditribuite the source code and make users compile it
using distutils, instead I have to compile it using the whole python
build system (changing setup.py in python sources to let it know about
my new module) and distribuite the compiled .so with a script to install
it, I suppose. Anyway, that's not too bad...
Reusing _socket.so, or the main wrapper socket.pyc I think is not
possible, because I need to modify low level functions that are not exposed

thanks again
jacopo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top