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 PyObject * CgVar_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { CgVar *self; // puts("CgVar_new"); self = (CgVar *)type->tp_alloc(type, 0); if (self != NULL) { self->cv = cv_new(CGV_ERR); if (self->cv == NULL) { Py_DECREF(self); return NULL; } } return (PyObject *)self; }
/* * match_variable * INPUT: * string Input string to match * pvt variable type (from definition) * cmd variable string (from definition) - can contain range * RETURNS: * -1 Error (print msg on stderr) * 0 Not match and reason returned as malloced string. * 1 Match * Who prints errors? */ static int match_variable(cg_obj *co, char *str, char **reason) { int retval = -1; cg_var *cv; cg_varspec *cs; cs = &co->u.cou_var; if ((cv = cv_new(co->co_vtype)) == NULL) goto done; if ((retval = cv_parse1(str, cv, reason)) <= 0) goto done; retval = cv_validate(cv, cs, reason); done: if (cv) cv_free(cv); return retval; }