diff --git a/contrib/py-bindings/Makefile b/contrib/py-bindings/Makefile index f68ac43cc..01b703698 100644 --- a/contrib/py-bindings/Makefile +++ b/contrib/py-bindings/Makefile @@ -2,6 +2,7 @@ src=../../src import=-i$src/runtime/haskell:$src/compiler cbind=../c-bindings pythoninc=/usr/include/python2.5 +debug=-optc '-DDEBUG=1' conf: ln -s $(cbind)/PGFFFI.hs @@ -12,7 +13,7 @@ gf.so: PGFFFI.hs gfmodule.c gf --make ../../examples/tutorial/embedded/QueryEng.gf ghc $(import) --make -fglasgow-exts -O2 -no-hs-main -c $< ghc -O2 --make -fglasgow-exts -no-hs-main -optl '-shared' \ - -optc '-DMODULE=PGFFFI' -optc '-I$(pythoninc)' -o $@ $^ + -optc '-DMODULE=PGFFFI' $(debug) -optc '-I$(pythoninc)' -o $@ $^ clean: rm -f *.hi *.o rm -f *_stub.* @@ -20,4 +21,4 @@ clean: superclean: make clean rm -f PGFFFI.hs pgf.h Query.pgf - rm -f gf.so \ No newline at end of file + rm -f gf.so diff --git a/contrib/py-bindings/gfmodule.c b/contrib/py-bindings/gfmodule.c index e70db604d..5ed4f1851 100644 --- a/contrib/py-bindings/gfmodule.c +++ b/contrib/py-bindings/gfmodule.c @@ -32,15 +32,28 @@ #define NEWGF(OBJ,GFTYPE,TYPE,NAME,DOC) NEWOBJECT(OBJ,GFTYPE) \ NEWTYPE(TYPE,NAME,OBJ,DOC) +#ifdef DEBUG #define DEALLOCFN(delname,t,cb,cbname) static void \ delname(t *self){ cb(self->obj);\ printf("gf_%s has been called for stable pointer 0x%x\n", cbname, self->obj);\ self->ob_type->tp_free((PyObject*)self); } +#else +#define DEALLOCFN(delname,t,cb,cbname) static void \ +delname(t *self){ cb(self->obj);\ + self->ob_type->tp_free((PyObject*)self); } +#endif +#ifdef DEBUG #define REPRCB(cbid,t,gfcb) static PyObject* \ cbid(t *self) { \ const char *str = gfcb(self->obj); \ return PyString_FromFormat("0x%x: %s", self->obj, str); } +#else +#define REPRCB(cbid,t,gfcb) static PyObject* \ +cbid(t *self) { \ + const char *str = gfcb(self->obj); \ + return PyString_FromString(str); } +#endif /* utilities */ diff --git a/contrib/py-bindings/script.py b/contrib/py-bindings/script.py index 885174f8b..6eb12d5e1 100644 --- a/contrib/py-bindings/script.py +++ b/contrib/py-bindings/script.py @@ -3,7 +3,8 @@ import gf query = gf.read_pgf("Query.pgf") lang = gf.read_language('QueryEng') cat = query.startcat() -print 'start category:',cat +print 'start category:', cat +print 'language is:', lang lexed = "is 2 prime" print "Parsing '%s':" % lexed for e in query.parse(lexed, lang):