Skip to content

Commit abce678

Browse files
committed
Remove inlines in bitreader and bitwriter
Upstream pull request: xiph#905: Extern inlines are not clearly defined by the C standard and are often interpreted differently depending in the compiler. These ones already involve workarounds for MSVC. Clang under certain optimization options (LTO etc.) also doesn't intepret this correctly and doesn't emit standalone symbols for those at all, leading to linking errors. Signed-off-by: Alexander Lobakin <alobakin@mailbox.org>
1 parent 267528f commit abce678

2 files changed

Lines changed: 10 additions & 79 deletions

File tree

src/libFLAC/bitreader.c

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@
5858
#define SWAP_BE_WORD_TO_HOST(x) ENDSWAP_32(x)
5959
#endif
6060

61-
#ifdef __WATCOMC__ /* see end of the file for inline issue ! */
62-
#define FLAC__bitreader_is_consumed_byte_aligned FLAC__bitreader_is_consumed_byte_aligned__inl_
63-
#define FLAC__bitreader_bits_left_for_byte_alignment FLAC__bitreader_bits_left_for_byte_alignment__inl_
64-
#define FLAC__bitreader_get_input_bits_unconsumed FLAC__bitreader_get_input_bits_unconsumed__inl_
65-
#define FLAC__bitreader_read_uint32_little_endian FLAC__bitreader_read_uint32_little_endian__inl_
66-
#endif
67-
6861
/*
6962
* This should be at least twice as large as the largest number of words
7063
* required to represent any 'number' (in any encoding) you are going to
@@ -333,17 +326,17 @@ FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
333326
return br->read_crc16;
334327
}
335328

336-
inline FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
329+
FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
337330
{
338331
return ((br->consumed_bits & 7) == 0);
339332
}
340333

341-
inline unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
334+
unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
342335
{
343336
return 8 - (br->consumed_bits & 7);
344337
}
345338

346-
inline unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
339+
unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
347340
{
348341
return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
349342
}
@@ -461,7 +454,7 @@ FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *va
461454
return true;
462455
}
463456

464-
inline FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
457+
FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
465458
{
466459
FLAC__uint32 x8, x32 = 0;
467460

@@ -1057,27 +1050,3 @@ FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *v
10571050
*val = v;
10581051
return true;
10591052
}
1060-
1061-
/* These functions a declared inline in this file but are also callable as
1062-
* externs from elsewhere.
1063-
* According to the C99 sepc, section 6.7.4, simply providing a function
1064-
* prototype in a header file without 'inline' and making the function inline
1065-
* in this file should be sufficient.
1066-
* Unfortunately, the Microsoft VS compiler doesn't pick them up externally. To
1067-
* fix that we add extern declarations here.
1068-
*/
1069-
#ifdef __WATCOMC__ /* the above trick doesn't work for Watcom */
1070-
#undef FLAC__bitreader_is_consumed_byte_aligned
1071-
#undef FLAC__bitreader_bits_left_for_byte_alignment
1072-
#undef FLAC__bitreader_get_input_bits_unconsumed
1073-
#undef FLAC__bitreader_read_uint32_little_endian
1074-
FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br) { return FLAC__bitreader_is_consumed_byte_aligned__inl_(br); }
1075-
unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br) { return FLAC__bitreader_bits_left_for_byte_alignment__inl_(br); }
1076-
unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br) { return FLAC__bitreader_get_input_bits_unconsumed__inl_(br); }
1077-
FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val) { return FLAC__bitreader_read_uint32_little_endian__inl_(br, val); }
1078-
#else
1079-
extern FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
1080-
extern unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
1081-
extern unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
1082-
extern FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val);
1083-
#endif

src/libFLAC/bitwriter.c

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,6 @@
5959
#define SWAP_BE_WORD_TO_HOST(x) ENDSWAP_32(x)
6060
#endif
6161

