[omniORB] Widening of _var types

Chris Newbold cnewbold at laurelnetworks.com
Wed Mar 2 17:33:19 GMT 2005


There seems to be a bug in the omniORB C++ mapping for _var, _member and
_element types that permits widening where the specification indicates a
compile-time error should be generated. The result is incorrect memory
management, with two _var objects calling CORBA::release() on the same
object.

The lines commented with "// error" in the example C++ code below
compile because the right-hand argument is converted to a pointer type
(via the user-defined conversion for _var, _member and _element types)
which is then implicitly widened to satisfy the T* assignment operator
or constructor for the target _var.

        // IDL
        interface B
        {
        ...
        };
        
        interface D : B
        {
        ...
        };
        
        struct S
        {
          B the_b;
        };
        
	// C++
        void f()
        {
             B_var bv;
             D_var dv;
        
             B_var bvl(dv);		// error
             bv = dv;			// error
        
             S s;
             s.the_b = dv;		// error
        }
        
After pondering the definitions of _CORBA_ObjRef_Var, etc. I found no
easy way to break these constructs without introducing other problems.
I've included the diff (against omniORB 4.0.3) of a fix we're going to
use locally which relies on member templates. While this works for us
since we use gcc 3.4.x exclusively, this is presumably not an acceptable
general fix.

Anyone else have some clever ideas?

-Chris


*** /u/lni/i686-pc-linux-gnu/CORBA/omniORB_4.0.3.9/include/i686-pc-linux-gnu/omniORB4/templatedecls.h   Wed Nov 12 15:54:55 2003
--- /u/lni/i686-pc-linux-gnu/CORBA/omniORB_4.0.3.10/include/i686-pc-linux-gnu/omniORB4/templatedecls.h  Tue Mar  1 08:53:22 2005
***************
*** 435,440 ****
--- 435,459 ----
    friend class _CORBA_ObjRef_tcDesc_arg<T,T_Helper>;

  private:
+
+   template<typename U, typename U_Helper>
+   _CORBA_ObjRef_Var(const _CORBA_ObjRef_Var<U, U_Helper>&);
+
+   template<typename U, typename U_Helper>
+   _CORBA_ObjRef_Var(const _CORBA_ObjRef_Member<U, U_Helper>&);
+
+   template<typename U, typename U_Helper>
+   _CORBA_ObjRef_Var(const _CORBA_ObjRef_Element<U, U_Helper>&);
+
+   template<typename U, typename U_Helper>
+   T_var& operator=(const _CORBA_ObjRef_Var<U, U_Helper>&);
+
+   template<typename U, typename U_Helper>
+   T_var& operator=(const _CORBA_ObjRef_Member<U, U_Helper>&);
+
+   template<typename U, typename U_Helper>
+   T_var& operator=(const _CORBA_ObjRef_Element<U, U_Helper>&);
+
    T_ptr pd_objref;
  };

***************
*** 523,528 ****
--- 542,556 ----
    }

    T_ptr          _ptr;
+ private:
+   template<typename U, typename U_Helper>
+   T_member& operator=(const _CORBA_ObjRef_Var<U, U_Helper>&);
+
+   template<typename U, typename U_Helper>
+   T_member& operator=(const _CORBA_ObjRef_Member<U, U_Helper>&);
+
+   template<typename U, typename U_Helper>
+   T_member& operator=(const _CORBA_ObjRef_Element<U, U_Helper>&);
  };

  //////////////////////////////////////////////////////////////////////
***************
*** 612,617 ****
--- 640,654 ----

    _CORBA_Boolean pd_rel;
    T_ptr&         pd_data;
+ private:
+   template<typename U, typename U_Helper>
+   T_element& operator=(const _CORBA_ObjRef_Var<U, U_Helper>&);
+
+   template<typename U, typename U_Helper>
+   T_element& operator=(const _CORBA_ObjRef_Member<U, U_Helper>&);
+
+   template<typename U, typename U_Helper>
+   T_element& operator=(const _CORBA_ObjRef_Element<U, U_Helper>&);
  };

  //////////////////////////////////////////////////////////////////////





More information about the omniORB-list mailing list