Bug or feature?

Sai-Lai Lo S.Lo@orl.co.uk
Thu, 5 Jun 1997 18:35:18 +0100


>>>>> John Connett writes:

> The following IDL file generates a skeleton file which gcc is unwilling
> to compile ...

>     typedef float RtFloat;
>     typedef RtFloat RtColor[3];
>     typedef sequence<RtColor> RtColorSeq;

>     interface Ri {
>       void Dummy(in RtColorSeq colors);
>     };

You've found a bug! The C++ template code for sequences does not handle
array correctly. I'll fix it properly later. 

In the mean time, at the end of this message is a patch to apply to Ri.hh 
that will fix the problem.

Regards,

Sai-Lai


--------- cut here -----------------------

*** Ri.hh	Thu Jun  5 18:20:00 1997
--- Ri.hh.patched Thu Jun  5 18:19:50 1997
***************
*** 21,28 ****
  typedef _CORBA_Array_Var<RtColor_copyHelper,RtColor_slice> RtColor_var;
  typedef _CORBA_Array_Forany<RtColor_copyHelper,RtColor_slice> RtColor_forany;
  
! typedef _CORBA_Unbounded_Sequence<RtColor > RtColorSeq;
  typedef _CORBA_Sequence_Var<RtColorSeq, RtColor > RtColorSeq_var;
  
  #ifndef __Ri__
  #define __Ri__
--- 21,278 ----
  typedef _CORBA_Array_Var<RtColor_copyHelper,RtColor_slice> RtColor_var;
  typedef _CORBA_Array_Forany<RtColor_copyHelper,RtColor_slice> RtColor_forany;
  
