diff options
author | John Wiegley <johnw@newartisans.com> | 2008-08-07 02:53:10 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-08-07 02:53:35 -0400 |
commit | 0eda1ad2c6db874a6fed9c45851d4222250a2255 (patch) | |
tree | b9e784574e417bd2f5d52b0c3895589d012149f7 /python | |
parent | 6ddc21dc5fe75c80df1bf383e5bfc2320deb8624 (diff) | |
download | fork-ledger-0eda1ad2c6db874a6fed9c45851d4222250a2255.tar.gz fork-ledger-0eda1ad2c6db874a6fed9c45851d4222250a2255.tar.bz2 fork-ledger-0eda1ad2c6db874a6fed9c45851d4222250a2255.zip |
The Python interface layer is building again.
Diffstat (limited to 'python')
-rw-r--r-- | python/py_amount.cc | 48 | ||||
-rw-r--r-- | python/py_times.cc | 12 | ||||
-rw-r--r-- | python/py_utils.cc | 12 | ||||
-rw-r--r-- | python/pyfstream.h | 18 | ||||
-rw-r--r-- | python/pyinterp.cc | 16 | ||||
-rw-r--r-- | python/pyinterp.h | 8 | ||||
-rw-r--r-- | python/pyutils.h | 7 | ||||
-rwxr-xr-x | python/setup.py | 2 |
8 files changed, 81 insertions, 42 deletions
diff --git a/python/py_amount.cc b/python/py_amount.cc index 16880f6f..4ec94132 100644 --- a/python/py_amount.cc +++ b/python/py_amount.cc @@ -48,12 +48,14 @@ amount_t py_round_1(const amount_t& amount, amount_t::precision_t prec) { return amount.round(prec); } +#ifdef HAVE_GDTOA double py_to_double_0(amount_t& amount) { return amount.to_double(); } double py_to_double_1(amount_t& amount, bool no_check) { return amount.to_double(no_check); } +#endif long py_to_long_0(amount_t& amount) { return amount.to_long(); @@ -66,7 +68,7 @@ boost::optional<amount_t> py_value_0(const amount_t& amount) { return amount.value(); } boost::optional<amount_t> py_value_1(const amount_t& amount, - const boost::optional<moment_t>& moment) { + const boost::optional<datetime_t>& moment) { return amount.value(moment); } @@ -136,7 +138,9 @@ void export_amount() .add_static_property("stream_fullstrings", &amount_t::stream_fullstrings) +#ifdef HAVE_GDTOA .def(init<double>()) +#endif .def(init<long>()) .def(init<std::string>()) @@ -152,80 +156,108 @@ internal precision.") .def(self == self) .def(self == long()) .def(long() == self) +#ifdef HAVE_GDTOA .def(self == double()) .def(double() == self) +#endif .def(self != self) .def(self != long()) .def(long() != self) +#ifdef HAVE_GDTOA .def(self != double()) .def(double() != self) +#endif .def(! self) .def(self < self) .def(self < long()) .def(long() < self) +#ifdef HAVE_GDTOA .def(self < double()) .def(double() < self) +#endif .def(self <= self) .def(self <= long()) .def(long() <= self) +#ifdef HAVE_GDTOA .def(self <= double()) .def(double() <= self) +#endif .def(self > self) .def(self > long()) .def(long() > self) +#ifdef HAVE_GDTOA .def(self > double()) .def(double() > self) +#endif .def(self >= self) .def(self >= long()) .def(long() >= self) +#ifdef HAVE_GDTOA .def(self >= double()) .def(double() >= self) +#endif .def(self += self) .def(self += long()) +#ifdef HAVE_GDTOA .def(self += double()) +#endif .def(self + self) .def(self + long()) .def(long() + self) +#ifdef HAVE_GDTOA .def(self + double()) .def(double() + self) +#endif .def(self -= self) .def(self -= long()) +#ifdef HAVE_GDTOA .def(self -= double()) +#endif .def(self - self) .def(self - long()) .def(long() - self) +#ifdef HAVE_GDTOA .def(self - double()) .def(double() - self) +#endif .def(self *= self) .def(self *= long()) +#ifdef HAVE_GDTOA .def(self *= double()) +#endif .def(self * self) .def(self * long()) .def(long() * self) +#ifdef HAVE_GDTOA .def(self * double()) .def(double() * self) +#endif .def(self /= self) .def(self /= long()) +#ifdef HAVE_GDTOA .def(self /= double()) +#endif .def(self / self) .def(self / long()) .def(long() / self) +#ifdef HAVE_GDTOA .def(self / double()) .def(double() / self) +#endif .add_property("precision", &amount_t::precision) @@ -259,9 +291,11 @@ internal precision.") .def("is_realzero", &amount_t::is_realzero) .def("is_null", &amount_t::is_null) +#ifdef HAVE_GDTOA .def("to_double", py_to_double_0) .def("to_double", py_to_double_1) .def("__float__", py_to_double_0) +#endif .def("to_long", py_to_long_0) .def("to_long", py_to_long_1) .def("__int__", py_to_long_0) @@ -270,7 +304,9 @@ internal precision.") .def("to_fullstring", &amount_t::to_fullstring) .def("__repr__", &amount_t::to_fullstring) +#ifdef HAVE_GDTOA .def("fits_in_double", &amount_t::fits_in_double) +#endif .def("fits_in_long", &amount_t::fits_in_long) .add_property("quantity_string", &amount_t::quantity_string) @@ -285,9 +321,11 @@ internal precision.") .def("clear_commodity", &amount_t::clear_commodity) .add_property("number", &amount_t::number) - .def("annotate_commodity", &amount_t::annotate_commodity) - .def("commodity_annotated", &amount_t::commodity_annotated) - .add_property("annotation_details", &amount_t::annotation_details) + .def("annotate", &amount_t::annotate) + .def("is_annotated", &amount_t::is_annotated) +#if 0 + .add_property("annotation", &amount_t::annotation) +#endif .def("strip_annotations", &amount_t::strip_annotations) .def("parse", py_parse_1) @@ -307,7 +345,9 @@ internal precision.") register_optional_to_python<amount_t>(); +#ifdef HAVE_GDTOA implicitly_convertible<double, amount_t>(); +#endif implicitly_convertible<long, amount_t>(); implicitly_convertible<string, amount_t>(); diff --git a/python/py_times.cc b/python/py_times.cc index 00108b04..2d7ce662 100644 --- a/python/py_times.cc +++ b/python/py_times.cc @@ -83,11 +83,11 @@ typedef register_python_conversion<date, date_to_python, date_from_python> struct datetime_to_python { - static PyObject* convert(const moment_t& moment) + static PyObject* convert(const datetime_t& moment) { PyDateTime_IMPORT; date dte = moment.date(); - moment_t::time_duration_type tod = moment.time_of_day(); + datetime_t::time_duration_type tod = moment.time_of_day(); return PyDateTime_FromDateAndTime(dte.year(), dte.month(), dte.day(), tod.hours(), tod.minutes(), tod.seconds(), tod.total_microseconds() % 1000000); @@ -112,13 +112,13 @@ struct datetime_from_python int h = PyDateTime_DATE_GET_HOUR(obj_ptr); int min = PyDateTime_DATE_GET_MINUTE(obj_ptr); int s = PyDateTime_DATE_GET_SECOND(obj_ptr); - moment_t* moment = new moment_t(date(y,m,d), - moment_t::time_duration_type(h, min, s)); + datetime_t* moment = new datetime_t(date(y,m,d), + datetime_t::time_duration_type(h, min, s)); data->convertible = (void*)moment; } }; -typedef register_python_conversion<moment_t, datetime_to_python, datetime_from_python> +typedef register_python_conversion<datetime_t, datetime_to_python, datetime_from_python> datetime_python_conversion; void export_times() @@ -126,7 +126,7 @@ void export_times() date_python_conversion(); datetime_python_conversion(); - register_optional_to_python<moment_t>(); + register_optional_to_python<datetime_t>(); } } // namespace ledger diff --git a/python/py_utils.cc b/python/py_utils.cc index 9fc375f6..99936a8e 100644 --- a/python/py_utils.cc +++ b/python/py_utils.cc @@ -95,7 +95,8 @@ struct string_from_python { const char* value = PyString_AsString(obj_ptr); if (value == 0) throw_error_already_set(); - void* storage = ((converter::rvalue_from_python_storage<string>*) data)->storage.bytes; + void* storage = + reinterpret_cast<converter::rvalue_from_python_storage<string> *>(data)->storage.bytes; new (storage) string(value); data->convertible = storage; } @@ -107,7 +108,7 @@ typedef register_python_conversion<string, string_to_python, string_from_python> struct istream_to_python { - static PyObject* convert(const std::istream& str) + static PyObject* convert(const std::istream&) { return incref(boost::python::detail::none()); } @@ -123,7 +124,8 @@ struct istream_from_python static void construct(PyObject* obj_ptr, converter::rvalue_from_python_stage1_data* data) { - void* storage = ((converter::rvalue_from_python_storage<pyifstream>*) data)->storage.bytes; + void* storage = + reinterpret_cast<converter::rvalue_from_python_storage<pyifstream> *>(data)->storage.bytes; new (storage) pyifstream(reinterpret_cast<PyFileObject *>(obj_ptr)); data->convertible = storage; } @@ -135,7 +137,7 @@ typedef register_python_conversion<std::istream, istream_to_python, istream_from struct ostream_to_python { - static PyObject* convert(const std::ostream& str) + static PyObject* convert(const std::ostream&) { return incref(boost::python::detail::none()); } @@ -151,7 +153,7 @@ struct ostream_from_python static void construct(PyObject* obj_ptr, converter::rvalue_from_python_stage1_data* data) { - void* storage = ((converter::rvalue_from_python_storage<pyofstream>*) data)->storage.bytes; + void* storage = reinterpret_cast<converter::rvalue_from_python_storage<pyofstream> *>(data)->storage.bytes; new (storage) pyofstream(reinterpret_cast<PyFileObject *>(obj_ptr)); data->convertible = storage; } diff --git a/python/pyfstream.h b/python/pyfstream.h index 1d72d471..aaa5cbeb 100644 --- a/python/pyfstream.h +++ b/python/pyfstream.h @@ -37,7 +37,7 @@ class pyoutbuf : public boost::noncopyable, public std::streambuf { - pyoutbf(); + pyoutbuf(); protected: PyFileObject * fo; // Python file object @@ -47,7 +47,7 @@ public: pyoutbuf(PyFileObject * _fo) : fo(_fo) { TRACE_CTOR(pyoutbuf, "PyFileObject *"); } - ~pyoutbuf() : throw() { + ~pyoutbuf() throw() { TRACE_DTOR(pyoutbuf); } @@ -58,7 +58,7 @@ protected: char z[2]; z[0] = c; z[1] = '\0'; - if (PyFile_WriteString(z, (PyObject *)fo) < 0) { + if (PyFile_WriteString(z, reinterpret_cast<PyObject *>(fo)) < 0) { return EOF; } } @@ -70,14 +70,14 @@ protected: char * buf = new char[num + 1]; std::strncpy(buf, s, num); buf[num] = '\0'; - if (PyFile_WriteString(buf, (PyObject *)fo) < 0) + if (PyFile_WriteString(buf, reinterpret_cast<PyObject *>(fo)) < 0) num = 0; - checked_array_delete(buf); + boost::checked_array_delete(buf); return num; } }; -class pyofstream : public noncopyable, public std::ostream +class pyofstream : public boost::noncopyable, public std::ostream { pyofstream(); @@ -97,7 +97,7 @@ public: // pyifstream // - a stream that reads on a file descriptor -class pyinbuf : public noncopyable, public std::streambuf +class pyinbuf : public boost::noncopyable, public std::streambuf { pyinbuf(); @@ -161,7 +161,7 @@ protected: // read at most bufSize new characters int num; - PyObject *line = PyFile_GetLine((PyObject *)fo, bufSize); + PyObject *line = PyFile_GetLine(reinterpret_cast<PyObject *>(fo), bufSize); if (! line || ! PyString_Check(line)) { // ERROR or EOF return EOF; @@ -183,7 +183,7 @@ protected: } }; -class pyifstream : public noncopyable, public std::istream +class pyifstream : public boost::noncopyable, public std::istream { pyifstream(); diff --git a/python/pyinterp.cc b/python/pyinterp.cc index 07a619fe..831852ad 100644 --- a/python/pyinterp.cc +++ b/python/pyinterp.cc @@ -177,8 +177,7 @@ object python_interpreter_t::eval(const string& str, py_eval_mode_t mode) return object(); } -value_t python_interpreter_t::functor_t::operator() - (expr_t::call_scope_t& args) +value_t python_interpreter_t::functor_t::operator()(call_scope_t& args) { try { if (! PyCallable_Check(func.ptr())) { @@ -201,7 +200,7 @@ value_t python_interpreter_t::functor_t::operator() } else if (PyObject * err = PyErr_Occurred()) { PyErr_Print(); - throw_(expr_t::calc_error, + throw_(calc_error, "While calling Python function '" /*<< name() <<*/ "': " << err); } else { assert(false); @@ -213,25 +212,22 @@ value_t python_interpreter_t::functor_t::operator() } catch (const error_already_set&) { PyErr_Print(); - throw_(expr_t::calc_error, + throw_(calc_error, "While calling Python function '" /*<< name() <<*/ "'"); } return NULL_VALUE; } -value_t python_interpreter_t::lambda_t::operator() - (expr_t::call_scope_t& args) +value_t python_interpreter_t::lambda_t::operator()(call_scope_t& args) { try { assert(args.size() == 1); value_t item = args[0]; - assert(item.is_xml_node()); - return call<value_t>(func.ptr(), item.as_xml_node()); + return call<value_t>(func.ptr(), item); } catch (const error_already_set&) { PyErr_Print(); - throw_(expr_t::calc_error, - "While evaluating Python lambda expression"); + throw_(calc_error, "While evaluating Python lambda expression"); } return NULL_VALUE; } diff --git a/python/pyinterp.h b/python/pyinterp.h index 5486eea5..1deeb11b 100644 --- a/python/pyinterp.h +++ b/python/pyinterp.h @@ -48,7 +48,7 @@ class python_interpreter_t : public noncopyable, public scope_t public: boost::python::dict nspace; - python_interpreter_t(expr_t::scope_t& parent); + python_interpreter_t(scope_t& parent); virtual ~python_interpreter_t() { TRACE_DTOR(python_interpreter_t); @@ -79,7 +79,7 @@ public: protected: boost::python::object func; public: - functor_t(const string& name, boost::python::object _func) : func(_func) { + functor_t(const string&, boost::python::object _func) : func(_func) { TRACE_CTOR(functor_t, "const string&, boost::python::object"); } functor_t(const functor_t& other) : func(other.func) { @@ -88,7 +88,7 @@ public: virtual ~functor_t() throw() { TRACE_DTOR(functor_t); } - virtual value_t operator()(expr_t::call_scope_t& args); + virtual value_t operator()(call_scope_t& args); }; virtual expr_t::ptr_op_t lookup(const string& name) { @@ -109,7 +109,7 @@ public: virtual ~lambda_t() throw() { TRACE_DTOR(lambda_t); } - virtual value_t operator()(expr_t::call_scope_t& args); + virtual value_t operator()(call_scope_t& args); }; }; diff --git a/python/pyutils.h b/python/pyutils.h index bdb1f142..006f75ac 100644 --- a/python/pyutils.h +++ b/python/pyutils.h @@ -90,12 +90,13 @@ struct register_optional_to_python : public boost::noncopyable { using namespace boost::python::converter; - void * const storage = ((rvalue_from_python_storage<T> *) data)->storage.bytes; + void * const storage = + reinterpret_cast<rvalue_from_python_storage<T> *>(data)->storage.bytes; if (data->convertible == source) // == None new (storage) boost::optional<T>(); // A Boost uninitialized value else - new (storage) boost::optional<T>(*static_cast<T *>(data->convertible)); + new (storage) boost::optional<T>(*reinterpret_cast<T *>(data->convertible)); data->convertible = storage; } @@ -103,7 +104,7 @@ struct register_optional_to_python : public boost::noncopyable explicit register_optional_to_python() { register_python_conversion<boost::optional<T>, - optional_to_python, optional_from_python>(); + optional_to_python, optional_from_python>(); } }; diff --git a/python/setup.py b/python/setup.py index 4413a88d..347b1e6f 100755 --- a/python/setup.py +++ b/python/setup.py @@ -15,5 +15,5 @@ setup(name = "Ledger", url = "http://www.newartisans.com/software/ledger.html", ext_modules = [ Extension("ledger", - [os.path.join(os.environ['SRCDIR'], "pyledger.cc")], + [os.path.join(os.environ['SRCDIR'], "python/pyledger.cc")], define_macros = defines, libraries = libs)]) |