[vlc-devel] [PATCH] include: Rename the bswap functions to vlc_bswap

Kamil Rytarowski n54 at gmx.com
Sun Mar 11 21:23:50 CET 2018


Ping!

On 05.03.2018 14:47, Thomas Guillem wrote:
> Fine with me.
> 
> On Mon, Mar 5, 2018, at 14:43, Kamil Rytarowski wrote:
>> The bswap16, bswap32 and bswap64 functions are already present on NetBSD
>> and cannot be redefined in include/vlc_common.h as this causes fatal build
>> errors.
>>
>> Rename these functions to vlc_bswap16, vlc_bswap32 and vlc_bswap64 and
>> keep them as they are without fallback to the NetBSD's libc one. These
>> functions are already small enough and we can bear with them as duplicates
>> on the gain of no extra ifdefs in the vlc_common.h public header.
>> ---
>>  include/vlc_common.h           | 24 ++++++++++++------------
>>  modules/codec/araw.c           | 10 +++++-----
>>  modules/codec/jpeg.c           |  8 ++++----
>>  modules/codec/lpcm.c           |  6 +++---
>>  modules/demux/avformat/demux.c |  2 +-
>>  modules/demux/ogg.c            |  2 +-
>>  6 files changed, 26 insertions(+), 26 deletions(-)
>>
>> diff --git a/include/vlc_common.h b/include/vlc_common.h
>> index d6a5c43b7b..30a8f32b67 100644
>> --- a/include/vlc_common.h
>> +++ b/include/vlc_common.h
>> @@ -754,14 +754,14 @@ VLC_USED static inline int vlc_popcount(unsigned 
>> long long x)
>>  
>>  /** Byte swap (16 bits) */
>>  VLC_USED
>> -static inline uint16_t (bswap16)(uint16_t x)
>> +static inline uint16_t (vlc_bswap16)(uint16_t x)
>>  {
>>      return (x << 8) | (x >> 8);
>>  }
>>  
>>  /** Byte swap (32 bits) */
>>  VLC_USED
>> -static inline uint32_t (bswap32)(uint32_t x)
>> +static inline uint32_t (vlc_bswap32)(uint32_t x)
>>  {
>>  #if defined (__GNUC__) || defined(__clang__)
>>      return __builtin_bswap32 (x);
>> @@ -775,7 +775,7 @@ static inline uint32_t (bswap32)(uint32_t x)
>>  
>>  /** Byte swap (64 bits) */
>>  VLC_USED
>> -static inline uint64_t (bswap64)(uint64_t x)
>> +static inline uint64_t (vlc_bswap64)(uint64_t x)
>>  {
>>  #if defined (__GNUC__) || defined(__clang__)
>>      return __builtin_bswap64 (x);
>> @@ -968,9 +968,9 @@ VLC_API char const * vlc_error( int ) VLC_USED;
>>  # define hton32(i) ((uint32_t)(i))
>>  # define hton64(i) ((uint64_t)(i))
>>  #else
>> -# define hton16(i) bswap16(i)
>> -# define hton32(i) bswap32(i)
>> -# define hton64(i) bswap64(i)
>> +# define hton16(i) vlc_bswap16(i)
>> +# define hton32(i) vlc_bswap32(i)
>> +# define hton64(i) vlc_bswap64(i)
>>  #endif
>>  #define ntoh16(i) hton16(i)
>>  #define ntoh32(i) hton32(i)
>> @@ -1018,7 +1018,7 @@ static inline uint16_t GetWLE (const void *p)
>>  
>>      memcpy (&x, p, sizeof (x));
>>  #ifdef WORDS_BIGENDIAN
>> -    x = bswap16 (x);
>> +    x = vlc_bswap16 (x);
>>  #endif
>>      return x;
>>  }
>> @@ -1031,7 +1031,7 @@ static inline uint32_t GetDWLE (const void *p)
>>  
>>      memcpy (&x, p, sizeof (x));
>>  #ifdef WORDS_BIGENDIAN
>> -    x = bswap32 (x);
>> +    x = vlc_bswap32 (x);
>>  #endif
>>      return x;
>>  }
>> @@ -1044,7 +1044,7 @@ static inline uint64_t GetQWLE (const void *p)
>>  
>>      memcpy (&x, p, sizeof (x));
>>  #ifdef WORDS_BIGENDIAN
>> -    x = bswap64 (x);
>> +    x = vlc_bswap64 (x);
>>  #endif
>>      return x;
>>  }
>> @@ -1074,7 +1074,7 @@ static inline void SetQWBE (void *p, uint64_t qw)
>>  static inline void SetWLE (void *p, uint16_t w)
>>  {
>>  #ifdef WORDS_BIGENDIAN
>> -    w = bswap16 (w);
>> +    w = vlc_bswap16 (w);
>>  #endif
>>      memcpy (p, &w, sizeof (w));
>>  }
>> @@ -1083,7 +1083,7 @@ static inline void SetWLE (void *p, uint16_t w)
>>  static inline void SetDWLE (void *p, uint32_t dw)
>>  {
>>  #ifdef WORDS_BIGENDIAN
>> -    dw = bswap32 (dw);
>> +    dw = vlc_bswap32 (dw);
>>  #endif
>>      memcpy (p, &dw, sizeof (dw));
>>  }
>> @@ -1092,7 +1092,7 @@ static inline void SetDWLE (void *p, uint32_t dw)
>>  static inline void SetQWLE (void *p, uint64_t qw)
>>  {
>>  #ifdef WORDS_BIGENDIAN
>> -    qw = bswap64 (qw);
>> +    qw = vlc_bswap64 (qw);
>>  #endif
>>      memcpy (p, &qw, sizeof (qw));
>>  }
>> diff --git a/modules/codec/araw.c b/modules/codec/araw.c
>> index 0d8145527a..605e4f3822 100644
>> --- a/modules/codec/araw.c
>> +++ b/modules/codec/araw.c
>> @@ -662,7 +662,7 @@ static void U16IEncode( void *outp, const uint8_t 
>> *inp, unsigned samples )
>>      uint16_t *out = outp;
>>  
>>      for( size_t i = 0; i < samples; i++ )
>> -        *(out++) =  bswap16( *(in++) + 0x8000 );
>> +        *(out++) =  vlc_bswap16( *(in++) + 0x8000 );
>>  }
>>  
>>  static void U16NEncode( void *outp, const uint8_t *inp, unsigned 
>> samples )
>> @@ -736,7 +736,7 @@ static void U32IEncode( void *outp, const uint8_t 
>> *inp, unsigned samples )
>>      uint32_t *out = outp;
>>  
>>      for( size_t i = 0; i < samples; i++ )
>> -        *(out++) =  bswap32( *(in++) + 0x80000000 );
>> +        *(out++) =  vlc_bswap32( *(in++) + 0x80000000 );
>>  }
>>  
>>  static void U32NEncode( void *outp, const uint8_t *inp, unsigned 
>> samples )
>> @@ -754,7 +754,7 @@ static void S32IEncode( void *outp, const uint8_t 
>> *inp, unsigned samples )
>>      int32_t *out = outp;
>>  
>>      for( size_t i = 0; i < samples; i++ )
>> -        *(out++) = bswap32( *(in++) );
>> +        *(out++) = vlc_bswap32( *(in++) );
>>  }
>>  
>>  static void F32IEncode( void *outp, const uint8_t *inp, unsigned 
>> samples )
>> @@ -767,7 +767,7 @@ static void F32IEncode( void *outp, const uint8_t 
>> *inp, unsigned samples )
>>          union { float f; uint32_t u; char b[4]; } s;
>>  
>>          s.f = *(in++);
>> -        s.u = bswap32( s.u );
>> +        s.u = vlc_bswap32( s.u );
>>          memcpy( out, s.b, 4 );
>>          out += 4;
>>      }
>> @@ -783,7 +783,7 @@ static void F64IEncode( void *outp, const uint8_t 
>> *inp, unsigned samples )
>>          union { double d; uint64_t u; char b[8]; } s;
>>  
>>          s.d = *(in++);
>> -        s.u = bswap64( s.u );
>> +        s.u = vlc_bswap64( s.u );
>>          memcpy( out, s.b, 8 );
>>          out += 8;
>>      }
>> diff --git a/modules/codec/jpeg.c b/modules/codec/jpeg.c
>> index 2c0224cc63..c071854725 100644
>> --- a/modules/codec/jpeg.c
>> +++ b/modules/codec/jpeg.c
>> @@ -216,13 +216,13 @@ de_get16( void * ptr, uint endian ) {
>>      if ( endian == G_BIG_ENDIAN )
>>      {
>>          #ifndef WORDS_BIGENDIAN
>> -        val = bswap16( val );
>> +        val = vlc_bswap16( val );
>>          #endif
>>      }
>>      else
>>      {
>>          #ifdef WORDS_BIGENDIAN
>> -        val = bswap16( val );
>> +        val = vlc_bswap16( val );
>>          #endif
>>      }
>>      return val;
>> @@ -236,13 +236,13 @@ de_get32( void * ptr, uint endian ) {
>>      if ( endian == G_BIG_ENDIAN )
>>      {
>>          #ifndef WORDS_BIGENDIAN
>> -        val = bswap32( val );
>> +        val = vlc_bswap32( val );
>>          #endif
>>      }
>>      else
>>      {
>>          #ifdef WORDS_BIGENDIAN
>> -        val = bswap32( val );
>> +        val = vlc_bswap32( val );
>>          #endif
>>      }
>>      return val;
>> diff --git a/modules/codec/lpcm.c b/modules/codec/lpcm.c
>> index b5ed190364..5a9b8c3d35 100644
>> --- a/modules/codec/lpcm.c
>> +++ b/modules/codec/lpcm.c
>> @@ -1204,7 +1204,7 @@ static void AobExtract( block_t *p_aout_buffer,
>>                                   | (p_block->p_buffer[2*i_src+1] << 16)
>>                                   | (p_block->p_buffer[4*g->i_channels
>> +i_src] <<  8);
>>  #ifdef WORDS_BIGENDIAN
>> -                        *p_out32 = bswap32(*p_out32);
>> +                        *p_out32 = vlc_bswap32(*p_out32);
>>  #endif
>>                          i_aout_written += 4;
>>                      }
>> @@ -1215,7 +1215,7 @@ static void AobExtract( block_t *p_aout_buffer,
>>                                   | (p_block->p_buffer[2*i_src+1] << 16)
>>                                   | (((p_block->p_buffer[4*g->i_channels
>> +i_src] << ((!n)?0:4) ) & 0xf0) <<  8);
>>  #ifdef WORDS_BIGENDIAN
>> -                        *p_out32 = bswap32(*p_out32);
>> +                        *p_out32 = vlc_bswap32(*p_out32);
>>  #endif
>>                          i_aout_written += 4;
>>                      }
>> @@ -1238,7 +1238,7 @@ static void AobExtract( block_t *p_aout_buffer,
>>                              *p_out32 = (p_block->p_buffer[2*i_src+0] << 
>> 24)
>>                                       | (p_block->p_buffer[2*i_src+1] << 
>> 16);
>>  #ifdef WORDS_BIGENDIAN
>> -                            *p_out32 = bswap32(*p_out32);
>> +                            *p_out32 = vlc_bswap32(*p_out32);
>>  #endif
>>                              i_aout_written += 4;
>>                          }
>> diff --git a/modules/demux/avformat/demux.c b/modules/demux/avformat/
>> demux.c
>> index 2538f79f15..ca69a50b04 100644
>> --- a/modules/demux/avformat/demux.c
>> +++ b/modules/demux/avformat/demux.c
>> @@ -100,7 +100,7 @@ static vlc_fourcc_t CodecTagToFourcc( uint32_t 
>> codec_tag )
>>  {
>>      // convert from little-endian avcodec codec_tag to VLC native-
>> endian fourcc
>>  #ifdef WORDS_BIGENDIAN
>> -    return bswap32(codec_tag);
>> +    return vlc_bswap32(codec_tag);
>>  #else
>>      return codec_tag;
>>  #endif
>> diff --git a/modules/demux/ogg.c b/modules/demux/ogg.c
>> index 284c0c39a3..b063a4de4e 100644
>> --- a/modules/demux/ogg.c
>> +++ b/modules/demux/ogg.c
>> @@ -2543,7 +2543,7 @@ static inline uint32_t GetDW24BE( const uint8_t 
>> *p )
>>  {
>>      uint32_t i = ( p[0] << 16 ) + ( p[1] << 8 ) + ( p[2] );
>>  #ifdef WORDS_BIGENDIAN
>> -    i = bswap32(i);
>> +    i = vlc_bswap32(i);
>>  #endif
>>      return i;
>>  }
>> -- 
>> 2.16.2
>>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 850 bytes
Desc: OpenPGP digital signature
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20180311/518d9e26/attachment.sig>


More information about the vlc-devel mailing list