forked from apache/cassandra-python-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.cpp
More file actions
54 lines (44 loc) · 1.22 KB
/
python.cpp
File metadata and controls
54 lines (44 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "python.hpp"
using namespace pyccassandra;
bool pyccassandra::VectorizePythonContainer(PyObject* container,
std::vector<PyObject*>& target)
{
if (PyTuple_Check(container))
{
Py_ssize_t numItems = PyTuple_Size(container);
target.reserve(numItems);
for (Py_ssize_t i = 0; i < numItems; ++i)
{
PyObject* pyItem = PyTuple_GetItem(container, i);
if (pyItem == NULL)
{
target.clear();
return false;
}
target.push_back(pyItem);
}
return true;
}
else if (PyList_Check(container))
{
Py_ssize_t numItems = PyList_Size(container);
target.reserve(numItems);
for (Py_ssize_t i = 0; i < numItems; ++i)
{
PyObject* pyItem = PyList_GetItem(container, i);
if (pyItem == NULL)
{
target.clear();
return false;
}
target.push_back(pyItem);
}
return true;
}
else
{
Py_DECREF(container);
PyErr_SetString(PyExc_TypeError, "cannot vectorize object");
return false;
}
}