MCPcopy Create free account
hub / github.com/arvidn/libtorrent / bytes_from_python

Class bytes_from_python

bindings/python/src/utility.cpp:47–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45};
46
47struct bytes_from_python
48{
49 bytes_from_python()
50 {
51 converter::registry::push_back(
52 &convertible, &construct, type_id<bytes>());
53 }
54
55 static void* convertible(PyObject* x)
56 {
57#if PY_MAJOR_VERSION >= 3
58 return (PyBytes_Check(x) || PyByteArray_Check(x)) ? x : nullptr;
59#else
60 return PyString_Check(x) ? x : nullptr;
61#endif
62 }
63
64 static void construct(PyObject* x, converter::rvalue_from_python_stage1_data* data)
65 {
66#if PY_MAJOR_VERSION >= 3
67 void* storage = ((converter::rvalue_from_python_storage<bytes>*)data)->storage.bytes;
68 bytes* ret = new (storage) bytes();
69 if (PyByteArray_Check(x))
70 {
71 ret->arr.resize(PyByteArray_Size(x));
72 memcpy(&ret->arr[0], PyByteArray_AsString(x), ret->arr.size());
73 }
74 else
75 {
76 ret->arr.resize(PyBytes_Size(x));
77 memcpy(&ret->arr[0], PyBytes_AsString(x), ret->arr.size());
78 }
79 data->convertible = storage;
80#else
81 void* storage = ((converter::rvalue_from_python_storage<bytes>*)data)->storage.bytes;
82 bytes* ret = new (storage) bytes();
83 ret->arr.resize(PyString_Size(x));
84 memcpy(&ret->arr[0], PyString_AsString(x), ret->arr.size());
85 data->convertible = storage;
86#endif
87 }
88};
89
90#if TORRENT_ABI_VERSION == 1
91object client_fingerprint_(peer_id const& id)

Callers 1

bind_utilityFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected