Re: [libtorrent] Python3 Bindings Patch
Brought to you by:
arvidn
From: arvid <ar...@cs...> - 2014-09-11 05:48:58
|
On 2014-09-10 12:04, Jason Fried wrote: > https://gist.githubusercontent.com/fried/06c08a4d0ef8b1f5a9c3/raw/779b86fd8808380ac3a1f406a372a2a6a31fbab2/libtorrent-python3 > > I have been using this patch for a few months now without issue, Most > of it > originated on this mailing list I believe. > It includes a __hash__ function added to big_number, so we can use > info_hashes as dict keys in python. > > I use these same bindings for both python3 and python2 and have not > noticed > any issues. could you explain how getHash works? it's not obvious that it's doing the right thing to me. long get_hash(boost::python::object o) { using namespace boost::python; return PyObject_Hash(str(o).ptr()); } why does it take a python object instead of a big_number? I imagine that would just include a redundant wrapping. Then it calls str(o), which presumably converts it to a string (not bytes, right?) and then .ptr() which I'm guessing returns a pointer to that string. How does pyObject_Hash() know how many bytes to read from that pointer? Doesn't python break if you try to feed binary data into a string (in python 3)? -- Arvid Norberg |