MSVC error: 'pos_' is not a member of 'BrotliBitReader' #10

Closed
opened 2026-01-29 20:28:41 +00:00 by claunia · 6 comments
Owner

Originally created by @anthrotype on GitHub (Aug 10, 2015).

after today's commit 94cd7085f7, I'm getting this error when trying to compile the Python extension on Windows. I'm using Microsoft Visual C compiler from Visual Studio 2010.

./dec/bit_reader.h(165) : error C2039: 'pos_' : is not a member of 'BrotliBitReader'
        ./dec/bit_reader.h(39) : see declaration of 'BrotliBitReader'
error: command 'cl.exe' failed with exit status 2

Cheers,

Cosimo

Originally created by @anthrotype on GitHub (Aug 10, 2015). after today's commit 94cd7085f79a707f5ba3d93086796e695b495975, I'm getting this error when trying to compile the Python extension on Windows. I'm using Microsoft Visual C compiler from Visual Studio 2010. ``` ./dec/bit_reader.h(165) : error C2039: 'pos_' : is not a member of 'BrotliBitReader' ./dec/bit_reader.h(39) : see declaration of 'BrotliBitReader' error: command 'cl.exe' failed with exit status 2 ``` Cheers, Cosimo
Author
Owner

@lvandeve commented on GitHub (Aug 10, 2015):

Thanks for the report, should be fixed now :)

@lvandeve commented on GitHub (Aug 10, 2015): Thanks for the report, should be fixed now :)
Author
Owner

@anthrotype commented on GitHub (Aug 10, 2015):

thanks!
it compiles now!

It is a bit strange though, because even with the undefined pos_ member, the decoder was still compiling fine on OS X (clang) whereas it wasn't on Windows (msvc)...

I believe the reason is because in the port.h module, the BROTLI_LITTLE_ENDIAN preprocessor flag is not being set for MSVC, whereas it should be, as I'm compiling on a little endian processor -- like virtually all Windows machines -- and for a 32-bit Python.

I suspect the problem could be that MSVC does not define __BYTE_ORDER__, and therefore the following check from port.h does not work on Windows:

#if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
#define BROTLI_LITTLE_ENDIAN 1
#else
#define BROTLI_LITTLE_ENDIAN 0
#endif

For example, see: http://www.reactos.org/pipermail/ros-diffs/2014-January/051494.html

I think it would be OK to simply assume that Windows is always little endian.
WDYT?

@anthrotype commented on GitHub (Aug 10, 2015): thanks! it compiles now! It is a bit strange though, because even with the undefined `pos_` member, the decoder was still compiling fine on OS X (clang) whereas it wasn't on Windows (msvc)... I believe the reason is because in the `port.h` module, the `BROTLI_LITTLE_ENDIAN` preprocessor flag is not being set for MSVC, whereas it should be, as I'm compiling on a little endian processor -- like virtually all Windows machines -- and for a 32-bit Python. I suspect the problem could be that MSVC does not define `__BYTE_ORDER__`, and therefore the following check from `port.h` does not work on Windows: ``` c #if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) #define BROTLI_LITTLE_ENDIAN 1 #else #define BROTLI_LITTLE_ENDIAN 0 #endif ``` For example, see: http://www.reactos.org/pipermail/ros-diffs/2014-January/051494.html I think it would be OK to simply assume that Windows is always little endian. WDYT?
Author
Owner

@anthrotype commented on GitHub (Aug 10, 2015):

if I change port.h like that, then it compiles fine on MSVC as well (even without applying patch #130):

diff --git a/dec/port.h b/dec/port.h
index 27c6b6b..0bceca3 100644
--- a/dec/port.h
+++ b/dec/port.h
@@ -102,7 +102,8 @@ OR:
 #define BROTLI_PRELOAD_SYMBOLS 0
 #endif

-#if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
+#if defined(_MSC_VER) || \
+    (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
 #define BROTLI_LITTLE_ENDIAN 1
 #else
 #define BROTLI_LITTLE_ENDIAN 0

that's because, when BROTLI_LITTLE_ENDIAN is defined, the pre-processor will trim the #else branch inside dec/bit_reader.h where the undefined pos_ was used.

@anthrotype commented on GitHub (Aug 10, 2015): if I change `port.h` like that, then it compiles fine on MSVC as well (even without applying patch #130): ``` diff diff --git a/dec/port.h b/dec/port.h index 27c6b6b..0bceca3 100644 --- a/dec/port.h +++ b/dec/port.h @@ -102,7 +102,8 @@ OR: #define BROTLI_PRELOAD_SYMBOLS 0 #endif -#if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) +#if defined(_MSC_VER) || \ + (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) #define BROTLI_LITTLE_ENDIAN 1 #else #define BROTLI_LITTLE_ENDIAN 0 ``` that's because, when `BROTLI_LITTLE_ENDIAN` is defined, the pre-processor will trim the `#else` branch inside `dec/bit_reader.h` where the undefined `pos_` was used.
Author
Owner

@lvandeve commented on GitHub (Aug 10, 2015):

Yeah I was just noticing the same thing, I did it with "_WIN32" instead, visual studio does not appear to have any flags related to endianness but _WIN32 can be assumed to be LE.

@lvandeve commented on GitHub (Aug 10, 2015): Yeah I was just noticing the same thing, I did it with "_WIN32" instead, visual studio does not appear to have any flags related to endianness but _WIN32 can be assumed to be LE.
Author
Owner

@anthrotype commented on GitHub (Aug 10, 2015):

that's great! thank you 👍

@anthrotype commented on GitHub (Aug 10, 2015): that's great! thank you :+1:
Author
Owner

@anthrotype commented on GitHub (Aug 10, 2015):

PS: maybe it'd be a good to set up Appveyor to make sure we test compiling Brotli on Windows...

@anthrotype commented on GitHub (Aug 10, 2015): PS: maybe it'd be a good to set up Appveyor to make sure we test compiling Brotli on Windows...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/brotli#10