diff options
| author | jordi.saludes <jordi.saludes@upc.edu> | 2010-07-22 15:03:49 +0000 |
|---|---|---|
| committer | jordi.saludes <jordi.saludes@upc.edu> | 2010-07-22 15:03:49 +0000 |
| commit | 75322d590497acb0af015c07b24a72f9769542e6 (patch) | |
| tree | 2ba53c27d76205b6c977329aa26c6f6818843410 | |
| parent | 0a053b3ddca839bf1095b77b98f35a6b2c5461f0 (diff) | |
Refactoring py object constructors.
| -rw-r--r-- | contrib/py-bindings/gfmodule.c | 13 | ||||
| -rw-r--r-- | contrib/py-bindings/pygf.h | 8 |
2 files changed, 11 insertions, 10 deletions
diff --git a/contrib/py-bindings/gfmodule.c b/contrib/py-bindings/gfmodule.c index 768fb5037..7da294560 100644 --- a/contrib/py-bindings/gfmodule.c +++ b/contrib/py-bindings/gfmodule.c @@ -97,8 +97,7 @@ languageCode(PGF *self, PyObject *args) Lang *lang; if (!PyArg_ParseTuple(args, "O", &lang)) return NULL; - if (!checkType(lang, &LangType)) - return NULL; + if (!checkType(lang, &LangType)) return NULL; char* scode = gf_languageCode(self, lang); if (scode) { PyObject* result = PyString_FromString(scode); @@ -296,9 +295,9 @@ PyModule_AddObject(m, "gf", (PyObject *)&t); } -inline Lang* newLang() { +/* inline Lang* newLang() { return (Lang*)LangType.tp_new(&LangType,NULL,NULL); -} + } inline Tree* newTree() { return (Tree*)TreeType.tp_new(&TreeType,NULL,NULL); @@ -307,9 +306,7 @@ inline Tree* newTree() { inline CId* newCId() { return (CId*)CIdType.tp_new(&CIdType,NULL,NULL); } +*/ inline PyObject* newList() { return PyList_New(0); } - -void append(PyObject* l, PyObject* ob) { - PyList_Append(l, ob); -} +inline void append(PyObject* l, PyObject* ob) { PyList_Append(l, ob); } diff --git a/contrib/py-bindings/pygf.h b/contrib/py-bindings/pygf.h index 101674dfa..04f142bcf 100644 --- a/contrib/py-bindings/pygf.h +++ b/contrib/py-bindings/pygf.h @@ -1,5 +1,4 @@ #include <Python.h> -//#include "pgf.h" #include "HsFFI.h" #ifdef __GLASGOW_HASKELL__ @@ -38,6 +37,10 @@ typedef struct { GFTYPE obj; \ } OBJ; +#define PYTYPE(OBJ) OBJ ## Type +#define NEWCONSTRUCTOR(OBJ) inline OBJ* new ## OBJ () {\ + return (OBJ*)PYTYPE(OBJ).tp_new(&PYTYPE(OBJ),NULL,NULL); } + #define NEWTYPE(TYPE,NAME,OBJECT,DOC) static PyTypeObject TYPE = {\ PyObject_HEAD_INIT(NULL)\ 0, /*ob_size*/\ @@ -63,7 +66,8 @@ typedef struct { DOC, /* tp_doc */\ }; #define NEWGF(OBJ,GFTYPE,TYPE,NAME,DOC) NEWOBJECT(OBJ,GFTYPE) \ - NEWTYPE(TYPE,NAME,OBJ,DOC) + NEWTYPE(TYPE,NAME,OBJ,DOC)\ + NEWCONSTRUCTOR(OBJ) // NEWOBJECT(CID, GF_CId) |
