mirror of
https://github.com/wassname/ray.git
synced 2026-07-30 12:30:30 +08:00
generate pytask from string and string from pytask (#188)
* pytask creation from bytestring: saving work * pytask now works * documentation and tests * linting * Lint and fix test case
This commit is contained in:
committed by
Philipp Moritz
parent
c45342e39d
commit
674ec3a3cb
@@ -68,6 +68,55 @@ PyObject *PyObjectID_make(object_id object_id) {
|
||||
return (PyObject *) result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string to a Ray task specification Python object.
|
||||
*
|
||||
* This is called from Python like
|
||||
*
|
||||
* task = photon.task_from_string("...")
|
||||
*
|
||||
* @param task_string String representation of the task specification.
|
||||
* @return Python task specification object.
|
||||
*/
|
||||
PyObject *PyTask_from_string(PyObject *self, PyObject *args) {
|
||||
const char *data;
|
||||
int size;
|
||||
if (!PyArg_ParseTuple(args, "s#", &data, &size)) {
|
||||
return NULL;
|
||||
}
|
||||
PyTask *result = PyObject_New(PyTask, &PyTaskType);
|
||||
result = (PyTask *) PyObject_Init((PyObject *) result, &PyTaskType);
|
||||
result->spec = malloc(size);
|
||||
memcpy(result->spec, data, size);
|
||||
/* TODO(pcm): Better error checking once we use flatbuffers. */
|
||||
if (size != task_spec_size(result->spec)) {
|
||||
PyErr_SetString(CommonError,
|
||||
"task_from_string: task specification string malformed");
|
||||
return NULL;
|
||||
}
|
||||
return (PyObject *) result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a Ray task specification Python object to a string.
|
||||
*
|
||||
* This is called from Python like
|
||||
*
|
||||
* s = photon.task_to_string(task)
|
||||
*
|
||||
* @param task Ray task specification Python object.
|
||||
* @return String representing the task specification.
|
||||
*/
|
||||
PyObject *PyTask_to_string(PyObject *self, PyObject *args) {
|
||||
PyObject *arg;
|
||||
if (!PyArg_ParseTuple(args, "O", &arg)) {
|
||||
return NULL;
|
||||
}
|
||||
PyTask *task = (PyTask *) arg;
|
||||
return PyBytes_FromStringAndSize((char *) task->spec,
|
||||
task_spec_size(task->spec));
|
||||
}
|
||||
|
||||
static PyObject *PyObjectID_id(PyObject *self) {
|
||||
PyObjectID *s = (PyObjectID *) self;
|
||||
return PyBytes_FromStringAndSize((char *) &s->object_id.id[0],
|
||||
|
||||
Reference in New Issue
Block a user