Issue 125: Passing of object reference in pointers (cxx_revision) Source: (, ) Nature: Uncategorized Severity: Summary: Summary: Suggest changing the mapping so that object references for an interface "T" are passed as "const T_ptr&" instead of just "T_ptr" for "in" parameters. Resolution: Close no change. This change is too intrusive and would break too much existing code. Revised Text: Actions taken: September 23, 1996: Received issue June 13, 2000: closed issue Discussion: End of Annotations:===== >From mml@mml.tiac.net Thu Sep 19 14:09:40 1996 Received: from mml.tiac.net by amethyst.omg.org.omg.org (5.4R2.01/1.34) id AA01130; Thu, 19 Sep 1996 14:09:40 -0400 Received: (from mml@localhost) by mml.tiac.net (8.6.12/8.6.9) id CAA00734 for cxx_revision@omg.org; Thu, 19 Sep 1996 02:11:20 -0400 From: Marc Laukien Message-Id: <199609190611.CAA00734@mml.tiac.net> Subject: passing of object reference in parameters To: cxx_revision@omg.org Date: Thu, 19 Sep 1996 02:11:19 -0400 (EDT) X-Mailer: ELM [version 2.4 PL24] Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Length: 1473 I'd like to suggest to change the IDL-to-C++ mapping, so that object references for an interface "T" are passed as "const T_ptr&" instead of just "T_ptr" for "in" parameters. Consider the following example: // IDL interface T; interface Intf { void op(in string str, in T obj); }; In this example, "Intf" is implemented by a class "Intf_impl". "Intf_impl" has a "String_var" and a "T_var" data member. The "op" function sets these data members: // C++ class Intf_impl : public Intf_skel { String_var str_; Intf_var obj_; public: virtual void op(const char* str, Intf_ptr obj) { str_ = str; obj_ = Intf::_duplicate(obj); } }; The assignments in the function "op" an unsymmetrically, i.e. for the string "str" it is not required to use "string_dup()", but for "obj" the "_duplicate()" functions must be used. If "obj" was passed as "const Intf_ptr&", it would be possible to overload the assignment operator (and also the constructor) of "Intf_var", so that assignment from "const Intf_ptr&" to "Intf_var" would automatically call "_duplicate()": // C++ class Intf_impl : public Intf_skel { String_var str_; Intf_var obj_; public: virtual void op(const char* str, const Intf_ptr& obj) { str_ = str; obj_ = obj; } }; Please note that this change to the mapping can be done compatible since assignment as "obj_ = Intf::_duplicate(obj)" would still be valid. Best regards, Marc Laukien Object-Oriented Concepts, Inc. >From linton@vitria.com Fri Sep 20 13:44:46 1996 Received: from gorgon.vitria.com by amethyst.omg.org.omg.org (5.4R2.01/1.34) id AA12388; Fri, 20 Sep 1996 13:44:46 -0400 Received: from hydra.vitria.com (hydra.vitria.com [10.206.138.5]) by vitria.com (8.7.4/8.7.3) with ESMTP id KAA16923; Fri, 20 Sep 1996 10:41:36 -0700 (PDT) Received: from glider (glider.vitria.com [10.206.138.16]) by hydra.vitria.com (8.7.4/8.7.3) with SMTP id KAA26863; Fri, 20 Sep 1996 10:41:25 -0700 (PDT) Message-Id: <1.5.4.32.19960920174239.00b10a4c@hydra.vitria.com> X-Sender: linton@hydra.vitria.com X-Mailer: Windows Eudora Light Version 1.5.4 (32) Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Fri, 20 Sep 1996 10:42:39 -0700 To: Marc Laukien From: Mark Linton Subject: Re: passing of object reference in parameters Cc: cxx_revision@omg.org At 02:11 AM 9/19/96 -0400, Marc Laukien wrote: >I'd like to suggest to change the IDL-to-C++ mapping, so that object >references for an interface "T" are passed as "const T_ptr&" instead >of just "T_ptr" for "in" parameters. Consider the following example: The mapping already allows in objrefs to be passed as const T_ptr&. There is no difference as far as usage is concerned. Keep in mind that a legimate implementation of T_ptr is as a typedef to T*. >// IDL >interface T; >interface Intf >{ > void op(in string str, in T obj); >}; > >In this example, "Intf" is implemented by a class "Intf_impl". >"Intf_impl" has a "String_var" and a "T_var" data member. The "op" >function sets these data members: > >// C++ >class Intf_impl : public Intf_skel >{ > String_var str_; > Intf_var obj_; > >public: > > virtual void op(const char* str, Intf_ptr obj) > { > str_ = str; > obj_ = Intf::_duplicate(obj); > } >}; The difference is a quirk of const char* vs. char* for String_var. Since we don't have const objrefs, we can't do the same thing for objref var types. Note that if you explictly copy the string parameter above, the behavior will be identical. So rather than try to make these look the same by eliminating the objref duplicate, you should explictly duplicate the string. >If "obj" was passed as "const Intf_ptr&", it would be possible to >overload the assignment operator (and also the constructor) of >"Intf_var", so that assignment from "const Intf_ptr&" to "Intf_var" >would automatically call "_duplicate()": No, this is not true. The code below uses the same assignment operator: void f(const Intf_ptr& p1, Intf_ptr p2) { Intf_var v1, v2; v1 = p1; v2 = p2; } The reason is that p2 can be passed as a const Intf_ptr&, so a RHS with that type will match both p1 and p2. This would therefore not be a compatible change. >From mml@tiac.net Fri Sep 20 14:54:06 1996 Received: from mail.bruker.com by amethyst.omg.org.omg.org (5.4R2.01/1.34) id AA13345; Fri, 20 Sep 1996 14:54:06 -0400 Received: by gateway.bruker.com id <35759>; Fri, 20 Sep 1996 15:50:04 -0400 Sender: ml@bruker.com Message-Id: <96Sep20.155004edt.35759@gateway.bruker.com> Date: Fri, 20 Sep 1996 14:45:38 -0400 From: Marc Laukien Organization: Object-Oriented Concepts, Inc. X-Mailer: Mozilla 3.0 (X11; I; IRIX 5.3 IP22) Mime-Version: 1.0 To: Mark Linton Cc: cxx_revision@omg.org Subject: Re: passing of object reference in parameters References: <1.5.4.32.19960920174239.00b10a4c@hydra.vitria.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Mark Linton wrote: > > No, this is not true. The code below uses the same assignment > operator: > > void f(const Intf_ptr& p1, Intf_ptr p2) { > Intf_var v1, v2; > v1 = p1; > v2 = p2; > } > > The reason is that p2 can be passed as a const Intf_ptr&, so a RHS > with that > type will match both p1 and p2. This would therefore not be a > compatible > change. You're right, this doesn't work. Overloading T_var::operator=() for T_ptr and const T_ptr& will make an assignment from const T_ptr& to T_var ambigious. However, I still think it would be nice if the T_var type would call _duplicate() automatically if an object reference in parameter is assigned (as it is the case with String_var and string in parameters). Of course, I could always use _duplicate() in my code (and always string_dup()) if I assign to a T_var. But since the call to _duplicate() isn't necessary in most cases, most CORBA users won't use _duplicate() everythere. Consider the following code: // IDL interface T typedef sequence TSeq; typedef T TArray[10]; Assignments between T_var, TSeq[index] and TArray[index] don't need any call to _duplicate(). For object reference return values, _duplicate() may not be called if the return value is assigned to a T_var, so I can't just make a rule like "always use _duplicate() if you assign to a T_var". I think these rules are quite confusing, though I don't know a possibility to change the mapping in a compatible way so that assignment to a T_var never needs a call to _duplicate(). >From linton@vitria.com Fri Sep 20 15:48:20 1996 Received: from gorgon.vitria.com by amethyst.omg.org.omg.org (5.4R2.01/1.34) id AA13899; Fri, 20 Sep 1996 15:48:20 -0400 Received: from hydra.vitria.com (hydra.vitria.com [10.206.138.5]) by vitria.com (8.7.4/8.7.3) with ESMTP id MAA17419 for ; Fri, 20 Sep 1996 12:45:06 -0700 (PDT) Received: from glider (glider.vitria.com [10.206.138.16]) by hydra.vitria.com (8.7.4/8.7.3) with SMTP id MAA27429 for ; Fri, 20 Sep 1996 12:45:04 -0700 (PDT) Message-Id: <1.5.4.32.19960920194607.00b55bb4@hydra.vitria.com> X-Sender: linton@hydra.vitria.com X-Mailer: Windows Eudora Light Version 1.5.4 (32) Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Fri, 20 Sep 1996 12:46:07 -0700 To: cxx_revision@omg.org From: Mark Linton Subject: Re: passing of object reference in parameters At 02:45 PM 9/20/96 -0400, Marc Laukien wrote: >However, I still think it would be nice if the T_var type would call >_duplicate() automatically if an object reference in parameter is >assigned. The only way to do this is to have T in parameters be a different type from T_ptr. Otherwise, return values would leak when assigned to a T_var. I got booed when I originally proposed that in parameters, return values, etc. all be different types, but that is really the only way to make these kind of fine-grain distinctions. The problem with introducing such fine-grain distinctions is that the mapping appears more complicated as a result. >From geoff Mon Sep 23 11:59:47 1996 Received: by amethyst.omg.org.omg.org (5.4R2.01/1.34) id AA05789; Mon, 23 Sep 1996 11:59:47 -0400 Date: Mon, 23 Sep 1996 11:59:47 -0400 From: geoff (Geoffrey Speare) Message-Id: <9609231559.AA05789@amethyst.omg.org.omg.org> To: mml@mml.tiac.net Cc: cxx_revision@omg.org, issues In-Reply-To: Marc Laukien's message of Thu, 19 Sep 1996 02:11:19 -0400 (EDT) <199609190611.CAA00734@mml.tiac.net> Subject: passing of object reference in parameters This is issue 125. > I'd like to suggest to change the IDL-to-C++ mapping, so that object > references for an interface "T" are passed as "const T_ptr&" instead > of just "T_ptr" for "in" parameters. Consider the following example: > // IDL > interface T; > interface Intf > { > void op(in string str, in T obj); > }; > In this example, "Intf" is implemented by a class "Intf_impl". > "Intf_impl" has a "String_var" and a "T_var" data member. The "op" > function sets these data members: > // C++ > class Intf_impl : public Intf_skel > { > String_var str_; > Intf_var obj_; > public: > virtual void op(const char* str, Intf_ptr obj) > { > str_ = str; > obj_ = Intf::_duplicate(obj); > } > }; > The assignments in the function "op" an unsymmetrically, i.e. for the > string "str" it is not required to use "string_dup()", but for "obj" > the "_duplicate()" functions must be used. > If "obj" was passed as "const Intf_ptr&", it would be possible to > overload the assignment operator (and also the constructor) of > "Intf_var", so that assignment from "const Intf_ptr&" to > "Intf_var" > would automatically call "_duplicate()": > // C++ > class Intf_impl : public Intf_skel > { > String_var str_; > Intf_var obj_; > public: > virtual void op(const char* str, const Intf_ptr& obj) > { > str_ = str; > obj_ = obj; > } > }; > Please note that this change to the mapping can be done compatible > since assignment as "obj_ = Intf::_duplicate(obj)" would still be > valid. > Best regards, > Marc Laukien > Object-Oriented Concepts, Inc. Geoff Speare OMG geoff@omg.org