summaryrefslogtreecommitdiff
path: root/py/modules/IcePy/Util.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2004-09-09 23:47:24 +0000
committerMark Spruiell <mes@zeroc.com>2004-09-09 23:47:24 +0000
commit3a8199d8d2ad149c592c66ff124b3ae241daba60 (patch)
tree068640dbec875aee07f876bf86d52c6c2d83ec31 /py/modules/IcePy/Util.cpp
parentclean up; migrating Operation implementation; adding isAbstract member to (diff)
downloadice-3a8199d8d2ad149c592c66ff124b3ae241daba60.tar.bz2
ice-3a8199d8d2ad149c592c66ff124b3ae241daba60.tar.xz
ice-3a8199d8d2ad149c592c66ff124b3ae241daba60.zip
clean up
Diffstat (limited to 'py/modules/IcePy/Util.cpp')
-rw-r--r--py/modules/IcePy/Util.cpp50
1 files changed, 31 insertions, 19 deletions
diff --git a/py/modules/IcePy/Util.cpp b/py/modules/IcePy/Util.cpp
index d01d56b3b76..58752eb8f52 100644
--- a/py/modules/IcePy/Util.cpp
+++ b/py/modules/IcePy/Util.cpp
@@ -189,28 +189,37 @@ PyObject*
IcePy::lookupType(const string& typeName)
{
string::size_type dot = typeName.rfind('.');
- string moduleName;
- string name;
- if(dot == string::npos)
+ assert(dot != string::npos);
+ string moduleName = typeName.substr(0, dot);
+ string name = typeName.substr(dot + 1);
+
+ //
+ // First search for the module in sys.modules.
+ //
+ PyObject* sysModules = PyImport_GetModuleDict();
+ assert(sysModules != NULL);
+
+ PyObject* module = PyDict_GetItemString(sysModules, const_cast<char*>(moduleName.c_str()));
+ PyObject* dict;
+ if(module == NULL)
{
- moduleName = "__main__";
- name = typeName;
+ //
+ // Not found, so we need to import the module.
+ //
+ PyObjectHandle h = PyImport_ImportModule(const_cast<char*>(moduleName.c_str()));
+ if(h.get() == NULL)
+ {
+ return NULL;
+ }
+
+ dict = PyModule_GetDict(h.get());
}
else
{
- moduleName = typeName.substr(0, dot);
- name = typeName.substr(dot + 1);
- }
-
- PyObjectHandle module = PyImport_ImportModule(const_cast<char*>(moduleName.c_str()));
- if(module.get() == NULL)
- {
- return NULL;
+ dict = PyModule_GetDict(module);
}
- PyObject* dict = PyModule_GetDict(module.get());
- assert(dict);
-
+ assert(dict != NULL);
return PyDict_GetItemString(dict, const_cast<char*>(name.c_str()));
}
@@ -383,7 +392,10 @@ IcePy::setPythonException(const Ice::Exception& ex)
static void
throwLocalException(PyObject* ex)
{
- string typeName = ex->ob_type->tp_name;
+ assert(PyInstance_Check(ex));
+ PyObject* cls = (PyObject*)((PyInstanceObject*)ex)->in_class;
+ IcePy::PyObjectHandle h = PyObject_Str(cls);
+ string typeName = PyString_AsString(h.get());
try
{
@@ -610,7 +622,7 @@ IcePy::getIdentity(PyObject* p, Ice::Identity& identity)
extern "C"
PyObject*
-Ice_identityToString(PyObject* /*self*/, PyObject* args)
+IcePy_identityToString(PyObject* /*self*/, PyObject* args)
{
PyObject* identityType = IcePy::lookupType("Ice.Identity");
PyObject* p;
@@ -640,7 +652,7 @@ Ice_identityToString(PyObject* /*self*/, PyObject* args)
extern "C"
PyObject*
-Ice_stringToIdentity(PyObject* /*self*/, PyObject* args)
+IcePy_stringToIdentity(PyObject* /*self*/, PyObject* args)
{
char* str;
if(!PyArg_ParseTuple(args, "s", &str))