[pygccxml-development] [FT] recent changes - generated code
Brought to you by:
mbaas,
roman_yakovenko
|
From: Roman Y. <rom...@gm...> - 2006-09-20 18:50:43
|
Hi. Few comments on generated code:
1. Boost.Python object.hpp defines "len" function.
This will impove next code:
if (v.attr("__len__")()!=3)
{
PyErr_SetString(PyExc_ValueError, "Invalid sequence size
(expected 3)");
boost::python::throw_error_already_set();
}
2. The next pattern is comming all the time:
if( not condition ){
set python error
throw boost::python exception
}
I know we are talking about code generator, but may be we can introduce few
convinience functions?
namespace pyplusplus{ namespace convinience{
void raise_error( exception, message ){
PyErr_SetString(exception, message);
boost::python::throw_error_already_set();
}
} }
3.
py_v = pyresult;
if (!PySequence_Check(py_v.ptr()))
{
PyErr_SetString(PyExc_ValueError, "fixed_output_array:
sequence expected as return value for output array 'v'");
boost::python::throw_error_already_set();
}
// Assert that the sequence has the correct size
if (PySequence_Length(py_v.ptr())!=3)
{
PyErr_SetString(PyExc_ValueError, "fixed_output_array:
sequence with 3 values expected as return value for output array
'v'");
boost::python::throw_error_already_set();
}
It is obvious to me that we have to have hear "ensure_sequence" function
template< class ItemType=any >
void ensure_sequence( PyObject* x, Py_ssize_t expected_size=-1 ) {
if not sequence: raise
if does not have desired length raise
if items in sequence are not from desired type raise
}
Something like this.
I would like to see these changes. The generated code should not be
too different
from the one, that human would write. I don't write code like this.
P.S. Matthias I hope you don't mind I do the review, right?
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
|