summaryrefslogtreecommitdiff
path: root/python.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-09-14 20:32:42 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-09-14 20:32:42 -0400
commit50a322adcfa3c1ac375e061270e73bc76c57cc47 (patch)
treea53a4e358507e16c933e9b428d9a0a00d6d4d840 /python.cc
parent5d99b1e24179d65e75431b8d5dfbe6e11acb0d24 (diff)
downloadfork-ledger-50a322adcfa3c1ac375e061270e73bc76c57cc47.tar.gz
fork-ledger-50a322adcfa3c1ac375e061270e73bc76c57cc47.tar.bz2
fork-ledger-50a322adcfa3c1ac375e061270e73bc76c57cc47.zip
main.py (via ledger.so) and main.cc can now use the same shared library
Diffstat (limited to 'python.cc')
-rw-r--r--python.cc50
1 files changed, 27 insertions, 23 deletions
diff --git a/python.cc b/python.cc
index 980df95c..b5d7d493 100644
--- a/python.cc
+++ b/python.cc
@@ -6,6 +6,11 @@
using namespace boost::python;
+namespace {
+ bool python_initialized = false;
+ bool module_initialized = false;
+}
+
void export_amount();
void export_balance();
void export_value();
@@ -18,27 +23,13 @@ void export_qif();
void export_gnucash();
#endif
void export_option();
+void export_config();
void export_walk();
void export_format();
void export_valexpr();
void export_datetime();
-namespace ledger {
-
-python_support * python_interpretor = NULL;
-
-#ifndef PYTHON_MODULE
-
-static struct cleanup_python {
- ~cleanup_python() {
- if (python_interpretor) {
- Py_Finalize();
- delete python_interpretor;
- }
- }
-} _cleanup;
-
-void init_module()
+void initialize_ledger_for_python()
{
export_amount();
export_balance();
@@ -52,22 +43,35 @@ void init_module()
export_gnucash();
#endif
export_option();
+ export_config();
export_walk();
export_format();
export_valexpr();
export_datetime();
+
+ module_initialized = true;
}
-#endif // PYTHON_MODULE
+namespace ledger {
+
+python_support * python_interpretor = NULL;
+
+static struct cleanup_python {
+ ~cleanup_python() {
+ if (python_initialized)
+ Py_Finalize();
+ if (python_interpretor)
+ delete python_interpretor;
+ }
+} _cleanup;
void init_python()
{
- assert(! python_interpretor);
-
-#ifndef PYTHON_MODULE
- Py_Initialize();
- detail::init_module("ledger", &init_module);
-#endif
+ if (! module_initialized) {
+ Py_Initialize();
+ python_initialized = true;
+ detail::init_module("ledger", &initialize_ledger_for_python);
+ }
python_interpretor = new python_support;
}