From aff9f220c9427ebd0d4869cf72ec79f005b4970e Mon Sep 17 00:00:00 2001 From: "jordi.saludes" Date: Thu, 22 Jul 2010 13:23:27 +0000 Subject: Refactored py-bindings using Storable. --- contrib/py-bindings/pygf.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'contrib/py-bindings/pygf.h') diff --git a/contrib/py-bindings/pygf.h b/contrib/py-bindings/pygf.h index 3a63090ca..101674dfa 100644 --- a/contrib/py-bindings/pygf.h +++ b/contrib/py-bindings/pygf.h @@ -32,6 +32,7 @@ typedef struct { HsStablePtr sp; } PyGF; + #define NEWOBJECT(OBJ, GFTYPE) typedef struct {\ PyObject_HEAD \ GFTYPE obj; \ @@ -65,4 +66,27 @@ typedef struct { NEWTYPE(TYPE,NAME,OBJ,DOC) -NEWOBJECT(CID, GF_CId) +// NEWOBJECT(CID, GF_CId) + +#ifdef DEBUG +#define DEALLOCFN(delname,t,cb,cbname) static void \ +delname(t *self){ cb(self);\ + 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);\ + 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); \ + 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); \ + return PyString_FromString(str); } +#endif -- cgit v1.2.3