From 5f08e2786d483eccdc2760451f0fbdb52727ccf1 Mon Sep 17 00:00:00 2001 From: "Tim D. Smith" Date: Mon, 4 May 2015 14:55:14 -0700 Subject: [PATCH 1/8] Don't explicitly link libpython on OS X Use -undefined dynamic_lookup to allow Python symbols to be discovered when the ledger module is imported instead of at build time. Without this change, the Python interpreter crashes when ledger is imported from a python that is different from (but compatible with) the python against which the module was built. --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index da075cde..6166780c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -225,7 +225,14 @@ macro(add_ledger_library_dependencies _target) target_link_libraries(${_target} ${INTL_LIB}) endif() if (HAVE_BOOST_PYTHON) - target_link_libraries(${_target} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES}) + if(APPLE) + # Don't link directly to a Python framework on OS X, to avoid segfaults + # when the module is imported from a different interpreter + target_link_libraries(${_target} ${Boost_LIBRARIES}) + set_target_properties(${_target} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") + else() + target_link_libraries(${_target} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES}) + endif() else() target_link_libraries(${_target} ${Boost_LIBRARIES}) endif() From c586e1e494487c43cf6da886739f69bb91a7e15b Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 5 May 2015 13:26:49 -0500 Subject: [PATCH 2/8] Add a --no-revalued option --- src/report.cc | 1 + src/report.h | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/report.cc b/src/report.cc index 2ce70151..ac08c247 100644 --- a/src/report.cc +++ b/src/report.cc @@ -1198,6 +1198,7 @@ option_t * report_t::lookup_option(const char * p) OPT_CH(collapse); else OPT(no_color); else OPT(no_pager); + else OPT(no_revalued); else OPT(no_rounding); else OPT(no_titles); else OPT(no_total); diff --git a/src/report.h b/src/report.h index c54c8444..10afbe6f 100644 --- a/src/report.h +++ b/src/report.h @@ -764,6 +764,10 @@ public: OTHER(color).off(); }); + OPTION_(report_t, no_revalued, DO() { + OTHER(revalued).off(); + }); + OPTION(report_t, no_rounding); OPTION(report_t, no_titles); OPTION(report_t, no_total); From 48aec0f093ff6494a3e4f7cd5166cb4a27c16814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johann=20Kl=C3=A4hn?= Date: Sun, 10 May 2015 12:45:28 +0200 Subject: [PATCH 3/8] boost::none_t no longer convertible from literal 0 in 1.58 Instead we use boost::none, which has been documented since boost 1.34.0. --- src/account.h | 6 +----- src/item.h | 6 +----- src/parser.h | 2 +- src/post.h | 6 +----- src/times.h | 6 +----- 5 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/account.h b/src/account.h index 7fae93e1..8d0fb1db 100644 --- a/src/account.h +++ b/src/account.h @@ -261,11 +261,7 @@ public: mutable optional xdata_; bool has_xdata() const { -#if BOOST_VERSION >= 105600 - return xdata_ != NULL; -#else - return xdata_; -#endif + return xdata_ != boost::none; } void clear_xdata(); xdata_t& xdata() { diff --git a/src/item.h b/src/item.h index ba812175..2c349bdc 100644 --- a/src/item.h +++ b/src/item.h @@ -174,11 +174,7 @@ public: static bool use_aux_date; virtual bool has_date() const { -#if BOOST_VERSION >= 105600 - return _date != NULL; -#else - return _date; -#endif + return _date != boost::none; } virtual date_t date() const { diff --git a/src/parser.h b/src/parser.h index e46fc719..25c4a7e3 100644 --- a/src/parser.h +++ b/src/parser.h @@ -118,7 +118,7 @@ public: ptr_op_t parse(std::istream& in, const parse_flags_t& flags = PARSE_DEFAULT, - const optional& original_string = NULL); + const optional& original_string = boost::none); }; } // namespace ledger diff --git a/src/post.h b/src/post.h index 0fb45e90..3fa67e56 100644 --- a/src/post.h +++ b/src/post.h @@ -205,11 +205,7 @@ public: mutable optional xdata_; bool has_xdata() const { -#if BOOST_VERSION >= 105600 - return xdata_ != NULL; -#else - return xdata_; -#endif + return xdata_ != boost::none; } void clear_xdata() { xdata_ = none; diff --git a/src/times.h b/src/times.h index 421d1462..cc980858 100644 --- a/src/times.h +++ b/src/times.h @@ -500,11 +500,7 @@ public: void stabilize(const optional& date = none); bool is_valid() const { -#if BOOST_VERSION >= 105600 - return start != NULL; -#else - return start; -#endif + return start != boost::none; } /** Find the current or next period containing date. Returns false if From 68c9d649caa2c7c7f222613efe86576c379a5a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johann=20Kl=C3=A4hn?= Date: Sun, 10 May 2015 13:41:26 +0200 Subject: [PATCH 4/8] fix build for boost 1.58 --- src/filters.cc | 2 +- src/iterators.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/filters.cc b/src/filters.cc index 2f97a0e5..b6530c04 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -707,7 +707,7 @@ namespace { insert_prices_in_map(price_map_t& _all_prices) : all_prices(_all_prices) {} - void operator()(datetime_t& date, const amount_t& price) { + void operator()(const datetime_t& date, const amount_t& price) { all_prices.insert(price_map_t::value_type(date, price)); } }; diff --git a/src/iterators.cc b/src/iterators.cc index 21bec5d9..0225e210 100644 --- a/src/iterators.cc +++ b/src/iterators.cc @@ -96,7 +96,7 @@ namespace { TRACE_DTOR(create_price_xact); } - void operator()(datetime_t& date, const amount_t& price) { + void operator()(const datetime_t& date, const amount_t& price) { xact_t * xact; string symbol = price.commodity().symbol(); From 7df6a515e244c0d399da2b77e16c248e50a70ed9 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 17 May 2015 17:50:44 -0500 Subject: [PATCH 5/8] Revert "fix build for boost 1.58" This reverts commit 68c9d649caa2c7c7f222613efe86576c379a5a7a. --- src/filters.cc | 2 +- src/iterators.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/filters.cc b/src/filters.cc index b6530c04..2f97a0e5 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -707,7 +707,7 @@ namespace { insert_prices_in_map(price_map_t& _all_prices) : all_prices(_all_prices) {} - void operator()(const datetime_t& date, const amount_t& price) { + void operator()(datetime_t& date, const amount_t& price) { all_prices.insert(price_map_t::value_type(date, price)); } }; diff --git a/src/iterators.cc b/src/iterators.cc index 0225e210..21bec5d9 100644 --- a/src/iterators.cc +++ b/src/iterators.cc @@ -96,7 +96,7 @@ namespace { TRACE_DTOR(create_price_xact); } - void operator()(const datetime_t& date, const amount_t& price) { + void operator()(datetime_t& date, const amount_t& price) { xact_t * xact; string symbol = price.commodity().symbol(); From a78e7358ecda264175e7bc00bb5e87b9348600a8 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 17 May 2015 17:50:45 -0500 Subject: [PATCH 6/8] Revert "boost::none_t no longer convertible from literal 0 in 1.58" This reverts commit 48aec0f093ff6494a3e4f7cd5166cb4a27c16814. --- src/account.h | 6 +++++- src/item.h | 6 +++++- src/parser.h | 2 +- src/post.h | 6 +++++- src/times.h | 6 +++++- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/account.h b/src/account.h index 8d0fb1db..7fae93e1 100644 --- a/src/account.h +++ b/src/account.h @@ -261,7 +261,11 @@ public: mutable optional xdata_; bool has_xdata() const { - return xdata_ != boost::none; +#if BOOST_VERSION >= 105600 + return xdata_ != NULL; +#else + return xdata_; +#endif } void clear_xdata(); xdata_t& xdata() { diff --git a/src/item.h b/src/item.h index 2c349bdc..ba812175 100644 --- a/src/item.h +++ b/src/item.h @@ -174,7 +174,11 @@ public: static bool use_aux_date; virtual bool has_date() const { - return _date != boost::none; +#if BOOST_VERSION >= 105600 + return _date != NULL; +#else + return _date; +#endif } virtual date_t date() const { diff --git a/src/parser.h b/src/parser.h index 25c4a7e3..e46fc719 100644 --- a/src/parser.h +++ b/src/parser.h @@ -118,7 +118,7 @@ public: ptr_op_t parse(std::istream& in, const parse_flags_t& flags = PARSE_DEFAULT, - const optional& original_string = boost::none); + const optional& original_string = NULL); }; } // namespace ledger diff --git a/src/post.h b/src/post.h index 3fa67e56..0fb45e90 100644 --- a/src/post.h +++ b/src/post.h @@ -205,7 +205,11 @@ public: mutable optional xdata_; bool has_xdata() const { - return xdata_ != boost::none; +#if BOOST_VERSION >= 105600 + return xdata_ != NULL; +#else + return xdata_; +#endif } void clear_xdata() { xdata_ = none; diff --git a/src/times.h b/src/times.h index cc980858..421d1462 100644 --- a/src/times.h +++ b/src/times.h @@ -500,7 +500,11 @@ public: void stabilize(const optional& date = none); bool is_valid() const { - return start != boost::none; +#if BOOST_VERSION >= 105600 + return start != NULL; +#else + return start; +#endif } /** Find the current or next period containing date. Returns false if From 41c8b3ad3e984c11feacb5bd6032f1fef69b41c3 Mon Sep 17 00:00:00 2001 From: Erik Hetzner Date: Sat, 30 May 2015 10:27:43 -0700 Subject: [PATCH 7/8] Use (interactive "r") in ledger-post-align-postings Use standard method (interactive "r") to get the current active region for use in ledger-post-align-postings. --- lisp/ledger-post.el | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/lisp/ledger-post.el b/lisp/ledger-post.el index 527a2044..21e856db 100644 --- a/lisp/ledger-post.el +++ b/lisp/ledger-post.el @@ -100,23 +100,15 @@ at beginning of account" (let ((bounds (ledger-navigate-find-xact-extents pos))) (ledger-post-align-postings (car bounds) (cadr bounds)))) -(defun ledger-post-align-postings (&optional beg end) - "Align all accounts and amounts between BEG and END, or the current line." - (interactive) +(defun ledger-post-align-postings (beg end) + "Align all accounts and amounts between BEG and END, or the current region, or, if no region, the current line." + (interactive "r") (save-excursion - (if (or (not (mark)) - (not (use-region-p))) - (set-mark (point))) - (let ((inhibit-modification-hooks t) - (mark-first (< (mark) (point))) acct-start-column acct-end-column acct-adjust amt-width amt-adjust (lines-left 1)) - (unless beg (setq beg (if mark-first (mark) (point)))) - (unless end (setq end (if mark-first (mark) (point)))) - ;; Extend region to whole lines (let ((start-marker (set-marker (make-marker) (save-excursion (goto-char beg) From 45e74103607a77c5945615692c3a35f9ce6aadde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johann=20Kl=C3=A4hn?= Date: Tue, 9 Jun 2015 00:00:04 +0200 Subject: [PATCH 8/8] enable access to item's position in python bindings --- src/py_item.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/py_item.cc b/src/py_item.cc index 473bbef8..4dd104c9 100644 --- a/src/py_item.cc +++ b/src/py_item.cc @@ -32,6 +32,7 @@ #include #include "pyinterp.h" +#include "pyutils.h" #include "scope.h" #include "mask.h" #include "item.h" @@ -64,6 +65,13 @@ namespace { return item.get_tag(tag_mask, value_mask); } + std::string py_position_pathname(position_t const& pos) { + return pos.pathname.native(); + } + void py_position_set_pathname(position_t& pos, string const& s) { + pos.pathname = s; + } + } // unnamed namespace #if 0 @@ -79,8 +87,8 @@ void export_item() { class_< position_t > ("Position") .add_property("pathname", - make_getter(&position_t::pathname), - make_setter(&position_t::pathname)) + make_function(py_position_pathname), + make_function(py_position_set_pathname)) .add_property("beg_pos", make_getter(&position_t::beg_pos), make_setter(&position_t::beg_pos)) @@ -169,6 +177,8 @@ void export_item() .def("valid", &item_t::valid) ; + + register_optional_to_python(); } } // namespace ledger