fix python binding for python 3

This commit is contained in:
arvidn 2016-04-15 18:40:46 -04:00
parent 6e50c8f2ef
commit c1fbac7fd3
1 changed files with 6 additions and 5 deletions

View File

@ -35,10 +35,12 @@ struct tuple_to_endpoint
{ {
if (!PyTuple_Check(x)) return NULL; if (!PyTuple_Check(x)) return NULL;
if (PyTuple_Size(x) != 2) return NULL; if (PyTuple_Size(x) != 2) return NULL;
if (!PyString_Check(PyTuple_GetItem(x, 0))) return NULL; extract<std::string> ip(object(borrowed(PyTuple_GetItem(x, 0))));
if (!PyNumber_Check(PyTuple_GetItem(x, 1))) return NULL; if (!ip.check()) return NULL;
extract<int> port(object(borrowed(PyTuple_GetItem(x, 1))));
if (!port.check()) return NULL;
lt::error_code ec; lt::error_code ec;
lt::address::from_string(PyString_AsString(PyTuple_GetItem(x, 0)), ec); lt::address::from_string(ip, ec);
if (ec) return NULL; if (ec) return NULL;
return x; return x;
} }
@ -50,8 +52,7 @@ struct tuple_to_endpoint
object o(borrowed(x)); object o(borrowed(x));
new (storage) T(lt::address::from_string( new (storage) T(lt::address::from_string(
extract<std::string>(o[0])) extract<std::string>(o[0])), extract<int>(o[1]));
, extract<int>(o[1]));
data->convertible = storage; data->convertible = storage;
} }
}; };