Commit 1eade878 authored by cyrush's avatar cyrush

merge from 2.0RC - python filters changes (This fixes #153)

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@11847 18c085ea-50e0-402c-830e-de6fd14e8384
parent c1320de2
......@@ -49,18 +49,25 @@
using namespace std;
PythonInterpreter *avtPythonFilterEnvironment::pyi=NULL;
// ****************************************************************************
// Method: avtPythonFilterEnvironment constructor
//
// Programmer: Cyrus Harrison
// Creation: Tue Feb 2 13:14:44 PST 2010
//
// Modifications:
// Cyrus Harrison, Fri Jul 9 10:31:03 PDT 2010
// Init singleton instance of the python interpreter.
//
// ****************************************************************************
avtPythonFilterEnvironment::avtPythonFilterEnvironment()
: pyi(NULL), pyFilter(NULL)
: pyFilter(NULL)
{
pyi = new PythonInterpreter();
if(pyi == NULL)
pyi = new PythonInterpreter();
}
// ****************************************************************************
......@@ -69,12 +76,18 @@ avtPythonFilterEnvironment::avtPythonFilterEnvironment()
// Programmer: Cyrus Harrison
// Creation: Tue Feb 2 13:14:44 PST 2010
//
// Modifications:
// Cyrus Harrison, Fri Jul 9 10:31:03 PDT 2010
// Handle filter cleanup. This was previously done in the 'Shutdown'
// method, which was removed due to the singleton use of the python
// interpreter.
//
// ****************************************************************************
avtPythonFilterEnvironment::~avtPythonFilterEnvironment()
{
Shutdown();
delete pyi;
if(pyFilter)
delete pyFilter; // calls decref
}
......@@ -90,7 +103,7 @@ avtPythonFilterEnvironment::~avtPythonFilterEnvironment()
// Programmer: Cyrus Harrison
// Creation: Tue Feb 2 13:14:44 PST 2010
//
// Modifications:
// Modifications:
// Kathleen Bonnell, Wed Mar 24 16:17:23 MST 2010
// Retrieve VISITARCHHOME via GetVisItArchitectureDirectory.
// Remove slash from end of paths passed to AddSystemPath.
......@@ -202,25 +215,6 @@ avtPythonFilterEnvironment::LoadFilter(const string &py_script)
}
// ****************************************************************************
// Method: avtPythonFilterEnvironment::Shutdown
//
// Purpose:
// Cleanup python filter environment.
//
// Programmer: Cyrus Harrison
// Creation: Tue Feb 2 13:14:44 PST 2010
//
// ****************************************************************************
void
avtPythonFilterEnvironment::Shutdown()
{
if(pyFilter)
delete pyFilter; // calls decref
pyi->Shutdown();
}
// ****************************************************************************
// Method: avtPythonFilterEnvironment::WrapVTKObject
//
......@@ -245,7 +239,7 @@ avtPythonFilterEnvironment::WrapVTKObject(void *obj,
// vtk constructor needs a string of the objects address.
oss << (void *) obj;
// remove 0x from front of string
if (oss.str().substr(0, 2) == "0x")
addy_str = oss.str().substr(2);
else
......
......@@ -55,6 +55,11 @@
// Programmer: Cyrus Harrison
// Creation: Tue Feb 2 13:14:44 PST 2010
//
// Modifications:
// Cyrus Harrison, Fri Jul 9 10:31:03 PDT 2010
// Use a singleton instance of the interpreter b/c python setup & teardown
// does not work reliably w/ c modules that use static vars.
//
// ****************************************************************************
class AVTPYTHON_FILTERS_API avtPythonFilterEnvironment
{
......@@ -65,7 +70,6 @@ public:
bool Initialize();
bool LoadFilter(const std::string &py_script);
bool FetchPythonError(std::string &msg_out);
void Shutdown();
PyObject *WrapVTKObject(void *obj,
const std::string &obj_type);
......@@ -77,8 +81,8 @@ public:
avtPythonFilter *Filter() { return pyFilter;}
private:
PythonInterpreter *pyi;
avtPythonFilter *pyFilter;
static PythonInterpreter *pyi;
avtPythonFilter *pyFilter;
};
......
......@@ -227,7 +227,7 @@ Buffer::Init(int buffer_size)
/*****************************************************************************
* Function: Buffer::Init
*
* Purpose:
* Purpose:
* Inits buffer to given type and size.
*
* Programmer: Cyrus Harrison
......@@ -268,6 +268,9 @@ Buffer::Init(int type_id, int data_size)
* Creation: Wed Jan 7 10:05:02 PST 2009
*
* Modifications:
* Cyrus Harrison, Fri Jul 9 10:31:03 PDT 2010
* Use pickle to encode empty python sequences & use faster
* PyObject_CallFunctionObjArgs() instead of PyObject_CallFunction().
*
* ***************************************************************************/
void
......@@ -301,6 +304,10 @@ Buffer::Init(PyObject *py_obj)
PyObject *py_seq = PySequence_Fast(py_obj,"Expected Sequence");
int length = PySequence_Size(py_seq);
// if we have an empty sequence let pickle take care of it.
if(length == 0)
pickle=true;
// check for list type all numeric entries
for(int i=0; i < length && !pickle; i++)
{
......@@ -315,7 +322,6 @@ Buffer::Init(PyObject *py_obj)
double *ptr = DataAsDoublePtr();
for(int i=0; i < length; i++)
{
// TODO
PyObject *py_itm = PySequence_Fast_GET_ITEM(py_seq,i); // borrowed
PyObject *py_val = PyNumber_Float(py_itm);
ptr[i] = PyFloat_AS_DOUBLE(py_val);
......@@ -329,8 +335,11 @@ Buffer::Init(PyObject *py_obj)
if(pickle)
{
PyObject *res=PyObject_CallFunction(pickleDumps, (char*)"O", py_obj);
// TODO
PyObject *res = PyObject_CallFunctionObjArgs(pickleDumps,py_obj,NULL);
// This case should't occur, but print an error msg just in case.
if(res == NULL || PyErr_Occurred())
PyErr_Print();
Init(res);
// Init will set the type to string - override it to identify as
// and object.
......@@ -410,6 +419,9 @@ Buffer::MPIType()
* Creation: Wed Jan 7 10:05:02 PST 2009
*
* Modifications:
* Cyrus Harrison, Fri Jul 9 10:31:03 PDT 2010
* Use faster PyObject_CallFunctionObjArgs() instead of
* PyObject_CallFunction().
*
* ***************************************************************************/
PyObject *
......@@ -450,7 +462,10 @@ Buffer::ToPyObject()
PyObject *py_str = PyString_FromStringAndSize(ptr,data_size-1);
if(type_id == STRING)
return py_str;
PyObject *res=PyObject_CallFunction(pickleLoads, (char*)"O", py_str);
PyObject *res=PyObject_CallFunctionObjArgs(pickleLoads,py_str,NULL);
// This case should't occur, but print an error msg just in case.
if(res == NULL || PyErr_Occurred())
PyErr_Print();
Py_DECREF(py_str);
return res;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment