static PyObject * _CgVar_type_set(CgVar *self, PyObject *args) { enum cv_type type; cg_var *cv; assert(self->cv); if (!PyArg_ParseTuple(args, "i", &type)) return NULL; if (type != cv_type_get(self->cv)) { /* Clean-up by creating new cg_var and free old */ if ((cv = cv_new(type)) == NULL || (cv_name_get(self->cv) && !cv_name_set(cv, cv_name_get(self->cv)))){ PyErr_SetString(PyExc_MemoryError, "cv_new"); return NULL; } cv_free(self->cv); self->cv = cv; } return PyLong_FromLong(type); }
static int CgVar_init(CgVar *self, PyObject *args, PyObject *kwds) { PyObject *ret; char *name = NULL; int type = CGV_ERR; PyObject *Str; PyObject *value = NULL; static char *kwlist[] = {"type", "name", "value", NULL}; if (! PyArg_ParseTupleAndKeywords(args, kwds, "|isO", kwlist, &type, &name, &value)) return -1; /* Set type */ cv_type_set(self->cv, type); /* Set name if given */ if (name && cv_name_set(self->cv, name) == NULL) { PyErr_SetNone(PyExc_MemoryError); return -1; } /* Parse value if specified */ if (value && (Str = PyObject_Str(value))) { ret = PyObject_CallMethod((PyObject *)self, "_parse", "O", Str); Py_DECREF(Str); if (ret == NULL) return -1; Py_DECREF(ret); } return 0; }
/* * Help function to append a cv to a cvec. For expansion cvec passed to pt_expand_2 * IN: * co A cligen variable that has a matching value * cmd Value in string of the variable * OUT: * cvec The cligen variable vector to push a cv with name of co and value in cmd */ static cg_var * add_cov_to_cvec(cg_obj *co, char *cmd, cvec *cvec) { cg_var *cv = NULL; if ((cv = cvec_add(cvec, co->co_vtype)) == NULL) return NULL; cv_name_set(cv, co->co_command); cv_const_set(cv, iskeyword(co)); if (cv_parse(cmd, cv) < 0) { cv_reset(cv); cvec_del(cvec, cv); return NULL; } return cv; }
static PyObject * _CgVar_name_set(CgVar *self, PyObject *args) { char *str; assert(self->cv); if (!PyArg_ParseTuple(args, "s", &str)) return NULL; if (cv_name_set(self->cv, str) == NULL) { PyErr_SetString(PyExc_MemoryError, "string_set"); return NULL; } return StringFromString(str); }