From 32cd2304e91df6dda16e2bf6a170bd38d19bb061 Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Sat, 17 Jul 2010 10:22:34 +0000 Subject: [PATCH] * All Main Python Modules: - Change: New problem identified with the Python modules: each module seems to be built as a complete binary, so all the static C++ initializers are allocated in each module. In particular the C++ tree inheritance is built for *each* module so we cannot longer uses the typeid() comparisons across modules... It was used by boost::program_options to perform is casts with boost::any and was starting throwing exceptions because of bad casts. program_option was first initialized in "configuration" first included by PyViewer then in PyCRL (see Utilities.cpp). A first solution is to re-order the import of Python modules in stratus1/st_model so that CRL is imported first. The second is to not not link "configuration" with boost::program_option as only the binary vlsisapd-conf-editor needs it. That is a serious problem of which we must be aware and can cause further strange behaviors. Debug code used to diagnostic has been kept commented in the sources a it may be needed again :-( This behavior do not affect our singletons because they are part of dynamic libraries that seems to be correctly shared between the various Python modules. * ./crlcore: - In PyCRL, module method "getAllianceFramework()" moved as static object method "get()" of AllianceFramework. Object AllianceFramework added to module CRL. --- crlcore/src/ccore/AllianceFramework.cpp | 2 + crlcore/src/ccore/Utilities.cpp | 17 ++++++ crlcore/src/pyCRL/PyAllianceFramework.cpp | 58 ++++++++++--------- crlcore/src/pyCRL/PyCRL.cpp | 8 ++- .../src/pyCRL/crlcore/PyAllianceFramework.h | 1 - 5 files changed, 56 insertions(+), 30 deletions(-) diff --git a/crlcore/src/ccore/AllianceFramework.cpp b/crlcore/src/ccore/AllianceFramework.cpp index ac53b209..1735e0af 100644 --- a/crlcore/src/ccore/AllianceFramework.cpp +++ b/crlcore/src/ccore/AllianceFramework.cpp @@ -63,6 +63,8 @@ namespace CRL { , _parentLibrary(NULL) , _routingGauges() { + //cerr << "AllianceFramework::AllianceFramework()" << endl; + // Triggers System singleton loading. System::get (); diff --git a/crlcore/src/ccore/Utilities.cpp b/crlcore/src/ccore/Utilities.cpp index a547f508..1aef5391 100644 --- a/crlcore/src/ccore/Utilities.cpp +++ b/crlcore/src/ccore/Utilities.cpp @@ -237,6 +237,23 @@ namespace CRL { bfs::path sysConfDir ( SYS_CONF_DIR ); if ( not sysConfDir.has_root_path() ) { if ( arguments.count("coriolis_top") ) { + // const boptions::variable_value& value = arguments["coriolis_top"]; + // cerr << "value:" + // << " empty:" << boolalpha << value.empty() + // << " defaulted:" << boolalpha << value.defaulted() + // << endl; + // const type_info& info = value.value().type(); + // cerr << "type_info:" << info.name() + // << " vs. " << typeid(string).name() << endl; + // cerr << "Equal:" << boolalpha << (info == typeid(std::string)) << endl; + + // const type_info& info2 = typeid(string); + // cerr << (void*)&(typeid(string)) + // << " vs. " << (void*)&info2 + // << " vs. " << (void*)&info + // << endl; + // cerr << "any_cast:" << boost::any_cast(value.value()) << endl; + sysConfDir = arguments["coriolis_top"].as() / sysConfDir; } else { cerr << Error("Environment variable CORIOLIS_TOP not set," diff --git a/crlcore/src/pyCRL/PyAllianceFramework.cpp b/crlcore/src/pyCRL/PyAllianceFramework.cpp index 9e5f4dc7..cb24607a 100644 --- a/crlcore/src/pyCRL/PyAllianceFramework.cpp +++ b/crlcore/src/pyCRL/PyAllianceFramework.cpp @@ -65,6 +65,26 @@ extern "C" { #if defined(__PYTHON_MODULE__) + static PyObject* PyAllianceFramework_get ( PyObject* ) + { + trace << "PyAllianceFramework_get()" << endl; + + AllianceFramework* af = NULL; + PyAllianceFramework* pyAf = NULL; + + HTRY + af = AllianceFramework::get (); + + pyAf = PyObject_NEW ( PyAllianceFramework, &PyTypeAllianceFramework ); + if ( pyAf == NULL ) return NULL; + + pyAf->_object = af; + HCATCH + + return (PyObject*)pyAf; + } + + extern PyObject* PyAllianceFramework_getLibrary ( PyAllianceFramework* self, PyObject* args ) { trace << "PyAllianceFramework_getLibrary ()" << endl; @@ -160,12 +180,18 @@ extern "C" { PyMethodDef PyAllianceFramework_Methods[] = - { { "getLibrary" , (PyCFunction)PyAllianceFramework_getLibrary, METH_VARARGS, "Gets a Library, by index." } - , { "getCell" , (PyCFunction)PyAllianceFramework_getCell , METH_VARARGS, "Gets an Alliance Cell." } - , { "saveCell" , (PyCFunction)PyAllianceFramework_saveCell , METH_VARARGS, "Saves an Alliance Cell." } - , { "createCell" , (PyCFunction)PyAllianceFramework_createCell, METH_VARARGS, "Create a Cell in the Alliance framework." } - //, { "destroy" , (PyCFunction)PyAllianceFramework_destroy , METH_NOARGS - // , "Destroy the associated hurricane object. The python object remains." } + { { "get" , (PyCFunction)PyAllianceFramework_get , METH_NOARGS|METH_STATIC + , "Gets the Alliance Framework." } + , { "getLibrary" , (PyCFunction)PyAllianceFramework_getLibrary, METH_VARARGS + , "Gets a Library, by index." } + , { "getCell" , (PyCFunction)PyAllianceFramework_getCell , METH_VARARGS + , "Gets an Alliance Cell." } + , { "saveCell" , (PyCFunction)PyAllianceFramework_saveCell , METH_VARARGS + , "Saves an Alliance Cell." } + , { "createCell" , (PyCFunction)PyAllianceFramework_createCell, METH_VARARGS + , "Create a Cell in the Alliance framework." } + //, { "destroy" , (PyCFunction)PyAllianceFramework_destroy , METH_NOARGS + // , "Destroy the associated hurricane object. The python object remains." } , {NULL, NULL, 0, NULL} /* sentinel */ }; @@ -182,26 +208,6 @@ extern "C" { // x=================================================================x - PyObject* PyAllianceFramework_get ( PyObject *module ) - { - trace << "PyAllianceFramework_get()" << endl; - - AllianceFramework* af = NULL; - PyAllianceFramework* pyAf = NULL; - - HTRY - af = AllianceFramework::get (); - - pyAf = PyObject_NEW ( PyAllianceFramework, &PyTypeAllianceFramework ); - if ( pyAf == NULL ) return NULL; - - pyAf->_object = af; - HCATCH - - return (PyObject*)pyAf; - } - - // Link/Creation Method. PyTypeObjectDefinitions(AllianceFramework) diff --git a/crlcore/src/pyCRL/PyCRL.cpp b/crlcore/src/pyCRL/PyCRL.cpp index 49474a6d..7b025773 100644 --- a/crlcore/src/pyCRL/PyCRL.cpp +++ b/crlcore/src/pyCRL/PyCRL.cpp @@ -65,9 +65,7 @@ extern "C" { static PyMethodDef PyCRL_Methods[] = - { { "getAllianceFramework", (PyCFunction)PyAllianceFramework_get, METH_NOARGS - , "Gets the Alliance Framework." } - , { "createPartRing" , (PyCFunction)PyToolBox_createPartRing, METH_VARARGS + { { "createPartRing" , (PyCFunction)PyToolBox_createPartRing, METH_VARARGS , "Partial build of a ring" } , {NULL, NULL, 0, NULL} /* sentinel */ }; @@ -103,12 +101,16 @@ extern "C" { Py_INCREF ( &PyTypeCatalog ); PyModule_AddObject ( module, "Catalog", (PyObject*)&PyTypeCatalog ); + Py_INCREF ( &PyTypeAllianceFramework ); + PyModule_AddObject ( module, "AllianceFramework", (PyObject*)&PyTypeAllianceFramework ); PyCatalog_postModuleInit (); PyObject* dictionnary = PyModule_GetDict ( module ); //DbULoadConstants ( dictionnary ); + + trace << "CRL.so loaded " << (void*)&typeid(string) << endl; } diff --git a/crlcore/src/pyCRL/crlcore/PyAllianceFramework.h b/crlcore/src/pyCRL/crlcore/PyAllianceFramework.h index 5135e95a..5684497f 100644 --- a/crlcore/src/pyCRL/crlcore/PyAllianceFramework.h +++ b/crlcore/src/pyCRL/crlcore/PyAllianceFramework.h @@ -51,7 +51,6 @@ extern "C" { extern PyTypeObject PyTypeAllianceFramework; extern PyMethodDef PyAllianceFramework_Methods[]; - extern PyObject* PyAllianceFramework_get ( PyObject* module ); extern PyObject* PyAllianceFramework_Link ( CRL::AllianceFramework* ); extern void PyAllianceFramework_LinkPyType ();