diff options
| author | jordi.saludes <jordi.saludes@upc.edu> | 2010-07-22 14:19:55 +0000 |
|---|---|---|
| committer | jordi.saludes <jordi.saludes@upc.edu> | 2010-07-22 14:19:55 +0000 |
| commit | 63a4c97e18a6eda261e451098d2360a9570b89a7 (patch) | |
| tree | 690f8f220e805c9ca8f0dde51d0be18912d42988 /contrib/py-bindings/gfmodule.c | |
| parent | aff9f220c9427ebd0d4869cf72ec79f005b4970e (diff) | |
Checking args passed to gf functions.
Diffstat (limited to 'contrib/py-bindings/gfmodule.c')
| -rw-r--r-- | contrib/py-bindings/gfmodule.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/contrib/py-bindings/gfmodule.c b/contrib/py-bindings/gfmodule.c index ba933ee76..fd6c003d9 100644 --- a/contrib/py-bindings/gfmodule.c +++ b/contrib/py-bindings/gfmodule.c @@ -3,6 +3,7 @@ // #include <Python.h> +#include <sys/stat.h> #include "pygf.h" /* utilities */ @@ -107,6 +108,8 @@ languageCode(PGFModule *self, PyObject *args) Lang *lang; if (!PyArg_ParseTuple(args, "O", &lang)) return NULL; + if (!checkType(lang, &LangType)) + return NULL; char* scode = gf_languageCode(self, lang); if (scode) { PyObject* result = PyString_FromString(scode); @@ -149,6 +152,8 @@ printName(PGFModule *self, PyObject *args) CId* id; if (!PyArg_ParseTuple(args, "OO", &lang, &id)) return NULL; + if (!checkType(lang,&LangType)) return NULL; + if (!checkType(id,&CIdType)) return NULL; char *pname = gf_showPrintName(self, lang, id); PyObject* result = PyString_FromString(pname); free(pname); @@ -199,13 +204,19 @@ static PGFModule* readPGF(PyObject *self, PyObject *args) { char *path; + struct stat info; PGFModule *pgf; if (!PyArg_ParseTuple(args, "s", &path)) return NULL; - pgf = (PGFModule*)PGFType.tp_new(&PGFType,NULL,NULL); - if (!pgf) return NULL; - gf_readPGF(pgf, path); - return pgf; + if (stat(path, &info) == 0) { + pgf = (PGFModule*)PGFType.tp_new(&PGFType,NULL,NULL); + if (!pgf) return NULL; + gf_readPGF(pgf, path); + return pgf; + } else { + PyErr_Format(PyExc_IOError, "No such file: %s", path); + return NULL; + } } //Todo: repr |
