Ticket #133 (closed defect: fixed)

Opened 11 months ago

Last modified 8 months ago

FreeBSD endian.hpp

Reported by: nrv2 Owned by: mloskot
Priority: minor Milestone: 1.2.1
Component: Base Library Version: 1.2
Keywords: endian Cc: cc
LAS Format Version: Not Applicable

Description (last modified by mloskot) (diff)

Hi, Thanks for providing such a great library. I have no complaints, but I have one little glitch that showed up for me... When building liblas on two FreeBSD systems, one i386, and one amd64, I ended up with a library that reads/writes in big-endian. After some investigation, the file include/liblas/detail/endian.hpp has the following lines appear after the initial test to see if GLIBC is defined (which it is not for me):

...
#elif defined(_BIG_ENDIAN)
# define LIBLAS_BIG_ENDIAN
# define LIBLAS_BYTE_ORDER 4321
#elif defined(_LITTLE_ENDIAN)
# define LIBLAS_LITTLE_ENDIAN
# define LIBLAS_BYTE_ORDER 1234
... 

However, on my system both _BIG_ENDIAN and _LITTLE_ENDIAN are defined, as 4321 and 1234 respectively. So the first test for _BIG_ENDIAN wins, and this results in LIBLAS_BIG_ENDIAN being defined and a big-endian reader/writer. All is well if I comment out these six lines. In the header, the following tests for architecture definitions work correctly for both my systems. I did not get to try it on any other systems/OSes.

This was a pretty simple fix, and I already sent patches to the FreeBSD port maintainer for liblas. So if that code is necessary for other OS types, no change is needed. However, it would be great if no changes were needed to build on FreeBSD in the future.

I'm attaching my slightly modified endian.hpp in case the description above is not clear.

Thanks, Nick

Attachments

endian.hpp.mod Download (4.2 KB) - added by nrv2 11 months ago.
Modified endian.hpp to allow proper build on FreeBSD
endian_hpp-ticket-133.patch Download (0.7 KB) - added by mloskot 11 months ago.
Nick's fix in form of patch generated against r1246

Change History

Changed 11 months ago by nrv2

Modified endian.hpp to allow proper build on FreeBSD

  Changed 11 months ago by hobu

  • cc cc added
  • owner changed from hobu to mloskot
  • component changed from Build System to Base Library
  • milestone set to 1.2.1

Thanks for the report. This one is Mateusz' :)

Changed 11 months ago by mloskot

Nick's fix in form of patch generated against r1246

follow-up: ↓ 3   Changed 11 months ago by mloskot

  • status changed from new to assigned
  • description modified (diff)

Nick,

Thanks for the patch, however I can not accept it because I'm not sure what it fixes actually. It just comments out important checks, is that right?

AFAIU, on FreeBSD (on your machine) there is 3rd situation possible which is currently not handled by libLAS, it is both _BIG_ENDIAN and _LITTLE_ENDIAN macros are defined. Am I correct?

If it is correct, then I'd suggest to fix according to this scheme - 3 cases:

#if defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN) // FreeBSD + Nick's machine
... // What to set? Nothing?
#else
# if defined(_BIG_ENDIAN)      // Big endian only
#  define LIBLAS_BIG_ENDIAN
#  define LIBLAS_BYTE_ORDER 4321
# elif defined(_LITTLE_ENDIAN) // Little endian only
#  define LIBLAS_LITTLE_ENDIAN
#  define LIBLAS_BYTE_ORDER 1234
# endif
#endif

in reply to: ↑ 2   Changed 8 months ago by nrv2

Sorry for the time delay, I did not realize there was another post. You understand the situation correctly. Both _BIG_ENDIAN and _LITTLE_ENDIAN macros are defined. Not sure what happens on a big endian system running FreeBSD, but your suggestion in the last post would work fine on my machines.

  Changed 8 months ago by hobu

  • status changed from assigned to closed
  • resolution set to fixed

I have attempted to fix this by testing for the case where both _BIG_ENDIAN and _LITTLE_ENDIAN are defined and just assuming LITTLE.

r1323 and r1324

Note: See TracTickets for help on using tickets.