[omniORB] object reference widening to a member

Zsolt Rizsanyi rizsanyi at myrealbox.com
Fri Mar 26 09:10:32 GMT 2004


Hi!

I had a nasty bug because I was implicitly widening an _var object 
reference to an Object_member of the of a CORBA struct.

After reading up in the C++ language mapping specification, I have found 
that a compile time error should be generated on an attempt to implicitly 
widen an _var reference to Object_var.

Here is the relevant section from the spec:
---------------------------------
1.3.2 Widening object references
[...]
Implicit widening from a B_var to A_var or Object_var is not supported; 
instead, widening between _var types for object references requires a call 
to _duplicate (described in Section 1.3.3, "Object Reference Operations," 
on page 1-8).1 An attempt to implicitly widen from one _var type to 
another must cause a compile-time error.2 Assignment between two _var 
objects of the same type is supported, but widening assignments are not 
and must cause a compile-time error. Widening assignments may be done 
using _duplicate. The same rules apply for object reference types that are 
nested in a complex type, such as a structure or sequence.
---------------------------------

I have written a small test case:

---------- Interface:
interface Echo
{
    string echoString(in string val);
};
struct ObjRefStruct
{
  Object obj;
  Echo echoObj;
};

---------------- code:
Echo_var echoVar = ....
ObjRefStruct ors;
ors.obj = echoVar;

In my understanding the ors.obj = echoVar assignment should generate a 
compile time error.
Am I mistaken? Or is this issue already known?

omniORB already works correctly when trying to widen to Object_var.
Object_var ov = echoVar;
correctly generates a compile time error.

I have seen mentioning widening in the omniORB mailing list archives only 
in 3 threads, but neither came to a conclusion.

Just to clear it up: In the above case both the echoVar and the ors.obj try 
to release the same reference when destroyed because first echoVar is 
converted to an Echo_ptr and then assigned to ors.obj which assumes 
ownership for the _ptr.
So the end result is an assert in Object::release.
The correct assignment would read:
ors.obj = Echo::_duplicate(echoVar);
The only problem is that omniORB should produce a compile time error on the 
'ors.obj = echoVar' assignment.

Thanks
Zsolt




More information about the omniORB-list mailing list