62-
#ifdef __WATCOMC__ /* see end of file for inline issue */
63-
#define FLAC__bitwriter_write_zeroes FLAC__bitwriter_write_zeroes__inl_
64-
#define FLAC__bitwriter_write_raw_uint32 FLAC__bitwriter_write_raw_uint32__inl_
65-
#define FLAC__bitwriter_write_raw_int32 FLAC__bitwriter_write_raw_int32__inl_
66-
#define FLAC__bitwriter_write_raw_uint64 FLAC__bitwriter_write_raw_uint64__inl_
67-
#define FLAC__bitwriter_write_raw_uint32_little_endian FLAC__bitwriter_write_raw_uint32_little_endian__inl_
68-
#define FLAC__bitwriter_write_byte_block FLAC__bitwriter_write_byte_block__inl_
69-
#endif
70-
7162
/*
7263
* The default capacity here doesn't matter too much. The buffer always grows
7364
* to hold whatever is written to it. Usually the encoder will stop adding at
@@ -277,7 +268,7 @@ void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
277268
(void)bw;
278269
}
279270

280-
inline FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
271+
FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
281272
{
282273
unsigned n;
283274

@@ -315,7 +306,7 @@ inline FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bit
315306
return true;
316307
}
317308

318-
inline FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
309+
FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
319310
{
320311
register unsigned left;
321312

@@ -354,7 +345,7 @@ inline FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__ui
354345
return true;
355346
}
356347

357-
inline FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
348+
FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
358349
{
359350
/* zero-out unused bits */
360351
if(bits < 32)
@@ -363,7 +354,7 @@ inline FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int
363354
return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
364355
}
365356

366-
inline FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
357+
FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
367358
{
368359
/* this could be a little faster but it's not used for much */
369360
if(bits > 32) {
@@ -375,7 +366,7 @@ inline FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__ui
375366
return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
376367
}
377368

378-
inline FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
369+
FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
379370
{
380371
/* this doesn't need to be that fast as currently it is only used for vorbis comments */
381372

@@ -391,7 +382,7 @@ inline FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter
391382
return true;
392383
}
393384

394-
inline FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
385+
FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
395386
{
396387
unsigned i;
397388

@@ -843,33 +834,4 @@ FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
843834
return true;
844835
}
845836

846-
/* These functions a declared inline in this file but are also callable as
847-
* externs from elsewhere.
848-
* According to the C99 sepc, section 6.7.4, simply providing a function
849-
* prototype in a header file without 'inline' and making the function inline
850-
* in this file should be sufficient.
851-
* Unfortunately, the Microsoft VS compiler doesn't pick them up externally. To
852-
* fix that we add extern declarations here.
853-
*/
854-
#ifdef __WATCOMC__ /* adding externs doesn't help with Watcom */
855-
#undef FLAC__bitwriter_write_zeroes
856-
#undef FLAC__bitwriter_write_raw_uint32
857-
#undef FLAC__bitwriter_write_raw_int32
858-
#undef FLAC__bitwriter_write_raw_uint64
859-
#undef FLAC__bitwriter_write_raw_uint32_little_endian
860-
#undef FLAC__bitwriter_write_byte_block
861-
FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits) { return FLAC__bitwriter_write_zeroes__inl_(bw, bits); }
862-
FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits) { return FLAC__bitwriter_write_raw_uint32__inl_(bw, val, bits); }
863-
FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits) { return FLAC__bitwriter_write_raw_int32__inl_(bw, val, bits); }
864-
FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits) { return FLAC__bitwriter_write_raw_uint64__inl_(bw, val, bits); }
865-
FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val) { return FLAC__bitwriter_write_raw_uint32_little_endian__inl_(bw, val); }
866-
FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals) { return FLAC__bitwriter_write_byte_block__inl_(bw, vals, nvals); }
867-
#else
868-
extern FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
869-
extern FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
870-
extern FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
871-
extern FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val);
872-
extern FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
873-
#endif
874-
875837
#endif /* FLAC_INCLUDE_ENCODER */

0 commit comments

Comments
 (0)