From: Ali Saidi Date: Tue, 4 Sep 2007 17:12:58 +0000 (-0400) Subject: Serialization: Fix unserialization of object pointers X-Git-Tag: m5_2.0_beta4~122^2 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=276a3825579e3a88dca6cec5e2af84c68f1194cc;p=gem5.git Serialization: Fix unserialization of object pointers --HG-- extra : convert_revision : a5aed880b2fc05841067e8597a58a9484e30b84a --- diff --git a/src/python/swig/pyobject.cc b/src/python/swig/pyobject.cc index fad280e1b..c682b0fd7 100644 --- a/src/python/swig/pyobject.cc +++ b/src/python/swig/pyobject.cc @@ -141,11 +141,6 @@ inifile() return inifile; } -/** - * Pointer to the Python function that maps names to SimObjects. - */ -PyObject *resolveFunc = NULL; - /** * Convert a pointer to the Python object that SWIG wraps around a C++ * SimObject pointer back to the actual C++ pointer. See main.i. @@ -155,16 +150,29 @@ extern "C" SimObject *convertSwigSimObjectPtr(PyObject *); SimObject * resolveSimObject(const string &name) { - PyObject *pyPtr = PyEval_CallFunction(resolveFunc, "(s)", name.c_str()); - if (pyPtr == NULL) { + PyObject *module = PyImport_ImportModule("m5.SimObject"); + if (module == NULL) + panic("Could not import m5.SimObject"); + + PyObject *resolver = PyObject_GetAttrString(module, "resolveSimObject"); + if (resolver == NULL) { + PyErr_Print(); + panic("resolveSimObject: failed to find resolveSimObject"); + } + + PyObject *ptr = PyObject_CallFunction(resolver, "(s)", name.c_str()); + if (ptr == NULL) { PyErr_Print(); panic("resolveSimObject: failure on call to Python for %s", name); } - SimObject *simObj = convertSwigSimObjectPtr(pyPtr); - if (simObj == NULL) + SimObject *obj = convertSwigSimObjectPtr(ptr); + if (obj == NULL) panic("resolveSimObject: failure on pointer conversion for %s", name); - return simObj; -} + Py_DECREF(module); + Py_DECREF(resolver); + Py_DECREF(ptr); + return obj; +}