[omniORB] access to CDR encapsulations from python (patch)

Ted Horst Ted.Horst@wdr.com
Fri, 18 Feb 2000 14:55:04 -0600


Here is my first take at providing access to CDR encapsulations from =
python.  Usage is thus:


<smaller>import MyIDLModule

foo =3D MyIDLModule.MyIDLStructClass(....)

encap =3D _omnipy.marshal(foo, MyIDLModule._d_MyIDLStructClass)


foo2 =3D _omnipy.unmarshal(encap, MyIDLModule._d_MyIDLStructClass)


The resulting string (encap here) is a CDR encapsulation which means that =
it can be unencoded on a different platform, in a different language =
provided that you have access to the IDL definitions for that language.


Unmarshal seems to be leaking pretty badly at the moment.  I would =
appreciate any pointers in helping to track that down.


I would also appreciate any feedback on the interface.  This particular =
choice was driven by the desire to as little change as possible to the =
underlying C++ code.  If there is a more elegant or useful way to present =
this functionality, I would be happy to make it better.




</smaller>*** omni/src/lib/omniORBpy/modules/omnipy/omnipy.cc.orig        =
Wed Feb 16 17:09:39 2000

--- omni/src/lib/omniORBpy/modules/omnipy/omnipy.cc     Fri Feb 18 =
11:54:06 2000

***************

*** 987,992 ****

--- 987,1025 ----

   =20

 =20

 =20

+   static PyObject*

+   omnipy_marshal(PyObject* self, PyObject* args)

+  =20

+     PyObject *inst, *type;

+     MemBufferedStream mstream;

+=20

+     if (!PyArg_ParseTuple(args, (char*)"OO", &inst, &type))

+       return NULL;

+=20

+     mstream.byteOrder() >>=3D mstream;

+     omniPy::marshalPyObject(mstream, type, inst);

+     return PyString_FromStringAndSize((char *)mstream.data(), =
mstream.alreadyWritten());

+  =20

+=20

+=20

+   static PyObject*

+   omnipy_unmarshal(PyObject* self, PyObject* args)

+  =20

+     PyObject *type;

+     const unsigned char *cstream;

+     int len;

+     MemBufferedStream mstream;

+     _CORBA_Char bo;

+=20

+     if (!PyArg_ParseTuple(args, (char*)"s#O", &cstream, &len, &type))

+       return NULL;

+=20

+     mstream.put_char_array(cstream, len);

+     bo <<<<=3D mstream;

+     mstream.byteOrder(bo);

+     return omniPy::unmarshalPyObject(mstream, type);

+  =20

+=20

    =
////////////////////////////////////////////////////////////////////////////=


    // Python method table                                                 =
   //

    =
////////////////////////////////////////////////////////////////////////////=


***************

*** 1025,1030 ****

--- 1058,1067 ----

      (char*)"isEquivalent",      omnipy_isEquivalent,            =
METH_VARARGS,

      (char*)"hash",              omnipy_hash,                    =
METH_VARARGS,

      (char*)"narrow",            omnipy_narrow,                  =
METH_VARARGS,

+=20

+     // Wrappers for marshalling, unmarshalling

+     (char*)"marshal",           omnipy_marshal,                 =
METH_VARARGS,

+     (char*)"unmarshal",         omnipy_unmarshal,               =
METH_VARARGS,

      NULL,NULL

    ;


-----------------------------

Ted Horst <<Ted.Horst@wdr.com>

"the day serious reasoning about programs becomes widespread is the day

most programmers abandon their craft to resume drug trafficking <<wink>."

--Tim Peters on comp.lang.python