! 
! class _CORBA_Sequence<RtColor> {
! public:
!   inline _CORBA_Sequence() : pd_max(0), pd_len(0), pd_rel(1), pd_buf(0) { }
!   inline _CORBA_Sequence(_CORBA_ULong max) :
!              pd_max(max), pd_len(0), pd_rel(1)
!   {
!     if (!(pd_buf = allocbuf(max))) {
!       _CORBA_new_operator_return_null();
!       // never reach here
!     }
!     return;
!   }
! 
!   inline _CORBA_Sequence(_CORBA_ULong max,
! 			 _CORBA_ULong length,
! 			 RtColor           *value,
! 			 _CORBA_Boolean release = 0) 
!       : pd_max(max), 
! 	pd_len(length), 
! 	pd_rel(release),
! 	pd_buf(value)
!   {
!     if (length > max) {
!       _CORBA_bound_check_error();
!       // never reach here
!     }
!     return;
!   }
! 
!   inline _CORBA_Sequence(const _CORBA_Sequence<RtColor>& s)
!               : pd_max(s.pd_max), 
! 		pd_len(s.pd_len),
! 		pd_rel(1)
!   {
!     if (!(pd_buf = allocbuf(s.pd_len))) {
!       _CORBA_new_operator_return_null();
!       // never reach here
!     }
!     for (_CORBA_ULong i=0; i < s.pd_len; i++) {
!       for (unsigned long i2=0; i2 < 3; i2++) {
! 	pd_buf[i][i2] = s.pd_buf[i][i2];
!       }
!     }
!   }
! 
!   inline ~_CORBA_Sequence() {
!     if (pd_rel && pd_buf) freebuf(pd_buf);
!     pd_buf = 0;
!     return;
!   }
!   inline _CORBA_Sequence<RtColor> &operator= (const _CORBA_Sequence<RtColor> &s)
!   {
!     if (pd_max < s.pd_max)
!       {
! 	RtColor *newbuf = allocbuf(s.pd_max);
! 	if (!newbuf) {
! 	  _CORBA_new_operator_return_null();
! 	  // never reach here
! 	}
! 	pd_max = s.pd_max;
! 	if (pd_rel && pd_buf) {
! 	  freebuf(pd_buf);
! 	}
! 	else {
! 	  pd_rel = 1;
! 	}
! 	pd_buf = newbuf;
!       }
!     pd_len = s.pd_len;
!     for (unsigned long i=0; i < pd_len; i++) {
!       for (unsigned long i2=0; i2 < 3; i2++) {
! 	pd_buf[i][i2] = s.pd_buf[i][i2];
!       }
!     }
!     return *this;
!   }
! 
!   inline _CORBA_ULong maximum() const { return pd_max; }
!   inline _CORBA_ULong length() const { return pd_len; }
!   inline void length(_CORBA_ULong length)
!   {
!     if (length > pd_max)
!       {
! 	RtColor *newbuf = allocbuf(length);
! 	if (!newbuf) {
! 	  _CORBA_new_operator_return_null();
! 	  // never reach here
! 	}
! 	for (unsigned long i=0; i < pd_len; i++) {
! 	  for (unsigned long i2=0; i2<3; i2++) {
! 	    newbuf[i][i2] = pd_buf[i][i2];
! 	  }
! 	}
! 	pd_max = length;
! 	if (pd_rel && pd_buf) {
! 	  freebuf(pd_buf);
! 	}
! 	else {
! 	  pd_rel = 1;
! 	}
! 	pd_buf = newbuf;
!       }
!     pd_len = length;
!     return;
!   }
!   inline RtColor &operator[] (_CORBA_ULong index)
!   {
!     if (index >= length()) {
!       _CORBA_bound_check_error();
!     }
!     return pd_buf[index];
!   }
!   inline const RtColor &operator[] (_CORBA_ULong index) const
!   {
!     if (index >= length()) {
!       _CORBA_bound_check_error();
!     }
!     return pd_buf[index];
!   }
!   static inline RtColor* allocbuf(_CORBA_ULong nelems)
!   {
!     return new RtColor[nelems];
!   }
!   static inline void freebuf(RtColor * b)
!   {
!     if (b) delete [] b; 
!     return;
!   }
!   // omniORB2 extensions
!   inline RtColor *NP_data() const { return pd_buf; }
!   inline void operator>>= (NetBufferedStream &s) const;
!   inline void operator<<= (NetBufferedStream &s);
!   inline void operator>>= (MemBufferedStream &s) const;
!   inline void operator<<= (MemBufferedStream &s);
! 
! private:
!   _CORBA_ULong    pd_max;
!   _CORBA_ULong    pd_len;
!   _CORBA_Boolean  pd_rel;
!   RtColor        *pd_buf;
! };
! 
! inline 
! void 
! _CORBA_Sequence<RtColor>::operator>>= (NetBufferedStream &s) const
! {
!   _CORBA_ULong l = length();
!   l >>= s;
!   if (l==0) return;
!   s.put_char_array((_CORBA_Char*)NP_data(),(int)l*4*3);
! }
! 
! inline
! void
! _CORBA_Sequence<RtColor>::operator<<= (NetBufferedStream &s)
! {
!   _CORBA_ULong l;
!   l <<= s;
!   if (l*4*3 > s.RdMessageUnRead()) {
!     _CORBA_marshal_error();
!     // never reach here
!   }
!   length(l);
!   if (l==0) return;
!   s.get_char_array((_CORBA_Char*)NP_data(),(int)l*4*3);
!   if (s.RdMessageByteOrder() != omni::myByteOrder) {
!     for (_CORBA_ULong i=0; i<l*3; i++) {
!       _CORBA_ULong t = ((_CORBA_ULong*)NP_data())[i];
!       ((_CORBA_ULong*)NP_data())[i] = ((((t) & 0xff000000) >> 24) |
! 				       (((t) & 0x00ff0000) >> 8)  |
! 				       (((t) & 0x0000ff00) << 8)  |
! 				       (((t) & 0x000000ff) << 24));
!     }
!   }
! }
! 
! inline
! void 
! _CORBA_Sequence<RtColor>::operator>>= (MemBufferedStream &s) const
! {
!   _CORBA_ULong l = length();
!   l >>= s;
!   if (l==0) return;
!   s.put_char_array((_CORBA_Char*)NP_data(),(int)l*4*3);
! }
! 
! inline
! void 
! _CORBA_Sequence<RtColor>::operator<<= (MemBufferedStream &s)
! {
!   _CORBA_ULong l;
!   l <<= s;
!   if (l*4*3 > s.unRead()) {
!     _CORBA_marshal_error();
!     // never reach here
!   }
!   length(l);
!   if (l==0) return;
!   s.get_char_array((_CORBA_Char*)NP_data(),(int)l*4*3);
!   if (s.byteOrder() != omni::myByteOrder) {
!     for (_CORBA_ULong i=0; i<l*3; i++) {
!       _CORBA_ULong t = ((_CORBA_ULong*)NP_data())[i];
!       ((_CORBA_ULong*)NP_data())[i] = ((((t) & 0xff000000) >> 24) |
! 				       (((t) & 0x00ff0000) >> 8)  |
! 				       (((t) & 0x0000ff00) << 8)  |
! 				       (((t) & 0x000000ff) << 24));
!     }
!   }	
! }
! 
! class _CORBA_Unbounded_Sequence<RtColor> : public _CORBA_Sequence<RtColor> {
! public:
!   inline _CORBA_Unbounded_Sequence() {}
!   inline _CORBA_Unbounded_Sequence(_CORBA_ULong max) : _CORBA_Sequence<RtColor>(max) {}
!   inline _CORBA_Unbounded_Sequence(_CORBA_ULong max,
! 				   _CORBA_ULong length,
! 				   RtColor           *value,
! 				   _CORBA_Boolean release = 0)
!      : _CORBA_Sequence<RtColor>(max,length,value,release) {}
!   inline _CORBA_Unbounded_Sequence(const _CORBA_Unbounded_Sequence<RtColor>& s) 
!      : _CORBA_Sequence<RtColor>(s) {}
!   inline ~_CORBA_Unbounded_Sequence() {}
!   inline _CORBA_Unbounded_Sequence<RtColor> &operator= (const _CORBA_Unbounded_Sequence<RtColor> &s) {
!     _CORBA_Sequence<RtColor>::operator= (s);
!     return *this;
!   }
!   inline size_t NP_alignedSize(size_t initialoffset) const {
!     size_t alignedsize = ((initialoffset+3) & ~((int)3))+sizeof(_CORBA_ULong);
!     if (length()) {
!       alignedsize = ((alignedsize+(3)) & ~(3));
!       alignedsize += length() * 4 * 3;
!     }
!     return alignedsize;
!   }
!   inline void operator>>= (NetBufferedStream &s) const {
!     _CORBA_Sequence<RtColor>::operator>>=(s);
!   }
!   inline void operator<<= (NetBufferedStream &s) {
!       _CORBA_Sequence<RtColor>::operator<<=(s);
!   }
!   inline void operator>>= (MemBufferedStream &s) const {
!     _CORBA_Sequence<RtColor>::operator>>=(s);
!   }
!   inline void operator<<= (MemBufferedStream &s) {
!     _CORBA_Sequence<RtColor>::operator<<=(s);
!   }
! };
! 
! typedef _CORBA_Unbounded_Sequence<RtColor> RtColorSeq;
  typedef _CORBA_Sequence_Var<RtColorSeq, RtColor > RtColorSeq_var;
+ 
  
  #ifndef __Ri__
  #define __Ri__


--------- end ----------------------------