[omniORB] omniorbpy patch for new style python objects

Alastair Tse acnt2 at cam.ac.uk
Wed Dec 14 11:55:00 GMT 2005


Hi,

I posted this a couple months back but didn't get a response, so I'm  
reposting it again so at least I get a comment on why it might not be  
suitable for inclusion in the tree.

Since Python 2.3, the threading.Thread class in python (and many  
others) are new style objects. That means the inherit from the  
"object" class rather than no class at all.

The new style objects have a different style of attribute access  
under the C-API, and therefore, if you attempted to subclass anything  
from a new style object, either from the Python Library or your own  
classes, omniORB would not recognise it as a CORBA object and thus  
throw an error.

So my solution is to use the new say of setting and deleting the  
hidden omniORB reference attribute using PyObject_{Get,Set,Del}Attr  
rather than directly assuming an object has a PyDict in_dict  
attribute. And also a more compatible way of checking if an object  
has the magic variable set that tells omniORB it's a CORBA object.

A demonstration of the problem can be done simply by taking the  
example_echo example in the omniORBpy distribution, compiling the idl  
and changing example_echo_srv.py in this way:

-class Echo_i (Example__POA.Echo):
+class Echo_i (object, Example__POA.Echo):

Try running the server, and you'll get:

Traceback (most recent call last):
   File "example_echo_srv.py", line 25, in ?
     eo = ei._this()
   File "/usr/lib/python2.4/site-packages/omniORB/PortableServer.py",  
line 95, in _this
     return _omnipy.poa_func.servantThis(self)
omniORB.CORBA.BAD_PARAM: Minor: BAD_PARAM_WrongPythonType, COMPLETED_NO.

An example of why you need to do this is when passing an object to a  
server for callback purposes, and that object is a subclass of the  
threading.Thread class.

Here is the URL of the patch:

http://www.cl.cam.ac.uk/~acnt2/files/omniORBpy-2.4-newstyleobjs02.patch

Cheers,

--
Alastair Tse
PhD Student, LCE, Computer Lab, University of Cambridge
[Tel] +44 1223 767 017  [Mob] +44 7795 973639
[Web] http://www.cl.cam.ac.uk/Research/DTG/~acnt2/





More information about the omniORB-list mailing list