Orber doubles problem unmasked

Luke Gorrie luke@REDACTED
Sun Apr 18 15:44:03 CEST 1999


Hi,

I've had a further look into my problem with Orber not marshalling
doubles.  It turns out that Orber is aligning relative to the end of
the GIOP header, while it should be relative to the beginning of the
octet stream (corba 2.2 spec 13.3.1).  Because the GIOP header is 12
bytes long, this doesn't affect alignments of 2 or 4 octets, which
accounts for the obscurity.

I've included diffs of my changes:
* Fix for alignment in cdr_encode and cdr_decode modules
* Relaxed guards in cdrlib to accept number()s rather than just
  float()s for float and double types (for reasons outlined in my
  previous mail).

Sorry to not send a proper patch file, but I'm a bit pressed for time, 
just my RCS diffs included.

P.S. Could someone please confirm that there is no subtle problem I'm
missing with the guard change?

Cheers,
Luke

*** cdrlib.erl	1999/04/16 09:53:29	1.1
--- cdrlib.erl	1999/04/18 13:17:34
***************
*** 265,271 ****
  %%-----------------------------------------------------------------
  %% Func: enc_float/2
  %%-----------------------------------------------------------------
! enc_float(X, Message) when float(X) ->
      {S, E, F} = enc_ieee(X, ?FLOAT_BASE, ?FLOAT_BIAS),
      [ (S bsl 7) bor ((E bsr 1) band 16#7f),
       ((F bsr 16) band 16#7f) bor ((E band 1) bsl 7),
--- 265,271 ----
  %%-----------------------------------------------------------------
  %% Func: enc_float/2
  %%-----------------------------------------------------------------
! enc_float(X, Message) when number(X) ->
      {S, E, F} = enc_ieee(X, ?FLOAT_BASE, ?FLOAT_BIAS),
      [ (S bsl 7) bor ((E bsr 1) band 16#7f),
       ((F bsr 16) band 16#7f) bor ((E band 1) bsl 7),
***************
*** 275,281 ****
  %%-----------------------------------------------------------------
  %% Func: enc_r_float/2
  %%-----------------------------------------------------------------
! enc_r_float(X, Message) when float(X) ->
      {S, E, F} = enc_ieee(X, ?FLOAT_BASE, ?FLOAT_BIAS),
      [ (F band 16#ff),
       (F bsr 8) band 16#ff,
--- 275,281 ----
  %%-----------------------------------------------------------------
  %% Func: enc_r_float/2
  %%-----------------------------------------------------------------
! enc_r_float(X, Message) when number(X) ->
      {S, E, F} = enc_ieee(X, ?FLOAT_BASE, ?FLOAT_BIAS),
      [ (F band 16#ff),
       (F bsr 8) band 16#ff,
***************
*** 319,325 ****
  %%-----------------------------------------------------------------
  %% Func: enc_double/2
  %%-----------------------------------------------------------------
! enc_double(X, Message) when float(X) ->
      {S, E, F} = enc_ieee(X, ?DOUBLE_BASE, ?DOUBLE_BIAS),
      [ (S bsl 7) bor ((E bsr 4) band 16#7f),
       ((F bsr 48) band 16#0f) bor ((E band 16#f) bsl 4),
--- 319,325 ----
  %%-----------------------------------------------------------------
  %% Func: enc_double/2
  %%-----------------------------------------------------------------
! enc_double(X, Message) when number(X) ->
      {S, E, F} = enc_ieee(X, ?DOUBLE_BASE, ?DOUBLE_BIAS),
      [ (S bsl 7) bor ((E bsr 4) band 16#7f),
       ((F bsr 48) band 16#0f) bor ((E band 16#f) bsl 4),
***************
*** 333,339 ****
  %%-----------------------------------------------------------------
  %% Func: enc_r_double/2
  %%-----------------------------------------------------------------
! enc_r_double(X, Message) when float(X) ->
      {S, E, F} = enc_ieee(X, ?DOUBLE_BASE, ?DOUBLE_BIAS),
      [(F band 16#ff),
       (F bsr 8) band 16#ff,
--- 333,339 ----
  %%-----------------------------------------------------------------
  %% Func: enc_r_double/2
  %%-----------------------------------------------------------------
! enc_r_double(X, Message) when number(X) ->
      {S, E, F} = enc_ieee(X, ?DOUBLE_BASE, ?DOUBLE_BIAS),
      [(F band 16#ff),
       (F bsr 8) band 16#ff,
*** cdr_encode.erl	1999/04/16 10:12:17	1.1
--- cdr_encode.erl	1999/04/18 13:16:47	1.3
***************
*** 584,590 ****
  %% Func: enc_align/1
  %%-----------------------------------------------------------------
  enc_align(R, Len, Alignment) ->
!     Rem = Len rem Alignment,
      if Rem == 0 ->
  	    {R, Len};
         true ->
--- 584,592 ----
  %% Func: enc_align/1
  %%-----------------------------------------------------------------
  enc_align(R, Len, Alignment) ->
!     Rem = (Len + ?GIOP_HEADER_SIZE) rem Alignment,
      if Rem == 0 ->
  	    {R, Len};
         true ->
*** cdr_decode.erl	1999/04/18 13:07:17	1.1
--- cdr_decode.erl	1999/04/18 13:17:08	1.3
***************
*** 885,891 ****
  %%       An aligned byte sequence.
  %%-----------------------------------------------------------------
  dec_align(R, Len, Alignment) ->
!     Rem = Len rem Alignment,
      if Rem == 0 ->
  	    {R, Len};
         true ->
--- 885,893 ----
  %%       An aligned byte sequence.
  %%-----------------------------------------------------------------
  dec_align(R, Len, Alignment) ->
!     Rem = (Len + ?GIOP_HEADER_SIZE) rem Alignment,
      if Rem == 0 ->
  	    {R, Len};
         true ->
*** orber_iiop.hrl	1999/04/18 13:38:52	1.1
--- orber_iiop.hrl	1999/04/18 13:38:58
***************
*** 56,61 ****
--- 56,65 ----
  %% PROFILE_ID's
  -define(TAG_INTERNET_IOP, 0).
  -define(TAG_MULTIPPLE_COMPONENTS, 1).
+ 
+ %% GIOP header size
+ -define(GIOP_HEADER_SIZE, 12).
+ 
  %%----------------------------------------------------------------------
  %% GIOP Message Header
  %% 




More information about the erlang-questions mailing list