From be1b9b6f19162891626ffa57c3645e6272ee855b Mon Sep 17 00:00:00 2001 From: Olivier Parcollet Date: Sun, 27 Jul 2014 16:27:16 +0200 Subject: [PATCH] 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 ? --- pytriqs/wrap_generator/wrapper.mako.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pytriqs/wrap_generator/wrapper.mako.cpp b/pytriqs/wrap_generator/wrapper.mako.cpp index 0aa7d1c6..5fac2508 100644 --- a/pytriqs/wrap_generator/wrapper.mako.cpp +++ b/pytriqs/wrap_generator/wrapper.mako.cpp @@ -148,6 +148,8 @@ typedef struct { ${c.c_type} * _c; } ${c.py_type}; +## The new function, only if there is constructor +%if c.constructor: // the new static PyObject* ${c.py_type}_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { ${c.py_type} *self; @@ -169,6 +171,7 @@ static PyObject* ${c.py_type}_new(PyTypeObject *type, PyObject *args, PyObject * } return (PyObject *)self; } +%endif // dealloc static void ${c.py_type}_dealloc(${c.py_type}* self) { @@ -366,7 +369,11 @@ static PyTypeObject ${c.py_type}Type = { 0, /* tp_dictoffset */ ${"(initproc)%s___init__"%c.py_type if c.constructor else 0}, /* tp_init */ 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 -----------------------------