static int PyLibPlot_init(struct PyLibPlot* self, PyObject *args, PyObject *kwds) { int status=0; PyObject *params_dict=NULL; char *type=NULL; char *filename=NULL; plPlotterParams *params; self->fptr=NULL; if ( !PyArg_ParseTuple( args, "sOs", &type, ¶ms_dict, &filename) ) { return -1; } // for the repr snprintf(self->type, sizeof(self->type), "%s", type); params = pl_newplparams(); if (!extract_params(params_dict, params)) { // exception set inside goto bail; } if (0 != strcmp(filename, "")) { // a filename was passed self->fptr = fopen(filename,"w"); if (self->fptr==NULL) { fprintf(stderr,"error opening %s\n", filename); PyErr_Format( PyExc_TypeError, "could not open file: %s", filename); goto bail; } } self->pl = pl_newpl_r( type, NULL, self->fptr, NULL, params ); if (!self->pl) { PyErr_SetString(PyExc_RuntimeError, "could not create plotter"); goto bail; } status=1; bail: pl_deleteplparams( params ); if (!status) { return -1; } else { return 0; } }
size_t free_plparams (SCM x) { plPlotterParams *plparams; assert (SCM_SMOB_PREDICATE (plparams_tag, x)); plparams = (plPlotterParams *) SCM_SMOB_DATA (x); if (plparams != NULL) { pl_deleteplparams (plparams); SCM_SET_SMOB_DATA (x, 0); } return 0; }