Bug 59057 - APR_VERSION_STRING_CSV from apr_version.h is malformed and fails compilation with some compilers
Summary: APR_VERSION_STRING_CSV from apr_version.h is malformed and fails compilation ...
Status: NEW
Alias: None
Product: APR
Classification: Unclassified
Component: APR (show other bugs)
Version: HEAD
Hardware: PC All
: P2 blocker (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-24 00:48 UTC by vitaly.krugl.web
Modified: 2016-02-24 02:49 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description vitaly.krugl.web 2016-02-24 00:48:47 UTC
APR_VERSION_STRING_CSV definition is malformed in apr HEAD and as far back as v1.5.1. I discovered this while attempting to build a win32 version using the mingwpy (gcc-based) toolchain. Some compilers (e.g., clang on macosx) don't fail until you actually reference the malformed definition, which is how I am guessing this malformed constant passed your builds. However, other compilers (e.g., in mingwpy toolchain) choke on it.

To reproduce, try compiling the following code sample, first as is to see how the HEAD version of the macro breaks; then comment out the first APR_VERSION_STRING_CSV definition and uncomment the second definition to see how the one from apr v1.5.1 breaks.

```c
#define APR_MAJOR_VERSION 2
#define APR_MINOR_VERSION 0
#define APR_PATCH_VERSION 0

# From apr 2.0.0
#define APR_VERSION_STRING_CSV APR_MAJOR_VERSION, \
                               APR_MINOR_VERSION, \
                               APR_PATCH_VERSION


# From apr 1.5.1; was also malformed
//#define APR_VERSION_STRING_CSV APR_MAJOR_VERSION ##, \
//                               ##APR_MINOR_VERSION ##, \
//                               ##APR_PATCH_VERSION


int main() {
    char* version = APR_VERSION_STRING_CSV;
    return 0;
}
```

The error that I got while building apr with the mingwpy toolchain was the following:

[ 97%] Building RC object CMakeFiles/libapr-1.dir/libapr.rc.obj
C:\mingwpy\bin\windres.exe  -O coff -DAPR_DECLARE_EXPORT -DWINNT -Dlibapr_1_EXPORTS -IC:\Users\Administrator\nta\nupic.c
ore\build\apr\build -IC:\Users\Administrator\nta\nupic.core\build\apr\include -IC:\Users\Administrator\nta\nupic.core\bu
ild\apr\include\arch\win32 -IC:\Users\Administrator\nta\nupic.core\build\apr\include\arch\unix -IC:\Users\Administrator\
nta\nupic.core\build\apr\include\private   C:\Users\Administrator\nta\nupic.core\build\apr\libapr.rc CMakeFiles\libapr-1
.dir\libapr.rc.obj
In file included from C:\Users\Administrator\nta\nupic.core\build\apr\libapr.rc:1:0:
C:\Users\Administrator\nta\nupic.core\build\apr\include/apr_version.h:117:32: error: pasting "APR_MAJOR_VERSION" and ","
 does not give a valid preprocessing token
 #define APR_VERSION_STRING_CSV APR_MAJOR_VERSION ##, \
                                ^
C:\Users\Administrator\nta\nupic.core\build\apr\libapr.rc:21:14: note: in expansion of macro 'APR_VERSION_STRING_CSV'
  FILEVERSION APR_VERSION_STRING_CSV,0
              ^
C:\Users\Administrator\nta\nupic.core\build\apr\include/apr_version.h:117:52: error: pasting "," and "APR_MINOR_VERSION"
 does not give a valid preprocessing token
 #define APR_VERSION_STRING_CSV APR_MAJOR_VERSION ##, \
                                                    ^
C:\Users\Administrator\nta\nupic.core\build\apr\libapr.rc:21:14: note: in expansion of macro 'APR_VERSION_STRING_CSV'
  FILEVERSION APR_VERSION_STRING_CSV,0
              ^
C:\Users\Administrator\nta\nupic.core\build\apr\include/apr_version.h:118:32: error: pasting "APR_MINOR_VERSION" and ","
 does not give a valid preprocessing token
                              ##APR_MINOR_VERSION ##, \
                                ^
C:\Users\Administrator\nta\nupic.core\build\apr\libapr.rc:21:14: note: in expansion of macro 'APR_VERSION_STRING_CSV'
  FILEVERSION APR_VERSION_STRING_CSV,0
              ^
C:\Users\Administrator\nta\nupic.core\build\apr\include/apr_version.h:118:52: error: pasting "," and "APR_PATCH_VERSION"
 does not give a valid preprocessing token
                              ##APR_MINOR_VERSION ##, \
                                                    ^
C:\Users\Administrator\nta\nupic.core\build\apr\libapr.rc:21:14: note: in expansion of macro 'APR_VERSION_STRING_CSV'
  FILEVERSION APR_VERSION_STRING_CSV,0
              ^
C:\Users\Administrator\nta\nupic.core\build\apr\include/apr_version.h:117:32: error: pasting "APR_MAJOR_VERSION" and ","
 does not give a valid preprocessing token
 #define APR_VERSION_STRING_CSV APR_MAJOR_VERSION ##, \
                                ^
C:\Users\Administrator\nta\nupic.core\build\apr\libapr.rc:22:17: note: in expansion of macro 'APR_VERSION_STRING_CSV'
  PRODUCTVERSION APR_VERSION_STRING_CSV,0
                 ^
C:\Users\Administrator\nta\nupic.core\build\apr\include/apr_version.h:117:52: error: pasting "," and "APR_MINOR_VERSION"
 does not give a valid preprocessing token
 #define APR_VERSION_STRING_CSV APR_MAJOR_VERSION ##, \
                                                    ^
C:\Users\Administrator\nta\nupic.core\build\apr\libapr.rc:22:17: note: in expansion of macro 'APR_VERSION_STRING_CSV'
  PRODUCTVERSION APR_VERSION_STRING_CSV,0
                 ^
C:\Users\Administrator\nta\nupic.core\build\apr\include/apr_version.h:118:32: error: pasting "APR_MINOR_VERSION" and ","
 does not give a valid preprocessing token
                              ##APR_MINOR_VERSION ##, \
                                ^
C:\Users\Administrator\nta\nupic.core\build\apr\libapr.rc:22:17: note: in expansion of macro 'APR_VERSION_STRING_CSV'
  PRODUCTVERSION APR_VERSION_STRING_CSV,0
                 ^
C:\Users\Administrator\nta\nupic.core\build\apr\include/apr_version.h:118:52: error: pasting "," and "APR_PATCH_VERSION"
 does not give a valid preprocessing token
                              ##APR_MINOR_VERSION ##, \
                                                    ^
C:\Users\Administrator\nta\nupic.core\build\apr\libapr.rc:22:17: note: in expansion of macro 'APR_VERSION_STRING_CSV'
  PRODUCTVERSION APR_VERSION_STRING_CSV,0
                 ^
C:\mingwpy\bin\windres.exe: preprocessing failed.
Comment 1 vitaly.krugl.web 2016-02-24 00:51:37 UTC
The head version of the file containing malformed APR_VERSION_STRING_CSV definition is http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_version.h?view=markup


The 1.5.1 version of the file containing the malformed definition of APR_VERSION_STRING_CSV is http://svn.apache.org/viewvc/apr/apr/tags/1.5.1/include/apr_version.h?view=markup
Comment 2 vitaly.krugl.web 2016-02-24 00:55:21 UTC
It should have been defined similarly to APR_VERSION_STRING (using APR_STRINGIFY and quotes around punctuation), but with commas instead of periods.
Comment 3 vitaly.krugl.web 2016-02-24 02:49:35 UTC
Ignore my earlier comment about "It should have been defined similarly to APR_VERSION_STRING (using APR_STRINGIFY and quotes around punctuation), but with commas instead of periods."

I see what's going on here, and it's a catch-22 situation given how the *OLDER* apr_version.h and libapr.rc were implemented:


First, apr_version.h in apr v1.5.1 contains a definition considered malformed by the gcc toolchain (mingwpy in particular):

#define APR_VERSION_STRING_CSV APR_MAJOR_VERSION ##, \
                               ##APR_MINOR_VERSION ##, \
                               ##APR_PATCH_VERSION

So, the gcc compiler chokes on it. this was intended to produce the equivalent of

#define APR_VERSION_STRING_CSV 1,5,1

which libapr.rc relies on here:

FILEVERSION APR_VERSION_STRING_CSV,0
PRODUCTVERSION APR_VERSION_STRING_CSV,0




The ones in HEAD should be okay, though, since APR_VERSION_STRING_CSV has been redefined as the following, which passes the mingwpy build:

#define APR_VERSION_STRING_CSV APR_MAJOR_VERSION, \
                               APR_MINOR_VERSION, \
                               APR_PATCH_VERSION