mirror of
https://github.com/triqs/dft_tools
synced 2024-12-25 13:53:40 +01:00
python wrapper. No new function if no constructor
- When a type has no python constructor (E.g. parameters) do not define the xxx_new function. - Leads to a better error message when trying to construct such an object in python. - TODO : check there is no issue with serialization ?
This commit is contained in:
parent
522477eb2d
commit
be1b9b6f19
@ -148,6 +148,8 @@ typedef struct {
|
|||||||
${c.c_type} * _c;
|
${c.c_type} * _c;
|
||||||
} ${c.py_type};
|
} ${c.py_type};
|
||||||
|
|
||||||
|
## The new function, only if there is constructor
|
||||||
|
%if c.constructor:
|
||||||
// the new
|
// the new
|
||||||
static PyObject* ${c.py_type}_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
|
static PyObject* ${c.py_type}_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
|
||||||
${c.py_type} *self;
|
${c.py_type} *self;
|
||||||
@ -169,6 +171,7 @@ static PyObject* ${c.py_type}_new(PyTypeObject *type, PyObject *args, PyObject *
|
|||||||
}
|
}
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
%endif
|
||||||
|
|
||||||
// dealloc
|
// dealloc
|
||||||
static void ${c.py_type}_dealloc(${c.py_type}* self) {
|
static void ${c.py_type}_dealloc(${c.py_type}* self) {
|
||||||
@ -366,7 +369,11 @@ static PyTypeObject ${c.py_type}Type = {
|
|||||||
0, /* tp_dictoffset */
|
0, /* tp_dictoffset */
|
||||||
${"(initproc)%s___init__"%c.py_type if c.constructor else 0}, /* tp_init */
|
${"(initproc)%s___init__"%c.py_type if c.constructor else 0}, /* tp_init */
|
||||||
0, /* tp_alloc */
|
0, /* tp_alloc */
|
||||||
${c.py_type}_new, /* tp_new */
|
%if c.constructor:
|
||||||
|
${c.py_type}_new, /* tp_new */
|
||||||
|
%else:
|
||||||
|
0, /* tp_new */
|
||||||
|
%endif
|
||||||
};
|
};
|
||||||
|
|
||||||
//--------------------- converters for the class c -----------------------------
|
//--------------------- converters for the class c -----------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user