Coder Social home page Coder Social logo

PyuTp under Snow Leopard about libutp HOT 6 CLOSED

bittorrent avatar bittorrent commented on June 25, 2024
PyuTp under Snow Leopard

from libutp.

Comments (6)

ghazel avatar ghazel commented on June 25, 2024

I don't think changing the struct format to big endian is the correct thing to do there. socket.inet_aton already returns network byte order, so adding the "!" to the struct unpack essentially flips it back.

I find it very strange that struct.unpack("L", '\x7f\x00\x00\x01') would throw "struct.error: unpack requires a string argument of length 8", since the format size for "L" is clearly defined as 4: http://docs.python.org/library/struct.html#format-characters
What does struct.calcsize("L") return?

As for the crash, UTP_SetCallbacks is a very simple function, so my only guess is that the utp_socket is not set or created properly. Can you provide a minimal example which reproduces the crash?

from libutp.

roverso avatar roverso commented on June 25, 2024

You can reproduce the first issue in Mac using this:
import socket
import struct
ip = '127.0.0.1'
size = struct.calcsize("L")
print "struct calcsize returns:"+str(size)
print "socket.inet_aton returns:"+str(len(socket.inet_aton(ip)))

The return size of the struct and of the socket.inet_aton will be 8 and 4 bytes respectively. No Match. I found out in a forum (http://code.activestate.com/recipes/66517-ip-address-conversion-functions-with-the-builtin-s/) that the interpretation via the struct-module is not correct on most platforms and consequently you have to force the format manually using "!L" instead of only "L".

Regarding the crash, I tried to debug a minimal python program that uses pyutp together with gdb for stepping through C++ libutp code. I found out that the program crashes when trying to access the UTP_Socket in the UTP_SetCallbacks function. It looks as if python provides a wrong pointer to the libutp C++ code in the latter.

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000002182160
0x00000001015e45a5 in UTP_SetCallbacks ()

I choose a stripped down version of WriteDataTestCase to reproduce the issue but any of the default tests where an actual connection is triggered should cause the error.

from libutp.

ghazel avatar ghazel commented on June 25, 2024

That forum post is referring to endianness. I believe the endianness is correct in libutp, it's the Python struct module size which is wrong. Looking closer at the Python struct documentation I linked to, I think this is a "native" vs. "standard" size problem. Try the format string "=L".

from libutp.

roverso avatar roverso commented on June 25, 2024

I tried the format string "=L" but this does not solve the crash I mentioned earlier. Can you reproduce the issue on your end?

from libutp.

ghazel avatar ghazel commented on June 25, 2024

Does "=L" solve the struct.error?

I do not have access to OS X at the moment since I have a PC. I'll see if I can borrow a Mac later this week.

from libutp.

roverso avatar roverso commented on June 25, 2024

As I mentioned in the previous post, the "=L" has not fixed the bug. Have you been able to reproduce the issue on a Mac machine?

from libutp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.