Commit 8d4a02a0 authored by Stanislav Bohm's avatar Stanislav Bohm

ENH: bytes() accepted as a result from py call

parent b4a41743
......@@ -87,26 +87,37 @@ std::shared_ptr<Data> PyCallTask::run()
return nullptr;
}
if (!PyUnicode_Check(result)) {
Py_DECREF(result);
set_error("Invalid result from python code");
PyGILState_Release(gstate);
return nullptr;
if (PyUnicode_Check(result)) {
// Result is string
Py_ssize_t size;
char *ptr = PyUnicode_AsUTF8AndSize(result, &size);
assert(ptr);
auto output = std::make_shared<RawData>();
output->init_from_mem(worker, ptr, size);
Py_DECREF(result);
PyGILState_Release(gstate);
return output;
} else if (PyBytes_Check(result)) {
// Result is bytes
Py_ssize_t size = PyBytes_GET_SIZE(result);
char *ptr = PyBytes_AsString(result);
assert(ptr);
auto output = std::make_shared<RawData>();
output->init_from_mem(worker, ptr, size);
Py_DECREF(result);
PyGILState_Release(gstate);
return output;
} else {
set_error("Invalid result from python code");
Py_DECREF(result);
PyGILState_Release(gstate);
return nullptr;
}
Py_ssize_t size;
char *str = PyUnicode_AsUTF8AndSize(result, &size);
assert(str);
Py_DECREF(result);
auto output = std::make_shared<RawData>();
output->init_from_mem(worker, str, size);
// Release GIL
PyGILState_Release(gstate);
return output;
}
void PyCallTask::set_python_error()
......
......@@ -20,9 +20,6 @@ data_wrapper_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return (PyObject *)self;
}
static PyObject *
data_wrapper_size(DataWrapper* self)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment