mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
Add deallocator functions to all classes
This commit is contained in:
@@ -57,13 +57,22 @@ Type_init(TypeObject *self, PyObject *args, PyObject *kwds)
|
|||||||
self->hypos = hypos;
|
self->hypos = hypos;
|
||||||
self->name = name;
|
self->name = name;
|
||||||
self->exprs = exprs;
|
self->exprs = exprs;
|
||||||
Py_INCREF(hypos);
|
Py_INCREF(self->hypos);
|
||||||
// Py_INCREF(name);
|
Py_INCREF(self->name);
|
||||||
Py_INCREF(exprs);
|
Py_INCREF(self->exprs);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
Type_dealloc(TypeObject *self)
|
||||||
|
{
|
||||||
|
Py_XDECREF(self->hypos);
|
||||||
|
Py_XDECREF(self->name);
|
||||||
|
Py_XDECREF(self->exprs);
|
||||||
|
Py_TYPE(self)->tp_free(self);
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
Type_str(TypeObject *self)
|
Type_str(TypeObject *self)
|
||||||
{
|
{
|
||||||
@@ -128,7 +137,7 @@ PyTypeObject pgf_TypeType = {
|
|||||||
"pgf.Type", /*tp_name*/
|
"pgf.Type", /*tp_name*/
|
||||||
sizeof(TypeObject), /*tp_basicsize*/
|
sizeof(TypeObject), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
0, //(destructor) Type_dealloc, /*tp_dealloc*/
|
(destructor) Type_dealloc, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
@@ -247,12 +256,21 @@ ExprAbs_init(ExprAbsObject *self, PyObject *args, PyObject *kwds)
|
|||||||
self->bind_type = bind_type;
|
self->bind_type = bind_type;
|
||||||
self->name = name;
|
self->name = name;
|
||||||
self->body = body;
|
self->body = body;
|
||||||
Py_INCREF(bind_type);
|
Py_INCREF(self->bind_type);
|
||||||
Py_INCREF(name);
|
Py_INCREF(self->name);
|
||||||
Py_INCREF(body);
|
Py_INCREF(self->body);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ExprAbs_dealloc(ExprAbsObject *self)
|
||||||
|
{
|
||||||
|
Py_XDECREF(self->bind_type);
|
||||||
|
Py_XDECREF(self->name);
|
||||||
|
Py_XDECREF(self->body);
|
||||||
|
Py_TYPE(self)->tp_free(self);
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
ExprAbs_richcompare(ExprAbsObject *e1, PyObject *p2, int op)
|
ExprAbs_richcompare(ExprAbsObject *e1, PyObject *p2, int op)
|
||||||
{
|
{
|
||||||
@@ -289,7 +307,7 @@ PyTypeObject pgf_ExprAbsType = {
|
|||||||
"pgf.ExprAbs", /*tp_name*/
|
"pgf.ExprAbs", /*tp_name*/
|
||||||
sizeof(ExprAbsObject), /*tp_basicsize*/
|
sizeof(ExprAbsObject), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
0, //(destructor)Expr_dealloc, /*tp_dealloc*/
|
(destructor) ExprAbs_dealloc, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
@@ -344,11 +362,19 @@ ExprApp_init(ExprAppObject *self, PyObject *args, PyObject *kwds)
|
|||||||
}
|
}
|
||||||
self->fun = (ExprObject *)fun;
|
self->fun = (ExprObject *)fun;
|
||||||
self->arg = (ExprObject *)arg;
|
self->arg = (ExprObject *)arg;
|
||||||
Py_INCREF(fun);
|
Py_INCREF(self->fun);
|
||||||
Py_INCREF(arg);
|
Py_INCREF(self->arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ExprApp_dealloc(ExprAppObject *self)
|
||||||
|
{
|
||||||
|
Py_XDECREF(self->fun);
|
||||||
|
Py_XDECREF(self->arg);
|
||||||
|
Py_TYPE(self)->tp_free(self);
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
ExprApp_richcompare(ExprAppObject *e1, PyObject *p2, int op)
|
ExprApp_richcompare(ExprAppObject *e1, PyObject *p2, int op)
|
||||||
{
|
{
|
||||||
@@ -383,7 +409,7 @@ PyTypeObject pgf_ExprAppType = {
|
|||||||
"pgf.ExprApp", /*tp_name*/
|
"pgf.ExprApp", /*tp_name*/
|
||||||
sizeof(ExprAppObject), /*tp_basicsize*/
|
sizeof(ExprAppObject), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
0, //(destructor)Expr_dealloc, /*tp_dealloc*/
|
(destructor) ExprApp_dealloc, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
@@ -437,14 +463,21 @@ ExprLit_init(ExprLitObject *self, PyObject *args, PyObject *kwds)
|
|||||||
}
|
}
|
||||||
if (PyLong_Check(lit) || PyFloat_Check(lit) || PyUnicode_Check(lit)) {
|
if (PyLong_Check(lit) || PyFloat_Check(lit) || PyUnicode_Check(lit)) {
|
||||||
self->lit = lit;
|
self->lit = lit;
|
||||||
Py_INCREF(lit);
|
Py_INCREF(self->lit);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
PyErr_SetString(PyExc_TypeError, "invalid argument in ExprLit_init");
|
PyErr_SetString(PyExc_TypeError, "a literal expression can be initialised with an integer, float, or string");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ExprLit_dealloc(ExprLitObject *self)
|
||||||
|
{
|
||||||
|
Py_XDECREF(self->lit);
|
||||||
|
Py_TYPE(self)->tp_free(self);
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
ExprLit_richcompare(ExprLitObject *e1, PyObject *p2, int op)
|
ExprLit_richcompare(ExprLitObject *e1, PyObject *p2, int op)
|
||||||
{
|
{
|
||||||
@@ -493,7 +526,7 @@ PyTypeObject pgf_ExprLitType = {
|
|||||||
"pgf.ExprLit", /*tp_name*/
|
"pgf.ExprLit", /*tp_name*/
|
||||||
sizeof(ExprLitObject), /*tp_basicsize*/
|
sizeof(ExprLitObject), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
0, //(destructor)Expr_dealloc, /*tp_dealloc*/
|
(destructor) ExprLit_dealloc, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
@@ -547,17 +580,26 @@ ExprMeta_init(ExprMetaObject *self, PyObject *args, PyObject *kwds)
|
|||||||
}
|
}
|
||||||
if (lit == NULL) {
|
if (lit == NULL) {
|
||||||
self->id = PyLong_FromLong(0);
|
self->id = PyLong_FromLong(0);
|
||||||
|
Py_INCREF(self->id);
|
||||||
return 0;
|
return 0;
|
||||||
} else if (PyLong_Check(lit)) {
|
} else if (PyLong_Check(lit)) {
|
||||||
self->id = lit;
|
self->id = lit;
|
||||||
Py_INCREF(lit);
|
Py_INCREF(self->id);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
PyErr_SetString(PyExc_TypeError, "invalid argument in ExprMeta_init");
|
// TODO check positive
|
||||||
|
PyErr_SetString(PyExc_TypeError, "a meta variable must be initialised with an integer");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ExprMeta_dealloc(ExprMetaObject *self)
|
||||||
|
{
|
||||||
|
Py_XDECREF(self->id);
|
||||||
|
Py_TYPE(self)->tp_free(self);
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
ExprMeta_richcompare(ExprMetaObject *e1, PyObject *p2, int op)
|
ExprMeta_richcompare(ExprMetaObject *e1, PyObject *p2, int op)
|
||||||
{
|
{
|
||||||
@@ -590,7 +632,7 @@ PyTypeObject pgf_ExprMetaType = {
|
|||||||
"pgf.ExprMeta", /*tp_name*/
|
"pgf.ExprMeta", /*tp_name*/
|
||||||
sizeof(ExprMetaObject), /*tp_basicsize*/
|
sizeof(ExprMetaObject), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
0, //(destructor)Expr_dealloc, /*tp_dealloc*/
|
(destructor) ExprMeta_dealloc, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
@@ -643,10 +685,17 @@ ExprFun_init(ExprFunObject *self, PyObject *args, PyObject *kwds)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
self->name = lit;
|
self->name = lit;
|
||||||
Py_INCREF(lit);
|
Py_INCREF(self->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ExprFun_dealloc(ExprFunObject *self)
|
||||||
|
{
|
||||||
|
Py_XDECREF(self->name);
|
||||||
|
Py_TYPE(self)->tp_free(self);
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
ExprFun_richcompare(ExprFunObject *e1, PyObject *p2, int op)
|
ExprFun_richcompare(ExprFunObject *e1, PyObject *p2, int op)
|
||||||
{
|
{
|
||||||
@@ -679,7 +728,7 @@ PyTypeObject pgf_ExprFunType = {
|
|||||||
"pgf.ExprFun", /*tp_name*/
|
"pgf.ExprFun", /*tp_name*/
|
||||||
sizeof(ExprFunObject), /*tp_basicsize*/
|
sizeof(ExprFunObject), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
0, //(destructor)Expr_dealloc, /*tp_dealloc*/
|
(destructor) ExprFun_dealloc, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
@@ -733,17 +782,26 @@ ExprVar_init(ExprVarObject *self, PyObject *args, PyObject *kwds)
|
|||||||
}
|
}
|
||||||
if (lit == NULL) {
|
if (lit == NULL) {
|
||||||
self->var = PyLong_FromLong(0);
|
self->var = PyLong_FromLong(0);
|
||||||
|
Py_INCREF(self->var);
|
||||||
return 0;
|
return 0;
|
||||||
} else if (PyLong_Check(lit)) {
|
} else if (PyLong_Check(lit)) {
|
||||||
self->var = lit;
|
self->var = lit;
|
||||||
Py_INCREF(lit);
|
Py_INCREF(self->var);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
PyErr_SetString(PyExc_TypeError, "invalid argument in ExprVar_init");
|
// TODO check positive
|
||||||
|
PyErr_SetString(PyExc_TypeError, "variable expression must be initialised with an integer");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ExprVar_dealloc(ExprVarObject *self)
|
||||||
|
{
|
||||||
|
Py_XDECREF(self->var);
|
||||||
|
Py_TYPE(self)->tp_free(self);
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
ExprVar_richcompare(ExprVarObject *e1, PyObject *p2, int op)
|
ExprVar_richcompare(ExprVarObject *e1, PyObject *p2, int op)
|
||||||
{
|
{
|
||||||
@@ -776,7 +834,7 @@ PyTypeObject pgf_ExprVarType = {
|
|||||||
"pgf.ExprVar", /*tp_name*/
|
"pgf.ExprVar", /*tp_name*/
|
||||||
sizeof(ExprVarObject), /*tp_basicsize*/
|
sizeof(ExprVarObject), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
0, //(destructor)Expr_dealloc, /*tp_dealloc*/
|
(destructor) ExprVar_dealloc, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
@@ -831,11 +889,19 @@ ExprTyped_init(ExprTypedObject *self, PyObject *args, PyObject *kwds)
|
|||||||
}
|
}
|
||||||
self->expr = expr;
|
self->expr = expr;
|
||||||
self->type = type;
|
self->type = type;
|
||||||
Py_INCREF(expr);
|
Py_INCREF(self->expr);
|
||||||
Py_INCREF(type);
|
Py_INCREF(self->type);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ExprTyped_dealloc(ExprTypedObject *self)
|
||||||
|
{
|
||||||
|
Py_XDECREF(self->expr);
|
||||||
|
Py_XDECREF(self->type);
|
||||||
|
Py_TYPE(self)->tp_free(self);
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
ExprTyped_richcompare(ExprTypedObject *e1, PyObject *p2, int op)
|
ExprTyped_richcompare(ExprTypedObject *e1, PyObject *p2, int op)
|
||||||
{
|
{
|
||||||
@@ -870,7 +936,7 @@ PyTypeObject pgf_ExprTypedType = {
|
|||||||
"pgf.ExprTyped", /*tp_name*/
|
"pgf.ExprTyped", /*tp_name*/
|
||||||
sizeof(ExprTypedObject), /*tp_basicsize*/
|
sizeof(ExprTypedObject), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
0, //(destructor)Expr_dealloc, /*tp_dealloc*/
|
(destructor) ExprTyped_dealloc, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
@@ -923,10 +989,17 @@ ExprImplArg_init(ExprImplArgObject *self, PyObject *args, PyObject *kwds)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
self->expr = expr;
|
self->expr = expr;
|
||||||
Py_INCREF(expr);
|
Py_INCREF(self->expr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ExprImplArg_dealloc(ExprImplArgObject *self)
|
||||||
|
{
|
||||||
|
Py_XDECREF(self->expr);
|
||||||
|
Py_TYPE(self)->tp_free(self);
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
ExprImplArg_richcompare(ExprImplArgObject *e1, PyObject *p2, int op)
|
ExprImplArg_richcompare(ExprImplArgObject *e1, PyObject *p2, int op)
|
||||||
{
|
{
|
||||||
@@ -959,7 +1032,7 @@ PyTypeObject pgf_ExprImplArgType = {
|
|||||||
"pgf.ExprImplArg", /*tp_name*/
|
"pgf.ExprImplArg", /*tp_name*/
|
||||||
sizeof(ExprImplArgObject), /*tp_basicsize*/
|
sizeof(ExprImplArgObject), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
0, //(destructor)Expr_dealloc, /*tp_dealloc*/
|
(destructor) ExprImplArg_dealloc, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ PGF_dealloc(PGFObject *self)
|
|||||||
{
|
{
|
||||||
if (self->db != NULL && self->revision != 0)
|
if (self->db != NULL && self->revision != 0)
|
||||||
pgf_free_revision(self->db, self->revision);
|
pgf_free_revision(self->db, self->revision);
|
||||||
Py_TYPE(self)->tp_free((PyObject *)self);
|
Py_TYPE(self)->tp_free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@@ -65,6 +65,12 @@ PGF_newTransaction(PGFObject *self, PyObject *args)
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static void
|
||||||
|
Transaction_dealloc(TransactionObject *self)
|
||||||
|
{
|
||||||
|
Py_TYPE(self)->tp_free(self);
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
Transaction_commit(TransactionObject *self, PyObject *args)
|
Transaction_commit(TransactionObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
@@ -229,12 +235,6 @@ exit:
|
|||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static void
|
|
||||||
// Transaction_dealloc(PGFObject* self)
|
|
||||||
// {
|
|
||||||
// Py_TYPE(self)->tp_free((PyObject*)self);
|
|
||||||
// }
|
|
||||||
|
|
||||||
static PyGetSetDef Transaction_getseters[] = {
|
static PyGetSetDef Transaction_getseters[] = {
|
||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
@@ -277,7 +277,7 @@ PyTypeObject pgf_TransactionType = {
|
|||||||
"pgf.Transaction", /*tp_name*/
|
"pgf.Transaction", /*tp_name*/
|
||||||
sizeof(TransactionObject), /*tp_basicsize*/
|
sizeof(TransactionObject), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
0, //(destructor)Transaction_dealloc, /*tp_dealloc*/
|
(destructor) Transaction_dealloc, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
|
|||||||
Reference in New Issue
Block a user