-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvstack.h
More file actions
51 lines (48 loc) · 1.41 KB
/
vstack.h
File metadata and controls
51 lines (48 loc) · 1.41 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
#ifndef ATOM_VSTACK_H
#define ATOM_VSTACK_H
#include "common.h"
static PyObject *py_make_vstack(PyObject *self, PyObject *args)
{
(void) self;
PyObject *list_obj;
if (!PyArg_ParseTuple(args, "O", &list_obj))
{
return NULL;
}
if (!PyList_Check(list_obj))
{
PyErr_SetString(PyExc_TypeError,
"First argument must be a list of expr capsules");
return NULL;
}
Py_ssize_t n_args = PyList_Size(list_obj);
if (n_args == 0)
{
PyErr_SetString(PyExc_ValueError, "List of expr capsules cannot be empty");
return NULL;
}
expr **expr_args = (expr **) calloc(n_args, sizeof(expr *));
for (Py_ssize_t i = 0; i < n_args; ++i)
{
PyObject *item = PyList_GetItem(list_obj, i);
expr *e = (expr *) PyCapsule_GetPointer(item, EXPR_CAPSULE_NAME);
if (!e)
{
free(expr_args);
PyErr_SetString(PyExc_ValueError, "Invalid expr capsule in list");
return NULL;
}
expr_args[i] = e;
}
int n_vars = expr_args[0]->n_vars;
expr *node = new_vstack(expr_args, (int) n_args, n_vars);
free(expr_args);
if (!node)
{
PyErr_SetString(PyExc_RuntimeError, "failed to create vstack node");
return NULL;
}
expr_retain(node);
return PyCapsule_New(node, EXPR_CAPSULE_NAME, expr_capsule_destructor);
}
#endif // ATOM_VSTACK_H