Skip to content

Commit

Permalink
try to make save/restore 64 bits work for 64b bits BigEndian machines.
Browse files Browse the repository at this point in the history
modified test_save_restore to get more coverage
  • Loading branch information
GillesDuvert committed Nov 11, 2023
1 parent d248356 commit f72029f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
50 changes: 33 additions & 17 deletions src/saverestore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,13 @@ bool_t xdr_set_gdl_pos(XDR *x, long int y){
uint32_t first,second;
first = ((uint32_t *) &next)[0];
second = ((uint32_t *) &next)[1];
xdr_uint32_t(xdrs, &first);
xdr_uint32_t(xdrs, &second);
if (BigEndian()) { //swap: we write in LittleEndian
xdr_uint32_t(xdrs, &second);
xdr_uint32_t(xdrs, &first);

Check warning on line 191 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L190-L191

Added lines #L190 - L191 were not covered by tests
} else {
xdr_uint32_t(xdrs, &first);
xdr_uint32_t(xdrs, &second);
}
xdr_set_gdl_pos(xdrs, next);
return next;
}
Expand Down Expand Up @@ -1601,7 +1606,7 @@ bool_t xdr_set_gdl_pos(XDR *x, long int y){
//will start at TMESTAMP
uint64_t currentptr = 0;
uint64_t nextptr = LONG;
uint32_t ptrs0, ptrs1;
uint32_t ptr_low, ptr_high;
int32_t rectype;
int32_t UnknownLong;
bool SomethingFussyHappened = true;
Expand Down Expand Up @@ -1629,12 +1634,18 @@ bool_t xdr_set_gdl_pos(XDR *x, long int y){
if (!xdr_int32_t(xdrs, &UnknownLong)) break;
if (!xdr_int32_t(xdrs, &UnknownLong)) break;
} else //the 2 pointers may point together to a l64 address, bug #1545
{
if (!xdr_uint32_t(xdrs, &ptrs0)) break;
nextptr = ptrs0;
if (!xdr_uint32_t(xdrs, &ptrs1)) break;
DULong64 tmp = ptrs1;
nextptr |= (tmp << 32);
{ //we read LittleEndian format
if (!xdr_uint32_t(xdrs, &ptr_low)) break;
if (!xdr_uint32_t(xdrs, &ptr_high)) break;
if (BigEndian()) { //swap & merge
nextptr = ptr_high;
uint64_t tmp = ptr_low;
nextptr |= (tmp << 32);

Check warning on line 1643 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L1641-L1643

Added lines #L1641 - L1643 were not covered by tests
} else { //merge
nextptr = ptr_low;
uint64_t tmp = ptr_high;
nextptr |= (tmp << 32);
}
if (!xdr_int32_t(xdrs, &UnknownLong)) break;
if (nextptr <=LONG) e->Throw("error in pointers, please report.");
}
Expand Down Expand Up @@ -1808,14 +1819,19 @@ bool_t xdr_set_gdl_pos(XDR *x, long int y){
nextptr = my_ulong64;
if (!xdr_int32_t(xdrs, &UnknownLong)) break;
if (!xdr_int32_t(xdrs, &UnknownLong)) break;
} else
{
if (!xdr_uint32_t(xdrs, &ptrs0)) break;
nextptr = ptrs0;
if (!xdr_uint32_t(xdrs, &ptrs1)) break;
DULong64 tmp = ptrs1;
nextptr |= (tmp << 32);
if (!xdr_int32_t(xdrs, &UnknownLong)) break;
} else {//we read LittleEndian format
if (!xdr_uint32_t(xdrs, &ptr_low)) break;
if (!xdr_uint32_t(xdrs, &ptr_high)) break;
if (BigEndian()) { //swap & merge
nextptr = ptr_high;
uint64_t tmp = ptr_low;
nextptr |= (tmp << 32);

Check warning on line 1828 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L1826-L1828

Added lines #L1826 - L1828 were not covered by tests
} else { //merge
nextptr = ptr_low;
uint64_t tmp = ptr_high;
nextptr |= (tmp << 32);
}
if (!xdr_int32_t(xdrs, &UnknownLong)) break;
}

//dispatch accordingly:
Expand Down
11 changes: 9 additions & 2 deletions testsuite/test_save_restore.pro
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,15 @@ for ii=0,N_ELEMENTS(list_numeric_names)-1 do begin
ok2=EXECUTE(type_name+'_s_a2d=INDGEN(dim2, type=type_value)')
if KEYWORD_SET(test) then print, type_name, ok0, ok1, ok2
endfor
;
SAVE, file=file, compress=compress, dim1, dim2, $
; This just to manage all options, and augment the coverage of our functions by the coverage programs.
; Does not test the accuracy of what is saved with the following options: /COMM /SYSTEM
common test_saverestore,toto,tata
toto=10
tata=!X

;
SAVE, file=file, /COMM, /SYSTEM, DESCRIPTION="made by test_save_restore", $
compress=compress, dim1, dim2, $
byte_s, byte_s_a1d, byte_s_a2d, $
int_s, int_s_a1d, int_s_a2d, $
long_s, long_s_a1d, long_s_a2d, $
Expand Down

0 comments on commit f72029f

Please sign in to comment.