CPP 1.3 NO IDEA Avatar
  1. OMG Issue

CPP13 — Object Reference insertion/extration to Any

  • Key: CPP13-30
  • Legacy Issue Number: 3248
  • Status: open  
  • Source: Cisco Systems ( Paul Kyzivat)
  • Summary:

    I believe the specification for insertion of object references to Anys is
    somewhat ambiguous. And, if it is intended to be as I think, it may also be
    less than ideal.

    Consider the following idl:

    interface B

    interface D : B {...}


    And then consider the following code:

    D_ptr d; // initialize this to non-null value somehow
    B_ptr b = B::_narrow(d);
    Any ab;
    ab <<= b;
    Any ad;
    ad <<= d;
    // ...
    B_ptr b_val;
    if (ab>>=b_val)

    { /* do stuff with b_val */ }; // 1
    if (ad>>=b_val) { /* do stuff with b_val */ }

    ; // 2
    D_ptr d_val;
    if (ab>>=d_val)

    { /* do stuff with d_val */ }; // 3
    if (ad>>=d_val) { /* do stuff with d_val */ }

    ; // 4

    >From what I can see of the spec, it is a bit unclear about whether then
    insertion of an object should use the static type or the dynamic type of the
    object to initialize the typecode. Simplicity and consistency with other
    related operations suggests that it should use the static type. That is what
    we currently do, and a quick test of ORBIX 2000 seems to tell me it does it
    that way too.

    With that interpretation, 1&4 will work, while 2&3 will fail.
    Nobody should be surprised that 3 fails, but it is inconvenient
    that 2 doesn't work.

    If insertion used the dynamic type of its argument, then 1&2
    would work, while 3&4 would fail.

    To get reasonable behavior when derived types might be present,
    (and how often can you be certain they cannot?)
    it seems that one should almost never use type specific object
    extraction. Instead, one must do something like:

    Object_var o;
    B_var bv;
    if (ad>>=to_object(o._out()) &&
    !CORBA::is_nil(bv = B::_narrow(o)))

    { // do stuff with bv }


    This is unfortunately a bit inconvenient.

    So, is there any text in the spec that says, when inserting an object
    reference type into an any, if the repository id in the typecode should be
    the static type of the inserted argument or the dynamic type of the value of
    the argument?

    If not, I think we need to add some text.

  • Reported: CPP 1.1 — Thu, 27 Jan 2000 05:00 GMT
  • Updated: Fri, 6 Mar 2015 20:57 GMT